Module: ElasticsearchServerless::API::Security::Actions
- Defined in:
- lib/elasticsearch-serverless/api/security/get_api_key.rb,
lib/elasticsearch-serverless/api/security/authenticate.rb,
lib/elasticsearch-serverless/api/security/create_api_key.rb,
lib/elasticsearch-serverless/api/security/has_privileges.rb,
lib/elasticsearch-serverless/api/security/query_api_keys.rb,
lib/elasticsearch-serverless/api/security/update_api_key.rb,
lib/elasticsearch-serverless/api/security/invalidate_api_key.rb
Instance Method Summary collapse
-
#authenticate(arguments = {}) ⇒ Object
Enables you to submit a request with a basic auth header to authenticate a user and retrieve information about the authenticated user.
-
#create_api_key(arguments = {}) ⇒ Object
Creates an API key for access without requiring basic authentication.
-
#get_api_key(arguments = {}) ⇒ Object
Retrieves information for one or more API keys.
-
#has_privileges(arguments = {}) ⇒ Object
Determines whether the specified user has a specified list of privileges.
-
#invalidate_api_key(arguments = {}) ⇒ Object
Invalidates one or more API keys.
-
#query_api_keys(arguments = {}) ⇒ Object
Retrieves information for API keys in a paginated manner.
-
#update_api_key(arguments = {}) ⇒ Object
Updates attributes of an existing API key.
Instance Method Details
#authenticate(arguments = {}) ⇒ Object
Enables you to submit a request with a basic auth header to authenticate a user and retrieve information about the authenticated user. A successful call returns a JSON structure that shows user information such as their username, the roles that are assigned to the user, any assigned metadata, and information about the realms that authenticated and authorized the user. If the user cannot be authenticated, this API returns a 401 status code.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/elasticsearch-serverless/api/security/authenticate.rb', line 33 def authenticate(arguments = {}) arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil method = ElasticsearchServerless::API::HTTP_GET path = "_security/_authenticate" params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#create_api_key(arguments = {}) ⇒ Object
Creates an API key for access without requiring basic authentication. A successful request returns a JSON structure that contains the API key, its unique id, and its name. If applicable, it also returns expiration information for the API key in milliseconds. NOTE: By default, API keys never expire. You can specify expiration information when you create the API keys.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elasticsearch-serverless/api/security/create_api_key.rb', line 36 def create_api_key(arguments = {}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) method = ElasticsearchServerless::API::HTTP_PUT path = "_security/api_key" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#get_api_key(arguments = {}) ⇒ Object
Retrieves information for one or more API keys. NOTE: If you have only the manage_own_api_key privilege, this API returns only the API keys that you own. If you have read_security, manage_api_key or greater privileges (including manage_security), this API returns all API keys regardless of ownership.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch-serverless/api/security/get_api_key.rb', line 41 def get_api_key(arguments = {}) arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil method = ElasticsearchServerless::API::HTTP_GET path = "_security/api_key" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#has_privileges(arguments = {}) ⇒ Object
Determines whether the specified user has a specified list of privileges.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch-serverless/api/security/has_privileges.rb', line 33 def has_privileges(arguments = {}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) _user = arguments.delete(:user) method = ElasticsearchServerless::API::HTTP_POST path = if _user "_security/user/#{Utils.listify(_user)}/_has_privileges" else "_security/user/_has_privileges" end params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#invalidate_api_key(arguments = {}) ⇒ Object
Invalidates one or more API keys. The manage_api_key privilege allows deleting any API keys. The manage_own_api_key only allows deleting API keys that are owned by the user. In addition, with the manage_own_api_key privilege, an invalidation request must be issued in one of the three formats:
-
Set the parameter owner=true.
-
Or, set both
usernameandrealm_nameto match the user’s identity. -
Or, if the request is issued by an API key, i.e. an API key invalidates itself, specify its ID in the
idsfield.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elasticsearch-serverless/api/security/invalidate_api_key.rb', line 38 def invalidate_api_key(arguments = {}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) method = ElasticsearchServerless::API::HTTP_DELETE path = "_security/api_key" params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#query_api_keys(arguments = {}) ⇒ Object
Retrieves information for API keys in a paginated manner. You can optionally filter the results with a query.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/elasticsearch-serverless/api/security/query_api_keys.rb', line 35 def query_api_keys(arguments = {}) arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) method = if body ElasticsearchServerless::API::HTTP_POST else ElasticsearchServerless::API::HTTP_GET end path = "_security/_query/api_key" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |
#update_api_key(arguments = {}) ⇒ Object
Updates attributes of an existing API key. Users can only update API keys that they created or that were granted to them. Use this API to update API keys created by the create API Key or grant API Key APIs. If you need to apply the same update to many API keys, you can use bulk update API Keys to reduce overhead. It’s not possible to update expired API keys, or API keys that have been invalidated by invalidate API Key. This API supports updates to an API key’s access scope and metadata. The access scope of an API key is derived from the role_descriptors you specify in the request, and a snapshot of the owner user’s permissions at the time of the request. The snapshot of the owner’s permissions is updated automatically on every call. If you don’t specify role_descriptors in the request, a call to this API might still change the API key’s access scope. This change can occur if the owner user’s permissions have changed since the API key was created or last modified. To update another user’s API key, use the run_as feature to submit a request on behalf of another user. IMPORTANT: It’s not possible to use an API key as the authentication credential for this API. To update an API key, the owner user’s credentials are required.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/elasticsearch-serverless/api/security/update_api_key.rb', line 45 def update_api_key(arguments = {}) raise ArgumentError, "Required argument 'id' missing" unless arguments[:id] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) _id = arguments.delete(:id) method = ElasticsearchServerless::API::HTTP_PUT path = "_security/api_key/#{Utils.listify(_id)}" params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers) ) end |