Files
opensearch-pyd/elasticsearch/client/security.py
T

498 lines
20 KiB
Python
Raw Normal View History

2020-04-23 11:22:08 -05:00
# Licensed to Elasticsearch B.V under one or more agreements.
# Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information
from .utils import NamespacedClient, query_params, _make_path, SKIP_IN_PATH
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
2018-03-20 12:36:13 -06:00
class SecurityClient(NamespacedClient):
@query_params()
2020-03-11 16:33:15 -05:00
def authenticate(self, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Enables authentication as a user and retrieve information about the
authenticated user.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-authenticate.html>`_
2018-03-20 12:36:13 -06:00
"""
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", "/_security/_authenticate", params=params, headers=headers
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def change_password(self, body, username=None, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Changes the passwords of users in the native realm and built-in users.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-change-password.html>`_
2018-03-20 12:36:13 -06:00
:arg body: the new password for the user
2019-12-17 22:31:35 +01:00
:arg username: The username of the user to change the password
for
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
"PUT",
_make_path("_security", "user", username, "_password"),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
body=body,
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("usernames")
2020-03-11 16:33:15 -05:00
def clear_cached_realms(self, realms, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Evicts users from the user cache. Can completely clear the cache or evict
specific users.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-clear-cache.html>`_
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
:arg realms: Comma-separated list of realms to clear
2019-12-17 22:31:35 +01:00
:arg usernames: Comma-separated list of usernames to clear from
the cache
2018-03-20 12:36:13 -06:00
"""
2019-03-29 09:25:23 -06:00
if realms in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'realms'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
"POST",
_make_path("_security", "realm", realms, "_clear_cache"),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
@query_params()
2020-03-11 16:33:15 -05:00
def clear_cached_roles(self, name, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Evicts roles from the native role cache.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-clear-role-cache.html>`_
2018-03-20 12:36:13 -06:00
:arg name: Role name
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"POST",
_make_path("_security", "role", name, "_clear_cache"),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def create_api_key(self, body, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Creates an API key for access without requiring basic authentication.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-create-api-key.html>`_
2019-03-29 09:25:23 -06:00
:arg body: The api key request to create an API key
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT", "/_security/api_key", params=params, headers=headers, body=body
2019-03-29 09:25:23 -06:00
)
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def delete_privileges(self, application, name, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Removes application privileges.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-delete-privilege.html>`_
2019-03-29 09:25:23 -06:00
:arg application: Application name
:arg name: Privilege name
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
for param in (application, name):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
"DELETE",
_make_path("_security", "privilege", application, name),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
)
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def delete_role(self, name, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Removes roles in the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-delete-role.html>`_
2018-03-20 12:36:13 -06:00
:arg name: Role name
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
_make_path("_security", "role", name),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def delete_role_mapping(self, name, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Removes role mappings.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-delete-role-mapping.html>`_
2018-03-20 12:36:13 -06:00
:arg name: Role-mapping name
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'name'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
_make_path("_security", "role_mapping", name),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def delete_user(self, username, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Deletes users from the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-delete-user.html>`_
2019-03-29 09:25:23 -06:00
:arg username: username
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'username'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
_make_path("_security", "user", username),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def disable_user(self, username, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Disables users in the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-disable-user.html>`_
2018-03-20 12:36:13 -06:00
:arg username: The username of the user to disable
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
2019-03-29 09:25:23 -06:00
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'username'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT",
_make_path("_security", "user", username, "_disable"),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def enable_user(self, username, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Enables users in the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-enable-user.html>`_
2018-03-20 12:36:13 -06:00
:arg username: The username of the user to enable
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
2019-03-29 09:25:23 -06:00
if username in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'username'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT",
_make_path("_security", "user", username, "_enable"),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2019-12-17 22:31:35 +01:00
@query_params("id", "name", "owner", "realm_name", "username")
2020-03-11 16:33:15 -05:00
def get_api_key(self, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves information for one or more API keys.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-api-key.html>`_
2019-03-29 09:25:23 -06:00
:arg id: API key id of the API key to be retrieved
:arg name: API key name of the API key to be retrieved
2019-12-17 22:31:35 +01:00
:arg owner: flag to query API keys owned by the currently
authenticated user
:arg realm_name: realm name of the user who created this API key
to be retrieved
:arg username: user name of the user who created this API key to
be retrieved
2019-03-29 09:25:23 -06:00
"""
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", "/_security/api_key", params=params, headers=headers
2019-03-29 09:25:23 -06:00
)
@query_params()
2020-03-11 16:33:15 -05:00
def get_privileges(self, application=None, name=None, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves application privileges.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-privileges.html>`_
2019-03-29 09:25:23 -06:00
:arg application: Application name
:arg name: Privilege name
"""
return self.transport.perform_request(
"GET",
_make_path("_security", "privilege", application, name),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
)
@query_params()
2020-03-11 16:33:15 -05:00
def get_role(self, name=None, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves roles in the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-role.html>`_
2019-03-29 09:25:23 -06:00
:arg name: Role name
"""
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", _make_path("_security", "role", name), params=params, headers=headers
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
@query_params()
2020-03-11 16:33:15 -05:00
def get_role_mapping(self, name=None, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves role mappings.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-role-mapping.html>`_
2018-03-20 12:36:13 -06:00
:arg name: Role-Mapping name
"""
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET",
_make_path("_security", "role_mapping", name),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
@query_params()
2020-03-11 16:33:15 -05:00
def get_token(self, body, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Creates a bearer token for access without requiring basic authentication.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-token.html>`_
2018-03-20 12:36:13 -06:00
:arg body: The token request to get
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"POST", "/_security/oauth2/token", params=params, headers=headers, body=body
2019-03-29 09:25:23 -06:00
)
@query_params()
2020-03-11 16:33:15 -05:00
def get_user(self, username=None, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves information about users in the native realm and built-in users.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-user.html>`_
2019-03-29 09:25:23 -06:00
:arg username: A comma-separated list of usernames
"""
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET",
_make_path("_security", "user", username),
params=params,
headers=headers,
2019-03-29 09:25:23 -06:00
)
@query_params()
2020-03-11 16:33:15 -05:00
def get_user_privileges(self, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Retrieves application privileges.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-privileges.html>`_
2019-03-29 09:25:23 -06:00
"""
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", "/_security/user/_privileges", params=params, headers=headers
2019-03-29 09:25:23 -06:00
)
@query_params()
2020-03-11 16:33:15 -05:00
def has_privileges(self, body, user=None, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Determines whether the specified user has a specified list of privileges.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-has-privileges.html>`_
2019-03-29 09:25:23 -06:00
:arg body: The privileges to test
:arg user: Username
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-13 13:44:46 -05:00
"POST",
2019-03-29 09:25:23 -06:00
_make_path("_security", "user", user, "_has_privileges"),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
body=body,
)
@query_params()
2020-03-11 16:33:15 -05:00
def invalidate_api_key(self, body, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Invalidates one or more API keys.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-invalidate-api-key.html>`_
2019-03-29 09:25:23 -06:00
:arg body: The api key request to invalidate API key(s)
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE", "/_security/api_key", params=params, headers=headers, body=body
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
@query_params()
2020-03-11 16:33:15 -05:00
def invalidate_token(self, body, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Invalidates one or more access tokens or refresh tokens.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-invalidate-token.html>`_
2018-03-20 12:36:13 -06:00
:arg body: The token to invalidate
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"DELETE",
"/_security/oauth2/token",
params=params,
headers=headers,
body=body,
2019-03-29 09:25:23 -06:00
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def put_privileges(self, body, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Adds or updates application privileges.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-put-privileges.html>`_
2019-03-29 09:25:23 -06:00
:arg body: The privilege(s) to add
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT", "/_security/privilege/", params=params, headers=headers, body=body
2019-03-29 09:25:23 -06:00
)
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def put_role(self, name, body, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Adds and updates roles in the native realm.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-put-role.html>`_
2019-03-29 09:25:23 -06:00
:arg name: Role name
:arg body: The role to add
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
for param in (name, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT",
_make_path("_security", "role", name),
params=params,
headers=headers,
body=body,
2019-03-29 09:25:23 -06:00
)
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def put_role_mapping(self, name, body, params=None, headers=None):
2018-03-20 12:36:13 -06:00
"""
2020-04-03 12:52:11 -05:00
Creates and updates role mappings.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-put-role-mapping.html>`_
2018-03-20 12:36:13 -06:00
:arg name: Role-mapping name
2019-12-17 22:31:35 +01:00
:arg body: The role mapping to add
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2018-03-20 12:36:13 -06:00
"""
for param in (name, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
"PUT",
_make_path("_security", "role_mapping", name),
params=params,
2020-03-11 16:33:15 -05:00
headers=headers,
2019-03-29 09:25:23 -06:00
body=body,
)
2018-03-20 12:36:13 -06:00
2019-03-29 09:25:23 -06:00
@query_params("refresh")
2020-03-11 16:33:15 -05:00
def put_user(self, username, body, params=None, headers=None):
2019-03-29 09:25:23 -06:00
"""
2020-04-03 12:52:11 -05:00
Adds and updates users in the native realm. These users are commonly referred
to as native users.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-put-user.html>`_
2019-03-29 09:25:23 -06:00
:arg username: The username of the User
:arg body: The user to add
2019-12-17 22:31:35 +01:00
:arg refresh: If `true` (the default) then refresh the affected
shards to make this operation visible to search, if `wait_for` then wait
for a refresh to make this operation visible to search, if `false` then
do nothing with refreshes. Valid choices: true, false, wait_for
2019-03-29 09:25:23 -06:00
"""
for param in (username, body):
if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
2019-12-17 22:31:35 +01:00
2019-03-29 09:25:23 -06:00
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"PUT",
_make_path("_security", "user", username),
params=params,
headers=headers,
body=body,
2019-03-29 09:25:23 -06:00
)
2019-12-17 22:31:35 +01:00
@query_params()
2020-03-11 16:33:15 -05:00
def get_builtin_privileges(self, params=None, headers=None):
2019-12-17 22:31:35 +01:00
"""
2020-04-03 12:52:11 -05:00
Retrieves the list of cluster privileges and index privileges that are
available in this version of Elasticsearch.
2020-04-23 11:22:08 -05:00
`<https://www.elastic.co/guide/en/elasticsearch/reference/7.x/security-api-get-builtin-privileges.html>`_
2019-12-17 22:31:35 +01:00
"""
return self.transport.perform_request(
2020-03-11 16:33:15 -05:00
"GET", "/_security/privilege/_builtin", params=params, headers=headers
2019-12-17 22:31:35 +01:00
)