/// <summary> /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with /// required current subscription. /// </summary> /// <param name="azureSubscription">Azure Subscription</param> public PSRecoveryServicesClient(IAzureProfile azureProfile) { this.Profile = azureProfile; this.cloudServicesClient = AzureSession.ClientFactory.CreateClient <CloudServiceManagementClient>(azureProfile.Context, AzureEnvironment.Endpoint.ResourceManager); System.Configuration.Configuration siteRecoveryConfig = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)siteRecoveryConfig.GetSection("appSettings"); string resourceNamespace = ""; if (appSettings.Settings.Count == 0) { resourceNamespace = "Microsoft.SiteRecovery"; // ProviderNameSpace for Production is taken as default } else { resourceNamespace = appSettings.Settings["ProviderNamespace"].Value; } Utilities.UpdateVaultSettingsProviderNamespace(resourceNamespace); this.recoveryServicesClient = AzureSession.ClientFactory.CreateCustomClient <RecoveryServicesManagementClient>( asrVaultCreds.ResourceNamespace, cloudServicesClient.Credentials, Profile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); }
/// <summary> /// Registers resource providers for Sparta. /// </summary> /// <typeparam name="T">The client type</typeparam> private void RegisterResourceManagerProviders <T>(IAzureProfile profile) { var providersToRegister = RequiredResourceLookup.RequiredProvidersForResourceManager <T>(); var registeredProviders = profile.Context.Subscription.GetPropertyAsArray(AzureSubscription.Property.RegisteredResourceProviders); var unregisteredProviders = providersToRegister.Where(p => !registeredProviders.Contains(p)).ToList(); var successfullyRegisteredProvider = new List <string>(); SubscriptionCloudCredentials creds = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(profile.Context); if (unregisteredProviders.Count > 0) { using (var client = ClientFactory.CreateCustomClient <ResourceManagementClient>( creds, profile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager))) { foreach (string provider in unregisteredProviders) { try { client.Providers.Register(provider); successfullyRegisteredProvider.Add(provider); } catch { // Ignore this as the user may not have access to service management endpoint or the provider is already registered } } } } }
/// <summary> /// Get the current storage account /// </summary> /// <returns>True if it need to init the service channel, otherwise false</returns> internal virtual bool TryGetStorageAccount(IAzureProfile profile, out string account) { account = null; bool result = false; //Storage Context is empty and have already set the current storage account in subscription if (Context == null && profile != null && profile.Context != null && profile.Context.Subscription != null && profile.Context.Subscription != null) { account = profile.Context.Subscription.GetProperty(AzureSubscription.Property.StorageAccount); result = !string.IsNullOrWhiteSpace(account); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with /// required current subscription. /// </summary> /// <param name="azureSubscription">Azure Subscription</param> public PSRecoveryServicesClient(IAzureProfile azureProfile) { System.Configuration.Configuration recoveryServicesConfig = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)recoveryServicesConfig.GetSection("appSettings"); string resourceNamespace = string.Empty; string resourceType = string.Empty; // Get Resource provider namespace from config if needed to communicate with internal deployments if (string.IsNullOrEmpty(arsVaultCreds.ResourceNamespace)) { if (appSettings.Settings.Count == 0) { resourceNamespace = "Microsoft.RecoveryServices"; } else { resourceNamespace = null == appSettings.Settings["ProviderNamespace"] ? "Microsoft.RecoveryServices" : appSettings.Settings["ProviderNamespace"].Value; } Utilities.UpdateCurrentVaultContext(new ASRVaultCreds() { ResourceNamespace = resourceNamespace, ARMResourceType = resourceType }); } this.recoveryServicesClient = AzureSession.ClientFactory.CreateCustomClient <RecoveryServicesManagementClient>( arsVaultCreds.ResourceNamespace, AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(azureProfile.Context), azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); }
/// <summary> /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with /// required current subscription. /// </summary> /// <param name="azureSubscription">Azure Subscription</param> public PSRecoveryServicesClient(IAzureProfile azureProfile) { System.Configuration.Configuration recoveryServicesConfig = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)recoveryServicesConfig.GetSection("appSettings"); string resourceNamespace = string.Empty; string resourceType = string.Empty; // Get Resource provider namespace from config if needed to communicate with internal deployments if (string.IsNullOrEmpty(asrVaultCreds.ResourceNamespace)) { if (appSettings.Settings.Count == 0) { resourceNamespace = "Microsoft.RecoveryServices"; } else { resourceNamespace = null == appSettings.Settings["ProviderNamespace"] ? "Microsoft.RecoveryServices" : appSettings.Settings["ProviderNamespace"].Value; } Utilities.UpdateCurrentVaultContext(new ASRVaultCreds() { ResourceNamespace = resourceNamespace, ARMResourceType = resourceType }); } this.recoveryServicesClient = AzureSession.ClientFactory.CreateCustomClient<RecoveryServicesManagementClient>( asrVaultCreds.ResourceNamespace, AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(azureProfile.Context), azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); }
/// <summary> /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with /// required current subscription. /// </summary> /// <param name="azureSubscription">Azure Subscription</param> public PSRecoveryServicesClient(IAzureProfile azureProfile) { System.Configuration.Configuration siteRecoveryConfig = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)siteRecoveryConfig.GetSection("appSettings"); string resourceNamespace = string.Empty; string resourceType = string.Empty; // Get Resource provider namespace and type from config only if Vault context is not set // (hopefully it is required only for Vault related cmdlets) if (string.IsNullOrEmpty(asrVaultCreds.ResourceNamespace) || string.IsNullOrEmpty(asrVaultCreds.ARMResourceType)) { if (appSettings.Settings.Count == 0) { resourceNamespace = "Microsoft.SiteRecovery"; // ProviderNameSpace for Production is taken as default resourceType = ARMResourceTypeConstants.SiteRecoveryVault; } else { resourceNamespace = null == appSettings.Settings["ProviderNamespace"] ? "Microsoft.SiteRecovery" : appSettings.Settings["ProviderNamespace"].Value; resourceType = null == appSettings.Settings["ResourceType"] ? ARMResourceTypeConstants.SiteRecoveryVault : appSettings.Settings["ResourceType"].Value; } Utilities.UpdateCurrentVaultContext(new ASRVaultCreds() { ResourceNamespace = resourceNamespace, ARMResourceType = resourceType }); } if (null == endPointUri) { if (appSettings.Settings.Count == 0) { endPointUri = azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager); } else { if (null == appSettings.Settings["RDFEProxy"]) { endPointUri = azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager); } else { // Setting Endpoint to RDFE Proxy if (null == ServicePointManager.ServerCertificateValidationCallback) { ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; } endPointUri = new Uri(appSettings.Settings["RDFEProxy"].Value); } } } cloudCredentials = AzureSession.AuthenticationFactory.GetSubscriptionCloudCredentials(azureProfile.Context); this.recoveryServicesClient = AzureSession.ClientFactory.CreateCustomClient <SiteRecoveryVaultManagementClient>( asrVaultCreds.ResourceNamespace, asrVaultCreds.ARMResourceType, cloudCredentials, azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); }