Esempio n. 1
0
        public async Task <List <AzureSubscription> > GetAzureARMSubscriptions(AzureTenant azureTenant)
        {
            _AzureContext.LogProvider.WriteLog("GetAzureARMSubscriptions", "Start - azureTenant: " + azureTenant.ToString());

            String subscriptionsUrl = _AzureContext.AzureServiceUrls.GetARMServiceManagementUrl() + "subscriptions?api-version=2015-01-01";
            String accessToken      = _AzureContext.TokenProvider.AccessToken;

            AuthenticationResult subscriptionAuthenticationResult = await _AzureContext.TokenProvider.GetAzureToken(azureTenant.TenantId.ToString());

            if (subscriptionAuthenticationResult != null)
            {
                accessToken = subscriptionAuthenticationResult.AccessToken;
            }

            _AzureContext.StatusProvider.UpdateStatus("BUSY: Getting Subscriptions...");

            AzureRestRequest  azureRestRequest  = new AzureRestRequest(subscriptionsUrl, accessToken, "GET", false);
            AzureRestResponse azureRestResponse = await _AzureContext.AzureRetriever.GetAzureRestResponse(azureRestRequest);

            JObject subscriptionsJson = JObject.Parse(azureRestResponse.Response);

            var subscriptions = from subscription in subscriptionsJson["value"]
                                select subscription;

            List <AzureSubscription> tenantSubscriptions = new List <AzureSubscription>();

            foreach (JObject azureSubscriptionJson in subscriptions)
            {
                AzureSubscription azureSubscription = new AzureSubscription(_AzureContext, azureSubscriptionJson, azureTenant, _AzureContext.AzureEnvironment);
                tenantSubscriptions.Add(azureSubscription);
            }

            return(tenantSubscriptions);
        }
Esempio n. 2
0
        public async Task <List <AzureDomain> > GetAzureARMDomains(AzureTenant azureTenant)
        {
            _AzureContext.LogProvider.WriteLog("GetAzureARMDomains", "Start");

            if (_AzureContext == null)
            {
                throw new ArgumentNullException("AzureContext is null.  Unable to call Azure API without Azure Context.");
            }
            if (_AzureContext.TokenProvider == null)
            {
                throw new ArgumentNullException("TokenProvider Context is null.  Unable to call Azure API without TokenProvider.");
            }
            if (_AzureContext.TokenProvider.AccessToken == null)
            {
                throw new ArgumentNullException("AccessToken Context is null.  Unable to call Azure API without AccessToken.");
            }

            String accessToken = _AzureContext.TokenProvider.AccessToken;

            String domainUrl = _AzureContext.AzureServiceUrls.GetGraphApiUrl() + "myorganization/domains?api-version=1.6";

            AuthenticationResult tenantAuthenticationResult = await _AzureContext.TokenProvider.GetGraphToken(azureTenant.TenantId.ToString());

            if (tenantAuthenticationResult != null)
            {
                accessToken = tenantAuthenticationResult.AccessToken;
            }

            _AzureContext.StatusProvider.UpdateStatus("BUSY: Getting Tenant Domain details from Graph...");

            AzureRestRequest  azureRestRequest  = new AzureRestRequest(domainUrl, accessToken, "GET", false);
            AzureRestResponse azureRestResponse = await _AzureContext.AzureRetriever.GetAzureRestResponse(azureRestRequest);

            JObject domainsJson = JObject.Parse(azureRestResponse.Response);

            var domains = from domain in domainsJson["value"]
                          select domain;

            List <AzureDomain> armTenantDomains = new List <AzureDomain>();

            foreach (JObject domainJson in domains)
            {
                AzureDomain azureDomain = new AzureDomain(domainJson, _AzureContext);
                armTenantDomains.Add(azureDomain);
            }

            return(armTenantDomains);
        }
