示例#1
0
        public async Task <YHttpResponse <JObject> > DeletePurviewSourceScansAsync(Guid engineId, string dataSourceName, string scanName)
        {
            var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false);

            if (engine == null)
            {
                throw new Exception("Engine does not exists");
            }

            var baseURI     = hostOptions.PurviewScanEndpoint;
            var query       = PurviewApiVersion;
            var accessToken = await this.authProvider.GetAccessTokenForAsync(hostOptions.PurviewResource + "/.default").ConfigureAwait(false);

            //check if the datasource is in the specified engine
            var pathURISource = $"datasources/{dataSourceName}";
            var uriSource     = new System.Uri($"{baseURI}/{pathURISource}?{query}");
            YHttpResponse <JObject> yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uriSource, null, System.Net.Http.HttpMethod.Get, accessToken).ConfigureAwait(false);

            var engineSource = yHttpResponse.Value.SelectToken($"$.properties.parentCollection.referenceName");

            if (engineSource.Value <string>() != engine.EngineName)
            {
                throw new Exception($"The source {dataSourceName} does not belong to the collection {engine.EngineName}");
            }

            var pathURI = $"datasources/{dataSourceName}/scans/{scanName}";
            var uri     = new System.Uri($"{baseURI}/{pathURI}?{query}");

            yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uri, null, System.Net.Http.HttpMethod.Delete, accessToken).ConfigureAwait(false);

            return(yHttpResponse);
        }
示例#2
0
        /// <summary>
        /// Gets a specific Purview source that belongs to an engine
        /// Assumes the Purview sources will be in a collection with the name of the engine
        /// </summary>
        public async Task <YHttpResponse <JObject> > GetPurviewSourcesAsync(Guid engineId, string dataSourceName)
        {
            var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false);

            if (engine == null)
            {
                throw new Exception("Engine does not exists");
            }

            var baseURI     = hostOptions.PurviewScanEndpoint;
            var query       = PurviewApiVersion;
            var pathURI     = $"datasources/{dataSourceName}";
            var uri         = new System.Uri($"{baseURI}/{pathURI}?{query}");
            var accessToken = await this.authProvider.GetAccessTokenForAsync(hostOptions.PurviewResource + "/.default").ConfigureAwait(false);

            YHttpResponse <JObject> yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uri, null, System.Net.Http.HttpMethod.Get, accessToken).ConfigureAwait(false);

            var engineSources = yHttpResponse.Value.SelectToken($"$.properties.parentCollection.referenceName");

            if (engineSources.Value <string>() != engine.EngineName)
            {
                yHttpResponse.Value = new JObject();
            }
            //yHttpResponse.Value = engineSources.Value<string>()!=engine.EngineName ? new JObject() : engineSources.ToObject<JObject>();
            return(yHttpResponse);
        }
示例#3
0
        /// <summary>
        /// Registers a new datasource in Purview.
        /// Adds the source to a collection with the name of the engine
        /// </summary>
        public async Task <YHttpResponse <JObject> > AddPurviewSourcesAsync(Guid engineId, string dataSourceName, [FromBody] YPurviewSourcePayload dataSource)
        {
            var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false);

            if (engine == null)
            {
                throw new Exception("Engine does not exists");
            }

            if (dataSource.Kind != YPurviewSourceKind.AdlsGen2)
            {
                throw new Exception("Purview Source Type not supported yet, please use AdlsGen2");
            }

            var accessToken = await this.authProvider.GetAccessTokenForAsync(hostOptions.PurviewResource + "/.default").ConfigureAwait(false);

            var baseURI = hostOptions.PurviewScanEndpoint;
            var query   = PurviewApiVersion;

            // Upsert the collection before creating the source
            var pathURICollection  = $"datasources/{engine.EngineName}";
            var uriCollection      = new System.Uri($"{baseURI}/{pathURICollection}?{query}");
            var jsondataCollection = new JObject {
                { "kind", "Collection" },
                { "properties", new JObject {
                  } }
            };
            YHttpResponse <JObject> yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uriCollection, jsondataCollection, System.Net.Http.HttpMethod.Put, accessToken).ConfigureAwait(false);

            var pathURI  = $"datasources/{dataSourceName}";
            var uri      = new System.Uri($"{baseURI}/{pathURI}?{query}");
            var jsondata = new JObject {
                { "kind", dataSource.Kind.ToString() },
                { "properties", new JObject {
                      { "endpoint", dataSource.Properties.endpoint },
                      { "subscriptionId", dataSource.Properties.subscriptionId },
                      { "resourceGroup", dataSource.Properties.resourceGroup },
                      { "location", dataSource.Properties.location },
                      { "parentCollection", new JObject {
                                { "type", "DataSourceReference" },
                                { "referenceName", engine.EngineName }
                            } }
                  } }
            };

            yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uri, jsondata, System.Net.Http.HttpMethod.Put, accessToken).ConfigureAwait(false);

            return(yHttpResponse);
        }
示例#4
0
        /// <summary>
        /// Gets all sources registered in Purview. Can only be run by Admins
        /// </summary>
        public async Task <YHttpResponse <JObject> > GetPurviewSourcesAsync()
        {
            HttpContext.VerifyUserHasAnyAcceptedScope(scopeRequiredByApi);

            if (!this.User.IsInRole("Admin"))
            {
                throw new Exception("You should be admin to make a deployment");
            }

            var baseURI     = hostOptions.PurviewScanEndpoint;
            var query       = PurviewApiVersion;
            var pathURI     = "datasources/";
            var uri         = new System.Uri($"{baseURI}/{pathURI}?{query}");
            var accessToken = await this.authProvider.GetAccessTokenForAsync(hostOptions.PurviewResource + "/.default").ConfigureAwait(false);

            YHttpResponse <JObject> yHttpResponse = await this.client.ProcessRequestAsync <JObject>(uri, null, System.Net.Http.HttpMethod.Get, accessToken).ConfigureAwait(false);

            return(yHttpResponse);
        }