Esempio n. 1
0
        private static AzureCredentials GetTestCredentials()
        {
            var env = new AzureEnvironment()
            {
                AuthenticationEndpoint  = "https://www.contoso.com",
                ManagementEndpoint      = "https://www.contoso.com",
                ResourceManagerEndpoint = "https://www.contoso.com",
                GraphEndpoint           = "https://www.contoso.com"
            };

            AzureCredentials credentials = new TestAzureCredentials(
                new ServicePrincipalLoginInformation
            {
                ClientId = HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.AADTenantKey)
                        ? HttpMockServer.Variables[ConnectionStringKeys.ServicePrincipalKey]
                        : "servicePrincipalNotRecorded",
                ClientSecret = null
            },
                HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.AADTenantKey)
                    ? HttpMockServer.Variables[ConnectionStringKeys.AADTenantKey]
                    : "tenantIdNotRecorded", env);

            credentials.WithDefaultSubscription(
                HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.SubscriptionIdKey)
                    ? HttpMockServer.Variables[ConnectionStringKeys.SubscriptionIdKey]
                    : "subscriptionIdNotRecorded");

            return(credentials);
        }
        public override AzureCredentials FromFile(string authFile)
        {
            if (HttpMockServer.Mode == HttpRecorderMode.Playback)
            {
                var env = new AzureEnvironment()
                {
                    AuthenticationEndpoint  = "https://www.contoso.com",
                    ManagementEndpoint      = "https://www.contoso.com",
                    ResourceManagerEndpoint = "https://www.contoso.com",
                    GraphEndpoint           = "https://www.contoso.com"
                };

                AzureCredentials credentials = new TestAzureCredentials(
                    new ServicePrincipalLoginInformation
                {
                    ClientId = HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.AADTenantKey) ?
                               HttpMockServer.Variables[ConnectionStringKeys.ServicePrincipalKey] : "servicePrincipalNotRecorded",
                    ClientSecret = null
                },
                    HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.AADTenantKey) ?
                    HttpMockServer.Variables[ConnectionStringKeys.AADTenantKey] : "tenantIdNotRecorded", env);
                credentials.WithDefaultSubscription(
                    HttpMockServer.Variables.ContainsKey(ConnectionStringKeys.SubscriptionIdKey) ?
                    HttpMockServer.Variables[ConnectionStringKeys.SubscriptionIdKey] : "subscriptionIdNotRecorded");

                return(credentials);
            }

            var retValue = base.FromFile(authFile);

            HttpMockServer.Variables[ConnectionStringKeys.ServicePrincipalKey] = retValue.ClientId;
            HttpMockServer.Variables[ConnectionStringKeys.AADTenantKey]        = retValue.TenantId;
            HttpMockServer.Variables[ConnectionStringKeys.SubscriptionIdKey]   = retValue.DefaultSubscriptionId;

            return(retValue);
        }