public static T GetServiceClient <T>() where T : class
        {
            var factory         = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();
            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

            RecoveryServicesManagementClient client;
            var credentials = new SubscriptionCredentialsAdapter(
                testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management],
                testEnvironment.SubscriptionId);

            if (testEnvironment.UsesCustomUri())
            {
                client = new RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServicesBVTD",
                    credentials,
                    testEnvironment.BaseUri);
            }
            else
            {
                client = new RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServicesBVTD",
                    credentials);
            }
            return(GetServiceClient <T>(factory, client));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with
        /// required current subscription.
        /// </summary>
        /// <param name="azureSubscription">Azure Subscription</param>
        public PSRecoveryServicesClient(AzureProfile azureProfile, AzureSubscription azureSubscription)
        {
            this.Profile = azureProfile;

            this.cloudServicesClient = AzureSession.ClientFactory.CreateClient <CloudServiceManagementClient>(azureProfile, azureSubscription, 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));
        }
        protected void SetupManagementClients()
        {
            RecoveryServicesMgmtClient = GetRecoveryServicesManagementClient();
            SiteRecoveryMgmtClient     = GetSiteRecoveryManagementClient();

            helper.SetupManagementClients(RecoveryServicesMgmtClient, SiteRecoveryMgmtClient);
        }
        protected void SetupManagementClients()
        {
            RecoveryServicesMgmtClient = GetRecoveryServicesManagementClient();
            SiteRecoveryMgmtClient = GetSiteRecoveryManagementClient();

            helper.SetupManagementClients(RecoveryServicesMgmtClient, SiteRecoveryMgmtClient);
        }
Пример #5
0
        public T GetServiceClient <T>() where T : class
        {
            var factory         = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();
            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

            if (typeof(T) == typeof(RecoveryServicesManagementClient))
            {
                RecoveryServicesManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new RecoveryServicesManagementClient(
                        "Microsoft.RecoveryServices",
                        "vaults",
                        testEnvironment.Credentials as SubscriptionCloudCredentials,
                        testEnvironment.BaseUri);
                }
                else
                {
                    client = new RecoveryServicesManagementClient(
                        "Microsoft.RecoveryServices",
                        "vaults",
                        testEnvironment.Credentials as SubscriptionCloudCredentials);
                }
                return(GetRSMServiceClient <T>(factory, client));
            }
            else
            {
                SiteRecoveryManagementClient client;

                if (testEnvironment.UsesCustomUri())
                {
                    client = new SiteRecoveryManagementClient(
                        asrVaultCreds.ResourceName,
                        asrVaultCreds.ResourceGroupName,
                        "Microsoft.RecoveryServices",
                        "vaults",
                        testEnvironment.Credentials as SubscriptionCloudCredentials,
                        testEnvironment.BaseUri);
                }

                else
                {
                    client = new SiteRecoveryManagementClient(
                        asrVaultCreds.ResourceName,
                        asrVaultCreds.ResourceGroupName,
                        "Microsoft.RecoveryServices",
                        "vaults",
                        testEnvironment.Credentials as SubscriptionCloudCredentials);
                }

                return(GetSRMServiceClient <T>(factory, client));
            }
        }
Пример #6
0
        public static T GetServiceClient <T>(TestEnvironmentFactory factory, RecoveryServicesManagementClient client) where T : class
        {
            TestEnvironment testEnvironment = factory.GetTestEnvironment();

            HttpMockServer instance;

            try
            {
                instance = HttpMockServer.CreateInstance();
            }
            catch (ApplicationException)
            {
                HttpMockServer.Initialize("TestEnvironment", "InitialCreation");
                instance = HttpMockServer.CreateInstance();
            }
            T obj2 = typeof(T).GetMethod("WithHandler", new Type[1]
            {
                typeof(DelegatingHandler)
            }).Invoke((object)client, new object[1]
            {
                (object)instance
            }) as T;

            if (HttpMockServer.Mode == HttpRecorderMode.Record)
            {
                HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId;
            }

            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int));
                PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int));
                if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null)
                {
                    property1.SetValue((object)obj2, (object)0);
                    property2.SetValue((object)obj2, (object)0);
                }
            }
            return(obj2);
        }
        /// <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));
        }
Пример #8
0
        public static T GetServiceClient <T>() where T : class
        {
            var factory         = (TestEnvironmentFactory) new CSMTestEnvironmentFactory();
            var testEnvironment = factory.GetTestEnvironment();

            ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler;

            RecoveryServicesManagementClient client;

            if (testEnvironment.UsesCustomUri())
            {
                client = new RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServices",
                    testEnvironment.Credentials as SubscriptionCloudCredentials,
                    testEnvironment.BaseUri);
            }
            else
            {
                client = new RecoveryServicesManagementClient(
                    "Microsoft.RecoveryServices",
                    testEnvironment.Credentials as SubscriptionCloudCredentials);
            }
            return(GetServiceClient <T>(factory, client));
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="PSRecoveryServicesClient" /> class with
 /// required current subscription.
 /// </summary>
 /// <param name="azureSubscription">Azure Subscription</param>
 public PSRecoveryServicesClient(AzureSMProfile AzureSMProfile, AzureSubscription azureSubscription)
 {
     this.Profile = AzureSMProfile;
     this.recoveryServicesClient =
         AzureSession.ClientFactory.CreateClient <RecoveryServicesManagementClient>(AzureSMProfile, azureSubscription, AzureEnvironment.Endpoint.ServiceManagement);
 }
        /// <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));
        }
Пример #11
0
        /// <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 <RecoveryServicesManagementClient>(
                    asrVaultCreds.ResourceNamespace,
                    asrVaultCreds.ARMResourceType,
                    cloudCredentials,
                    azureProfile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager));
        }