public async Task LoadAsync() { var secrets = _client.ListSecrets(_projectName); foreach (var secret in secrets) { try { if (!_loader.Load(secret)) { continue; } var secretVersionName = new SecretVersionName(secret.SecretName.ProjectId, secret.SecretName.SecretId, "latest"); var secretVersion = await _client.AccessSecretVersionAsync(secretVersionName); Set(_loader.GetKey(secret), secretVersion.Payload.Data.ToStringUtf8()); } catch (Grpc.Core.RpcException) { // This might happen if secret is created but it has no versions available // For now just ignore. Maybe in future we should log that something went wrong? } } }
public void ListSecrets(string projectId = "my-project") { // Create the client. SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Build the resource name. ProjectName projectName = new ProjectName(projectId); // Call the API. foreach (Secret secret in client.ListSecrets(projectName)) { // ... } }
// [END secretmanager_list_secret_versions] // [START secretmanager_list_secrets] /// <summary> /// List all secret for a project /// </summary> /// <param name="projectId">ID of the project where secrets reside.</param> /// <example> /// List all secrets. /// <code>ListSecrets("my-project")</code> /// </example> public static void ListSecrets(string projectId) { SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Create the request. var request = new ListSecretsRequest { ParentAsProjectName = new ProjectName(projectId), }; // List all secrets in the project. foreach (var secret in client.ListSecrets(request)) { Console.WriteLine($"Secret {secret.Name}"); } }
public static int Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Error: please specify a project ID"); return(1); } string projectId = args[0]; // Create client SecretManagerServiceClient client = SecretManagerServiceClient.Create(); var secrets = client.ListSecrets(new ProjectName(projectId)); foreach (var secret in secrets) { Console.WriteLine(secret.Name); } Console.WriteLine("Smoke test passed OK"); return(0); }
public override void Load() { var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var request = new ListSecretsRequest { ParentAsProjectName = ProjectName.FromProject(projectName), }; var secrets = secretManagerServiceClient.ListSecrets(request); foreach (var secret in secrets) { var value = secretManagerServiceClient.AccessSecretVersion($"{secret.Name}/versions/latest"); string secretVal = this.manager.Load(value.Payload); string configKey = this.manager.GetKey(secret.SecretName); data.Add(configKey, secretVal); } Data = data; }
/// <inheritdoc/> public override void Load() { if (_projectId == null) { return; } IEnumerable <SecretName>?secretNames = _client? .ListSecrets(new ProjectName(_projectId))? .Select(i => i.SecretName); if (secretNames?.Any() == false) { return; } Console.WriteLine($"Retrieved {secretNames!.Count()} secrets from Secret Manager."); foreach (SecretName secretName in secretNames !) { try { SecretVersionName secretVersionName = new( secretName.ProjectId, secretName.SecretId, "latest"); AccessSecretVersionResponse?secretVersion = _client ! .AccessSecretVersion(secretVersionName); Set( NormalizeDelimiter(secretName.SecretId), secretVersion.Payload.Data.ToStringUtf8()); } catch (Grpc.Core.RpcException) { // Ignore. This might happen if the secret has no versions available. } } }