def list_permissions( self, content_source_id, current_page=None, page_size=None, params=None, headers=None, http_auth=DEFAULT, request_timeout=DEFAULT, ignore_status=(), ): """ Lists all permissions for all users `<https://www.elastic.co/guide/en/workplace-search/current/workplace-search-document-permissions-api.html#list>`_ :arg content_source_id: Unique ID for a Custom API source, provided upon creation of a Custom API Source :arg current_page: Which page of results to request :arg page_size: The number of results to return in a page :arg params: Additional query params to send with the request :arg headers: Additional headers to send with the request :arg http_auth: Access token or HTTP basic auth username and password to send with the request :arg request_timeout: Timeout in seconds :arg ignore_status: HTTP status codes to not raise an error :raises elastic_enterprise_search.BadRequestError: :raises elastic_enterprise_search.UnauthorizedError: :raises elastic_enterprise_search.PaymentRequiredError: :raises elastic_enterprise_search.NotFoundError: """ if content_source_id in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument") params = QueryParams(params) if current_page is not None: params.add("page[current]", current_page) if page_size is not None: params.add("page[size]", page_size) return self.perform_request( "GET", to_path( "api", "ws", "v1", "sources", content_source_id, "permissions", ), params=params, headers=headers, http_auth=http_auth, request_timeout=request_timeout, ignore_status=ignore_status, )
def list_content_sources( self, current_page=None, page_size=None, params=None, headers=None, http_auth=DEFAULT, request_timeout=DEFAULT, ignore_status=(), ): """ Retrieves all content sources `<https://www.elastic.co/guide/en/workplace-search/current/workplace-search-content-sources-api.html#list-content-sources-api>`_ :arg current_page: Which page of results to request :arg page_size: The number of results to return in a page :arg params: Additional query params to send with the request :arg headers: Additional headers to send with the request :arg http_auth: Access token or HTTP basic auth username and password to send with the request :arg request_timeout: Timeout in seconds :arg ignore_status: HTTP status codes to not raise an error :raises elastic_enterprise_search.UnauthorizedError: :raises elastic_enterprise_search.NotFoundError: """ params = QueryParams(params) if current_page is not None: params.add("page[current]", current_page) if page_size is not None: params.add("page[size]", page_size) return self.perform_request( "GET", "/api/ws/v1/sources", params=params, headers=headers, http_auth=http_auth, request_timeout=request_timeout, ignore_status=ignore_status, )
def get_stats( self, include=None, params=None, headers=None, http_auth=DEFAULT, request_timeout=DEFAULT, ignore_status=(), ): """ Get information about the resource usage of the application, the state of different internal queues, etc. `<https://www.elastic.co/guide/en/enterprise-search/current/monitoring-apis.html#stats-api-example>`_ :arg include: Comma-separated list of stats to return :arg params: Additional query params to send with the request :arg headers: Additional headers to send with the request :arg http_auth: Access token or HTTP basic auth username and password to send with the request :arg request_timeout: Timeout in seconds :arg ignore_status: HTTP status codes to not raise an error :raises elastic_enterprise_search.UnauthorizedError: """ params = QueryParams(params) if include is not None: params.add("include", include) return self.perform_request( "GET", "/api/ent/v1/internal/stats", params=params, headers=headers, http_auth=http_auth, request_timeout=request_timeout, ignore_status=ignore_status, )
def oauth_exchange_for_access_token(self, client_id, client_secret, redirect_uri, code=None, refresh_token=None): """Exchanges either an authorization code or refresh token for an access token via the confidential OAuth flow. :param client_id: Client ID as generated when setting up an OAuth application :param client_secret: Client secret as generated when setting up an OAuth application :param redirect_uri: Location to redirect user once the OAuth process is completed. Must match one of the URIs configured in the OAuth application :param code: Authorization code as returned by the '/ws/oauth/authorize' endpoint :param refresh_token: Refresh token returned at the same time as receiving an access token :returns: The HTTP response containing the access_token and refresh_token along with other token-related metadata """ values = [client_id, client_secret, redirect_uri] # Check that 'code' and 'refresh_token' are mutually exclusive if code is None and refresh_token is None: raise ValueError( "Either the 'code' or 'refresh_token' parameter must be used") elif code is not None and refresh_token is not None: raise ValueError( "'code' and 'refresh_token' parameters are mutually exclusive") elif code is not None: values.append(code) grant_type = "authorization_code" else: assert refresh_token is not None values.append(refresh_token) grant_type = "refresh_token" if not all(isinstance(value, str) for value in values): raise TypeError("All parameters must be of type 'str'") params = QueryParams() params.add("grant_type", grant_type) params.add("client_id", client_id) params.add("client_secret", client_secret) params.add("redirect_uri", redirect_uri) if code is not None: params.add("code", code) else: params.add("refresh_token", refresh_token) return self.perform_request( method="POST", path="/ws/oauth/token", params=params, # Note that we don't want any authentication on this # request, the 'code'/'refresh_token' is enough! http_auth=None, )