public async Task <ActionResult <YDataSource> > AddDataSourceAsync(Guid engineId, string dataSourceName, [FromBody] YDataSourceUnknown dataSource) { var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false); if (engine == null) { throw new Exception("Engine does not exists"); } var regex = new Regex(@"^[a-zA-Z0-9--]{3,24}$"); if (!regex.IsMatch(dataSourceName)) { throw new Exception($"DataSource name {dataSourceName} is incorrect"); } var resourceGroupName = engine.ResourceGroupName; var factoryName = engine.FactoryName; var pathUri = $"/subscriptions/{options.SubscriptionId}" + $"/resourceGroups/{resourceGroupName}/providers/Microsoft.DataFactory" + $"/factories/{factoryName}/linkedservices/{dataSourceName}"; var query = $"api-version={DataFactoryApiVersion}"; var typedDataSource = YDataSourceFactory.GetTypedDatSource(dataSource); // get sensitive string if any string sensitiveString = typedDataSource.GetSensitiveString(); if (!string.IsNullOrEmpty(sensitiveString)) { // Save the connection string to KeyVault await keyVaultsController.SetKeyVaultSecret(engineId, dataSourceName, new YKeyVaultSecretPayload { Key = dataSourceName, Value = sensitiveString }); } // Get the response. we may want to create a real class for this result ? var response = await this.client.ProcessRequestManagementAsync <YDataSourceUnknown>( pathUri, query, typedDataSource, HttpMethod.Put).ConfigureAwait(false); return(response.Value); }
public async Task <IActionResult> TestAsync(Guid engineId, [FromBody] YDataSourceUnknown dataSource) { var isOk = await this.dataSourcesService.TestAsync(dataSource); return(new JsonResult(isOk)); }