Skip to content

Commit 4e2e66c

Browse files
updated license headers, cleanup
1 parent c45a3b9 commit 4e2e66c

15 files changed

Lines changed: 196 additions & 317 deletions

alteon-orchestrator.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "alteon-orchestrator", "alte
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{583BA6E4-B528-45FE-B027-3ECE30FB7500}"
99
ProjectSection(SolutionItems) = preProject
10+
docsource\alteonlb.md = docsource\alteonlb.md
1011
CHANGELOG.md = CHANGELOG.md
12+
docsource\content.md = docsource\content.md
1113
integration-manifest.json = integration-manifest.json
1214
readme_source.md = readme_source.md
1315
EndProjectSection

alteon-orchestrator/AlteonLoadBalancerClient.cs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -26,35 +26,48 @@ namespace Keyfactor.Extensions.Orchestrator.AlteonLoadBalancer
2626
public class AlteonLoadBalancerClient
2727
{
2828
private RestClient _restClient { get; set; }
29-
ILogger logger = LogHandler.GetClassLogger<AlteonLoadBalancerClient>();
29+
protected ILogger logger { get; set; }
3030

31-
public AlteonLoadBalancerClient(string baseUrl, string username, string password)
31+
public AlteonLoadBalancerClient(string baseUrl, string username, string password, ILogger logger)
3232
{
33+
this.logger = logger;
34+
3335
var options = new RestClientOptions(baseUrl)
3436
{
35-
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true,
37+
RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true, // this is to allow self-signed appliance certs
3638
Authenticator = new HttpBasicAuthenticator(username, password)
3739
};
3840
_restClient = new RestClient(options);
3941
}
4042

4143
public async Task<CertificateTableEntryCollection> GetCertificates()
4244
{
45+
logger.MethodEntry();
46+
4347
var request = new RestRequest(Endpoints.CertificateRepository);
48+
49+
logger.LogTrace($"making request to retrieve certificates from endpoint: {request.Resource}");
4450
try
4551
{
4652
var response = await _restClient.GetAsync<CertificateTableEntryCollection>(request);
4753
return response;
4854
}
4955
catch (Exception ex)
5056
{
57+
logger.LogError($"An error occurred when attempting to retrieve the certificates from {_restClient.BuildUri(request)?.ToString()}");
5158
logger.LogError(ex.Message, ex);
5259
throw;
5360
}
61+
finally
62+
{
63+
logger.MethodExit();
64+
}
5465
}
5566

5667
public async Task<CertificateTableEntryCollection> GetCertificatesById(string id)
5768
{
69+
logger.MethodEntry();
70+
5871
var url = $"{Endpoints.CertificateRepository}?filter=ID:{id}&filtertype=exact&props=ID,Type";
5972
var request = new RestRequest(url);
6073

@@ -72,6 +85,7 @@ public async Task<CertificateTableEntryCollection> GetCertificatesById(string id
7285
logger.LogError(ex.Message, ex);
7386
throw;
7487
}
88+
finally { logger.MethodExit(); }
7589
}
7690

7791
public string GetCertificateContent(string certId)
@@ -82,7 +96,7 @@ public string GetCertificateContent(string certId)
8296
request.AddQueryParameter("type", "srvcrt");
8397
var fullUri = _restClient.BuildUri(request);
8498

85-
logger.LogTrace($"making request to get certificate to uri: {fullUri}");
99+
logger.LogTrace($"making request to get certificate from the endpoint: {fullUri}");
86100

87101
try
88102
{
@@ -93,9 +107,11 @@ public string GetCertificateContent(string certId)
93107
}
94108
catch (Exception ex)
95109
{
110+
logger.LogError($"An error occurred when attempting to retrieve the certificate with id '{certId}' from {fullUri}");
96111
logger.LogError(ex.Message, ex);
97112
throw;
98113
}
114+
finally { logger.MethodExit(); }
99115
}
100116

101117
public async Task AddCertificate(string alias, string pfxPassword, string certContents, string type, bool overwrite)
@@ -149,6 +165,7 @@ public async Task AddCertificate(string alias, string pfxPassword, string certCo
149165
internal async Task RemoveCertificate(string alias)
150166
{
151167
logger.MethodEntry();
168+
var url = string.Empty;
152169

153170
var existing = (await GetCertificatesById(alias)).SlbNewSslCfgCertsTable;
154171
if (existing.Count == 0)
@@ -157,28 +174,32 @@ internal async Task RemoveCertificate(string alias)
157174
}
158175
try
159176
{
160-
existing.ForEach(c =>
177+
foreach (var c in existing)
161178
{
162-
var url = $"{Endpoints.CertificateRepository}/{c.ID}/{c.Type}";
179+
url = $"{Endpoints.CertificateRepository}/{c.ID}/{c.Type}";
163180
var request = new RestRequest(url, Method.Delete);
164181
var fullUri = _restClient.BuildUri(request);
165182
logger.LogTrace($"making request to remove certificate to uri {fullUri}");
166-
var response = _restClient.DeleteAsync(request).Result;
183+
var response = await _restClient.DeleteAsync(request);
167184

168185
if (!response.IsSuccessful)
169186
{
170187
throw new Exception($"Failed to remove certificate: {alias}", response.ErrorException);
171188
}
172-
});
189+
}
173190
// apply and save changes
174191
await ApplyAndSave();
175192
}
176193
catch (Exception ex)
177194
{
195+
logger.LogError($"An error occurred when attempting to remove the certificate with alias {alias} via endpoint: '{url}'");
178196
logger.LogError(ex.Message, ex);
179197
throw;
180198
}
181-
logger.MethodExit();
199+
finally
200+
{
201+
logger.MethodExit();
202+
}
182203
}
183204

