Skip to content

Commit de018b4

Browse files
change rename alias functionality
1 parent dc85ae6 commit de018b4

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

a10vthunder-orchestrator/ImplementedStoreTypes/Ssl/Management.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected internal virtual void Replace(ManagementJobConfiguration config, Inven
201201
_logger.LogInformation($"Certificate {originalAlias} is currently assigned to one or more templates. Preparing to rename and re-import.");
202202

203203
string timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
204-
string newAlias = $"{originalAlias}_{timestamp}";
204+
string newAlias = GenerateNewAlias(originalAlias);
205205

206206
_logger.LogTrace($"Generated new alias: {newAlias}");
207207
config.JobCertificate.Alias = newAlias;
@@ -269,6 +269,37 @@ protected internal virtual void Replace(ManagementJobConfiguration config, Inven
269269
}
270270
}
271271

272+
private string GenerateNewAlias(string originalAlias)
273+
{
274+
string timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString();
275+
string newAlias;
276+
277+
// Match a Unix timestamp suffix pattern (e.g., _1234567890 at the end of the string)
278+
var match = System.Text.RegularExpressions.Regex.Match(originalAlias, @"_(\d{10})$");
279+
280+
if (match.Success)
281+
{
282+
// Replace the matched timestamp with the current one
283+
newAlias = originalAlias.Substring(0, match.Index) + "_" + timestamp;
284+
}
285+
else
286+
{
287+
newAlias = $"{originalAlias}_{timestamp}";
288+
}
289+
290+
// Ensure the alias is no more than 240 characters
291+
if (newAlias.Length > 240)
292+
{
293+
// Truncate the beginning to fit the length
294+
int maxBaseLength = 240 - (timestamp.Length + 1); // +1 for underscore
295+
string truncatedBase = originalAlias.Length > maxBaseLength
296+
? originalAlias.Substring(0, maxBaseLength)
297+
: originalAlias;
298+
newAlias = $"{truncatedBase}_{timestamp}";
299+
}
300+
301+
return newAlias;
302+
}
272303

273304

274305
protected internal virtual void Remove(ManagementJobConfiguration configInfo, InventoryResult inventoryResult,

0 commit comments

Comments
 (0)