void ClearContext(AzureRmProfile profile, RMProfileClient client)
        {
            bool result = false;

            if (profile != null)
            {
                var contexts = profile.Contexts.Values;
                foreach (var context in contexts)
                {
                    client.TryRemoveContext(context);
                }

                PowerShellTokenCacheProvider tokenCacheProvider;
                if (!AzureSession.Instance.TryGetComponent(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, out tokenCacheProvider))
                {
                    WriteWarning(Resources.ClientFactoryNotRegisteredClear);
                }
                else
                {
                    tokenCacheProvider.ClearCache();
                    var defaultContext = new AzureContext();
                    profile.TrySetDefaultContext(defaultContext);
                    result = true;
                }
            }

            AzureSession.Instance.RaiseContextClearedEvent();

            if (PassThru.IsPresent)
            {
                WriteObject(result);
            }
        }
        public void RemovesAzureEnvironment()
        {
            var commandRuntimeMock = new Mock <ICommandRuntime>();

            commandRuntimeMock.Setup(f => f.ShouldProcess(It.IsAny <string>(), It.IsAny <string>())).Returns(true);

            const string    name   = "test";
            RMProfileClient client = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

            client.AddOrSetEnvironment(new AzureEnvironment
            {
                Name = name
            });

            var cmdlet = new RemoveAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = name
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            Assert.False(AzureRmProfileProvider.Instance.Profile.HasEnvironment(name));
        }
        protected override void ProcessRecord()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
            var result        = profileClient.ListEnvironments(Name).Select(s => (PSAzureEnvironment)s).ToList();

            WriteObject(result, enumerateCollection: true);
        }
        public void AddsAzureEnvironment()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                PublishSettingsFileUrl = "http://microsoft.com",
                ServiceEndpoint        = "endpoint.net",
                ManagementPortalUrl    = "management portal url",
                StorageEndpoint        = "endpoint.net",
                GalleryEndpoint        = "http://galleryendpoint.com",
            };

            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            var profileClient    = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
            AzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments["KaTaL"];

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl], cmdlet.PublishSettingsFileUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ServiceManagement], cmdlet.ServiceEndpoint);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl], cmdlet.ManagementPortalUrl);
            Assert.Equal(env.Endpoints[AzureEnvironment.Endpoint.Gallery], "http://galleryendpoint.com");
        }
Ejemplo n.º 5
0
        public override void ExecuteCmdlet()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            var result        = profileClient.ListEnvironments(Name).Select(s => new PSAzureEnvironment(s)).ToList();

            WriteObject(result, enumerateCollection: true);
        }
Ejemplo n.º 6
0
        protected override void ProcessRecord()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

            var newEnvironment = new AzureEnvironment
            {
                Name      = Name,
                OnPremise = EnableAdfsAuthentication
            };

            newEnvironment.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl] = PublishSettingsFileUrl;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement]      = ServiceEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.ResourceManager]        = ResourceManagerEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl]    = ManagementPortalUrl;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix]  = StorageEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory]        = ActiveDirectoryEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId] = ActiveDirectoryServiceEndpointResourceId;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.Gallery] = GalleryEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.Graph]   = GraphEndpoint;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix] = AzureKeyVaultDnsSuffix;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId] = AzureKeyVaultServiceEndpointResourceId;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.TrafficManagerDnsSuffix] = TrafficManagerDnsSuffix;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix]    = SqlDatabaseDnsSuffix;
            newEnvironment.Endpoints[AzureEnvironment.Endpoint.AdTenant] = AdTenant;
            WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
        }
        public void AddsAzureEnvironment()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Katal",
            };
            var dict = new Dictionary <string, object>
            {
                { "PublishSettingsFileUrl", "http://microsoft.com" },
                { "ServiceEndpoint", "https://endpoint.net" },
                { "ManagementPortalUrl", "http://management.portal.url" },
                { "StorageEndpoint", "http://endpoint.net" },
                { "GalleryEndpoint", "http://galleryendpoint.com" },
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl), dict["PublishSettingsFileUrl"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement), dict["ServiceEndpoint"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.ManagementPortalUrl), dict["ManagementPortalUrl"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.Gallery), "http://galleryendpoint.com");
        }
Ejemplo n.º 8
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ContextParameterSet)
            {
                AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account,
                                                                                             Context.Environment, Context.Tenant));
            }
            else if (ParameterSetName == SubscriptionNameParameterSet || ParameterSetName == SubscriptionIdParameterSet)
            {
                if (string.IsNullOrWhiteSpace(SubscriptionId) &&
                    string.IsNullOrWhiteSpace(SubscriptionName) &&
                    string.IsNullOrWhiteSpace(TenantId))
                {
                    throw new PSInvalidOperationException(Resources.SetAzureRmContextNoParameterSet);
                }

                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
                if (!string.IsNullOrWhiteSpace(SubscriptionId) || !string.IsNullOrWhiteSpace(SubscriptionName))
                {
                    profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId);
                }
                else
                {
                    profileClient.SetCurrentContext(TenantId);
                }
            }
            WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
        }
        protected override void ProcessRecord()
        {
            if (SubscriptionId != null && SubscriptionName != null)
            {
                throw new PSInvalidOperationException(Resources.BothSubscriptionIdAndNameProvided);
            }

            Guid subscrptionIdGuid;

            if (SubscriptionId != null && !Guid.TryParse(SubscriptionId, out subscrptionIdGuid))
            {
                throw new PSInvalidOperationException(Resources.InvalidSubscriptionId);
            }

            AzureAccount azureAccount = new AzureAccount();

            if (!string.IsNullOrEmpty(AccessToken))
            {
                if (string.IsNullOrWhiteSpace(AccountId))
                {
                    throw new PSInvalidOperationException(Resources.AccountIdRequired);
                }

                azureAccount.Type = AzureAccount.AccountType.AccessToken;
                azureAccount.Id   = AccountId;
                azureAccount.SetProperty(AzureAccount.Property.AccessToken, AccessToken);
            }
            else if (ServicePrincipal.IsPresent)
            {
                azureAccount.Type = AzureAccount.AccountType.ServicePrincipal;
            }
            else
            {
                azureAccount.Type = AzureAccount.AccountType.User;
            }

            SecureString password = null;

            if (Credential != null)
            {
                azureAccount.Id = Credential.UserName;
                password        = Credential.Password;
            }

            if (!string.IsNullOrEmpty(Tenant))
            {
                azureAccount.SetProperty(AzureAccount.Property.Tenants, new[] { Tenant });
            }

            if (AzureRmProfileProvider.Instance.Profile == null)
            {
                AzureRmProfileProvider.Instance.Profile = new AzureRMProfile();
            }

            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

            WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, Tenant, SubscriptionId,
                                                            SubscriptionName, password));
        }
        public override void ExecuteCmdlet()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

            ConfirmAction(
                "removing environment",
                Name,
                () => WriteObject(new PSAzureEnvironment(profileClient.RemoveEnvironment(Name))));
        }
 /// <summary>
 /// Modify the context according to the appropriate scope for this cmdlet invocation
 /// </summary>
 /// <param name="contextAction">The action that modifies the context given a profile and profile client</param>
 protected virtual void ModifyContext(Action <AzureRmProfile, RMProfileClient> contextAction)
 {
     using (var profile = GetDefaultProfile())
     {
         var client = new RMProfileClient(profile)
         {
             WarningLog = (s) => WriteWarning(s)
         };
         contextAction(profile.ToProfile(), client);
     }
 }
Ejemplo n.º 12
0
        public override void ExecuteCmdlet()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

            profileClient.WarningLog = (message) => _tasks.Enqueue(new Task(() => this.WriteWarning(message)));

            var tenants = profileClient.ListTenants(TenantId).Select((t) => new PSAzureTenant(t));

            HandleActions();
            WriteObject(tenants, enumerateCollection: true);
        }
        void ClearContext(AzureRmProfile profile, RMProfileClient client)
        {
            bool result = false;

            if (profile != null)
            {
                var contexts = profile.Contexts.Values;
                foreach (var context in contexts)
                {
                    client.TryRemoveContext(context);
                }

                var defaultContext = new AzureContext();
                var cache          = AzureSession.Instance.TokenCache;
                if (GetContextModificationScope() == ContextModificationScope.CurrentUser)
                {
                    var fileCache = cache as ProtectedFileTokenCache;
                    if (fileCache == null)
                    {
                        try
                        {
                            var session = AzureSession.Instance;
                            fileCache = new ProtectedFileTokenCache(Path.Combine(session.TokenCacheDirectory, session.TokenCacheFile), session.DataStore);
                            fileCache.Clear();
                        }
                        catch
                        {
                            // ignore exceptions from creating a token cache
                        }
                    }

                    cache.Clear();
                }
                else
                {
                    var localCache = cache as AuthenticationStoreTokenCache;
                    if (localCache != null)
                    {
                        localCache.Clear();
                    }
                }

                defaultContext.TokenCache = cache;
                profile.TrySetDefaultContext(defaultContext);
                result = true;
            }

            if (PassThru.IsPresent)
            {
                WriteObject(result);
            }
        }
        protected override void ProcessRecord()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

            ConfirmAction(
                Force.IsPresent,
                string.Format(
                    "Removing an environment will remove all associated subscriptions and accounts. Are you sure you want to remove an environment '{0}'?",
                    Name),
                "Removing environment",
                Name,
                () => WriteObject((PSAzureEnvironment)profileClient.RemoveEnvironment(Name)));
        }
Ejemplo n.º 15
0
        protected override void BeginProcessing()
        {
            base.BeginProcessing();
            var profile = DefaultProfile as AzureRmProfile;

            if (profile == null)
            {
                throw new InvalidOperationException(Resources.RmProfileNull);
            }

            _client            = new RMProfileClient(profile);
            _client.WarningLog = (s) => WriteWarning(s);
        }
Ejemplo n.º 16
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ContextParameterSet)
            {
                if (ShouldProcess(string.Format(Resources.ChangingContextUsingPipeline, Context.Tenant, Context.Subscription),
                                  Resources.ContextChangeWarning, string.Empty))
                {
                    AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription,
                                                                                                 Context.Account,
                                                                                                 Context.Environment, Context.Tenant));
                    CompleteContextProcessing();
                }
            }
            else if (ParameterSetName == SubscriptionNameParameterSet || ParameterSetName == SubscriptionIdParameterSet)
            {
                if (string.IsNullOrWhiteSpace(SubscriptionId) &&
                    string.IsNullOrWhiteSpace(SubscriptionName) &&
                    string.IsNullOrWhiteSpace(TenantId))
                {
                    throw new PSInvalidOperationException(Resources.SetAzureRmContextNoParameterSet);
                }

                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
                if (!string.IsNullOrWhiteSpace(SubscriptionId) || !string.IsNullOrWhiteSpace(SubscriptionName))
                {
                    if (ShouldProcess(string.Format(Resources.ChangingContextSubscription,
                                                    SubscriptionName ?? SubscriptionId),
                                      Resources.SubscriptionChangeWarning, string.Empty))
                    {
                        profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId);
                        CompleteContextProcessing();
                    }
                }
                else
                {
                    if (ShouldProcess(string.Format(Resources.ChangingContextTenant, TenantId),
                                      Resources.TenantChangeWarning, string.Empty))
                    {
                        profileClient.SetCurrentContext(TenantId);
                        CompleteContextProcessing();
                    }
                }
            }
            else
            {
                CompleteContextProcessing();
            }
        }
        public void AddsAzureEnvironmentUsingARMEndpoint()
        {
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime = commandRuntimeMock.Object,
                Name           = "Stack",
                ARMEndpoint    = "https://management.local.azurestack.external/"
            };

            Mock <EnvironmentHelper> envHelperMock     = new Mock <EnvironmentHelper>();
            MetadataResponse         metadataEndpoints = new MetadataResponse
            {
                GalleryEndpoint = "https://galleryendpoint",
                GraphEndpoint   = "https://graphendpoint",
                PortalEndpoint  = "https://portalendpoint",
                authentication  = new Authentication
                {
                    Audiences     = new[] { "audience1", "audience2" },
                    LoginEndpoint = "https://loginendpoint"
                }
            };

            envHelperMock.Setup(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>())).ReturnsAsync(metadataEndpoints);
            envHelperMock.Setup(f => f.RetrieveDomain(It.IsAny <string>())).Returns("domain");
            cmdlet.EnvHelper = envHelperMock.Object;
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny <PSAzureEnvironment>()), Times.Once());
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.GetEnvironment("Stack");

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(cmdlet.ARMEndpoint, env.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager));
            Assert.Equal("https://loginendpoint/", env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectory));
            Assert.Equal("audience1", env.GetEndpoint(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId));
            Assert.Equal("https://graphendpoint", env.GetEndpoint(AzureEnvironment.Endpoint.GraphEndpointResourceId));
            envHelperMock.Verify(f => f.RetrieveDomain(It.IsAny <string>()), Times.Once);
            envHelperMock.Verify(f => f.RetrieveMetaDataEndpoints(It.IsAny <string>()), Times.Once);
        }
 protected override void ProcessRecord()
 {
     if (ParameterSetName == ContextParameterSet)
     {
         AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account,
                                                                                      Context.Environment, Context.Tenant));
     }
     else
     {
         var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
         profileClient.SetCurrentContext(SubscriptionId, TenantId);
         if (!string.IsNullOrWhiteSpace(SubscriptionName))
         {
             AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = SubscriptionName;
         }
     }
     WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
 }
