Beispiel #1
0
        protected override CredentialsRefreshState GenerateNewCredentials()
        {
            SecurityCredentials credentials = null;
            Uri           ecsEndpointUri    = Uri;
            JitteredDelay retry             = new JitteredDelay(new TimeSpan(0, 0, 0, 0, 200), new TimeSpan(0, 0, 0, 0, 50));

            // Attempt to get the credentials 4 times ignoring null return/exceptions and on the 5th try, escalate the exception if there is one.
            for (int i = 1; ; i++)
            {
                try
                {
                    // AWS_CONTAINER_AUTHORIZATION_TOKEN is optional environment variable
                    // If this variable is set the SDK will set the Authorization header on the HTTP request with the environment variable's value.
                    var headers = CreateAuthorizationHeader();

                    credentials = GetObjectFromResponse <SecurityCredentials>(ecsEndpointUri, Proxy, headers);
                    if (credentials != null)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (i == MaxRetries)
                    {
                        throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture,
                                                                       "Unable to retrieve credentials. Message = \"{0}\".",
                                                                       e.Message));
                    }
                };
                Util.AWSSDKUtils.Sleep(retry.Next());
            }

            return(new CredentialsRefreshState(new ImmutableCredentials(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.Token), credentials.Expiration));
        }
        protected override CredentialsRefreshState GenerateNewCredentials()
        {
            SecurityCredentials credentials = null;
            Uri           ecsEndpointUri    = new Uri(Server + Uri);
            JitteredDelay retry             = new JitteredDelay(new TimeSpan(0, 0, 0, 0, 200), new TimeSpan(0, 0, 0, 0, 50));

            // Attempt to get the credentials 4 times ignoring null return/exceptions and on the 5th try, escalate the exception if there is one.
            for (int i = 1; ; i++)
            {
                try
                {
                    credentials = GetObjectFromResponse <SecurityCredentials>(ecsEndpointUri, Proxy);
                    if (credentials != null)
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    if (i == MaxRetries)
                    {
                        throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture,
                                                                       "Unable to retrieve credentials. Message = \"{0}\".",
                                                                       e.Message));
                    }
                };
                Util.AWSSDKUtils.Sleep(retry.Next());
            }

            return(new CredentialsRefreshState(new ImmutableCredentials(credentials.AccessKeyId, credentials.SecretAccessKey, credentials.Token), credentials.Expiration));
        }
Beispiel #3
0
        protected override CredentialsRefreshState GenerateNewCredentials()
        {
            SecurityCredentials securityCredentials = null;
            Uri           uri           = new Uri(Server + Uri);
            JitteredDelay jitteredDelay = new JitteredDelay(new TimeSpan(0, 0, 0, 0, 200), new TimeSpan(0, 0, 0, 0, 50));
            int           num           = 1;

            while (true)
            {
                try
                {
                    securityCredentials = URIBasedRefreshingCredentialHelper.GetObjectFromResponse <SecurityCredentials>(uri);
                    if (securityCredentials != null)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    if (num == MaxRetries)
                    {
                        throw new AmazonServiceException(string.Format(CultureInfo.InvariantCulture, "Unable to retrieve credentials. Message = \"{0}\".", ex.Message));
                    }
                }
                AWSSDKUtils.Sleep(jitteredDelay.Next());
                num++;
            }
            return(new CredentialsRefreshState
            {
                Credentials = new ImmutableCredentials(securityCredentials.AccessKeyId, securityCredentials.SecretAccessKey, securityCredentials.Token),
                Expiration = securityCredentials.Expiration
            });
        }