Exemplo n.º 1
0
 public ExampleCapture(string secretsFile, string outputFolder, string outputFolderWorkarounds = null)
 {
     this.secrets                 = ExampleHelpers.ReadSecretsFile(secretsFile);
     this.outputFolder            = outputFolder;
     this.outputFolderWorkarounds = outputFolderWorkarounds;
     this.client      = ExampleHelpers.GetRealClient(secrets);
     this.rmClient    = ExampleHelpers.GetRealRmClient(secrets);
     this.authClient  = ExampleHelpers.GetAuthorizationClient(secrets);
     this.interceptor = new ExampleTracingInterceptor(client.SubscriptionId, client.ApiVersion);
     ServiceClientTracing.AddTracingInterceptor(interceptor);
 }
Exemplo n.º 2
0
 public static void WriteExamples(List <Example> examples, string folder, ExampleSecrets secrets, string folderWorkarounds = null)
 {
     foreach (Example example in examples)
     {
         JsonSerializerSettings settings = new JsonSerializerSettings()
         {
             Formatting = Formatting.Indented
         };
         string json = SafeJsonConvert.SerializeObject(example, settings);
         if (secrets != null)
         {
             json = secrets.ReplaceSecretsWithExampleStrings(json);
         }
         WriteTextFile(json, folder, example.Name + ".json");
     }
 }
Exemplo n.º 3
0
        public static IAuthorizationManagementClient GetAuthorizationClient(ExampleSecrets secrets)
        {
            IAuthorizationManagementClient client = null;

            if (secrets.Environment == "dogfood")
            {
                string ArmTenant = secrets.TenantId;
                string ArmServicePrincipalIdentity = secrets.ClientId;
                string SubId = secrets.SubId;
                // Use service principal with key to authenticate against Azure
                string secret  = secrets.ClientSecret;
                var    cac     = new ClientCredential(ArmServicePrincipalIdentity, secret);
                var    context = new AuthenticationContext("https://login.windows-ppe.net/" + ArmTenant);
                AuthenticationResult     result = context.AcquireTokenAsync("https://management.core.windows.net/", cac).Result;
                ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
                client = new AuthorizationManagementClient(creds)
                {
                    SubscriptionId = secrets.SubId,
                    BaseUri        = new Uri("https://api-dogfood.resources.windows-int.net/")
                };
            }

            return(client);
        }
Exemplo n.º 4
0
 public static Rm.IResourceManagementClient GetRealRmClient(ExampleSecrets secrets)
 {
     Rm.IResourceManagementClient client = null;
     if (secrets.Environment == "test")
     {
         string ArmTenant = secrets.TenantId;
         string ArmServicePrincipalIdentity = secrets.ClientId;
         string SubId = secrets.SubId;
         string Thumb = secrets.ClientSecret;
         // Use service principal with cert to authenticate against Azure
         X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
         store.Open(OpenFlags.ReadOnly);
         X509Certificate2           cert = store.Certificates.Find(X509FindType.FindByThumbprint, Thumb, false)[0];
         ClientAssertionCertificate cac  = new ClientAssertionCertificate(ArmServicePrincipalIdentity, cert);
         var context = new AuthenticationContext("https://login.windows-ppe.net/" + ArmTenant);
         AuthenticationResult     result = context.AcquireTokenAsync("https://management.core.windows.net/", cac).Result;
         ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
         client = new Rm.ResourceManagementClient(creds)
         {
             SubscriptionId = secrets.SubId
         };
         client.BaseUri = new Uri("https://api-dogfood.resources.windows-int.net/");
     }
     else if (secrets.Environment == "dogfood")
     {
         string ArmTenant = secrets.TenantId;
         string ArmServicePrincipalIdentity = secrets.ClientId;
         string SubId = secrets.SubId;
         // Use service principal with cert to authenticate against Azure
         string secret  = secrets.ClientSecret;
         var    cac     = new ClientCredential(ArmServicePrincipalIdentity, secret);
         var    context = new AuthenticationContext("https://login.windows-ppe.net/" + ArmTenant);
         AuthenticationResult     result = context.AcquireTokenAsync("https://management.core.windows.net/", cac).Result;
         ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
         client = new Rm.ResourceManagementClient(creds)
         {
             SubscriptionId = secrets.SubId
         };
         client.BaseUri = new Uri("https://api-dogfood.resources.windows-int.net/");
     }
     else if (secrets.Environment == "prod")
     {
         // Use Service Principal to authenticate against Azure
         var context = new AuthenticationContext("https://login.windows.net/" + secrets.TenantId);
         ClientCredential         cc     = new ClientCredential(secrets.ClientId, secrets.ClientSecret);
         AuthenticationResult     result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
         ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
         client = new Rm.ResourceManagementClient(creds)
         {
             SubscriptionId = secrets.SubId
         };
     }
     else if (secrets.Environment == "nightly")
     {
         return(null); // Nightly environment is direct access to our RP, so no ARM
     }
     else
     {
         throw new ArgumentException("Secrets environment must be test, prod, or nightly, currently {0}", secrets.Environment);
     }
     return(client);
 }