Ejemplo n.º 19
0
        public override void ExecuteCmdlet()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

            foreach (var key in AzureEnvironment.PublicEnvironments.Keys)
            {
                if (string.Equals(Name, key, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                      "Cannot change built-in environment {0}.", key));
                }
            }

            var newEnvironment = new AzureEnvironment {
                Name = Name, OnPremise = EnableAdfsAuthentication
            };

            if (AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey(Name))
            {
                newEnvironment = AzureRmProfileProvider.Instance.Profile.Environments[Name];
            }

            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.PublishSettingsFileUrl, PublishSettingsFileUrl);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ServiceManagement, ServiceEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ResourceManager, ResourceManagerEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ManagementPortalUrl, ManagementPortalUrl);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.StorageEndpointSuffix, StorageEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectory, ActiveDirectoryEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, ActiveDirectoryServiceEndpointResourceId);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Gallery, GalleryEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Graph, GraphEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix, AzureKeyVaultDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId, AzureKeyVaultServiceEndpointResourceId);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.TrafficManagerDnsSuffix, TrafficManagerDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix, SqlDatabaseDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix, AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix, AzureDataLakeStoreFileSystemEndpointSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AdTenant, AdTenant);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.GraphEndpointResourceId, GraphAudience);
            profileClient.AddOrSetEnvironment(newEnvironment);

            WriteObject((PSAzureEnvironment)newEnvironment);
        }
Ejemplo n.º 20
0
        protected override void ProcessRecord()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

            if ((Name == "AzureCloud") ||
                (Name == "AzureChinaCloud") ||
                (Name == "AzureUSGovernment"))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                  "Cannot change built-in environment {0}.", Name));
            }

            var newEnvironment = new AzureEnvironment {
                Name = Name, OnPremise = EnableAdfsAuthentication
            };

            if (AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey(Name))
            {
                newEnvironment = AzureRmProfileProvider.Instance.Profile.Environments[Name];
            }
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.PublishSettingsFileUrl, PublishSettingsFileUrl);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ServiceManagement, ServiceEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ResourceManager, ResourceManagerEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ManagementPortalUrl, ManagementPortalUrl);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.StorageEndpointSuffix, StorageEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectory, ActiveDirectoryEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId, ActiveDirectoryServiceEndpointResourceId);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Gallery, GalleryEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Graph, GraphEndpoint);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix, AzureKeyVaultDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId, AzureKeyVaultServiceEndpointResourceId);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.TrafficManagerDnsSuffix, TrafficManagerDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix, SqlDatabaseDnsSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix, AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix, AzureDataLakeStoreFileSystemEndpointSuffix);
            SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AdTenant, AdTenant);

            profileClient.AddOrSetEnvironment(newEnvironment);

            WriteObject((PSAzureEnvironment)newEnvironment);
        }
