@@ -411,6 +411,13 @@ public Dictionary<string, PropertyConfigInfo> GetCAConnectorAnnotations()
411411 DefaultValue = "" ,
412412 Type = "String"
413413 } ,
414+ [ CertCentralConstants . Config . SYNC_DIV_FILTER ] = new PropertyConfigInfo ( )
415+ {
416+ 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." ,
417+ Hidden = false ,
418+ DefaultValue = "" ,
419+ Type = "String"
420+ } ,
414421 [ CertCentralConstants . Config . FILTER_EXPIRED ] = new PropertyConfigInfo ( )
415422 {
416423 Comments = "If set to 'true', syncing will apply a filter to not return orders that are expired for longer than specified in SyncExpirationDays." ,
@@ -700,10 +707,16 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
700707
701708 caList . ForEach ( c => c . ToUpper ( ) ) ;
702709
710+ List < string > divFilters = new List < string > ( ) { "" } ;
711+ if ( ! string . IsNullOrEmpty ( _config . SyncDivisionFilter ) )
712+ {
713+ divFilters = new List < string > ( ) ;
714+ divFilters . AddRange ( _config . SyncDivisionFilter . Split ( ',' ) ) ;
715+ }
703716
704717 if ( fullSync )
705718 {
706- bool ignoreExpired = false ; int expiredWindow = 0 ;
719+ bool ignoreExpired = false ; int expiredWindow = 0 ;
707720 if ( _config . FilterExpiredOrders . HasValue && _config . FilterExpiredOrders . Value )
708721 {
709722 ignoreExpired = true ;
@@ -712,50 +725,56 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
712725 expiredWindow = _config . SyncExpirationDays . Value ;
713726 }
714727 }
728+
715729 long time = DateTime . Now . Ticks ;
716730 long starttime = time ;
717731 _logger . LogDebug ( $ "SYNC: Starting sync at time { time } ") ;
718- ListCertificateOrdersResponse ordersResponse = client . ListAllCertificateOrders ( ignoreExpired , expiredWindow ) ;
719- if ( ordersResponse . Status == CertCentralBaseResponse . StatusType . ERROR )
732+ List < Order > allOrders = new List < Order > ( ) ;
733+ foreach ( string div in divFilters )
720734 {
721- Error error = ordersResponse . Errors [ 0 ] ;
722- _logger . LogError ( "Error in listing all certificate orders" ) ;
723- throw new Exception ( $ "DigiCert CertCentral web service returned { error . code } - { error . message } when retrieving all rows") ;
735+ ListCertificateOrdersResponse ordersResponse = client . ListAllCertificateOrders ( ignoreExpired , expiredWindow , div ) ;
736+ if ( ordersResponse . Status == CertCentralBaseResponse . StatusType . ERROR )
737+ {
738+ Error error = ordersResponse . Errors [ 0 ] ;
739+ _logger . LogError ( "Error in listing all certificate orders" ) ;
740+ throw new Exception ( $ "DigiCert CertCentral web service returned { error . code } - { error . message } when retrieving all rows") ;
741+ }
742+ else
743+ {
744+ allOrders . AddRange ( ordersResponse . orders ) ;
745+ }
724746 }
725- else
747+ _logger . LogDebug ( $ "SYNC: Found { allOrders . Count } records") ;
748+ foreach ( var orderDetails in allOrders )
726749 {
727- _logger . LogDebug ( $ "SYNC: Found { ordersResponse . orders . Count } records" ) ;
728- foreach ( var orderDetails in ordersResponse . orders )
750+ List < AnyCAPluginCertificate > orderCerts = new List < AnyCAPluginCertificate > ( ) ;
751+ try
729752 {
730- List < AnyCAPluginCertificate > orderCerts = new List < AnyCAPluginCertificate > ( ) ;
731- try
753+ cancelToken . ThrowIfCancellationRequested ( ) ;
754+ string caReqId = orderDetails . id + "-" + orderDetails . certificate . id ;
755+ _logger . LogDebug ( $ "SYNC: Retrieving certs for order id { orderDetails . id } ") ;
756+ orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList , divFilters ) ;
757+ if ( orderCerts == null || orderCerts . Count == 0 )
732758 {
733- cancelToken . ThrowIfCancellationRequested ( ) ;
734- string caReqId = orderDetails . id + "-" + orderDetails . certificate . id ;
735- _logger . LogDebug ( $ "SYNC: Retrieving certs for order id { orderDetails . id } ") ;
736- orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList ) ;
737- if ( orderCerts == null || orderCerts . Count == 0 )
738- {
739- continue ;
740- }
741- _logger . LogDebug ( $ "SYNC: Retrieved { orderCerts . Count } certs at time { DateTime . Now . Ticks } ") ;
742- }
743- catch
744- {
745- skippedOrders . Add ( orderDetails . id . ToString ( ) ) ;
746- _logger . LogWarning ( $ "An error occurred attempting to sync order '{ orderDetails . id } '. This order will be skipped.") ;
747759 continue ;
748760 }
761+ _logger . LogDebug ( $ "SYNC: Retrieved { orderCerts . Count } certs at time { DateTime . Now . Ticks } ") ;
762+ }
763+ catch
764+ {
765+ skippedOrders . Add ( orderDetails . id . ToString ( ) ) ;
766+ _logger . LogWarning ( $ "An error occurred attempting to sync order '{ orderDetails . id } '. This order will be skipped.") ;
767+ continue ;
768+ }
749769
750- foreach ( var cert in orderCerts )
751- {
752- certCount ++ ;
753- blockingBuffer . Add ( cert ) ;
754- }
755-
770+ foreach ( var cert in orderCerts )
771+ {
772+ certCount ++ ;
773+ blockingBuffer . Add ( cert ) ;
756774 }
757- _logger . LogDebug ( $ "SYNC: Complete after { DateTime . Now . Ticks - starttime } ticks" ) ;
775+
758776 }
777+ _logger . LogDebug ( $ "SYNC: Complete after { DateTime . Now . Ticks - starttime } ticks") ;
759778 }
760779 else
761780 {
@@ -776,7 +795,7 @@ public async Task Synchronize(BlockingCollection<AnyCAPluginCertificate> blockin
776795 {
777796 cancelToken . ThrowIfCancellationRequested ( ) ;
778797 string caReqId = order . order_id + "-" + order . certificate_id ;
779- orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList ) ;
798+ orderCerts = GetAllConnectorCertsForOrder ( caReqId , caList , divFilters ) ;
780799 if ( orderCerts == null || orderCerts . Count > 0 )
781800 {
782801 continue ;
@@ -1330,7 +1349,7 @@ string FormatSyncDate(DateTime? syncTime)
13301349 /// </summary>
13311350 /// <param name="caRequestID"></param>
13321351 /// <returns></returns>
1333- private List < AnyCAPluginCertificate > GetAllConnectorCertsForOrder ( string caRequestID , List < string > caFilterIds )
1352+ private List < AnyCAPluginCertificate > GetAllConnectorCertsForOrder ( string caRequestID , List < string > caFilterIds , List < string > divIds )
13341353 {
13351354 _logger . MethodEntry ( LogLevel . Trace ) ;
13361355 // Split ca request id into order and cert id
@@ -1348,6 +1367,11 @@ private List<AnyCAPluginCertificate> GetAllConnectorCertsForOrder(string caReque
13481367 _logger . LogTrace ( $ "Found order ID { orderId } that does not match SyncCAFilter. CA ID: { orderResponse . certificate . ca_cert . Id } Skipping...") ;
13491368 return null ;
13501369 }
1370+ if ( divIds != null && divIds . Count > 0 && ! divIds . Contains ( orderResponse . container . Id . ToString ( ) ) )
1371+ {
1372+ _logger . LogTrace ( $ "Found order ID { orderId } that does not match Division filter. Division ID: { orderResponse . container . Id . ToString ( ) } Skipping...") ;
1373+ return null ;
1374+ }
13511375
13521376 var orderCerts = GetAllCertsForOrder ( orderId ) ;
13531377
0 commit comments