Copy() public method

Returns a copy of the current credentials.
public Copy ( ) : ImmutableCredentials
return ImmutableCredentials
コード例 #1
0
        /// <summary>
        /// Returns a copy of the most recent instance profile credentials.
        /// </summary>
        public override ImmutableCredentials GetCredentials()
        {
            CheckIsIMDSEnabled();
            ImmutableCredentials credentials = null;

            // Try to acquire read lock. The thread would be blocked if another thread has write lock.
            if (credentialsLock.TryEnterReadLock(credentialsLockTimeout))
            {
                try
                {
                    credentials = lastRetrievedCredentials?.Copy();

                    if (credentials != null)
                    {
                        return(credentials);
                    }
                }
                finally
                {
                    credentialsLock.ExitReadLock();
                }
            }

            // If there's no credentials cached, hit IMDS directly. Try to acquire write lock.
            if (credentialsLock.TryEnterWriteLock(credentialsLockTimeout))
            {
                try
                {
                    // Check for last retrieved credentials again in case other thread might have already fetched it.
                    credentials = lastRetrievedCredentials?.Copy();
                    if (credentials == null)
                    {
                        credentials = FetchCredentials();
                        lastRetrievedCredentials = credentials;
                    }
                }
                finally
                {
                    credentialsLock.ExitWriteLock();
                }
            }

            if (credentials == null)
            {
                throw new AmazonServiceException(FailedToGetCredentialsMessage);
            }

            return(credentials);
        }
コード例 #2
0
        /// <summary>
        /// Returns a copy of the most recent instance profile credentials.
        /// </summary>
        public override ImmutableCredentials GetCredentials()
        {
            CheckIsIMDSEnabled();

            ImmutableCredentials credentials;

            try
            {
                refreshLock.EnterReadLock();
                credentials = lastRetrievedCredentials?.Copy();
            }
            finally
            {
                refreshLock.ExitReadLock();
            }

            if (credentials == null)
            {
                throw new AmazonServiceException(FailedToGetCredentialsMessage);
            }
            else
            {
                return(credentials);
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns an instance of ImmutableCredentials for this instance
        /// </summary>
        /// <returns></returns>
        public override ImmutableCredentials GetCredentials()
        {
            if (this._credentials == null)
            {
                return(null);
            }

            return(_credentials.Copy());
        }
コード例 #4
0
        /// <summary>
        /// Returns a copy of the most recent instance profile credentials.
        /// </summary>
        public override ImmutableCredentials GetCredentials()
        {
            CheckIsIMDSEnabled();

            var credentials = lastRetrievedCredentials?.Copy();

            // If there's no credentials cached, hit IMDS directly.
            if (credentials == null)
            {
                credentials = FetchCredentials();
                lastRetrievedCredentials = credentials;
            }

            if (credentials == null)
            {
                throw new AmazonServiceException(FailedToGetCredentialsMessage);
            }

            return(credentials);
        }
コード例 #5
0
 /// <summary>
 /// Returns an instance of ImmutableCredentials for this instance
 /// </summary>
 /// <returns></returns>
 public override ImmutableCredentials GetCredentials()
 {
     return(_lastCredentials.Copy());
 }