Ejemplo n.º 21
0
        public override void ExecuteCmdlet()
        {
            ConfirmAction("adding environment", Name,
                          () =>
            {
                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

                var newEnvironment = new AzureEnvironment
                {
                    Name      = Name,
                    OnPremise = EnableAdfsAuthentication
                };

                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.PublishSettingsFileUrl, PublishSettingsFileUrl);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.ServiceManagement, ServiceEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.ResourceManager, ResourceManagerEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.ManagementPortalUrl, ManagementPortalUrl);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix, StorageEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.ActiveDirectory,
                                           ActiveDirectoryEndpoint != null ? GeneralUtilities.EnsureTrailingSlash(ActiveDirectoryEndpoint)
                                                        : ActiveDirectoryEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId,
                                           ActiveDirectoryServiceEndpointResourceId);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.Gallery, GalleryEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.Graph, GraphEndpoint);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix, AzureKeyVaultDnsSuffix);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId,
                                           AzureKeyVaultServiceEndpointResourceId);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.TrafficManagerDnsSuffix,
                                           TrafficManagerDnsSuffix);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix, SqlDatabaseDnsSuffix);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix
                                           , AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix,
                                           AzureDataLakeStoreFileSystemEndpointSuffix);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.AdTenant, AdTenant);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.GraphEndpointResourceId, GraphAudience);
                newEnvironment.SetEndpoint(AzureEnvironment.Endpoint.DataLakeEndpointResourceId, DataLakeAudience);
                WriteObject(new PSAzureEnvironment(profileClient.AddOrSetEnvironment(newEnvironment)));
            });
        }
Ejemplo n.º 22
0
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName == ContextParameterSet)
            {
                AzureRmProfileProvider.Instance.Profile.SetContextWithCache(new AzureContext(Context.Subscription, Context.Account,
                                                                                             Context.Environment, Context.Tenant));
            }
            else if (ParameterSetName == SubscriptionNameParameterSet || ParameterSetName == SubscriptionIdParameterSet)
            {
                if (string.IsNullOrWhiteSpace(SubscriptionId) &&
                    string.IsNullOrWhiteSpace(SubscriptionName) &&
                    string.IsNullOrWhiteSpace(TenantId))
                {
                    throw new PSInvalidOperationException(Resources.SetAzureRmContextNoParameterSet);
                }

                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);
                if (!string.IsNullOrWhiteSpace(SubscriptionId) || !string.IsNullOrWhiteSpace(SubscriptionName))
                {
                    profileClient.SetCurrentContext(SubscriptionId, SubscriptionName, TenantId);
                }
                else
                {
                    profileClient.SetCurrentContext(TenantId);
                }
            }

            if (AzureRmProfileProvider.Instance.Profile.Context != null &&
                AzureRmProfileProvider.Instance.Profile.Context.Subscription != null &&
                AzureRmProfileProvider.Instance.Profile.Context.Subscription.State != null &&
                !AzureRmProfileProvider.Instance.Profile.Context.Subscription.State.Equals(
                    "Enabled",
                    StringComparison.OrdinalIgnoreCase))
            {
                WriteWarning(string.Format(
                                 Microsoft.Azure.Commands.Profile.Properties.Resources.SelectedSubscriptionNotActive,
                                 AzureRmProfileProvider.Instance.Profile.Context.Subscription.State));
            }
            WriteObject((PSAzureContext)AzureRmProfileProvider.Instance.Profile.Context);
        }
        public override void ExecuteCmdlet()
        {
            ConfirmAction("adding environment", Name,
                          () =>
            {
                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

                var newEnvironment = new AzureEnvironment
                {
                    Name      = Name,
                    OnPremise = EnableAdfsAuthentication
                };

                newEnvironment.Endpoints[AzureEnvironment.Endpoint.PublishSettingsFileUrl] = PublishSettingsFileUrl;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.ServiceManagement]      = ServiceEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.ResourceManager]        = ResourceManagerEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.ManagementPortalUrl]    = ManagementPortalUrl;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix]  = StorageEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectory]        =
                    ActiveDirectoryEndpoint != null ? GeneralUtilities.EnsureTrailingSlash(ActiveDirectoryEndpoint)
                                                        : ActiveDirectoryEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId] =
                    ActiveDirectoryServiceEndpointResourceId;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.Gallery] = GalleryEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.Graph]   = GraphEndpoint;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix] = AzureKeyVaultDnsSuffix;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId] =
                    AzureKeyVaultServiceEndpointResourceId;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.TrafficManagerDnsSuffix] =
                    TrafficManagerDnsSuffix;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix] = SqlDatabaseDnsSuffix;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix
                ] = AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix] =
                    AzureDataLakeStoreFileSystemEndpointSuffix;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.AdTenant] = AdTenant;
                newEnvironment.Endpoints[AzureEnvironment.Endpoint.GraphEndpointResourceId] = GraphAudience;
                WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment));
            });
        }
        /// <summary>
        /// Returns an array of available Azure Environment names.
        /// </summary>
        /// <returns></returns>
        public static string[] GetEnvironments()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

            return(profileClient.ListEnvironments(null).Select(x => x.Name).ToArray());
        }
