public void CanClearStorageAccountForRMProfile(string connectionString, string expected) { RunDataProfileTest( CreateAzureRMProfile(connectionString), CreateAzureSMProfile(null), () => { Assert.Equal(expected, AzureRmProfileProvider.Instance.Profile.DefaultContext.GetCurrentStorageAccountName()); GeneralUtilities.ClearCurrentStorageAccount(); Assert.True(string.IsNullOrEmpty(AzureRmProfileProvider.Instance.Profile.DefaultContext.GetCurrentStorageAccountName())); }); }
public void CanClearStorageAccountForEmptyProfile() { var rmProfile = new AzureRmProfile(); rmProfile.DefaultContext = new AzureContext(null, null, null, null); RunDataProfileTest( rmProfile, new AzureSMProfile(), () => { GeneralUtilities.ClearCurrentStorageAccount(true); Assert.True(string.IsNullOrEmpty(AzureSMProfileProvider.Instance.Profile.DefaultContext.GetCurrentStorageAccountName())); }); }
public IAzureSubscription SetSubscriptionAsDefault(Guid id, string accountName) { IAzureSubscription subscription = GetSubscription(id); if (subscription != null) { if (subscription.IsPropertySet(AzureSubscription.Property.StorageAccount)) { GeneralUtilities.ClearCurrentStorageAccount(); } Profile.DefaultSubscription = subscription; Profile.DefaultSubscription.SetAccount(accountName); } return(subscription); }
public override void ExecuteCmdlet() { CloudStorageAccount account; if (Context != null) { account = Context.StorageAccount; } else { account = StorageUtilities.GenerateCloudStorageAccount(new ARMStorageProvider(StorageClient), ResourceGroupName, Name); } // Clear the current storage account for both SM and RM GeneralUtilities.ClearCurrentStorageAccount(true); DefaultContext.SetCurrentStorageAccount(account.ToString(true)); WriteObject(account.Credentials.AccountName); }
protected override void ProcessRecord() { CloudStorageAccount account; if (Context != null) { account = Context.StorageAccount; } else { account = StorageUtilities.GenerateCloudStorageAccount(StorageClient, ResourceGroupName, StorageAccountName); } // Clear the current storage account for both SM and RM GeneralUtilities.ClearCurrentStorageAccount(true); DefaultContext.SetCurrentStorageAccount(account.ToString(true)); WriteObject(account.Credentials.AccountName); }
/// <summary> /// Executes the set subscription cmdlet operation. /// </summary> public override void ExecuteCmdlet() { AzureSubscription subscription = null; if (!string.IsNullOrEmpty(SubscriptionId) && string.IsNullOrEmpty(SubscriptionName)) { subscription = ProfileClient.GetSubscription(new Guid(SubscriptionId)); Environment = subscription.Environment; } else if (string.IsNullOrEmpty(SubscriptionId) && !string.IsNullOrEmpty(SubscriptionName)) { subscription = ProfileClient.GetSubscription(SubscriptionName); Environment = subscription.Environment; } else { subscription = new AzureSubscription(); subscription.Id = new Guid(SubscriptionId); subscription.Name = SubscriptionName; } AzureEnvironment environment = ProfileClient.GetEnvironment(Environment, ServiceEndpoint, ResourceManagerEndpoint); if (environment == null) { var profileClient = new ProfileClient(Profile); environment = profileClient.GetEnvironment(Environment, ServiceEndpoint, ResourceManagerEndpoint); } if (environment == null) { throw new ArgumentException("ServiceEndpoint and ResourceManagerEndpoint values do not " + "match existing environment. Please use Environment parameter."); } else { subscription.Environment = environment.Name; } if (ServiceEndpoint != null || ResourceManagerEndpoint != null) { WriteWarning("Please use Environment parameter to specify subscription environment. This " + "warning will be converted into an error in the upcoming release."); } if (Certificate != null) { ProfileClient.ImportCertificate(Certificate); subscription.Account = Certificate.Thumbprint; AzureAccount account = new AzureAccount { Id = Certificate.Thumbprint, Type = AzureAccount.AccountType.Certificate }; account.SetOrAppendProperty(AzureAccount.Property.Subscriptions, subscription.Id.ToString()); ProfileClient.AddOrSetAccount(account); if (subscription.Account == null) { subscription.Account = account.Id; } } if (subscription.Account == null) { throw new ArgumentException("Certificate is required for creating a new subscription."); } if (!string.IsNullOrEmpty(CurrentStorageAccountName) || Context != null) { ProfileClient.GetAccount(subscription.Account); if (Profile.Context != null && Profile.Context.Subscription != null && Profile.Context.Subscription.Id == subscription.Id) { GeneralUtilities.ClearCurrentStorageAccount(); } var context = new AzureContext(subscription, ProfileClient.GetAccount(subscription.Account), ProfileClient.GetEnvironmentOrDefault(subscription.Environment)); if (Context != null) { context.SetCurrentStorageAccount(this); } else { var client = AzureSession.ClientFactory.CreateClient <StorageManagementClient>(context, AzureEnvironment.Endpoint.ServiceManagement); var account = StorageUtilities.GenerateCloudStorageAccount(client, CurrentStorageAccountName); context.SetCurrentStorageAccount(account.ToString(true)); } } subscription = ProfileClient.AddOrSetSubscription(subscription); if (PassThru) { WriteObject(subscription); } }