Beispiel #1
0
        public override async Task <CrawlJobData> GetCrawlJobData(
            ProviderUpdateContext context,
            IDictionary <string, object> configuration,
            Guid organizationId,
            Guid userId,
            Guid providerDefinitionId)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var servicenowCrawlJobData = new ServiceNowCrawlJobData();

            if (configuration.ContainsKey(ServiceNowConstants.KeyName.Username))
            {
                servicenowCrawlJobData.Username = configuration[ServiceNowConstants.KeyName.Username].ToString();
            }

            if (configuration.ContainsKey(ServiceNowConstants.KeyName.Password))
            {
                servicenowCrawlJobData.Password = configuration[ServiceNowConstants.KeyName.Password].ToString();
            }

            if (configuration.ContainsKey(ServiceNowConstants.KeyName.BaseUrl))
            {
                servicenowCrawlJobData.BaseUrl = configuration[ServiceNowConstants.KeyName.BaseUrl].ToString();
            }

            return(await Task.FromResult(servicenowCrawlJobData));
        }
Beispiel #2
0
        public override List <RawQuery> GetRawQueries(IDictionary <string, object> config, IEntity entity, Core.Mesh.Properties properties)
        {
            var serviceNowCrawlJobData = new ServiceNowCrawlJobData(config);

            return(new List <Core.Messages.WebApp.RawQuery>()
            {
                new Core.Messages.WebApp.RawQuery()
                {
                    Query = string.Format("curl -X DELETE " + string.Format("{0}/api/now/table/", serviceNowCrawlJobData.BaseUrl) + EditUrl + "--header 'Authorization: Basic {0}' --header \"Content-Type: application/json\"" + " --data '{2}'", serviceNowCrawlJobData.Username, this.GetLookupId(entity), JsonUtility.Serialize(properties)),
                    Source = "cUrl"
                }
            });
        }
Beispiel #3
0
        public override List <QueryResponse> Validate(ExecutionContext context, MeshDataCommand command, IDictionary <string, object> config, string id, MeshQuery query)
        {
            var serviceNowCrawlJobData = new ServiceNowCrawlJobData(config);
            var client  = new RestClient(string.Format("{0}/api/now/table", serviceNowCrawlJobData.BaseUrl));
            var request = new RestRequest(EditUrl, Method.GET);

            client.Authenticator = new HttpBasicAuthenticator(serviceNowCrawlJobData.Username, serviceNowCrawlJobData.Password);

            var result = client.ExecuteTaskAsync(request).Result;

            return(new List <QueryResponse>()
            {
                new QueryResponse()
                {
                    Content = result.Content, StatusCode = result.StatusCode
                }
            });
        }
Beispiel #4
0
        public ServiceNowClient2(ILogger <ServiceNowClient2> log, ServiceNowCrawlJobData servicenowCrawlJobData, IRestClient client) // TODO: pass on any extra dependencies
        {
            if (servicenowCrawlJobData == null)
            {
                throw new ArgumentNullException(nameof(servicenowCrawlJobData));
            }

            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            this.log    = log ?? throw new ArgumentNullException(nameof(log));
            this.client = client ?? throw new ArgumentNullException(nameof(client));
            this._servicenowCrawlJobData = servicenowCrawlJobData;

            // TODO use info from servicenowCrawlJobData to instantiate the connection
            client.BaseUrl = new Uri(BaseUri);
        }
Beispiel #5
0
        public override List <QueryResponse> RunQueries(IDictionary <string, object> config, string id, Core.Mesh.Properties properties)
        {
            var serviceNowCrawlJobData = new ServiceNowCrawlJobData(config);
            var client  = new RestClient(string.Format("{0}/api/now/table", serviceNowCrawlJobData.BaseUrl));
            var request = new RestRequest(EditUrl, Method.DELETE);

            client.Authenticator = new HttpBasicAuthenticator(serviceNowCrawlJobData.Username, serviceNowCrawlJobData.Password);

            request.AddJsonBody(properties);

            var result = client.ExecuteTaskAsync(request).Result;

            return(new List <QueryResponse>()
            {
                new QueryResponse()
                {
                    Content = result.Content, StatusCode = result.StatusCode
                }
            });
        }