public void ListSecretVersions(string projectId = "my-project", string secretId = "my-secret")
    {
        // Create the client.
        SecretManagerServiceClient client = SecretManagerServiceClient.Create();

        // Build the resource name.
        SecretName secretName = new SecretName(projectId, secretId);

        // Call the API.
        foreach (SecretVersion secretVersion in client.ListSecretVersions(secretName))
        {
            // ...
        }
    }
Ejemplo n.º 2
0
        // [END secretmanager_get_secret]

        // [START secretmanager_list_secret_versions]
        /// <summary>
        /// List all secret versions for a secret.
        /// </summary>
        /// <param name="projectId">ID of the project where the secret resides.</param>
        /// <param name="secretId">ID of the secret.</param>
        /// <example>
        /// List all secret versions.
        /// <code>ListSecretVersions("my-project", "my-secret")</code>
        /// </example>
        public static void ListSecretVersions(string projectId, string secretId)
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Create the request.
            var request = new ListSecretVersionsRequest
            {
                ParentAsSecretName = new SecretName(projectId, secretId),
            };

            // List all versions and their state.
            foreach (var version in client.ListSecretVersions(request))
            {
                Console.WriteLine($"Secret version {version.Name}, {version.State}");
            }
        }