Exemple #1
0
    public SecretVersion DestroySecretVersion(
        string projectId = "my-project", string secretId = "my-secret", string secretVersionId = "123")
    {
        // Create the client.
        SecretManagerServiceClient client = SecretManagerServiceClient.Create();

        // Build the resource name.
        SecretVersionName secretVersionName = new SecretVersionName(projectId, secretId, secretVersionId);

        // Call the API.
        SecretVersion version = client.DestroySecretVersion(secretVersionName);

        return(version);
    }
        // [END secretmanager_delete_secret]

        // [START secretmanager_destroy_secret_version]
        /// <summary>
        /// Destroy an existing secret version.
        /// </summary>
        /// <param name="projectId">ID of the project where the secret resides.</param>
        /// <param name="secretId">ID of the secret.</param>
        /// <param name="secretVersion">Version of the secret.</param>
        /// <example>
        /// Destroy a secret version.
        /// <code>DestroySecretVersion("my-project", "my-secret", "5")</code>
        /// </example>
        public static void DestroySecretVersion(string projectId, string secretId, string secretVersion)
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Create the request.
            var request = new DestroySecretVersionRequest
            {
                SecretVersionName = new SecretVersionName(projectId, secretId, secretVersion),
            };

            // Destroy the secret version.
            var version = client.DestroySecretVersion(request);

            Console.WriteLine($"Destroyed secret version {version.Name}");
        }