-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add secret management functionalities
Introduced services and interfaces for secret name generation, validation, and updating. Updated secret handling to include expiration metadata. Refactored methods in ISecretManager to streamline secret creation and update processes.
- Loading branch information
1 parent
161f4f6
commit f5bcaa3
Showing
26 changed files
with
228 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...ules/Elsa.JavaScript/Activities/RunJavaScript/RunJavaScriptFunctionsDefinitionProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Elsa.JavaScript.TypeDefinitions.Abstractions; | ||
using Elsa.JavaScript.TypeDefinitions.Models; | ||
using Elsa.Workflows.Helpers; | ||
using JetBrains.Annotations; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace Elsa.JavaScript.Activities; | ||
|
||
/// Produces <see cref="FunctionDefinition"/>s for common functions. | ||
[UsedImplicitly] | ||
internal class RunJavaScriptFunctionsDefinitionProvider() : FunctionDefinitionProvider | ||
{ | ||
protected override IEnumerable<FunctionDefinition> GetFunctionDefinitions(TypeDefinitionContext context) | ||
{ | ||
if (context.ActivityTypeName != ActivityTypeNameHelper.GenerateTypeName<RunJavaScript>()) | ||
yield break; | ||
|
||
if(context.PropertyName != nameof(RunJavaScript.Script)) | ||
yield break; | ||
|
||
yield return CreateFunctionDefinition(builder => builder | ||
.Name("setOutcome") | ||
.Parameter("name", "string") | ||
.ReturnType("void")); | ||
|
||
yield return CreateFunctionDefinition(builder => builder | ||
.Name("setOutcomes") | ||
.Parameter("names", "string[]") | ||
.ReturnType("void")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/modules/Elsa.Secrets.Management/Contracts/ISecretNameGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Elsa.Secrets.Management; | ||
|
||
public interface ISecretNameGenerator | ||
{ | ||
Task<string> GenerateUniqueNameAsync(CancellationToken cancellationToken = default); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/modules/Elsa.Secrets.Management/Contracts/ISecretNameValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Elsa.Secrets.Management; | ||
|
||
public interface ISecretNameValidator | ||
{ | ||
Task<bool> IsNameUniqueAsync(string name, string? notId, CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/modules/Elsa.Secrets.Management/Contracts/ISecretUpdater.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace Elsa.Secrets.Management; | ||
|
||
public interface ISecretUpdater | ||
{ | ||
Task<Secret> UpdateAsync(Secret secret, SecretInputModel input, CancellationToken cancellationToken = default); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 10 additions & 15 deletions
25
src/modules/Elsa.Secrets.Management/Services/DefaultSecretEncryptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,42 @@ | ||
using Elsa.Common.Contracts; | ||
using Elsa.Workflows.Contracts; | ||
|
||
namespace Elsa.Secrets.Management; | ||
|
||
public class DefaultSecretEncryptor(IEncryptor encryptor, IDecryptor decryptor, IIdentityGenerator identityGenerator) : ISecretEncryptor | ||
public class DefaultSecretEncryptor(IEncryptor encryptor, IDecryptor decryptor, IIdentityGenerator identityGenerator, ISystemClock systemClock) : ISecretEncryptor | ||
{ | ||
public async Task<Secret> EncryptAsync(SecretInputModel input, CancellationToken cancellationToken = default) | ||
{ | ||
var encryptedValue = string.IsNullOrWhiteSpace(input.Value) ? "" : await encryptor.EncryptAsync(input.Value, cancellationToken); | ||
|
||
var secret = new Secret | ||
{ | ||
Id = identityGenerator.GenerateId(), | ||
SecretId = identityGenerator.GenerateId(), | ||
Version = 1, | ||
IsLatest = true, | ||
Name = input.Name.Trim(), | ||
Scope = input.Scope?.Trim(), | ||
Description = input.Description.Trim(), | ||
EncryptedValue = encryptedValue, | ||
ExpiresAt = input.ExpiresAt, | ||
Status = SecretStatus.Active | ||
IsLatest = true | ||
}; | ||
|
||
|
||
await EncryptAsync(secret, input, cancellationToken); | ||
return secret; | ||
} | ||
|
||
public async Task EncryptAsync(Secret secret, SecretInputModel input, CancellationToken cancellationToken = default) | ||
{ | ||
var encryptedValue = string.IsNullOrWhiteSpace(input.Value) ? "" : await encryptor.EncryptAsync(input.Value, cancellationToken); | ||
|
||
secret.Name = input.Name.Trim(); | ||
secret.Scope = input.Scope?.Trim(); | ||
secret.Description = input.Description.Trim(); | ||
secret.EncryptedValue = encryptedValue; | ||
secret.ExpiresAt = input.ExpiresAt; | ||
secret.ExpiresIn = input.ExpiresIn; | ||
secret.ExpiresAt = input.ExpiresIn != null ? systemClock.UtcNow + input.ExpiresIn.Value : null; | ||
secret.Status = SecretStatus.Active; | ||
} | ||
|
||
public async Task<string> DecryptAsync(Secret secret, CancellationToken cancellationToken = default) | ||
{ | ||
if(string.IsNullOrWhiteSpace(secret.EncryptedValue)) | ||
if (string.IsNullOrWhiteSpace(secret.EncryptedValue)) | ||
return ""; | ||
|
||
return await decryptor.DecryptAsync(secret.EncryptedValue, cancellationToken); | ||
} | ||
} |
Oops, something went wrong.