public Secret CreateSecret(string secretId) { SecretManagerServiceClient client = SecretManagerServiceClient.Create(); ProjectName projectName = new ProjectName(ProjectId); Secret secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }; return(client.CreateSecret(projectName, secretId, secret)); }
private Secret CreateSecret() { var secretId = RandomSecretId(); var request = new CreateSecretRequest { ParentAsProjectName = new ProjectName(s_projectId), SecretId = secretId, Secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }, }; return(_client.CreateSecret(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}"); }
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}"); }
// [END secretmanager_add_secret_version] // [START secretmanager_create_secret] /// <summary> /// Create a new secret in the given project with the given name. /// </summary> /// <param name="projectId">ID of the project in which to create the secret.</param> /// <param name="secretId">ID of the secret.</param> /// <example> /// Create a secret. /// <code>CreateSecret("my-project", "my-secret")</code> /// </example> public static void CreateSecret(string projectId, string secretId) { SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Create the request. var request = new CreateSecretRequest { ParentAsProjectName = new ProjectName(projectId), SecretId = secretId, Secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }, }; // Create the secret. var secret = client.CreateSecret(request); Console.WriteLine($"Created secret {secret.Name}"); }
public Secret CreateSecret( string projectId = "my-project", string secretId = "my-secret") { // Create the client. SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Build the parent resource name. ProjectName projectName = new ProjectName(projectId); // Build the secret. Secret secret = new Secret { Replication = new Replication { Automatic = new Replication.Types.Automatic(), }, }; // Call the API. Secret createdSecret = client.CreateSecret(projectName, secretId, secret); return(createdSecret); }
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}"); }