public async Task <string> CreateSecretAsync(string path, string secretValue, CancellationToken cancellationToken = default) { try { var slug = Normalize($"{_context.BasePathPrefix}:{path}"); var response = await _secretsClient.CreateSecretAsync(slug, new SecretUpsert( data : new Dictionary <string, object>() { { "password", secretValue }, })); return(response?.Path); } catch (ApiException ex) { throw ConvertException(ex); } }
public async Task TestCreateValue() { var secretPath = Guid.NewGuid().ToString(); var value = Guid.NewGuid().ToString(); var tokenReturn = Task.FromResult(new AccessTokenResponse("access-token", 3600, tokenType: "bearer")); _tokensApi.TokenAsync("client_credentials", clientId: _devOpsContext.ClientId, clientSecret: _devOpsContext.ClientSecret) .Returns(tokenReturn); var secretReturn = Task.FromResult(new SecretResponse(path: $"{_devOpsContext.BasePathPrefix}:{secretPath}")); _secretsApi.CreateSecretAsync($"{_devOpsContext.BasePathPrefix}:{secretPath}", Arg.Is <SecretUpsert>(x => x.Data["password"].Equals(value))) .Returns(secretReturn); var result = await _secureStore.CreateValueAsync(_ctxString, secretPath, value); Assert.AreEqual($"{_devOpsContext.BasePathPrefix}:{secretPath}", result); }