protected override void ProcessRecord() { 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); }
public void AddsAzureEnvironment() { Mock<ICommandRuntime> commandRuntimeMock = new Mock<ICommandRuntime>(); 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"); }
public override void ExecuteCmdlet() { var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile); ConfirmAction( "removing environment", Name, () => WriteObject((PSAzureEnvironment)profileClient.RemoveEnvironment(Name))); }
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))); }
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(); } }
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); }
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("updating environment", Name, () => { 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); }); }
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.Profile); client.AddOrSetEnvironment(new AzureEnvironment { Name = name }); var cmdlet = new RemoveAzureRMEnvironmentCommand() { CommandRuntime = commandRuntimeMock.Object, Force = true, Name = name }; cmdlet.InvokeBeginProcessing(); cmdlet.ExecuteCmdlet(); cmdlet.InvokeEndProcessing(); Assert.False(AzureRmProfileProvider.Instance.Profile.Environments.ContainsKey(name)); }
public override void ExecuteCmdlet() { var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile); var result = profileClient.ListEnvironments(Name).Select(s => (PSAzureEnvironment)s).ToList(); WriteObject(result, enumerateCollection: true); }
protected override void BeginProcessing() { base.BeginProcessing(); _client = new RMProfileClient(DefaultProfile); _client.WarningLog = (s) => WriteWarning(s); }
protected override void ProcessRecord() { var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile); WriteObject(profileClient.ListTenants(TenantId).Select((t) => (PSAzureTenant)t), enumerateCollection: true); }
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 }); } 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)); }
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.AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix] = AzureDataLakeAnalyticsCatalogAndJobEndpointSuffix; newEnvironment.Endpoints[AzureEnvironment.Endpoint.AzureDataLakeStoreFileSystemEndpointSuffix] = AzureDataLakeStoreFileSystemEndpointSuffix; newEnvironment.Endpoints[AzureEnvironment.Endpoint.AdTenant] = AdTenant; WriteObject((PSAzureEnvironment)profileClient.AddOrSetEnvironment(newEnvironment)); }
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); }
public override void ExecuteCmdlet() { var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.Profile); WriteObject(profileClient.ListTenants(TenantId).Select((t) => (PSAzureTenant)t), enumerateCollection: true); }