/// <summary>
        /// Determine if the given endpoint is set to the provided value
        /// </summary>
        /// <param name="environment">The environment to search</param>
        /// <param name="endpoint">The endpoint to check</param>
        /// <param name="url">The value to check for</param>
        /// <returns>True if the endpoint is set to the proviuded value, otherwise false</returns>
        public static bool IsEndpointSetToValue(this IAzureEnvironment environment, string endpoint, string url)
        {
            if (url == null && !environment.IsEndpointSet(endpoint))
            {
                return(true);
            }
            if (url != null && environment.IsEndpointSet(endpoint))
            {
                return(environment.GetEndpoint(endpoint)
                       .Trim(new[] { '/' })
                       .Equals(url.Trim(new[] { '/' }), StringComparison.InvariantCultureIgnoreCase));
            }

            return(false);
        }
Exemple #2
0
 private void CheckEndpoint(string endpoint, IAzureEnvironment environment, string valueToCheck)
 {
     if (environment.IsEndpointSet(endpoint))
     {
         Assert.Equal(environment.GetEndpoint(endpoint), valueToCheck);
     }
 }
Exemple #3
0
 private void SetEndpoint(string endpoint, IAzureEnvironment environment, string endpointValue)
 {
     if (!environment.IsEndpointSet(endpoint) && !string.IsNullOrEmpty(endpointValue))
     {
         environment.SetEndpoint(endpoint, endpointValue);
     }
 }
        private IEnumerable <IAzureSubscription> ListServiceManagementSubscriptions(IAzureAccount account, IAzureEnvironment environment, SecureString password, string promptBehavior, string[] tenants)
        {
            List <AzureSubscription> result = new List <AzureSubscription>();

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

            foreach (var tenant in tenants)
            {
                try
                {
                    IAzureAccount tenantAccount = new AzureAccount();
                    CopyAccount(account, tenantAccount);
                    var tenantToken = AzureSession.Instance.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.Instance.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();
                                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);
        }
        public static void CopyFrom(this IAzureEnvironment environment, IAzureEnvironment other)
        {
            if (environment != null && other != null)
            {
                environment.Name      = other.Name;
                environment.OnPremise = other.OnPremise;
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId))
                {
                    environment.ActiveDirectoryServiceEndpointResourceId = other.ActiveDirectoryServiceEndpointResourceId;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.AdTenant))
                {
                    environment.AdTenant = other.AdTenant;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.Gallery))
                {
                    environment.GalleryUrl = other.GalleryUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.ManagementPortalUrl))
                {
                    environment.ManagementPortalUrl = other.ManagementPortalUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
                {
                    environment.ServiceManagementUrl = other.ServiceManagementUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.PublishSettingsFileUrl))
                {
                    environment.PublishSettingsFileUrl = other.PublishSettingsFileUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.ResourceManager))
                {
                    environment.ResourceManagerUrl = other.ResourceManagerUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix))
                {
                    environment.SqlDatabaseDnsSuffix = other.SqlDatabaseDnsSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix))
                {
                    environment.StorageEndpointSuffix = other.StorageEndpointSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectory))
                {
                    environment.ActiveDirectoryAuthority = other.ActiveDirectoryAuthority;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.Graph))
                {
                    environment.GraphUrl = other.GraphUrl;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.GraphEndpointResourceId))
                {
                    environment.GraphEndpointResourceId = other.GraphEndpointResourceId;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix))
                {
                    environment.TrafficManagerDnsSuffix = other.TrafficManagerDnsSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix))
                {
                    environment.AzureKeyVaultDnsSuffix = other.AzureKeyVaultDnsSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix))
                {
                    environment.AzureDataLakeStoreFileSystemEndpointSuffix = other.AzureDataLakeStoreFileSystemEndpointSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix))
                {
                    environment.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix =
                        other.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
                }
                if (other.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId))
                {
                    environment.AzureKeyVaultServiceEndpointResourceId =
                        other.AzureKeyVaultServiceEndpointResourceId;
                }

                environment.VersionProfiles.Clear();
                foreach (var profile in other.VersionProfiles)
                {
                    environment.VersionProfiles.Add(profile);
                }

                environment.CopyPropertiesFrom(other);
            }
        }
 /// <summary>
 /// Initializes a new Azure environment from the given internal representation.
 /// </summary>
 /// <param name="environment">The internal representation of the environment.</param>
 public PSAzureEnvironment(IAzureEnvironment environment)
 {
     Name = environment.Name;
     EnableAdfsAuthentication = environment.OnPremise;
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId))
     {
         ActiveDirectoryServiceEndpointResourceId =
             environment.ActiveDirectoryServiceEndpointResourceId;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AdTenant))
     {
         AdTenant = environment.AdTenant;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.Gallery))
     {
         GalleryUrl =
             environment.GalleryUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ManagementPortalUrl))
     {
         ManagementPortalUrl =
             environment.ManagementPortalUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ServiceManagement))
     {
         ServiceManagementUrl =
             environment.ServiceManagementUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.PublishSettingsFileUrl))
     {
         PublishSettingsFileUrl =
             environment.PublishSettingsFileUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ResourceManager))
     {
         ResourceManagerUrl =
             environment.ResourceManagerUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix))
     {
         SqlDatabaseDnsSuffix =
             environment.SqlDatabaseDnsSuffix;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.StorageEndpointSuffix))
     {
         StorageEndpointSuffix =
             environment.StorageEndpointSuffix;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.ActiveDirectory))
     {
         ActiveDirectoryAuthority =
             environment.ActiveDirectoryAuthority;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.Graph))
     {
         GraphUrl =
             environment.GraphUrl;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix))
     {
         TrafficManagerDnsSuffix =
             environment.TrafficManagerDnsSuffix;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix))
     {
         AzureKeyVaultDnsSuffix =
             environment.AzureKeyVaultDnsSuffix;
     }
     if (environment.IsEndpointSet(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId))
     {
         AzureKeyVaultServiceEndpointResourceId =
             environment.AzureKeyVaultServiceEndpointResourceId;
     }
 }