public async Task LoadAsync()
        {
            var secrets = _client.ListSecrets(_projectName);

            foreach (var secret in secrets)
            {
                try
                {
                    if (!_loader.Load(secret))
                    {
                        continue;
                    }

                    var secretVersionName = new SecretVersionName(secret.SecretName.ProjectId,
                                                                  secret.SecretName.SecretId, "latest");
                    var secretVersion = await _client.AccessSecretVersionAsync(secretVersionName);

                    Set(_loader.GetKey(secret), secretVersion.Payload.Data.ToStringUtf8());
                }
                catch (Grpc.Core.RpcException)
                {
                    // This might happen if secret is created but it has no versions available
                    // For now just ignore. Maybe in future we should log that something went wrong?
                }
            }
        }
Ejemplo n.º 2
0
        private async Task <string> AccessSecretVersion(string secretId, string secretVersion)
        {
            m_logger.Trace($"Attempting to fetch version {secretVersion} of secret {secretId}");
            var request = new AccessSecretVersionRequest
            {
                SecretVersionName = new SecretVersionName(m_projectId, secretId, secretVersion),
            };

            var response = await m_client.AccessSecretVersionAsync(request);

            m_logger.Trace($"Fetched version {secretVersion} of secret {secretId}");
            return(response.Payload.Data.ToStringUtf8());
        }
        public async Task <String> getSecretManagerValues(String project_id, String secret_id, String secret_version_id)
        {
            client = await SecretManagerServiceClient.CreateAsync();

            // Create the request.
            var request = new AccessSecretVersionRequest
            {
                SecretVersionName = new SecretVersionName(project_id, secret_id, secret_version_id),
            };

            // Access the secret and print the result.
            //
            var version = await client.AccessSecretVersionAsync(request);

            string payload = version.Payload.Data.ToStringUtf8();

            return(payload);
        }
Ejemplo n.º 4
0
        private async Task LoadAsync()
        {
            logger.LogDebug($"Loading secrets from project: {projectName}");

            var secrets = client.ListSecretsAsync(projectName);

            await foreach (var secret in secrets)
            {
                var secretVersionName = new SecretVersionName(secret.SecretName.ProjectId, secret.SecretName.SecretId, "latest");

                logger.LogDebug($"Loading secret: {secretVersionName}");

                var version = await client.AccessSecretVersionAsync(secretVersionName);

                var payload = version.Payload.Data.ToStringUtf8();

                Data.Add(secret.SecretName.SecretId, payload);
            }
        }