IsEndpointSet() public method

public IsEndpointSet ( AzureEnvironment endpoint ) : bool
endpoint AzureEnvironment
return bool
Ejemplo n.º 1
0
        private IEnumerable<AzureSubscription> ListServiceManagementSubscriptions(AzureAccount account, AzureEnvironment environment, SecureString password, ShowDialog promptBehavior, string[] tenants)
        {
            List<AzureSubscription> result = new List<AzureSubscription>();

            if (!environment.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
            {
                return result;
            }

            foreach (var tenant in tenants)
            {
                try
                {
                    var tenantAccount = new AzureAccount();
                    CopyAccount(account, tenantAccount);
                    var tenantToken = AzureSession.AuthenticationFactory.Authenticate(tenantAccount, environment, tenant, password, ShowDialog.Never);
                    if (string.Equals(tenantAccount.Id, account.Id, StringComparison.InvariantCultureIgnoreCase))
                    {
                        tenantAccount = account;
                    }

                    tenantAccount.SetOrAppendProperty(AzureAccount.Property.Tenants, new string[] { tenant });
                    using (var subscriptionClient = AzureSession.ClientFactory.CreateCustomClient<SubscriptionClient>(
                            new TokenCloudCredentials(tenantToken.AccessToken),
                            environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)))
                    {
                        var subscriptionListResult = subscriptionClient.Subscriptions.List();
                        foreach (var subscription in subscriptionListResult.Subscriptions)
                        {
                            // only add the subscription if it's actually in this tenant
                            if (subscription.ActiveDirectoryTenantId == tenant)
                            {
                                AzureSubscription psSubscription = new AzureSubscription
                                {
                                    Id = new Guid(subscription.SubscriptionId),
                                    Name = subscription.SubscriptionName,
                                    Environment = environment.Name
                                };
                                psSubscription.SetProperty(AzureSubscription.Property.Tenants,
                                    subscription.ActiveDirectoryTenantId);
                                psSubscription.Account = tenantAccount.Id;
                                tenantAccount.SetOrAppendProperty(AzureAccount.Property.Subscriptions,
                                    new string[] { psSubscription.Id.ToString() });
                                result.Add(psSubscription);
                            }
                        }
                    }

                    AddOrSetAccount(tenantAccount);
                }
                catch (CloudException cEx)
                {
                    WriteOrThrowAadExceptionMessage(cEx);
                }
                catch (AadAuthenticationException aadEx)
                {
                    WriteOrThrowAadExceptionMessage(aadEx);
                }
            }

            return result;
        }
Ejemplo n.º 2
0
 private void SetEndpoint(AzureEnvironment.Endpoint endpoint, AzureEnvironment environment, string endpointValue)
 {
     if (!environment.IsEndpointSet(endpoint) && !string.IsNullOrEmpty(endpointValue))
     {
         environment.Endpoints[endpoint] = endpointValue;
     }
 }
Ejemplo n.º 3
0
 private void CheckEndpoint(AzureEnvironment.Endpoint endpoint, AzureEnvironment environment, string valueToCheck)
 {
     if (environment.IsEndpointSet(endpoint))
     {
         Assert.Equal(environment.GetEndpoint(endpoint), valueToCheck);
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new Azure environment from the given internal representation.
 /// </summary>
 /// <param name="environment">The internal representation of the environment.</param>
 public PSAzureEnvironment(AzureEnvironment environment)
 {
     Name = environment.Name;
     EnableAdfsAuthentication = environment.OnPremise;
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId))
     {
         ActiveDirectoryServiceEndpointResourceId =
             environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AdTenant))
     {
         AdTenant = environment.Endpoints[AzureEnvironment.Endpoint.AdTenant];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.Gallery))
     {
         GalleryUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.Gallery];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ManagementPortalUrl))
     {
         ManagementPortalUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
     {
         ServiceManagementUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.PublishSettingsFileUrl))
     {
         PublishSettingsFileUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ResourceManager))
     {
         ResourceManagerUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.ResourceManager];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix))
     {
         SqlDatabaseDnsSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix))
     {
         StorageEndpointSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectory))
     {
         ActiveDirectoryAuthority =
             environment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.Graph))
     {
         GraphUrl =
             environment.Endpoints[AzureEnvironment.Endpoint.Graph];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.GraphEndpointResourceId))
     {
         GraphEndpointResourceId =
             environment.Endpoints[AzureEnvironment.Endpoint.GraphEndpointResourceId];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix))
     {
         TrafficManagerDnsSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.TrafficManagerDnsSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix))
     {
         AzureKeyVaultDnsSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix))
     {
         AzureDataLakeStoreFileSystemEndpointSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix))
     {
         AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix =
             environment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix];
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId))
     {
         AzureKeyVaultServiceEndpointResourceId =
             environment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId];
     }
 }