Ejemplo n.º 25
0
        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrWhiteSpace(SubscriptionId) &&
                !string.IsNullOrWhiteSpace(SubscriptionName))
            {
                throw new PSInvalidOperationException(Resources.BothSubscriptionIdAndNameProvided);
            }

            Guid subscrptionIdGuid;

            if (!string.IsNullOrWhiteSpace(SubscriptionId) &&
                !Guid.TryParse(SubscriptionId, out subscrptionIdGuid))
            {
                throw new PSInvalidOperationException(
                          string.Format(Resources.InvalidSubscriptionId, SubscriptionId));
            }

            AzureAccount azureAccount = new AzureAccount();

            if (!string.IsNullOrEmpty(AccessToken))
            {
                if (string.IsNullOrWhiteSpace(AccountId))
                {
                    throw new PSInvalidOperationException(Resources.AccountIdRequired);
                }

                azureAccount.Type = AzureAccount.AccountType.AccessToken;
                azureAccount.Id   = AccountId;
                azureAccount.SetProperty(AzureAccount.Property.AccessToken, AccessToken);
            }
            else if (ServicePrincipal.IsPresent)
            {
                azureAccount.Type = AzureAccount.AccountType.ServicePrincipal;
            }
            else
            {
                azureAccount.Type = AzureAccount.AccountType.User;
            }

            if (!string.IsNullOrEmpty(CertificateThumbprint))
            {
                azureAccount.SetProperty(AzureAccount.Property.CertificateThumbprint, CertificateThumbprint);
            }

            SecureString password = null;

            if (Credential != null)
            {
                azureAccount.Id = Credential.UserName;
                password        = Credential.Password;
            }

            if (!string.IsNullOrEmpty(ApplicationId))
            {
                azureAccount.Id = ApplicationId;
            }

            if (!string.IsNullOrEmpty(TenantId))
            {
                azureAccount.SetProperty(AzureAccount.Property.Tenants, new[] { TenantId });
            }
#pragma warning disable 0618
            if (ShouldProcess(string.Format(Resources.LoginTarget, azureAccount.Type, Environment.Name), "log in"))
            {
                if (AzureRmProfileProvider.Instance.Profile == null)
                {
                    AzureRmProfileProvider.Instance.Profile = new AzureRMProfile();
                }

                var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile);

                WriteObject((PSAzureProfile)profileClient.Login(azureAccount, Environment, TenantId, SubscriptionId,
                                                                SubscriptionName, password));
            }
#pragma warning restore 0618
        }
