コード例 #1
0
        /// <summary>
        /// Queries any and all compartments in the specified tenancy to find resources that match the specified criteria.
        /// Results include resources that you have permission to view and can span different resource types.
        /// You can also sort results based on a specified resource attribute.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/resourcesearch/SearchResources.cs.html">here</a> to see an example of how to use SearchResources API.</example>
        public async Task <SearchResourcesResponse> SearchResources(SearchResourcesRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called searchResources");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/resources".Trim('/')));
            HttpMethod         method         = new HttpMethod("POST");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <SearchResourcesResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"SearchResources failed with error: {e.Message}");
                throw;
            }
        }
コード例 #2
0
        internal virtual SearchResourcesResponse SearchResources(SearchResourcesRequest request)
        {
            var marshaller   = SearchResourcesRequestMarshaller.Instance;
            var unmarshaller = SearchResourcesResponseUnmarshaller.Instance;

            return(Invoke <SearchResourcesRequest, SearchResourcesResponse>(request, marshaller, unmarshaller));
        }
コード例 #3
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonResourceGroupsConfig config = new AmazonResourceGroupsConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonResourceGroupsClient client = new AmazonResourceGroupsClient(creds, config);

            SearchResourcesResponse resp = new SearchResourcesResponse();

            do
            {
                SearchResourcesRequest req = new SearchResourcesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.SearchResources(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.ResourceIdentifiers)
                {
                    AddObject(obj);
                }

                foreach (var obj in resp.QueryErrors)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            SearchResourcesRequest request;

            try
            {
                request = new SearchResourcesRequest
                {
                    SearchDetails = SearchDetails,
                    Limit         = Limit,
                    Page          = Page,
                    TenantId      = TenantId,
                    OpcRequestId  = OpcRequestId
                };

                response = client.SearchResources(request).GetAwaiter().GetResult();
                WriteOutput(response, response.ResourceSummaryCollection);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
コード例 #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the SearchResources operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SearchResources operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/resource-groups-2017-11-27/SearchResources">REST API Reference for SearchResources Operation</seealso>
        public virtual Task <SearchResourcesResponse> SearchResourcesAsync(SearchResourcesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = SearchResourcesRequestMarshaller.Instance;
            var unmarshaller = SearchResourcesResponseUnmarshaller.Instance;

            return(InvokeAsync <SearchResourcesRequest, SearchResourcesResponse>(request, marshaller,
                                                                                 unmarshaller, cancellationToken));
        }
コード例 #6
0
        internal virtual SearchResourcesResponse SearchResources(SearchResourcesRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = SearchResourcesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = SearchResourcesResponseUnmarshaller.Instance;

            return(Invoke <SearchResourcesResponse>(request, options));
        }
コード例 #7
0
        public static void SearchResourcesExample(ClientConfig config)
        {
            var client = new SearchClient(config)
            {
                Region = Regions.US_ASHBURN_1
            };

            var param = new SearchResourcesRequest()
            {
                SearchDetails = new OCISDK.Core.Search.Model.SearchDetails()
                {
                    Type  = "Structured",
                    Query = "query instance resources where lifeCycleState = 'RUNNING'"
                }
            };
            var runningInstances = client.SearchResources(param);

            Console.WriteLine($"query:{param.SearchDetails.Query}");
            foreach (var run in runningInstances.ResourceSummaryCollection.Items)
            {
                Console.WriteLine($"\tname:{run.DisplayName}, state:{run.LifecycleState}");
            }

            param = new SearchResourcesRequest()
            {
                SearchDetails = new OCISDK.Core.Search.Model.SearchDetails()
                {
                    Type  = "Structured",
                    Query = "query user resources where displayName = '*****@*****.**'"
                }
            };
            var user = client.SearchResources(param);

            Console.WriteLine($"query:{param.SearchDetails.Query}");
            foreach (var u in user.ResourceSummaryCollection.Items)
            {
                Console.WriteLine($"\tname:{u.DisplayName}, state:{u.LifecycleState}");
            }

            param = new SearchResourcesRequest()
            {
                SearchDetails = new OCISDK.Core.Search.Model.SearchDetails()
                {
                    Type = "FreeText",
                    MatchingContextType = "HIGHLIGHTS",
                    Text = "admin"
                }
            };
            Console.WriteLine($"query:{param.SearchDetails.Query}");
            var freeSearch = client.SearchResources(param);

            foreach (var free in freeSearch.ResourceSummaryCollection.Items)
            {
                Console.WriteLine($"\tname:{free.DisplayName}, state:{free.LifecycleState}");
            }
        }
コード例 #8
0
        private static async Task StructuredQuerySearch(ResourceSearchClient client, string query)
        {
            var searchResourcesRequest = new SearchResourcesRequest
            {
                SearchDetails = new StructuredSearchDetails
                {
                    MatchingContextType = SearchDetails.MatchingContextTypeEnum.Highlights,
                    Query = query
                }
            };
            var searchResourcesResponse = await client.SearchResources(searchResourcesRequest);

            foreach (var resource in searchResourcesResponse.ResourceSummaryCollection.Items)
            {
                logger.Info($"Resource: {resource.DisplayName}");
            }
        }
コード例 #9
0
        private static async Task FreeTextSearch(ResourceSearchClient client, string text)
        {
            var searchResourcesRequest = new SearchResourcesRequest
            {
                SearchDetails = new FreeTextSearchDetails
                {
                    Text = text,
                    MatchingContextType = SearchDetails.MatchingContextTypeEnum.Highlights
                }
            };
            var searchResourcesResponse = await client.SearchResources(searchResourcesRequest);

            foreach (var resource in searchResourcesResponse.ResourceSummaryCollection.Items)
            {
                logger.Info($"Resource: {resource.DisplayName}");
            }
        }
コード例 #10
0
        /// <summary>
        /// Queries any and all compartments in the tenancy to find resources that match the specified criteria.
        /// Results include resources that you have permission to view and can span different resource types.
        /// You can also sort results based on a specified resource attribute.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public async Task <SearchResourcesResponse> SearchResources(SearchResourcesRequest request)
        {
            var uri = new Uri(GetEndPoint(SearchServices.RESOURCES, this.Region));

            using (var webResponse = await this.RestClientAsync.Post(uri, request.SearchDetails, new HttpRequestHeaderParam()
            {
                OpcRequestId = request.OpcRequestId
            }))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = await reader.ReadToEndAsync();

                        return(new SearchResourcesResponse()
                        {
                            ResourceSummaryCollection = JsonSerializer.Deserialize <ResourceSummaryCollection>(response),
                            OpcNextPage = webResponse.Headers.Get("opc-next-page"),
                            OpcRequestId = webResponse.Headers.Get("opc-request-id")
                        });
                    }
        }