public void TestDestroySecretVersion()
        {
            var name   = secretsFixture.SecretVersionToDestroy.SecretVersionName;
            var output = Run("destroy-version", name.ProjectId, name.SecretId, name.SecretVersionId);

            Assert.Contains($"Destroyed secret version {name}", output.Stdout);

            var version = s_client.GetSecretVersion(new GetSecretVersionRequest
            {
                SecretVersionName = name
            });

            Assert.Equal(SecretVersion.Types.State.Destroyed, version.State);
        }
Beispiel #2
0
    public SecretVersion GetSecretVersion(
        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.GetSecretVersion(secretVersionName);

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

        // [START secretmanager_get_secret_version]
        /// <summary>
        /// Get 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>
        /// Get an existing secret version.
        /// <code>GetSecretVersion("my-project", "my-secret", "5")</code>
        /// </example>
        /// <example>
        /// With an alias version.
        /// <code>GetSecretVersion("my-project", "my-secret", "latest")</code>
        /// </example>
        public static void GetSecretVersion(string projectId, string secretId, string secretVersion)
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

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

            // Get the secret version.
            var version = client.GetSecretVersion(request);

            Console.WriteLine($"Secret version {version.Name}, state {version.State}");
        }