Пример #1
0
        /// <summary>
        /// Gets information about the specified version of a secret.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/vault/GetSecretVersion.cs.html">here</a> to see an example of how to use GetSecretVersion API.</example>
        public async Task <GetSecretVersionResponse> GetSecretVersion(GetSecretVersionRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called getSecretVersion");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/secrets/{secretId}/version/{secretVersionNumber}".Trim('/')));
            HttpMethod         method         = new HttpMethod("GET");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <GetSecretVersionResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"GetSecretVersion failed with error: {e.Message}");
                throw;
            }
        }
Пример #2
0
        // [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}");
        }
Пример #3
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            GetSecretVersionRequest request;

            try
            {
                request = new GetSecretVersionRequest
                {
                    SecretId            = SecretId,
                    SecretVersionNumber = SecretVersionNumber,
                    OpcRequestId        = OpcRequestId
                };

                response = client.GetSecretVersion(request).GetAwaiter().GetResult();
                WriteOutput(response, response.SecretVersion);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }