Module: ElasticsearchServerless::API::Security::Actions
- Defined in:
- lib/elasticsearch-serverless/api/security/get_role.rb,
lib/elasticsearch-serverless/api/security/put_role.rb,
lib/elasticsearch-serverless/api/security/delete_role.rb,
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/invalidate_api_key.rb,
lib/elasticsearch-serverless/api/security/get_builtin_privileges.rb
Instance Method Summary collapse
-
#authenticate(arguments = {}) ⇒ Object
Authenticate a user.
-
#create_api_key(arguments = {}) ⇒ Object
Create an API key.
-
#delete_role(arguments = {}) ⇒ Object
Delete roles.
-
#get_api_key(arguments = {}) ⇒ Object
Get API key information.
-
#get_builtin_privileges(arguments = {}) ⇒ Object
Get builtin privileges.
-
#get_role(arguments = {}) ⇒ Object
Get roles.
-
#has_privileges(arguments = {}) ⇒ Object
Check user privileges.
-
#invalidate_api_key(arguments = {}) ⇒ Object
Invalidate API keys.
-
#put_role(arguments = {}) ⇒ Object
Create or update roles.
-
#query_api_keys(arguments = {}) ⇒ Object
Find API keys with a query.
Instance Method Details
#authenticate(arguments = {}) ⇒ Object
Authenticate a user. Authenticates a user and returns information about the authenticated user. Include the user information in a basic auth header. 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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/elasticsearch-serverless/api/security/authenticate.rb', line 35 def authenticate(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.authenticate" } 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, request_opts) ) end |
#create_api_key(arguments = {}) ⇒ Object
Create an API key. Create 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/elasticsearch-serverless/api/security/create_api_key.rb', line 37 def create_api_key(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.create_api_key" } 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, request_opts) ) end |
#delete_role(arguments = {}) ⇒ Object
Delete roles. Delete roles in the native realm.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/elasticsearch-serverless/api/security/delete_role.rb', line 34 def delete_role(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.delete_role" } defined_params = [:name].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? raise ArgumentError, "Required argument 'name' missing" unless arguments[:name] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil _name = arguments.delete(:name) method = ElasticsearchServerless::API::HTTP_DELETE path = "_security/role/#{Utils.listify(_name)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#get_api_key(arguments = {}) ⇒ Object
Get API key information. 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/elasticsearch-serverless/api/security/get_api_key.rb', line 51 def get_api_key(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.get_api_key" } 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, request_opts) ) end |
#get_builtin_privileges(arguments = {}) ⇒ Object
Get builtin privileges. Get the list of cluster privileges and index privileges that are available in this version of Elasticsearch.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/elasticsearch-serverless/api/security/get_builtin_privileges.rb', line 32 def get_builtin_privileges(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.get_builtin_privileges" } arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil method = ElasticsearchServerless::API::HTTP_GET path = "_security/privilege/_builtin" params = {} ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#get_role(arguments = {}) ⇒ Object
Get roles. Get roles in the native realm.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/elasticsearch-serverless/api/security/get_role.rb', line 33 def get_role(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.get_role" } defined_params = [:name].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? arguments = arguments.clone headers = arguments.delete(:headers) || {} body = nil _name = arguments.delete(:name) method = ElasticsearchServerless::API::HTTP_GET path = if _name "_security/role/#{Utils.listify(_name)}" else "_security/role" end params = Utils.process_params(arguments) if Array(arguments[:ignore]).include?(404) Utils.rescue_from_not_found { ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) } else ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end end |
#has_privileges(arguments = {}) ⇒ Object
Check user privileges. Determine whether the specified user has a specified list of privileges.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch-serverless/api/security/has_privileges.rb', line 34 def has_privileges(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.has_privileges" } defined_params = [:user].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? 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, request_opts) ) end |
#invalidate_api_key(arguments = {}) ⇒ Object
Invalidate API keys. This API invalidates API keys created by the create API key or grant API key APIs. Invalidated API keys fail authentication, but they can still be viewed using the get API key information and query API key information APIs, for at least the configured retention period, until they are automatically deleted. 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
username
andrealm_name
to match the user’s identity. -
Or, if the request is issued by an API key, that is to say an API key invalidates itself, specify its ID in the
ids
field.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/elasticsearch-serverless/api/security/invalidate_api_key.rb', line 40 def invalidate_api_key(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.invalidate_api_key" } 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, request_opts) ) end |
#put_role(arguments = {}) ⇒ Object
Create or update roles. The role management APIs are generally the preferred way to manage roles in the native realm, rather than using file-based role management. The create or update roles API cannot update roles that are defined in roles files. File-based role management is not available in Elastic Serverless.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/elasticsearch-serverless/api/security/put_role.rb', line 37 def put_role(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.put_role" } defined_params = [:name].inject({}) do |set_variables, variable| set_variables[variable] = arguments[variable] if arguments.key?(variable) set_variables end request_opts[:defined_params] = defined_params unless defined_params.empty? raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] raise ArgumentError, "Required argument 'name' missing" unless arguments[:name] arguments = arguments.clone headers = arguments.delete(:headers) || {} body = arguments.delete(:body) _name = arguments.delete(:name) method = ElasticsearchServerless::API::HTTP_PUT path = "_security/role/#{Utils.listify(_name)}" params = Utils.process_params(arguments) ElasticsearchServerless::API::Response.new( perform_request(method, path, params, body, headers, request_opts) ) end |
#query_api_keys(arguments = {}) ⇒ Object
Find API keys with a query. Get a paginated list of API keys and their information. You can optionally filter the results with a query.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/elasticsearch-serverless/api/security/query_api_keys.rb', line 37 def query_api_keys(arguments = {}) request_opts = { endpoint: arguments[:endpoint] || "security.query_api_keys" } 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, request_opts) ) end |