Exemple #1
0
    private SecretVersion AddSecretVersion(Secret secret)
    {
        SecretManagerServiceClient client = SecretManagerServiceClient.Create();

        SecretPayload payload = new SecretPayload
        {
            Data = ByteString.CopyFrom("my super secret data", Encoding.UTF8),
        };

        return(client.AddSecretVersion(secret.SecretName, payload));
    }
Exemple #2
0
        private SecretVersion AddSecretVersion(Secret secret)
        {
            var payload = "my super secret data";

            var request = new AddSecretVersionRequest
            {
                ParentAsSecretName = secret.SecretName,
                Payload            = new SecretPayload
                {
                    Data = ByteString.CopyFrom(payload, Encoding.UTF8),
                },
            };

            return(_client.AddSecretVersion(request));
        }
        public void StoreSecret([FromForm] string projectId, [FromForm] string secretId)
        {
            IDatabase db = Connection.GetDatabase();

            db.StringSet("name", "redis");
            Console.WriteLine(db.StringGet("name"));
            //call SDK
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the parent project name.
            ProjectName projectName = new ProjectName(projectId);

            // Build the secret to create.
            Secret secret = new Secret
            {
                Replication = new Replication
                {
                    Automatic = new Replication.Types.Automatic(),
                },
            };

            Secret createdSecret = client.CreateSecret(projectName, secretId, secret);

            // Build a payload.
            SecretPayload payload = new SecretPayload
            {
                Data = ByteString.CopyFrom("my super secret data", Encoding.UTF8),
            };

            // Add a secret version.
            SecretVersion createdVersion = client.AddSecretVersion(createdSecret.SecretName, payload);

            // Access the secret version.
            AccessSecretVersionResponse result = client.AccessSecretVersion(createdVersion.SecretVersionName);

            // Print the resultszxcvbnj
            //
            // WARNING: Do not print secrets in production environments. This
            // snippet is for demonstration purposes only.
            string data = result.Payload.Data.ToStringUtf8();

            Console.WriteLine($"Plaintext: {data}");
        }
Exemple #4
0
    public SecretVersion AddSecretVersion(
        string projectId = "my-project", string secretId = "my-secret",
        string data      = "my secret data")
    {
        // Create the client.
        SecretManagerServiceClient client = SecretManagerServiceClient.Create();

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

        // Convert the payload to bytes.
        SecretPayload payload = new SecretPayload
        {
            Data = ByteString.CopyFrom(data, Encoding.UTF8),
        };

        // Call the API.
        SecretVersion version = client.AddSecretVersion(secretName, payload);

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

        // [START secretmanager_add_secret_version]
        /// <summary>
        /// Add a secret version to the given secret. The given secret must
        /// already exist.
        /// </summary>
        /// <param name="projectId">ID of the project where the secret resides.</param>
        /// <param name="secretId">ID of the secret.</param>
        /// <example>
        /// Add a secret version.
        /// <code>AddSecretVersion("my-project", "my-secret")</code>
        /// </example>
        public static void AddSecretVersion(string projectId, string secretId)
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Create the secret payload.
            var payload = "my super secret data";

            // Create the request.
            var request = new AddSecretVersionRequest
            {
                ParentAsSecretName = new SecretName(projectId, secretId),
                Payload            = new SecretPayload
                {
                    Data = ByteString.CopyFrom(payload, Encoding.UTF8),
                },
            };

            // Add the secret version.
            var version = client.AddSecretVersion(request);

            Console.WriteLine($"Added secret version {version.Name}");
        }
    public void Quickstart(string projectId = "my-project", string secretId = "my-secret")
    {
        // Create the client.
        SecretManagerServiceClient client = SecretManagerServiceClient.Create();

        // Build the parent project name.
        ProjectName projectName = new ProjectName(projectId);

        // Build the secret to create.
        Secret secret = new Secret
        {
            Replication = new Replication
            {
                Automatic = new Replication.Types.Automatic(),
            },
        };

        Secret createdSecret = client.CreateSecret(projectName, secretId, secret);

        // Build a payload.
        SecretPayload payload = new SecretPayload
        {
            Data = ByteString.CopyFrom("my super secret data", Encoding.UTF8),
        };

        // Add a secret version.
        SecretVersion createdVersion = client.AddSecretVersion(createdSecret.SecretName, payload);

        // Access the secret version.
        AccessSecretVersionResponse result = client.AccessSecretVersion(createdVersion.SecretVersionName);

        // Print the results
        //
        // WARNING: Do not print secrets in production environments. This
        // snippet is for demonstration purposes only.
        string data = result.Payload.Data.ToStringUtf8();

        Console.WriteLine($"Plaintext: {data}");
    }
Exemple #7
0
        public static void Main(string[] args)
        {
            // GCP project in which to store secrets in Secret Manager.
            string projectId = "YOUR-PROJECT-ID";

            // ID of the secret to create.
            string secretId = "YOUR-SECRET-ID";

            // [END secretmanager_quickstart]
            if (args.Length > 1)
            {
                projectId = args[0];
                secretId  = args[1];
            }
            // [START secretmanager_quickstart]
            // Create a Secret Manager client.
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Create the parent secret.
            var createSecretRequest = new CreateSecretRequest
            {
                ParentAsProjectName = new ProjectName(projectId),
                SecretId            = secretId,
                Secret = new Secret
                {
                    Replication = new Replication
                    {
                        Automatic = new Replication.Types.Automatic(),
                    },
                },
            };

            var secret = client.CreateSecret(createSecretRequest);

            // Add a secret version.
            var addSecretVersionRequest = new AddSecretVersionRequest
            {
                ParentAsSecretName = secret.SecretName,
                Payload            = new SecretPayload
                {
                    Data = ByteString.CopyFrom("my super secret data", Encoding.UTF8),
                },
            };

            var version = client.AddSecretVersion(addSecretVersionRequest);

            // Access the secret version.
            var accessSecretVersionRequest = new AccessSecretVersionRequest
            {
                SecretVersionName = version.SecretVersionName,
            };

            var result = client.AccessSecretVersion(accessSecretVersionRequest);

            // Print the results
            //
            // WARNING: Do not print secrets in production environments. This
            // snippet is for demonstration purposes only.
            string payload = result.Payload.Data.ToStringUtf8();

            Console.WriteLine($"Plaintext: {payload}");
        }