Exemplo n.º 5
0
        public static IDataFactoryManagementClient GetRealClient(ExampleSecrets secrets)
        {
            IDataFactoryManagementClient client = null;

            if (secrets.Environment == "test")
            {
                string ArmTenant = secrets.TenantId;
                string ArmServicePrincipalIdentity = secrets.ClientId;
                string SubId = secrets.SubId;
                string Thumb = secrets.ClientSecret;
                // Use service principal with cert to authenticate against Azure
                X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2           cert = store.Certificates.Find(X509FindType.FindByThumbprint, Thumb, false)[0];
                ClientAssertionCertificate cac  = new ClientAssertionCertificate(ArmServicePrincipalIdentity, cert);
                var context = new AuthenticationContext("https://login.windows-ppe.net/" + ArmTenant);
                AuthenticationResult     result = context.AcquireTokenAsync("https://management.core.windows.net/", cac).Result;
                ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
                client = new DataFactoryManagementClient(creds)
                {
                    SubscriptionId = SubId
                };
                client.BaseUri = new Uri("https://api-dogfood.resources.windows-int.net/");
            }
            else if (secrets.Environment == "dogfood")
            {
                string ArmTenant = secrets.TenantId;
                string ArmServicePrincipalIdentity = secrets.ClientId;
                string SubId = secrets.SubId;
                // Use service principal with key to authenticate against Azure
                string secret  = secrets.ClientSecret;
                var    cac     = new ClientCredential(ArmServicePrincipalIdentity, secret);
                var    context = new AuthenticationContext("https://login.windows-ppe.net/" + ArmTenant);
                AuthenticationResult     result = context.AcquireTokenAsync("https://management.core.windows.net/", cac).Result;
                ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
                client = new DataFactoryManagementClient(creds)
                {
                    SubscriptionId = SubId
                };
                client.BaseUri = new Uri("https://api-dogfood.resources.windows-int.net/");
            }
            else if (secrets.Environment == "prod")
            {
                // Use Service Principal to authenticate against Azure
                var context = new AuthenticationContext("https://login.windows.net/" + secrets.TenantId);
                ClientCredential         cc     = new ClientCredential(secrets.ClientId, secrets.ClientSecret);
                AuthenticationResult     result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
                ServiceClientCredentials creds  = new TokenCredentials(result.AccessToken);
                client = new DataFactoryManagementClient(creds)
                {
                    SubscriptionId = secrets.SubId
                };
            }
            else if (secrets.Environment == "nightly")
            {
                // Use certificate for direct access to RP
                X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly);
                X509Certificate2       cert  = store.Certificates.Find(X509FindType.FindByThumbprint, "CF6DCEF6F6EB497A1B2A569319D157F875019A9E", false)[0];
                CertificateCredentials creds = new CertificateCredentials(cert);
                client = new DataFactoryManagementClient(creds)
                {
                    SubscriptionId = secrets.SubId
                };
                client.BaseUri = new Uri("https://adfrpnightly.svc.datafactory-test.azure.com");
            }
            else
            {
                throw new ArgumentException("Secrets environment must be test or prod, currently {0}", secrets.Environment);
            }
            return(client);
        }