184205
/// <summary>
@@ -187,7 +208,7 @@ internal async Task RemoveCertificate(string alias)
187208
/// <returns></returns>
188209
internal async Task ApplyAndSave()
189210
{
190-
logger.MethodEntry();
211+
logger.MethodEntry();
191212
logger.LogTrace($"making requests to apply and save changes");
192213
try
193214
{

alteon-orchestrator/CertificateTableEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

alteon-orchestrator/Constants/AlteonCertTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

alteon-orchestrator/Constants/Endpoints.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

alteon-orchestrator/Jobs/Inventory.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -25,27 +25,25 @@ namespace Keyfactor.Extensions.Orchestrator.AlteonLoadBalancer.Jobs
2525
{
2626
public class Inventory : JobBase, IInventoryJobExtension
2727
{
28-
ILogger logger = LogHandler.GetClassLogger<Inventory>();
29-
3028
public Inventory(IPAMSecretResolver resolver)
3129
{
3230
_resolver = resolver;
31+
logger = LogHandler.GetClassLogger<Inventory>();
3332
}
3433

3534
public JobResult ProcessJob(InventoryJobConfiguration config, SubmitInventoryUpdate submitInventoryUpdate)
3635
{
37-
InitializeStore(config, logger);
36+
InitializeStore(config);
3837

3938
List<CurrentInventoryItem> certs = new List<CurrentInventoryItem>();
4039
try
4140
{
42-
var tableCerts = aClient.GetCertificates().Result;
41+
var tableCerts = aClient.GetCertificates().GetAwaiter().GetResult();
4342
//"Generate" indicates whether a cert actually exists, or just the entry. 5 means it exists.
4443
var certsOnly = tableCerts.SlbNewSslCfgCertsTable.Where(c => c.Type == 3 && c.Generate == 5).ToList();
4544
var keysOnly = tableCerts.SlbNewSslCfgCertsTable.Where(c => c.Type == 1);
4645

4746
certsOnly.ForEach(certEntry => {
48-
var certStrings = new List<string>();
4947
var certContent = aClient.GetCertificateContent(certEntry.ID);
5048

5149
certs.Add(new CurrentInventoryItem()

alteon-orchestrator/Jobs/JobBase.cs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,9 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
using Keyfactor.Logging;
1516
using Keyfactor.Orchestrators.Extensions;
1617
using Keyfactor.Orchestrators.Extensions.Interfaces;
1718
using Microsoft.Extensions.Logging;
19+
using System.Reflection;
1820

1921
namespace Keyfactor.Extensions.Orchestrator.AlteonLoadBalancer.Jobs
2022
{
@@ -32,23 +34,42 @@ public abstract class JobBase
3234

3335
public IPAMSecretResolver _resolver;
3436

37+
internal protected ILogger logger { get; set; }
38+
3539
internal protected AlteonLoadBalancerClient aClient { get; set; }
3640

3741

38-
public void InitializeStore(InventoryJobConfiguration config, ILogger logger)
39-
{
42+
public void InitializeStore(InventoryJobConfiguration config)
43+
{
44+
logger.MethodEntry();
45+
LogPluginVersion();
4046
ServerUrl = config.CertificateStoreDetails.ClientMachine;
41-
Username = PAMUtilities.ResolvePAMField(_resolver, logger, "Server User Name", config.ServerUsername);
47+
Username = PAMUtilities.ResolvePAMField(_resolver, logger, "Server Username", config.ServerUsername);
4248
Password = PAMUtilities.ResolvePAMField(_resolver, logger, "Server Password", config.ServerPassword);
43-
aClient = new AlteonLoadBalancerClient(ServerUrl, Username, Password);
49+
aClient = new AlteonLoadBalancerClient(ServerUrl, Username, Password, logger);
50+
logger.LogTrace($"Configuration complete for inventory job. Server Url = {ServerUrl}");
51+
logger.MethodExit();
52+
4453
}
4554

46-
public void InitializeStore(ManagementJobConfiguration config, ILogger logger) {
55+
public void InitializeStore(ManagementJobConfiguration config) {
56+
logger.MethodEntry();
57+
LogPluginVersion();
4758
ServerUrl = config.CertificateStoreDetails.ClientMachine;
48-
Username = config.ServerUsername;
49-
Password = config.ServerPassword;
59+
Username = PAMUtilities.ResolvePAMField(_resolver, logger, "Server Username", config.ServerUsername);
60+
Password = PAMUtilities.ResolvePAMField(_resolver, logger, "Server Password", config.ServerPassword);
5061
Overwrite = config.Overwrite;
51-
aClient = new AlteonLoadBalancerClient(ServerUrl, Username, Password);
62+
aClient = new AlteonLoadBalancerClient(ServerUrl, Username, Password, logger);
63+
logger.LogTrace($"Configuration complete for management job. Server Url = {ServerUrl}, Overwrite = {Overwrite}, Certificate Alias = {config.JobCertificate.Alias}");
64+
logger.MethodExit();
65+
}
66+
protected void LogPluginVersion()
67+
{
68+
var targetAssembly = Assembly.GetExecutingAssembly();
69+
var assemblyName = targetAssembly?.GetName();
70+
var version = assemblyName?.Version;
71+
logger.LogTrace("Keyfactor Orchestrator Extension for Alteon Load Balancer");
72+
logger.LogTrace($"{assemblyName?.Name ?? "unknown"} v{version}");
5273
}
5374
}
5475
}

alteon-orchestrator/Jobs/Management.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2022 Keyfactor
1+
// Copyright 2026 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -30,16 +30,15 @@ namespace Keyfactor.Extensions.Orchestrator.AlteonLoadBalancer.Jobs
3030
{
3131
public class Management : JobBase, IManagementJobExtension
3232
{
33-
readonly ILogger logger = LogHandler.GetClassLogger<Management>();
34-
3533
public Management(IPAMSecretResolver resolver)
3634
{
3735
_resolver = resolver;
36+
logger = LogHandler.GetClassLogger<Management>();
3837
}
3938

4039
public JobResult ProcessJob(ManagementJobConfiguration config)
4140
{
42-
InitializeStore(config, logger);
41+
InitializeStore(config);
4342

4443
JobResult complete = new JobResult()
4544
{
@@ -83,7 +82,9 @@ protected virtual async Task<JobResult> PerformAddition(string alias, string pfx
8382
}
8483
catch (Exception ex)
8584
{
86-
logger.LogError("error decoding certificate", ex);
85+
logger.LogError("an error occurred when attempting to decode the certificate");
86+
logger.LogError($"certificate contents: \n{entryContents}");
87+
logger.LogError($"error: {ex.Message}");
8788
throw;
8889
}
8990

@@ -133,7 +134,7 @@ protected virtual async Task<JobResult> PerformAddition(string alias, string pfx
133134
}
134135
catch (Exception ex)
135136
{
136-
complete.FailureMessage = $"An error occured while adding {alias} to {ExtensionName}: " + ex.Message;
137+
complete.FailureMessage = $"An error occurred while adding {alias} to {ExtensionName}: " + ex.Message;
137138

138139
if (ex.InnerException != null)
139140
complete.FailureMessage += " - " + ex.InnerException.Message;
@@ -167,8 +168,8 @@ protected virtual async Task<JobResult> PerformRemoval(string alias, long jobHis
167168

168169
catch (Exception ex)
169170
{
170-
logger.LogError("Error deleting cert from device.", ex);
171-
complete.FailureMessage = $"An error occured while removing {alias} from {ExtensionName}: " + ex.Message;
171+
logger.LogError($"An error occurred when attempting to remove the certificate with alias {alias}: {ex.Message}");
172+
complete.FailureMessage = $"An error occurred while removing {alias} from {ExtensionName}: " + ex.Message;
172173
}
173174
return complete;
174175
}
@@ -229,7 +230,7 @@ private List<X509Certificate2> ReorderPEMLIst(List<X509Certificate2> certList)
229230
for (int i = 1; i < certList.Count; i++)
230231
{
231232
X509Certificate2 childCert = certList.FirstOrDefault(p => p.IssuerName.RawData.SequenceEqual(parentCert.SubjectName.RawData) && !p.IssuerName.RawData.SequenceEqual(p.SubjectName.RawData));
232-
if (root == null || string.IsNullOrEmpty(root.SerialNumber))
233+
if (childCert == null || string.IsNullOrEmpty(childCert.SerialNumber))
233234
throw new Exception("Invalid certificate chain. End entity or issuing CA certificate not found.");
234235

235236
rtnList.Insert(0, childCert);

alteon-orchestrator/PAMUtilities.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1-
// Copyright 2021 Keyfactor
2-
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
3-
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
4-
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
5-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
6-
// and limitations under the License.
1+
// Copyright 2026 Keyfactor
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
714

815
using Keyfactor.Orchestrators.Extensions.Interfaces;
916
using Microsoft.Extensions.Logging;

alteon-orchestrator/alteon-orchestrator.csproj

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="BouncyCastle" Version="1.8.9" />
18-
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.1" />
19-
<PackageReference Include="Keyfactor.Logging" Version="1.1.2" />
20-
<PackageReference Include="Keyfactor.Orchestrators.Common" Version="3.2.0" />
21-
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="0.7.0" />
18+
<PackageReference Include="BouncyCastle.Cryptography" Version="2.6.2" />
19+
<PackageReference Include="Keyfactor.Logging" Version="1.3.0" />
20+
<PackageReference Include="Keyfactor.Orchestrators.Common" Version="3.4.0" />
21+
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorJobExtensions" Version="1.0.0" />
2222
<PackageReference Include="Keyfactor.Orchestrators.IOrchestratorRegistrationUpdater" Version="1.0.3" />
23-
<PackageReference Include="Keyfactor.PKI" Version="5.5.0" />
24-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
25-
<PackageReference Include="NLog" Version="5.3.4" />
26-
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.15" />
27-
<PackageReference Include="RestSharp" Version="112.1.0" />
28-
<PackageReference Include="System.Formats.Asn1" Version="6.0.1" />
23+
<PackageReference Include="Keyfactor.PKI" Version="8.3.1" />
24+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.5" />
25+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
26+
<PackageReference Include="RestSharp" Version="114.0.0" />
27+
<PackageReference Include="System.Formats.Asn1" Version="10.0.5" />
2928
<PackageReference Include="System.Linq" Version="4.3.0" />
30-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
29+
<PackageReference Include="System.Text.Json" Version="10.0.5" />
3130
</ItemGroup>
3231

3332
<ItemGroup>

0 commit comments

Comments
 (0)