예제 #1
0
        public static async Task Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);

            SecretManagerServiceClient client = SecretManagerServiceClient.Create();
            var json = client.AccessSecretVersion(new SecretVersionName(ProjectId, "agones-allocator-info", "1")).Payload.Data.ToStringUtf8();
            var agonesAllocatorInfo = JsonConvert.DeserializeObject <AgonesAllocatorInfo>(json);

            while (true)
            {
                try {
                    List <Match> matches = await WaitingMatchAsync();

                    foreach (var match in matches)
                    {
                        await Task.Run(async() =>
                        {
                            var allocationResponse = await AllocateGameServerAsync(agonesAllocatorInfo);
                            await AssignTicketAsync(allocationResponse, match);
                        });
                    }
                } catch (Exception e) {
                    Console.WriteLine(e);
                } finally {
                    await Task.Delay(TaskDealyMillisecondsDelay);
                }
            }
        }
예제 #2
0
    public void AddsSecretVersions()
    {
        string        data          = "my secret data";
        SecretName    secretName    = _fixture.Secret.SecretName;
        SecretVersion secretVersion = _sample.AddSecretVersion(
            projectId: secretName.ProjectId, secretId: secretName.SecretId,
            data: data);

        SecretManagerServiceClient  client = SecretManagerServiceClient.Create();
        AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersion.SecretVersionName);

        Assert.Equal(data, result.Payload.Data.ToStringUtf8());
    }
예제 #3
0
 public string getDbString()
 {
     if (dbConnectionString != null)
     {
         return(this.dbConnectionString);
     }
     else
     {
         const string                secretId  = "DatabaseConnectionString";
         const string                versionId = "3";
         SecretVersionName           secret    = new SecretVersionName(projectId, secretId, versionId);
         AccessSecretVersionResponse result    = client.AccessSecretVersion(secret);
         this.dbConnectionString = result.Payload.Data.ToStringUtf8();
         return(this.dbConnectionString);
     }
 }
예제 #4
0
        /// <summary>
        /// GetSecretValue
        /// Retrieve latest secret value
        /// </summary>
        /// <param name="secretKey"></param>
        /// <returns></returns>
        public string GetSecretValue(string secretKey)
        {
            // Create the client.
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the resource name.
            SecretVersionName secretVersionName = new SecretVersionName(_configuration.GcpProjectId, secretKey, "latest");

            // Call the API.
            AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

            // Convert the payload to a string. Payloads are bytes by default.
            string payload = result.Payload.Data.ToStringUtf8();

            return(payload);
        }
예제 #5
0
        private string GetDBUserName()
        {
            // Create the client.
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the resource name.
            SecretVersionName secretVersionName = new SecretVersionName(
                "dev-office-294516",
                "db-user-name",
                "1");

            // Call the API.
            AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

            // Convert the payload to a string. Payloads are bytes by default.
            return(result.Payload.Data.ToStringUtf8());
        }
예제 #6
0
    public String AccessSecretVersion(
        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.
        AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

        // Convert the payload to a string. Payloads are bytes by default.
        String payload = result.Payload.Data.ToStringUtf8();

        return(payload);
    }
예제 #7
0
        string GetDBPassword()
        {
            // Create the client.
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the resource name.
            SecretVersionName secretVersionName = new SecretVersionName(
                Environment.GetEnvironmentVariable("PROJECT"),
                Environment.GetEnvironmentVariable("SECRET_ID"),
                Environment.GetEnvironmentVariable("SECRET_VER"));

            // Call the API.
            AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

            // Convert the payload to a string. Payloads are bytes by default.
            return(result.Payload.Data.ToStringUtf8());
        }
예제 #8
0
        // [START secretmanager_access_secret_version]
        /// <summary>
        /// Accesses a secret with provided 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>
        /// With a specific version.
        /// <code>AccessSecretVersion("my-project", "my-secret", "5")</code>
        /// </example>
        /// <example>
        /// With an alias version.
        /// <code>AccessSecretVersion("my-project", "my-secret", "latest")</code>
        /// </example>
        public static void AccessSecretVersion(string projectId, string secretId, string secretVersion)
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

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

            // Access the secret and print the result.
            //
            // WARNING: Do not print secrets in production environments. This
            // snippet is for demonstration purposes only.
            var    version = client.AccessSecretVersion(request);
            string payload = version.Payload.Data.ToStringUtf8();

            Console.WriteLine($"Payload: {payload}");
        }
        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}");
        }
예제 #10
0
        public string GetGoogleClientSecret()
        {
            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the resource name.
            SecretVersionName secretVersionName = new SecretVersionName("protean-bus-312220", "ApiClientId", "3");

            // Call the API.
            AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

            // Convert the payload to a string. Payloads are bytes by default.
            String payload = result.Payload.Data.ToStringUtf8();

            dynamic keys = JsonConvert.DeserializeObject(payload);

            JObject jObject = JObject.Parse(payload);
            JToken  jKey    = jObject["Authentication:Google:ClientSecret"].ToString();

            return(jKey.ToString());
        }
예제 #11
0
        public override void Load()
        {
            var data = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var request = new ListSecretsRequest
            {
                ParentAsProjectName = ProjectName.FromProject(projectName),
            };

            var secrets = secretManagerServiceClient.ListSecrets(request);

            foreach (var secret in secrets)
            {
                var    value     = secretManagerServiceClient.AccessSecretVersion($"{secret.Name}/versions/latest");
                string secretVal = this.manager.Load(value.Payload);
                string configKey = this.manager.GetKey(secret.SecretName);
                data.Add(configKey, secretVal);
            }
            Data = data;
        }
예제 #12
0
        public string GetSecret()
        {
            string secretName = "SqlUserSecret";
            //string region = Configuration.GetValue<string>("AWSRegion");
            var projectId = Configuration.GetValue <string>("projectid");

            SecretManagerServiceClient client = SecretManagerServiceClient.Create();

            // Build the resource name.
            SecretVersionName secretVersionName = new SecretVersionName(projectId, secretName, "latest");

            // Call the API.
            AccessSecretVersionResponse result = client.AccessSecretVersion(secretVersionName);

            // Convert the payload to a string. Payloads are bytes by default.
            String payload = result.Payload.Data.ToStringUtf8();

            return(payload);
            // Your code goes here.
        }
예제 #13
0
    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}");
    }
예제 #14
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}");
        }
예제 #15
0
        public string GetSecret(string key)
        {
            AccessSecretVersionResponse result = client.AccessSecretVersion($"projects/807819608558/secrets/{key}/versions/latest");

            return(result.Payload.Data.ToStringUtf8());
        }