private T GetTypedObject <T>(IDataFactoryManagementClient client, object objectRaw) { string jsonRaw = SafeJsonConvert.SerializeObject(objectRaw); T objectTyped = SafeJsonConvert.DeserializeObject <T>(jsonRaw, GetFullSerializerSettings(client)); return(objectTyped); }
/// <summary> /// The Get Operation Status operation returns the status of the /// specified operation. After calling an asynchronous operation, you /// can call Get Operation Status to determine whether the operation /// has succeeded, failed, or is still in progress. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.DataFactories.Core.IDataFactoryManagementClient. /// </param> /// <param name='operationStatusLink'> /// Required. Location value returned by the Begin operation. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse GetLongRunningOperationStatus(this IDataFactoryManagementClient operations, string operationStatusLink) { return(Task.Factory.StartNew((object s) => { return ((IDataFactoryManagementClient)s).GetLongRunningOperationStatusAsync(operationStatusLink); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
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); }
private T GetTypedParameter <T>(Example example, IDataFactoryManagementClient client, string paramName) { object objectRaw = example.Parameters[paramName]; Type parameterType = typeof(T); if (parameterType == typeof(DateTime)) { objectRaw = objectRaw.ToString().Replace("%3A", ":"); } return(GetTypedObject <T>(client, objectRaw)); }
public void TestJsonSample <TResource>(JsonSampleInfo sampleInfo) { RecordedDelegatingHandler handler = new RecordedDelegatingHandler(); IDataFactoryManagementClient client = this.CreateWorkflowClient(handler); string serializedJson; TResource resource = SafeJsonConvert.DeserializeObject <TResource>(sampleInfo.Json, client.DeserializationSettings); serializedJson = SafeJsonConvert.SerializeObject(resource, GetFullSerializerSettings(client)); JObject original = JObject.Parse(sampleInfo.Json); JObject serialized = JObject.Parse(serializedJson); Assert.True(JToken.DeepEquals(original, serialized), string.Format(CultureInfo.InvariantCulture, "Failed at case: {0}.", sampleInfo.Name)); }
public DataFactoryRepository(IDataFactoryManagementClient client, IConfigurationRepository configuration, ISecretsRepository secrets, IParameterFactory parameters) { _client = client; _secrets = secrets; _resourceGroup = configuration.ResourceGroup; _storage = configuration.StorageAccountName; _dataset = configuration.DatasetName; _pipeline = configuration.PipelineName; _parameters = parameters; }
private void CheckResponseBody <T>(Example example, IDataFactoryManagementClient client, int responseCode, T response) { // Compares original raw json captured "expected" response against strongly typed "actual" response from SDK method // Issues with workarounds noted inline Assert.NotNull(response as Object); object expectedObject = example.Responses[responseCode.ToString()].Body; string expectedJson = SafeJsonConvert.SerializeObject(expectedObject); JToken expectedJToken = JToken.Parse(expectedJson); string actualJson = SafeJsonConvert.SerializeObject(response, GetFullSerializerSettings(client)); JToken actualJToken = JToken.Parse(actualJson); Assert.True(JToken.DeepEquals(expectedJToken, actualJToken), string.Format(CultureInfo.InvariantCulture, "CheckResponseBody failed for example {0} response code {1}", example.Name, responseCode)); }
private void create_adf_client() { var authenticationContext = new AuthenticationContext($"https://login.windows.net/{tenant_id}"); var credential = new ClientCredential(clientId: client_id, clientSecret: client_key); var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential); if (result == null) { throw new InvalidOperationException("Failed to obtain the JWT token"); } var token = result.AccessToken; var _credentials = new TokenCloudCredentials(subscription_id, token); inner_client = new DataFactoryManagementClient(_credentials); }
public JsonSerializerSettings GetFullSerializerSettings(IDataFactoryManagementClient client, bool includeNulls = false) { // Issue: The client's serializer ignores read-only properties like resource Name and Id, and also ignores nulls. // That's fine for serializing requests, but not for serializing responses or testing JSON round-trip through OM. // So, we make our own serializer that differs from the client's only in that it also serializes read-only properties, // and optionally also serializes nulls. JsonSerializerSettings fullSerializationSettings = new JsonSerializerSettings { Formatting = client.SerializationSettings.Formatting, DateFormatHandling = client.SerializationSettings.DateFormatHandling, DateTimeZoneHandling = client.SerializationSettings.DateTimeZoneHandling, NullValueHandling = includeNulls? NullValueHandling.Include : client.SerializationSettings.NullValueHandling, ReferenceLoopHandling = client.SerializationSettings.ReferenceLoopHandling, ContractResolver = new DefaultContractResolver(), // not the one that drops read-only properties Converters = client.SerializationSettings.Converters }; return(fullSerializationSettings); }
/// <summary> /// Ensures correct generic json serialization of example parameters. /// For all parameter values that have client model types, use the client /// serializer to get the correct json, then replace the parameter value /// with the generic object deserialization of that json. /// </summary> /// <param name="examples"></param> /// <param name="client"></param> public static void FixExampleModelParameters(List <Example> examples, IDataFactoryManagementClient client) { foreach (Example example in examples) { Dictionary <string, object> fixes = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> kvp in example.Parameters) { if (kvp.Value != null && kvp.Value.GetType().Namespace == typeof(Factory).Namespace) { string jsonFixed = SafeJsonConvert.SerializeObject(kvp.Value, client.SerializationSettings); object objectFixed = SafeJsonConvert.DeserializeObject <object>(jsonFixed); fixes.Add(kvp.Key, objectFixed); } } foreach (KeyValuePair <string, object> kvpFixed in fixes) { example.Parameters[kvpFixed.Key] = kvpFixed.Value; } } }
private DataFlowResource DFR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <DataFlowResource>(example, client, "dataFlow")); }
private PipelineResource PR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <PipelineResource>(example, client, "pipeline")); }
private TriggerResource TR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <TriggerResource>(example, client, "trigger")); }
private LinkedServiceResource LSR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <LinkedServiceResource>(example, client, "linkedService")); }
private IntegrationRuntimeResource IRR(Example example, IDataFactoryManagementClient client, string paramName) { return(GetTypedParameter <IntegrationRuntimeResource>(example, client, paramName)); }
private Factory FR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <Factory>(example, client, "factory")); }
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); }
public static void ApplyTemporaryWorkaroundsForServiceDefects(List <Example> examples, IDataFactoryManagementClient client) { // Transform captured examples from actual to expected, for issues where service defects are known and expected to be fixed soon // Pass 1: // A. Save Factories_ListByResourceGroup responses // B. Save PipelineRuns_ListWithQueryByFactory responses (after A) // Pass 2: // C. Set Factories_List responses to saved ones from Factories_ListByResourceGroup // D. For IntegrationRuntimes_GetStatus, from responses/200/body/properties strip dataFactoryName, iRType, from responses/200/body/properties/typeProperties strip state. Dictionary <string, Example.Response> factories_ListByResourceGroupResponses = null; foreach (Example example in examples) { // Pass 1 if (example.Name.StartsWith("Factories_") && example.Responses != null && example.Responses.ContainsKey("200") && example.Responses["200"].Body != null) { // Pass 1, step A if (example.Name == "Factories_ListByResourceGroup") { factories_ListByResourceGroupResponses = example.Responses; } } } foreach (Example example in examples) { // Pass 2 if (example.Name == "Factories_List") { // Pass 2, step C example.Responses = Clone(factories_ListByResourceGroupResponses); } else if (example.Name == "IntegrationRuntimes_GetStatus") { // Pass 2, step D object body = example.Responses["200"].Body; string bodyJson = SafeJsonConvert.SerializeObject(body); JObject bodyJObject = JObject.Parse(bodyJson); JObject propertiesJObject = bodyJObject["properties"] as JObject; propertiesJObject.Remove("dataFactoryName"); propertiesJObject.Remove("iRType"); JObject typePropertiesJObject = propertiesJObject["typeProperties"] as JObject; typePropertiesJObject.Remove("state"); string bodyJsonNew = bodyJObject.ToString(Formatting.None); example.Responses["200"].Body = SafeJsonConvert.DeserializeObject <object>(bodyJsonNew); } } }
public DataFactoryClient(AzureProfile profile) { DataPipelineManagementClient = AzureSession.ClientFactory.CreateClient<DataFactoryManagementClient>( profile, AzureEnvironment.Endpoint.ResourceManager); }
public DataFactoryClient(AzureContext context) { DataPipelineManagementClient = AzureSession.ClientFactory.CreateClient<DataFactoryManagementClient>( context, AzureEnvironment.Endpoint.ResourceManager); }
private PrivateLinkConnectionApprovalRequestResource PLR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <PrivateLinkConnectionApprovalRequestResource>(example, client, "privateEndpointWrapper")); }
private ManagedPrivateEndpointResource MPER(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <ManagedPrivateEndpointResource>(example, client, "managedPrivateEndpoint")); }
public DataFactoryClient(IAzureContext context) { DataPipelineManagementClient = AzureSession.Instance.ClientFactory.CreateClient <DataFactoryManagementClient>( context, AzureEnvironment.Endpoint.ResourceManager); }
private ManagedVirtualNetworkResource MVR(Example example, IDataFactoryManagementClient client) { return(GetTypedParameter <ManagedVirtualNetworkResource>(example, client, "managedVirtualNetwork")); }
/// <summary> /// The Get Operation Status operation returns the status of the /// specified operation. After calling an asynchronous operation, you /// can call Get Operation Status to determine whether the operation /// has succeeded, failed, or is still in progress. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.DataFactories.Core.IDataFactoryManagementClient. /// </param> /// <param name='operationStatusLink'> /// Required. Location value returned by the Begin operation. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task <LongRunningOperationResponse> GetLongRunningOperationStatusAsync(this IDataFactoryManagementClient operations, string operationStatusLink) { return(operations.GetLongRunningOperationStatusAsync(operationStatusLink, CancellationToken.None)); }
public DataFactoryClient(AzureProfile profile) { DataPipelineManagementClient = AzureSession.ClientFactory.CreateClient <DataFactoryManagementClient>( profile, AzureEnvironment.Endpoint.ResourceManager); }