@@ -418,6 +418,13 @@ public Dictionary<string, PropertyConfigInfo> GetCAConnectorAnnotations()
418418 DefaultValue = "" ,
419419 Type = "String"
420420 } ,
421+ [ CertCentralConstants . Config . SYNC_DIV_FILTER ] = new PropertyConfigInfo ( )
422+ {
423+ Comments = "If you list one or more Divison IDs (also known as Container IDs) here (comma-separated), the sync process will filter records to only return orders from those divisions. If you want to sync all divisions, leave this field empty. Note that this has no relationship to the value of the DivisionId config field." ,
424+ Hidden = false ,
425+ DefaultValue = "" ,
426+ Type = "String"
427+ } ,
421428 [ CertCentralConstants . Config . FILTER_EXPIRED ] = new PropertyConfigInfo ( )
422429 {
423430 Comments = "If set to 'true', syncing will apply a filter to not return orders that are expired for longer than specified in SyncExpirationDays." ,
@@ -707,10 +714,16 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
707714
708715 caList . ForEach ( c => c . ToUpper ( ) ) ;
709716
717+ List < string > divFilters = new List < string > ( ) { "" } ;
718+ if ( ! string . IsNullOrEmpty ( _config . SyncDivisionFilter ) )
719+ {
720+ divFilters = new List < string > ( ) ;
721+ divFilters . AddRange ( _config . SyncDivisionFilter . Split ( ',' ) ) ;
722+ }
710723
711724 if ( fullSync )
712725 {
713- bool ignoreExpired = false ; int expiredWindow = 0 ;
726+ bool ignoreExpired = false ; int expiredWindow = 0 ;
714727 if ( _config . FilterExpiredOrders . HasValue && _config . FilterExpiredOrders . Value )
715728 {
716729 ignoreExpired = true ;
@@ -719,50 +732,56 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
719732 expiredWindow = _config . SyncExpirationDays . Value ;
720733 }
721734 }
735+
722736 long time = DateTime . Now . Ticks ;
723737 long starttime = time ;
724738 _logger . LogDebug ( $ "SYNC: Starting sync at time { time } ") ;
725- ListCertificateOrdersResponse ordersResponse = client . ListAllCertificateOrders ( ignoreExpired , expiredWindow ) ;
726- if ( ordersResponse . Status == CertCentralBaseResponse . StatusType . ERROR )
739+ List < Order > allOrders = new List < Order > ( ) ;
740+ foreach ( string div in divFilters )
727741 {
728- Error error = ordersResponse . Errors [ 0 ] ;
729- _logger . LogError ( "Error in listing all certificate orders" ) ;
730- throw new Exception ( $ "DigiCert CertCentral web service returned { error . code } - { error . message } when retrieving all rows") ;
742+ ListCertificateOrdersResponse ordersResponse = client . ListAllCertificateOrders ( ignoreExpired , expiredWindow , div ) ;
743+ if ( ordersResponse . Status == CertCentralBaseResponse . StatusType . ERROR )
744+ {
745+ Error error = ordersResponse . Errors [ 0 ] ;
746+ _logger . LogError ( "Error in listing all certificate orders" ) ;
747+ throw new Exception ( $ "DigiCert CertCentral web service returned { error . code } - { error . message } when retrieving all rows") ;
748+ }
749+ else
750+ {
751+ allOrders . AddRange ( ordersResponse . orders ) ;
752+ }
731753 }
732- else
754+ _logger . LogDebug ( $ "SYNC: Found { allOrders . Count } records") ;
755+ foreach ( var orderDetails in allOrders )
733756 {
734- _logger . LogDebug ( $ "SYNC: Found { ordersResponse . orders . Count } records" ) ;
735- foreach ( var orderDetails in ordersResponse . orders )
757+ List < AnyCAPluginCertificate > orderCerts = new List < AnyCAPluginCertificate > ( ) ;
758+ try
736759 {
737- List < AnyCAPluginCertificate > orderCerts = new List < AnyCAPluginCertificate > ( ) ;
738- try
760+ cancelToken . ThrowIfCancellationRequested ( ) ;
761+ string caReqId = orderDetails . id + "-" + orderDetails . certificate . id ;
762+ _logger . LogDebug ( $ "SYNC: Retrieving certs for order id { orderDetails . id } ") ;
763+ orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList , divFilters ) ;
764+ if ( orderCerts == null || orderCerts . Count == 0 )
739765 {
740- cancelToken . ThrowIfCancellationRequested ( ) ;
741- string caReqId = orderDetails . id + "-" + orderDetails . certificate . id ;
742- _logger . LogDebug ( $ "SYNC: Retrieving certs for order id { orderDetails . id } ") ;
743- orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList ) ;
744- if ( orderCerts == null || orderCerts . Count == 0 )
745- {
746- continue ;
747- }
748- _logger . LogDebug ( $ "SYNC: Retrieved { orderCerts . Count } certs at time { DateTime . Now . Ticks } ") ;
749- }
750- catch
751- {
752- skippedOrders . Add ( orderDetails . id . ToString ( ) ) ;
753- _logger . LogWarning ( $ "An error occurred attempting to sync order '{ orderDetails . id } '. This order will be skipped.") ;
754766 continue ;
755767 }
768+ _logger . LogDebug ( $ "SYNC: Retrieved { orderCerts . Count } certs at time { DateTime . Now . Ticks } ") ;
769+ }
770+ catch
771+ {
772+ skippedOrders . Add ( orderDetails . id . ToString ( ) ) ;
773+ _logger . LogWarning ( $ "An error occurred attempting to sync order '{ orderDetails . id } '. This order will be skipped.") ;
774+ continue ;
775+ }
756776
757- foreach ( var cert in orderCerts )
758- {
759- certCount ++ ;
760- blockingBuffer . Add ( cert ) ;
761- }
762-
777+ foreach ( var cert in orderCerts )
778+ {
779+ certCount ++ ;
780+ blockingBuffer . Add ( cert ) ;
763781 }
764- _logger . LogDebug ( $ "SYNC: Complete after { DateTime . Now . Ticks - starttime } ticks" ) ;
782+
765783 }
784+ _logger . LogDebug ( $ "SYNC: Complete after { DateTime . Now . Ticks - starttime } ticks") ;
766785 }
767786 else
768787 {
@@ -783,7 +802,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
783802 {
784803 cancelToken . ThrowIfCancellationRequested ( ) ;
785804 string caReqId = order . order_id + "-" + order . certificate_id ;
786- orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList ) ;
805+ orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList , divFilters ) ;
787806 if ( orderCerts == null || orderCerts . Count > 0 )
788807 {
789808 continue ;
@@ -1337,7 +1356,7 @@ string FormatSyncDate(DateTime? syncTime)
13371356 /// </summary>
13381357 /// <param name="caRequestID"></param>
13391358 /// <returns></returns>
1340- private List < AnyCAPluginCertificate > GetAllConnectorCertsForOrder ( string caRequestID , List < string > caFilterIds )
1359+ private List < AnyCAPluginCertificate > GetAllConnectorCertsForOrder ( string caRequestID , List < string > caFilterIds , List < string > divIds )
13411360 {
13421361 _logger . MethodEntry ( LogLevel . Trace ) ;
13431362 // Split ca request id into order and cert id
@@ -1355,6 +1374,11 @@ private List<AnyCAPluginCertificate> GetAllConnectorCertsForOrder(string caReque
13551374 _logger . LogTrace ( $ "Found order ID { orderId } that does not match SyncCAFilter. CA ID: { orderResponse . certificate . ca_cert . Id } Skipping...") ;
13561375 return null ;
13571376 }
1377+ if ( divIds != null && divIds . Count > 0 && ! divIds . Contains ( orderResponse . container . Id . ToString ( ) ) )
1378+ {
1379+ _logger . LogTrace ( $ "Found order ID { orderId } that does not match Division filter. Division ID: { orderResponse . container . Id . ToString ( ) } Skipping...") ;
1380+ return null ;
1381+ }
13581382
13591383 var orderCerts = GetAllCertsForOrder ( orderId ) ;
13601384
0 commit comments