Exemple #1
0
        internal static InstanceProfileCredentials GetCredentials()
        {
            var cachedCredentials = GetCachedCredentials();

            if (cachedCredentials != null)
            {
                return(cachedCredentials);
            }

            lock (CacheLock)
            {
                if (GetCachedCredentials() == null)
                {
                    var role        = GetFirstRole();
                    var json        = GetContents(new Uri(Server + RolesPath + role));
                    var credentials = JsonConvert.DeserializeObject <InstanceProfileCredentials>(json);

                    if (credentials.Code != SuccessCode)
                    {
                        return(null);
                    }

                    _cachedCredentials = credentials;
                }
            }

            return(GetCachedCredentials());
        }
        internal static InstanceProfileCredentials GetCredentials()
        {
            var cachedCredentials = GetCachedCredentials();

            if (cachedCredentials != null)
            {
                return(cachedCredentials);
            }

            lock (CacheLock)
            {
                cachedCredentials = GetCachedCredentials();
                if (cachedCredentials != null)
                {
                    return(cachedCredentials);
                }

                var role = GetFirstRole();
                if (role == null)
                {
                    return(null);
                }
                var json        = GetContents(new Uri(Server + RolesPath + role));
                var credentials = JsonConvert.DeserializeObject <InstanceProfileCredentials>(json);

                if (credentials.Code != SuccessCode)
                {
                    return(null);
                }

                credentials.LastObtained = DateTime.UtcNow;

                return(_cachedCredentials = credentials);
            }
        }
        internal static InstanceProfileCredentials GetCredentials()
        {
            var cachedCredentials = GetCachedCredentials();
            if (cachedCredentials != null)
                return cachedCredentials;

            lock (CacheLock)
            {
                if (GetCachedCredentials() == null)
                {
                    var role = GetFirstRole();
                    var json = GetContents(new Uri(Server + RolesPath + role));
                    var credentials = JsonConvert.DeserializeObject<InstanceProfileCredentials>(json);

                    if (credentials.Code != SuccessCode)
                        return null;

                    _cachedCredentials = credentials;

                }
            }

            return GetCachedCredentials();
        }