Esempio n. 3
0
        public async Task <List <AzureTenant> > GetAzureARMTenants(bool allowRestCacheUse = false)
        {
            this.LogProvider.WriteLog("GetAzureARMTenants", "Start");

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

            if (this.TokenProvider == null)
            {
                throw new ArgumentNullException("TokenProvider Context is null.  Unable to call Azure API without TokenProvider.");
            }

            AuthenticationResult tenantAuthenticationResult = await this.TokenProvider.GetToken(this.AzureEnvironment.ResourceManagerEndpoint, Guid.Empty);

            String tenantUrl = this.AzureEnvironment.ResourceManagerEndpoint + "tenants?api-version=2015-01-01";

            this.StatusProvider.UpdateStatus("BUSY: Getting Tenants...");

            AzureRestRequest  azureRestRequest  = new AzureRestRequest(tenantUrl, tenantAuthenticationResult, "GET", allowRestCacheUse);
            AzureRestResponse azureRestResponse = await this.AzureRetriever.GetAzureRestResponse(azureRestRequest);

            JObject tenantsJson = JObject.Parse(azureRestResponse.Response);

            var tenants = from tenant in tenantsJson["value"]
                          select tenant;

            _ArmTenants = new List <AzureTenant>();

            foreach (JObject tenantJson in tenants)
            {
                try
                {
                    AzureTenant azureTenant = new AzureTenant(this, tenantJson);
                    await azureTenant.InitializeChildren(this, allowRestCacheUse);

                    _ArmTenants.Add(azureTenant);
                }
                catch (Exception exc)
                {
                    this.LogProvider.WriteLog("GetAzureARMTenants", "Error getting Azure Tenant: '" + exc.Message);
                }
            }

            return(_ArmTenants);
        }
Esempio n. 4
0
        public async Task <List <AzureTenant> > GetAzureARMTenants()
        {
            _AzureContext.LogProvider.WriteLog("GetAzureARMTenants", "Start");

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

            if (_AzureContext == null)
            {
                throw new ArgumentNullException("AzureContext is null.  Unable to call Azure API without Azure Context.");
            }
            if (_AzureContext.TokenProvider == null)
            {
                throw new ArgumentNullException("TokenProvider Context is null.  Unable to call Azure API without TokenProvider.");
            }
            if (_AzureContext.TokenProvider.AccessToken == null)
            {
                throw new ArgumentNullException("AccessToken Context is null.  Unable to call Azure API without AccessToken.");
            }

            String tenantUrl = _AzureContext.AzureServiceUrls.GetARMServiceManagementUrl() + "tenants?api-version=2015-01-01";

            _AzureContext.StatusProvider.UpdateStatus("BUSY: Getting Tenants...");

            AzureRestRequest  azureRestRequest  = new AzureRestRequest(tenantUrl, _AzureContext.TokenProvider.AccessToken, "GET", true);
            AzureRestResponse azureRestResponse = await _AzureContext.AzureRetriever.GetAzureRestResponse(azureRestRequest);

            JObject tenantsJson = JObject.Parse(azureRestResponse.Response);

            var tenants = from tenant in tenantsJson["value"]
                          select tenant;

            _ArmTenants = new List <AzureTenant>();

            foreach (JObject tenantJson in tenants)
            {
                AzureTenant azureTenant = new AzureTenant(tenantJson, _AzureContext);
                await azureTenant.InitializeChildren();

                _ArmTenants.Add(azureTenant);
            }

            return(_ArmTenants);
        }
Esempio n. 5
0
        public async Task SetTenantContext(AzureTenant azureTenant)
        {
            if (azureTenant == null && this._AzureSubscription != null)
            {
                await this.SetSubscriptionContext(null);
            }

            if (BeforeAzureTenantChange != null)
            {
                await BeforeAzureTenantChange?.Invoke(this);
            }

            _AzureTenant = azureTenant;

            if (AfterAzureTenantChange != null)
            {
                await AfterAzureTenantChange?.Invoke(this);
            }
        }
Esempio n. 6
0
 internal AzureSubscription(JObject subscriptionJson, AzureTenant parentAzureTenant, AzureEnvironment azureEnvironment)
 {
     _SubscriptionJson = subscriptionJson;
     _ParentTenant     = parentAzureTenant;
     _AzureEnvironment = azureEnvironment;
 }
Esempio n. 7
0
 public AzureDomain(AzureTenant azureTenant, JObject domainJson)
 {
     _DomainJson  = domainJson;
     _AzureTenant = azureTenant;
 }