Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Handle the case where the secret is not serialized as json #3223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/ApiService/ApiService/onefuzzlib/Secrets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task<SecretData<T>> StoreSecretData<T>(SecretData<T> secretData) {
return new SecretData<T>(new SecretAddress<T>(address));
}

public Task<T?> GetSecretValue<T>(ISecret<T> data);
public Task<T?> GetSecretValue<T>(ISecret<T> data) where T : class;

Task<Uri> StoreSecret(ISecret secret);

Expand Down Expand Up @@ -52,14 +52,20 @@ public async Task<Uri> StoreSecret(ISecret secret) {
};
}

public async Task<T?> GetSecretValue<T>(ISecret<T> data) {
public async Task<T?> GetSecretValue<T>(ISecret<T> data) where T : class {
switch ((data)) {
case SecretAddress<T> secretAddress:
var secretValue = (await GetSecret(secretAddress.Url))?.Value;
if (secretValue is null)
return default;

if (typeof(T) == typeof(string)) {
return secretValue as T;
}

return JsonSerializer.Deserialize<T>(secretValue, EntityConverter.GetJsonSerializerOptions());


case SecretValue<T> sValue:
return sValue.Value;

Expand Down
2 changes: 1 addition & 1 deletion src/ApiService/Tests/OrmTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class TestSecretOperations : ISecretsOperations {

private readonly ConcurrentDictionary<Guid, string> _secrets = new();

public Task<T?> GetSecretValue<T>(ISecret<T> data) {
public Task<T?> GetSecretValue<T>(ISecret<T> data) where T : class {
switch (data) {
case SecretAddress<T> secretAddress:
var key = Guid.Parse(secretAddress.Url.Authority);
Expand Down