private static AzureSubscription PublishSubscriptionToAzureSubscription( ProfileClient azureProfileClient, PublishDataPublishProfile profile, PublishDataPublishProfileSubscription s, string environment) { var certificate = GetCertificate(profile, s); if (string.IsNullOrEmpty(environment)) { var azureEnvironment = azureProfileClient.GetEnvironment(environment, s.ServiceManagementUrl ?? profile.Url, null); if (azureEnvironment != null) { environment = azureEnvironment.Name; } else { environment = EnvironmentName.AzureCloud; } } return new AzureSubscription { Id = new Guid(s.Id), Name = s.Name, Environment = environment, Account = certificate.Thumbprint }; }
/// <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)) { subscription.Properties[AzureSubscription.Property.StorageAccount] = CurrentStorageAccountName; } subscription = ProfileClient.AddOrSetSubscription(subscription); if (PassThru) { WriteObject(subscription); } }