Skip to content

Commit

Permalink
Merge 794f33b into 6cddd9e
Browse files Browse the repository at this point in the history
  • Loading branch information
dgaley authored Aug 12, 2024
2 parents 6cddd9e + 794f33b commit 7d62d76
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ This is the number of seconds between retries when attempting to download a cert
This is the username that will be used to connect to the GlobalSign API
* ```Password```
This is the password that will be used to connect to the GlobalSign API
* ```SyncStartDate```
OPTIONAL: If provided, full syncs will start at the specified date.
* ```SyncIntervalDays```
OPTIONAL: Required if SyncStartDate is used. Specifies how to page the certificate sync. Should be a value such that no interval of that length contains > 500 certificate enrollments.

```json
"CAConnection": {
Expand Down
4 changes: 4 additions & 0 deletions readme_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ This is the number of seconds between retries when attempting to download a cert
This is the username that will be used to connect to the GlobalSign API
* ```Password```
This is the password that will be used to connect to the GlobalSign API
* ```SyncStartDate```
OPTIONAL: If provided, full syncs will start at the specified date.
* ```SyncIntervalDays```
OPTIONAL: Required if SyncStartDate is used. Specifies how to page the certificate sync. Should be a value such that no interval of that length contains > 500 certificate enrollments.

```json
"CAConnection": {
Expand Down
29 changes: 27 additions & 2 deletions src/GlobalSignCAProxy/Client/GlobalSignApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,39 @@ public GlobalSignApiClient(GlobalSignCAConfig config)
OrderService = new ManagedSSLService() { Url = config.GetUrl(GlobalSignServiceType.ORDER) };
}

public List<OrderDetail> GetCertificatesForSync(bool fullSync, DateTime? lastSync)
public List<OrderDetail> GetCertificatesForSync(bool fullSync, DateTime? lastSync, DateTime startDate, int intervalDays)
{
Logger.MethodEntry(ILogExtensions.MethodLogLevel.Debug);
using (this.QueryService)
{
if (fullSync)
{
return GetCertificatesByDateRange(DateTime.MinValue, DateTime.UtcNow);
if (startDate > new DateTime(2000, 01, 01))
{
DateTime finalStop = DateTime.UtcNow;
List<OrderDetail > certs = new List<OrderDetail>();
DateTime endDate = startDate.AddDays(intervalDays);
if (endDate > finalStop)
{
endDate = finalStop;
}
certs.AddRange(GetCertificatesByDateRange(startDate, endDate));
while (endDate < finalStop)
{
startDate = endDate.AddSeconds(1);
endDate = startDate.AddDays(intervalDays);
if (endDate > finalStop)
{
endDate = finalStop;
}
certs.AddRange(GetCertificatesByDateRange(startDate, endDate));
}
return certs;
}
else
{
return GetCertificatesByDateRange(startDate, DateTime.UtcNow);
}
}
else //Incremental Sync
{
Expand Down
4 changes: 4 additions & 0 deletions src/GlobalSignCAProxy/GlobalSignCAConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Newtonsoft.Json.Converters;
using query = Keyfactor.Extensions.AnyGateway.GlobalSign.Services.Query;
using order = Keyfactor.Extensions.AnyGateway.GlobalSign.Services.Order;
using System.Diagnostics.Contracts;

namespace Keyfactor.Extensions.AnyGateway.GlobalSign
{
Expand All @@ -22,6 +23,9 @@ public class GlobalSignCAConfig
public string Username { get; set; }
public string Password { get; set; }

public string SyncStartDate { get; set; }
public int SyncIntervalDays { get; set; }

public string GetUrl(GlobalSignServiceType queryType)
{
switch (queryType)
Expand Down
20 changes: 18 additions & 2 deletions src/GlobalSignCAProxy/GlobalSignCAProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading;
using System.Web.Services.Configuration;
Expand Down Expand Up @@ -233,8 +234,14 @@ public override void Synchronize(ICertificateDataReader certificateDataReader, B
{
GlobalSignApiClient apiClient = new GlobalSignApiClient(Config);

DateTime? syncFrom = certificateAuthoritySyncInfo.DoFullSync ? new DateTime(2000, 01, 01) : certificateAuthoritySyncInfo.OverallLastSync;
var certs = apiClient.GetCertificatesForSync(certificateAuthoritySyncInfo.DoFullSync, syncFrom);
DateTime fullSyncFrom = new DateTime(2000, 01, 01);
if (!string.IsNullOrEmpty(Config.SyncStartDate))
{
fullSyncFrom = DateTime.Parse(Config.SyncStartDate);
}

DateTime? syncFrom = certificateAuthoritySyncInfo.DoFullSync ? fullSyncFrom : certificateAuthoritySyncInfo.OverallLastSync;
var certs = apiClient.GetCertificatesForSync(certificateAuthoritySyncInfo.DoFullSync, syncFrom, fullSyncFrom, Config.SyncIntervalDays);

foreach (var c in certs)
{
Expand Down Expand Up @@ -332,6 +339,15 @@ public override void ValidateCAConnectionInfo(Dictionary<string, object> connect

var apiClient = new GlobalSignApiClient(validateConfig);
apiClient.GetDomains().ForEach(x => Logger.Info($"Connection established for {x.DomainName}"));

if (!string.IsNullOrEmpty(validateConfig.SyncStartDate))
{
_ = DateTime.Parse(validateConfig.SyncStartDate);
if (validateConfig.SyncIntervalDays <= 0)
{
throw new Exception("SyncIntervalDays must be a value greater than 0 when using SyncStartDate");
}
}
Logger.MethodExit(ILogExtensions.MethodLogLevel.Debug);
}

Expand Down

0 comments on commit 7d62d76

Please sign in to comment.