Ejemplo n.º 26
0
        public void SetEnvironmentForMultipleContexts()
        {
            // Add new environment
            Mock <ICommandRuntime> commandRuntimeMock = new Mock <ICommandRuntime>();

            SetupConfirmation(commandRuntimeMock);
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "vault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external"
            };
            var dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" }
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            // Create contexts using the new environment
            var    profile = new AzureRmProfile();
            string contextName1;
            var    context1 = (new AzureContext {
                Environment = env
            })
                              .WithAccount(new AzureAccount {
                Id = "*****@*****.**"
            })
                              .WithTenant(new AzureTenant {
                Id = Guid.NewGuid().ToString(), Directory = "contoso.com"
            })
                              .WithSubscription(new AzureSubscription {
                Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 1"
            });

            profile.TryAddContext(context1, out contextName1);
            string contextName2;
            var    context2 = (new AzureContext {
                Environment = env
            })
                              .WithAccount(new AzureAccount {
                Id = "*****@*****.**"
            })
                              .WithTenant(new AzureTenant {
                Id = Guid.NewGuid().ToString(), Directory = "contoso.cn"
            })
                              .WithSubscription(new AzureSubscription {
                Id = Guid.NewGuid().ToString(), Name = "Contoso Subscription 2"
            });

            profile.TryAddContext(context2, out contextName2);
            profile.TrySetDefaultContext(context1);
            AzureRmProfileProvider.Instance.Profile = profile;

            // Update the environment with new endpoints
            commandRuntimeMock = new Mock <ICommandRuntime>();
            SetupConfirmation(commandRuntimeMock);
            var cmdlet2 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock.Object,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external"
            };

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" }
            };

            cmdlet2.SetBoundParameters(dict);
            cmdlet2.SetParameterSet("ARMEndpoint");
            cmdlet2.InvokeBeginProcessing();
            cmdlet2.ExecuteCmdlet();
            cmdlet2.InvokeEndProcessing();

            profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            env           = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            // Validate that the endpoints were updated in the contexts
            profile = (AzureRmProfile)AzureRmProfileProvider.Instance.Profile;
            Assert.NotNull(profile);
            Assert.NotNull(profile.Contexts);
            Assert.NotEmpty(profile.Contexts);
            foreach (var context in profile.Contexts.Values)
            {
                Assert.NotNull(context);
                Assert.NotNull(context.Environment);
                Assert.Equal(context.Environment.Name, env.Name);
                Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix);
                Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId);
            }
        }
        public override void ExecuteCmdlet()
        {
            var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());

            WriteObject(profileClient.ListTenants(TenantId).Select((t) => new PSAzureTenant(t)), enumerateCollection: true);
        }
Ejemplo n.º 28
0
        public override void ExecuteCmdlet()
        {
            ConfirmAction("updating environment", Name,
                          () =>
            {
                var profileClient = new RMProfileClient(DefaultProfile as AzureRmProfile);

                if (AzureEnvironment.PublicEnvironments.Keys.Any((k) => string.Equals(k, Name, StringComparison.CurrentCultureIgnoreCase)))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture,
                                                                      "Cannot change built-in environment {0}.", Name));
                }
                else
                {
                    IAzureEnvironment newEnvironment = new AzureEnvironment {
                        Name = Name, OnPremise = EnableAdfsAuthentication
                    };
                    var profile = DefaultProfile as AzureRmProfile;
                    if (profile.EnvironmentTable.ContainsKey(Name))
                    {
                        newEnvironment = profile.EnvironmentTable[Name];
                    }

                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.PublishSettingsFileUrl,
                                          PublishSettingsFileUrl);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ServiceManagement, ServiceEndpoint);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ResourceManager,
                                          ResourceManagerEndpoint);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ManagementPortalUrl,
                                          ManagementPortalUrl);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.StorageEndpointSuffix,
                                          StorageEndpoint);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.ActiveDirectory,
                                          ActiveDirectoryEndpoint);
                    SetEndpointIfProvided(newEnvironment,
                                          AzureEnvironment.Endpoint.ActiveDirectoryServiceEndpointResourceId,
                                          ActiveDirectoryServiceEndpointResourceId);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Gallery, GalleryEndpoint);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.Graph, GraphEndpoint);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix,
                                          AzureKeyVaultDnsSuffix);
                    SetEndpointIfProvided(newEnvironment,
                                          AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId,
                                          AzureKeyVaultServiceEndpointResourceId);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.TrafficManagerDnsSuffix,
                                          TrafficManagerDnsSuffix);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.SqlDatabaseDnsSuffix,
                                          SqlDatabaseDnsSuffix);
                    SetEndpointIfProvided(newEnvironment,
                                          AzureEnvironment.Endpoint.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix,
                                          AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix);
                    SetEndpointIfProvided(newEnvironment,
                                          AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix,
                                          AzureDataLakeStoreFileSystemEndpointSuffix);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.AdTenant, AdTenant);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.GraphEndpointResourceId,
                                          GraphAudience);
                    SetEndpointIfProvided(newEnvironment, AzureEnvironment.Endpoint.DataLakeEndpointResourceId,
                                          DataLakeAudience);
                    profileClient.AddOrSetEnvironment(newEnvironment);
                    WriteObject(new PSAzureEnvironment(newEnvironment));
                }
            });
        }
