示例#1
0
        /// <summary>
        /// Convert a context from a PSObject
        /// </summary>
        /// <param name="other"></param>
        public PSAzureContext(PSObject other)
        {
            if (other == null || other.Properties == null)
            {
                throw new ArgumentNullException(nameof(other));
            }
            PSObject property;

            if (other.TryGetProperty(nameof(Account), out property))
            {
                Account = new PSAzureRmAccount(property);
            }
            if (other.TryGetProperty(nameof(Environment), out property))
            {
                Environment = new PSAzureEnvironment(property);
            }
            if (other.TryGetProperty(nameof(Subscription), out property))
            {
                Subscription = new PSAzureSubscription(property);
            }
            if (other.TryGetProperty(nameof(Tenant), out property))
            {
                Tenant = new PSAzureTenant(property);
            }
            if (other.TryGetProperty(nameof(TokenCache), out property))
            {
                AzureTokenCache cache = new AzureTokenCache();
                cache.Populate(property);
                TokenCache = new AuthenticationStoreTokenCache(cache);
            }

            VersionProfile = other.GetProperty <string>(nameof(VersionProfile));
            this.PopulateExtensions(other);
        }
        public void TokenCacheUsesValidData()
        {
            var store = new AzureTokenCache {
                CacheData = new byte[] { 2, 0, 0, 0, 0, 0, 0, 0 }
            };
            var cache = new AuthenticationStoreTokenCache(store);

            Assert.Equal(cache.CacheData, store.CacheData);
        }
        public void TokenCacheIgnoresInvalidData()
        {
            var store = new AzureTokenCache {
                CacheData = new byte[] { 3, 0, 0, 0, 0, 0, 0, 0 }
            };
            var cache = new AuthenticationStoreTokenCache(store);

            Assert.NotEqual(cache.CacheData, store.CacheData);
        }
示例#4
0
        IAzureTokenCache GetDefaultTokenCache()
        {
            var cache = new AzureTokenCache
            {
                CacheData = new byte[] { 2, 0, 0, 0, 0, 0, 0, 0 }
            };

            return(cache);
        }
示例#5
0
        /// <summary>
        /// Create a token cache, copying any data from the given token cache
        /// </summary>
        /// <param name="cache">The cache to copy</param>
        /// <param name="store">The store to use for persisting state</param>
        public AuthenticationStoreTokenCache(TokenCache cache, AzureTokenCache store) : this(store)
        {
            if (null == cache)
            {
                throw new ArgumentNullException("Cache");
            }

            Deserialize(cache.Serialize());
        }
        public AuthenticationStoreTokenCache(AzureTokenCache store) : base()
        {
            if (null == store)
            {
                throw new ArgumentNullException("store");
            }

            if (store.CacheData != null && store.CacheData.Length > 0)
            {
                CacheData = store.CacheData;
            }

            AfterAccess += HandleAfterAccess;
        }
示例#7
0
        public AuthenticationStoreTokenCache(AzureTokenCache store) : base()
        {
            if (null == store)
            {
                throw new ArgumentNullException("store");
            }

            _tokenStore = store;
            if (_tokenStore != null && _tokenStore.CacheData != null && _tokenStore.CacheData.Length > 0)
            {
                base.Deserialize(_tokenStore.CacheData);
            }

            AfterAccess += HandleAfterAccess;
        }