Ejemplo n.º 29
0
 protected override void BeginProcessing()
 {
     base.BeginProcessing();
     _client            = new RMProfileClient(DefaultProfile);
     _client.WarningLog = (s) => WriteWarning(s);
 }
Ejemplo n.º 30
0
        public void AddEnvironmentUpdatesContext()
        {
            var cmdlet = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "vault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://vault.local.azurestack.external"
            };
            var dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "vault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://vault.local.azurestack.external" }
            };

            cmdlet.SetBoundParameters(dict);
            cmdlet.SetParameterSet("ARMEndpoint");
            cmdlet.InvokeBeginProcessing();
            cmdlet.ExecuteCmdlet();
            cmdlet.InvokeEndProcessing();

            commandRuntimeMock = new MockCommandRuntime();
            var profileClient     = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            IAzureEnvironment env = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));

            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            var cmdlet1 = new ConnectAzureRmAccountCommand();

            cmdlet1.CommandRuntime = commandRuntimeMock;
            cmdlet1.Environment    = "Katal";

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "Environment", cmdlet1.Environment }
            };

            cmdlet1.SetBoundParameters(dict);
            cmdlet1.InvokeBeginProcessing();
            cmdlet1.ExecuteCmdlet();
            cmdlet1.InvokeEndProcessing();
            commandRuntimeMock = new MockCommandRuntime();

            Assert.NotNull(AzureRmProfileProvider.Instance.Profile.DefaultContext);
            Assert.Equal(AzureRmProfileProvider.Instance.Profile.DefaultContext.Environment.Name, cmdlet1.Environment);

            var cmdlet2 = new AddAzureRMEnvironmentCommand()
            {
                CommandRuntime         = commandRuntimeMock,
                Name                   = "Katal",
                ARMEndpoint            = "https://management.azure.com/",
                AzureKeyVaultDnsSuffix = "adminvault.local.azurestack.external",
                AzureKeyVaultServiceEndpointResourceId = "https://adminvault.local.azurestack.external"
            };

            dict.Clear();
            dict = new Dictionary <string, object>
            {
                { "ARMEndpoint", "https://management.azure.com/" },
                { "AzureKeyVaultDnsSuffix", "adminvault.local.azurestack.external" },
                { "AzureKeyVaultServiceEndpointResourceId", "https://adminvault.local.azurestack.external" }
            };

            cmdlet2.SetBoundParameters(dict);
            cmdlet2.SetParameterSet("ARMEndpoint");
            cmdlet2.InvokeBeginProcessing();
            cmdlet2.ExecuteCmdlet();
            cmdlet2.InvokeEndProcessing();

            profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile <AzureRmProfile>());
            env           = AzureRmProfileProvider.Instance.Profile.Environments.First((e) => string.Equals(e.Name, "KaTaL", StringComparison.OrdinalIgnoreCase));
            Assert.Equal(env.Name, cmdlet.Name);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultDnsSuffix), dict["AzureKeyVaultDnsSuffix"]);
            Assert.Equal(env.GetEndpoint(AzureEnvironment.Endpoint.AzureKeyVaultServiceEndpointResourceId), dict["AzureKeyVaultServiceEndpointResourceId"]);

            var context = AzureRmProfileProvider.Instance.Profile.DefaultContext;

            Assert.NotNull(context);
            Assert.NotNull(context.Environment);
            Assert.Equal(context.Environment.Name, env.Name);
            Assert.Equal(context.Environment.AzureKeyVaultDnsSuffix, env.AzureKeyVaultDnsSuffix);
            Assert.Equal(context.Environment.AzureKeyVaultServiceEndpointResourceId, env.AzureKeyVaultServiceEndpointResourceId);
        }