Updated Security Client APIs (#450)

Signed-off-by: saimedhi <[email protected]>
This commit is contained in:
Sai Medhini Reddy Maryada
2023-07-26 18:38:49 -04:00
committed by GitHub
parent 87b402c16e
commit caeaa13250
10 changed files with 311 additions and 120 deletions
+1
View File
@@ -22,6 +22,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added the ability to run tests matching a pattern to `.ci/run-tests` ([#454](https://github.com/opensearch-project/opensearch-py/pull/454)) - Added the ability to run tests matching a pattern to `.ci/run-tests` ([#454](https://github.com/opensearch-project/opensearch-py/pull/454))
### Changed ### Changed
- Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442)) - Moved security from `plugins` to `clients` ([#442](https://github.com/opensearch-project/opensearch-py/pull/442))
- Updated Security Client APIs ([#450](https://github.com/opensearch-project/opensearch-py/pull/450))
### Deprecated ### Deprecated
### Removed ### Removed
- Removed support for Python 2.7 ([#421](https://github.com/opensearch-project/opensearch-py/pull/421)) - Removed support for Python 2.7 ([#421](https://github.com/opensearch-project/opensearch-py/pull/421))
+2 -2
View File
@@ -26,7 +26,7 @@ role_content = {
], ],
} }
response = client.security.put_role(role_name, body=role_content) response = client.security.create_role(role_name, body=role_content)
print(response) print(response)
``` ```
@@ -45,7 +45,7 @@ print(response)
user_name = "test-user" user_name = "test-user"
user_content = {"password": "test_password", "opendistro_security_roles": []} user_content = {"password": "test_password", "opendistro_security_roles": []}
response = client.security.put_role(user_name, body=user_content) response = client.security.create_user(user_name, body=user_content)
print(response) print(response)
``` ```
+74 -44
View File
@@ -24,21 +24,19 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def change_password( async def change_password(self, body, params=None, headers=None):
self, current_password, password, params=None, headers=None
):
""" """
Changes the password for the current user. Changes the password for the current user.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
_make_path("_plugins", "_security", "api", "account"), _make_path("_plugins", "_security", "api", "account"),
params=params, params=params,
headers=headers, headers=headers,
body={ body=body,
"current_password": current_password,
"password": password,
},
) )
@query_params() @query_params()
@@ -88,14 +86,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_action_group(self, action_group, body, params=None, headers=None): async def create_action_group(self, action_group, body, params=None, headers=None):
""" """
Creates or replaces the specified action group. Creates or replaces the specified action group.
""" """
if action_group in SKIP_IN_PATH: for param in (action_group, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'action-group'." raise ValueError("Empty value passed for a required argument.")
)
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -110,10 +107,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of an action group. Updates individual attributes of an action group.
""" """
if action_group in SKIP_IN_PATH: for param in (action_group, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'action-group'." raise ValueError("Empty value passed for a required argument.")
)
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
@@ -128,6 +124,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple action groups in a single call. Creates, updates, or deletes multiple action groups in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "actiongroups"), _make_path("_plugins", "_security", "api", "actiongroups"),
@@ -179,12 +178,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_user(self, username, body, params=None, headers=None): async def create_user(self, username, body, params=None, headers=None):
""" """
Creates or replaces the specified user. Creates or replaces the specified user.
""" """
if username in SKIP_IN_PATH: for param in (username, body):
raise ValueError("Empty value passed for a required argument 'username'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -199,8 +199,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of an internal user. Updates individual attributes of an internal user.
""" """
if username in SKIP_IN_PATH: for param in (username, body):
raise ValueError("Empty value passed for a required argument 'username'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
@@ -215,6 +216,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple internal users in a single call. Creates, updates, or deletes multiple internal users in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "internalusers"), _make_path("_plugins", "_security", "api", "internalusers"),
@@ -266,12 +270,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_role(self, role, body, params=None, headers=None): async def create_role(self, role, body, params=None, headers=None):
""" """
Creates or replaces the specified role. Creates or replaces the specified role.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -286,8 +291,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of a role. Updates individual attributes of a role.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
@@ -302,6 +308,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple roles in a single call. Creates, updates, or deletes multiple roles in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "roles"), _make_path("_plugins", "_security", "api", "roles"),
@@ -338,7 +347,7 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def delete_role_mappings(self, role, params=None, headers=None): async def delete_role_mapping(self, role, params=None, headers=None):
""" """
Deletes the specified role mapping. Deletes the specified role mapping.
""" """
@@ -353,12 +362,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_role_mappings(self, role, body, params=None, headers=None): async def create_role_mapping(self, role, body, params=None, headers=None):
""" """
Creates or replaces the specified role mapping. Creates or replaces the specified role mapping.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -373,8 +383,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of a role mapping. Updates individual attributes of a role mapping.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
@@ -389,6 +400,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates or updates multiple role mappings in a single call. Creates or updates multiple role mappings in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "rolesmapping"), _make_path("_plugins", "_security", "api", "rolesmapping"),
@@ -440,12 +454,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_tenant(self, tenant, body, params=None, headers=None): async def create_tenant(self, tenant, body, params=None, headers=None):
""" """
Creates or replaces the specified tenant. Creates or replaces the specified tenant.
""" """
if tenant in SKIP_IN_PATH: for param in (tenant, body):
raise ValueError("Empty value passed for a required argument 'tenant'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -460,8 +475,9 @@ class SecurityClient(NamespacedClient):
""" """
Add, delete, or modify a single tenant. Add, delete, or modify a single tenant.
""" """
if tenant in SKIP_IN_PATH: for param in (tenant, body):
raise ValueError("Empty value passed for a required argument 'tenant'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
@@ -476,6 +492,9 @@ class SecurityClient(NamespacedClient):
""" """
Add, delete, or modify multiple tenants in a single call. Add, delete, or modify multiple tenants in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "tenants"), _make_path("_plugins", "_security", "api", "tenants"),
@@ -497,10 +516,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_configuration(self, body, params=None, headers=None): async def update_configuration(self, body, params=None, headers=None):
""" """
Retrieves the current Security plugin configuration in JSON format. Retrieves the current Security plugin configuration in JSON format.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
_make_path("_plugins", "_security", "api", "securityconfig", "config"), _make_path("_plugins", "_security", "api", "securityconfig", "config"),
@@ -514,6 +536,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates the existing configuration using the REST API. Updates the existing configuration using the REST API.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "securityconfig"), _make_path("_plugins", "_security", "api", "securityconfig"),
@@ -537,16 +562,15 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_distinguished_names( async def update_distinguished_names(
self, cluster_name, body, params=None, headers=None self, cluster_name, body, params=None, headers=None
): ):
""" """
Adds or updates the specified distinguished names in the cluster's or node's allow list. Adds or updates the specified distinguished names in the cluster's or node's allow list.
""" """
if cluster_name in SKIP_IN_PATH: for param in (cluster_name, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'cluster-name'." raise ValueError("Empty value passed for a required argument.")
)
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
@@ -648,10 +672,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
async def put_audit_configuration(self, body, params=None, headers=None): async def update_audit_config(self, body, params=None, headers=None):
""" """
A PUT call updates the audit configuration. A PUT call updates the audit configuration.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PUT", "PUT",
_make_path("_opendistro", "_security", "api", "audit", "config"), _make_path("_opendistro", "_security", "api", "audit", "config"),
@@ -665,6 +692,9 @@ class SecurityClient(NamespacedClient):
""" """
A PATCH call is used to update specified fields in the audit configuration. A PATCH call is used to update specified fields in the audit configuration.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return await self.transport.perform_request( return await self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_opendistro", "_security", "api", "audit"), _make_path("_opendistro", "_security", "api", "audit"),
+10 -11
View File
@@ -16,8 +16,7 @@ class SecurityClient(NamespacedClient):
) -> Any: ... ) -> Any: ...
async def change_password( async def change_password(
self, self,
current_password: Any, body: Any,
current_papasswordssword: Any,
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Any: ... ) -> Any: ...
@@ -36,7 +35,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Any: ... ) -> Any: ...
async def put_action_group( async def create_action_group(
self, self,
action_group: Any, action_group: Any,
body: Any, body: Any,
@@ -68,7 +67,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Any: ... ) -> Any: ...
async def put_user( async def create_user(
self, self,
username: Any, username: Any,
body: Any, body: Any,
@@ -94,7 +93,7 @@ class SecurityClient(NamespacedClient):
async def delete_role( async def delete_role(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def put_role( async def create_role(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def patch_role( async def patch_role(
@@ -109,10 +108,10 @@ class SecurityClient(NamespacedClient):
async def get_role_mappings( async def get_role_mappings(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def delete_role_mappings( async def delete_role_mapping(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def put_role_mappings( async def create_role_mapping(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def patch_role_mapping( async def patch_role_mapping(
@@ -136,7 +135,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Any: ... ) -> Any: ...
async def put_tenant( async def create_tenant(
self, self,
tenant: Any, tenant: Any,
body: Any, body: Any,
@@ -156,7 +155,7 @@ class SecurityClient(NamespacedClient):
async def get_configuration( async def get_configuration(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def put_configuration( async def update_configuration(
self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def patch_configuration( async def patch_configuration(
@@ -168,7 +167,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Any: ... ) -> Any: ...
async def put_distinguished_names( async def update_distinguished_names(
self, self,
cluster_name: Any, cluster_name: Any,
body: Any, body: Any,
@@ -199,7 +198,7 @@ class SecurityClient(NamespacedClient):
async def get_audit_configuration( async def get_audit_configuration(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def put_audit_configuration( async def update_audit_config(
self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Any: ... ) -> Any: ...
async def patch_audit_configuration( async def patch_audit_configuration(
+74 -42
View File
@@ -24,19 +24,19 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def change_password(self, current_password, password, params=None, headers=None): def change_password(self, body, params=None, headers=None):
""" """
Changes the password for the current user. Changes the password for the current user.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
_make_path("_plugins", "_security", "api", "account"), _make_path("_plugins", "_security", "api", "account"),
params=params, params=params,
headers=headers, headers=headers,
body={ body=body,
"current_password": current_password,
"password": password,
},
) )
@query_params() @query_params()
@@ -86,14 +86,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_action_group(self, action_group, body, params=None, headers=None): def create_action_group(self, action_group, body, params=None, headers=None):
""" """
Creates or replaces the specified action group. Creates or replaces the specified action group.
""" """
if action_group in SKIP_IN_PATH: for param in (action_group, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'action-group'." raise ValueError("Empty value passed for a required argument.")
)
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -108,10 +107,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of an action group. Updates individual attributes of an action group.
""" """
if action_group in SKIP_IN_PATH: for param in (action_group, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'action-group'." raise ValueError("Empty value passed for a required argument.")
)
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
@@ -126,6 +124,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple action groups in a single call. Creates, updates, or deletes multiple action groups in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "actiongroups"), _make_path("_plugins", "_security", "api", "actiongroups"),
@@ -177,12 +178,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_user(self, username, body, params=None, headers=None): def create_user(self, username, body, params=None, headers=None):
""" """
Creates or replaces the specified user. Creates or replaces the specified user.
""" """
if username in SKIP_IN_PATH: for param in (username, body):
raise ValueError("Empty value passed for a required argument 'username'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -197,8 +199,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of an internal user. Updates individual attributes of an internal user.
""" """
if username in SKIP_IN_PATH: for param in (username, body):
raise ValueError("Empty value passed for a required argument 'username'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
@@ -213,6 +216,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple internal users in a single call. Creates, updates, or deletes multiple internal users in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "internalusers"), _make_path("_plugins", "_security", "api", "internalusers"),
@@ -264,12 +270,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_role(self, role, body, params=None, headers=None): def create_role(self, role, body, params=None, headers=None):
""" """
Creates or replaces the specified role. Creates or replaces the specified role.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -284,8 +291,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of a role. Updates individual attributes of a role.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
@@ -300,6 +308,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates, updates, or deletes multiple roles in a single call. Creates, updates, or deletes multiple roles in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "roles"), _make_path("_plugins", "_security", "api", "roles"),
@@ -336,7 +347,7 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def delete_role_mappings(self, role, params=None, headers=None): def delete_role_mapping(self, role, params=None, headers=None):
""" """
Deletes the specified role mapping. Deletes the specified role mapping.
""" """
@@ -351,12 +362,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_role_mappings(self, role, body, params=None, headers=None): def create_role_mapping(self, role, body, params=None, headers=None):
""" """
Creates or replaces the specified role mapping. Creates or replaces the specified role mapping.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -371,8 +383,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates individual attributes of a role mapping. Updates individual attributes of a role mapping.
""" """
if role in SKIP_IN_PATH: for param in (role, body):
raise ValueError("Empty value passed for a required argument 'role'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
@@ -387,6 +400,9 @@ class SecurityClient(NamespacedClient):
""" """
Creates or updates multiple role mappings in a single call. Creates or updates multiple role mappings in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "rolesmapping"), _make_path("_plugins", "_security", "api", "rolesmapping"),
@@ -438,12 +454,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_tenant(self, tenant, body, params=None, headers=None): def create_tenant(self, tenant, body, params=None, headers=None):
""" """
Creates or replaces the specified tenant. Creates or replaces the specified tenant.
""" """
if tenant in SKIP_IN_PATH: for param in (tenant, body):
raise ValueError("Empty value passed for a required argument 'tenant'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -458,8 +475,9 @@ class SecurityClient(NamespacedClient):
""" """
Add, delete, or modify a single tenant. Add, delete, or modify a single tenant.
""" """
if tenant in SKIP_IN_PATH: for param in (tenant, body):
raise ValueError("Empty value passed for a required argument 'tenant'.") if param in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
@@ -474,6 +492,9 @@ class SecurityClient(NamespacedClient):
""" """
Add, delete, or modify multiple tenants in a single call. Add, delete, or modify multiple tenants in a single call.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "tenants"), _make_path("_plugins", "_security", "api", "tenants"),
@@ -495,10 +516,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_configuration(self, body, params=None, headers=None): def update_configuration(self, body, params=None, headers=None):
""" """
Retrieves the current Security plugin configuration in JSON format. Retrieves the current Security plugin configuration in JSON format.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
_make_path("_plugins", "_security", "api", "securityconfig", "config"), _make_path("_plugins", "_security", "api", "securityconfig", "config"),
@@ -512,6 +536,9 @@ class SecurityClient(NamespacedClient):
""" """
Updates the existing configuration using the REST API. Updates the existing configuration using the REST API.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_plugins", "_security", "api", "securityconfig"), _make_path("_plugins", "_security", "api", "securityconfig"),
@@ -533,14 +560,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_distinguished_names(self, cluster_name, body, params=None, headers=None): def update_distinguished_names(self, cluster_name, body, params=None, headers=None):
""" """
Adds or updates the specified distinguished names in the cluster's or node's allow list. Adds or updates the specified distinguished names in the cluster's or node's allow list.
""" """
if cluster_name in SKIP_IN_PATH: for param in (cluster_name, body):
raise ValueError( if param in SKIP_IN_PATH:
"Empty value passed for a required argument 'cluster-name'." raise ValueError("Empty value passed for a required argument.")
)
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
@@ -642,10 +668,13 @@ class SecurityClient(NamespacedClient):
) )
@query_params() @query_params()
def put_audit_configuration(self, body, params=None, headers=None): def update_audit_config(self, body, params=None, headers=None):
""" """
A PUT call updates the audit configuration. A PUT call updates the audit configuration.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PUT", "PUT",
_make_path("_opendistro", "_security", "api", "audit", "config"), _make_path("_opendistro", "_security", "api", "audit", "config"),
@@ -659,6 +688,9 @@ class SecurityClient(NamespacedClient):
""" """
A PATCH call is used to update specified fields in the audit configuration. A PATCH call is used to update specified fields in the audit configuration.
""" """
if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")
return self.transport.perform_request( return self.transport.perform_request(
"PATCH", "PATCH",
_make_path("_opendistro", "_security", "api", "audit"), _make_path("_opendistro", "_security", "api", "audit"),
+10 -11
View File
@@ -16,8 +16,7 @@ class SecurityClient(NamespacedClient):
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def change_password( def change_password(
self, self,
current_password: Any, body: Any,
current_papasswordssword: Any,
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
@@ -36,7 +35,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_action_group( def create_action_group(
self, self,
action_group: Any, action_group: Any,
body: Any, body: Any,
@@ -68,7 +67,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_user( def create_user(
self, self,
username: Any, username: Any,
body: Any, body: Any,
@@ -94,7 +93,7 @@ class SecurityClient(NamespacedClient):
def delete_role( def delete_role(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_role( def create_role(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def patch_role( def patch_role(
@@ -109,10 +108,10 @@ class SecurityClient(NamespacedClient):
def get_role_mappings( def get_role_mappings(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def delete_role_mappings( def delete_role_mapping(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_role_mappings( def create_role_mapping(
self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, role: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def patch_role_mapping( def patch_role_mapping(
@@ -136,7 +135,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_tenant( def create_tenant(
self, self,
tenant: Any, tenant: Any,
body: Any, body: Any,
@@ -156,7 +155,7 @@ class SecurityClient(NamespacedClient):
def get_configuration( def get_configuration(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_configuration( def update_configuration(
self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def patch_configuration( def patch_configuration(
@@ -168,7 +167,7 @@ class SecurityClient(NamespacedClient):
params: Union[Any, None] = ..., params: Union[Any, None] = ...,
headers: Union[Any, None] = ..., headers: Union[Any, None] = ...,
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_distinguished_names( def update_distinguished_names(
self, self,
cluster_name: Any, cluster_name: Any,
body: Any, body: Any,
@@ -199,7 +198,7 @@ class SecurityClient(NamespacedClient):
def get_audit_configuration( def get_audit_configuration(
self, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def put_audit_configuration( def update_audit_config(
self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ... self, body: Any, params: Union[Any, None] = ..., headers: Union[Any, None] = ...
) -> Union[bool, Any]: ... ) -> Union[bool, Any]: ...
def patch_audit_configuration( def patch_audit_configuration(
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
# A basic OpenSearch sample that create and manage roles.
from opensearchpy import OpenSearch
# connect to OpenSearch
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
client = OpenSearch(
hosts = [{'host': host, 'port': port}],
http_auth = auth,
use_ssl = True,
verify_certs = False,
ssl_show_warn = False
)
# Create a Role
role_name = "test-role"
role_content = {
"cluster_permissions": ["cluster_monitor"],
"index_permissions": [
{
"index_patterns": ["index", "test-*"],
"allowed_actions": [
"data_access",
"indices_monitor",
],
}
],
}
response = client.security.create_role(role_name, body=role_content)
print(response)
# Get a Role
role_name = "test-role"
response = client.security.get_role(role_name)
print(response)
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
# A basic OpenSearch sample that create and manage users.
from opensearchpy import OpenSearch
# connect to OpenSearch
host = 'localhost'
port = 9200
auth = ('admin', 'admin') # For testing only. Don't store credentials in code.
client = OpenSearch(
hosts = [{'host': host, 'port': port}],
http_auth = auth,
use_ssl = True,
verify_certs = False,
ssl_show_warn = False
)
# Create a User
user_name = "test-user"
user_content = {"password": "opensearch@123", "opendistro_security_roles": []}
response = client.security.create_user(user_name, body=user_content)
print(response)
# Get a User
user_name = "test-user"
response = client.security.get_user(user_name)
print(response)
@@ -52,13 +52,21 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase):
async def test_create_role(self): async def test_create_role(self):
# Test to create role # Test to create role
response = await self.client.security.put_role( response = await self.client.security.create_role(
self.ROLE_NAME, body=self.ROLE_CONTENT self.ROLE_NAME, body=self.ROLE_CONTENT
) )
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"]) self.assertIn(response.get("status"), ["CREATED", "OK"])
async def test_create_role_with_body_param_empty(self):
try:
await self.client.security.create_role(self.ROLE_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
async def test_get_role(self): async def test_get_role(self):
# Create a role # Create a role
await self.test_create_role() await self.test_create_role()
@@ -77,7 +85,7 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase):
role_content["cluster_permissions"] = ["cluster_all"] role_content["cluster_permissions"] = ["cluster_all"]
# Test to update role # Test to update role
response = await self.client.security.put_role( response = await self.client.security.create_role(
self.ROLE_NAME, body=role_content self.ROLE_NAME, body=role_content
) )
@@ -99,18 +107,26 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase):
async def test_create_user(self): async def test_create_user(self):
# Test to create user # Test to create user
response = await self.client.security.put_user( response = await self.client.security.create_user(
self.USER_NAME, body=self.USER_CONTENT self.USER_NAME, body=self.USER_CONTENT
) )
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"]) self.assertIn(response.get("status"), ["CREATED", "OK"])
async def test_create_user_with_body_param_empty(self):
try:
await self.client.security.create_user(self.USER_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
async def test_create_user_with_role(self): async def test_create_user_with_role(self):
await self.test_create_role() await self.test_create_role()
# Test to create user # Test to create user
response = await self.client.security.put_user( response = await self.client.security.create_user(
self.USER_NAME, self.USER_NAME,
body={ body={
"password": "opensearchpy@123", "password": "opensearchpy@123",
@@ -139,7 +155,7 @@ class TestSecurityPlugin(IsolatedAsyncioTestCase):
user_content["password"] = "123@opensearchpy" user_content["password"] = "123@opensearchpy"
# Test to update user # Test to update user
response = await self.client.security.put_user( response = await self.client.security.create_user(
self.USER_NAME, body=user_content self.USER_NAME, body=user_content
) )
@@ -46,11 +46,21 @@ class TestSecurityPlugin(TestCase):
def test_create_role(self): def test_create_role(self):
# Test to create role # Test to create role
response = self.client.security.put_role(self.ROLE_NAME, body=self.ROLE_CONTENT) response = self.client.security.create_role(
self.ROLE_NAME, body=self.ROLE_CONTENT
)
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"]) self.assertIn(response.get("status"), ["CREATED", "OK"])
def test_create_role_with_body_param_empty(self):
try:
self.client.security.create_role(self.ROLE_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
def test_get_role(self): def test_get_role(self):
# Create a role # Create a role
self.test_create_role() self.test_create_role()
@@ -69,7 +79,7 @@ class TestSecurityPlugin(TestCase):
role_content["cluster_permissions"] = ["cluster_all"] role_content["cluster_permissions"] = ["cluster_all"]
# Test to update role # Test to update role
response = self.client.security.put_role(self.ROLE_NAME, body=role_content) response = self.client.security.create_role(self.ROLE_NAME, body=role_content)
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertEqual("OK", response.get("status")) self.assertEqual("OK", response.get("status"))
@@ -89,16 +99,26 @@ class TestSecurityPlugin(TestCase):
def test_create_user(self): def test_create_user(self):
# Test to create user # Test to create user
response = self.client.security.put_user(self.USER_NAME, body=self.USER_CONTENT) response = self.client.security.create_user(
self.USER_NAME, body=self.USER_CONTENT
)
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertIn(response.get("status"), ["CREATED", "OK"]) self.assertIn(response.get("status"), ["CREATED", "OK"])
def test_create_user_with_body_param_empty(self):
try:
self.client.security.create_user(self.USER_NAME, body="")
except ValueError as error:
assert str(error) == "Empty value passed for a required argument."
else:
assert False
def test_create_user_with_role(self): def test_create_user_with_role(self):
self.test_create_role() self.test_create_role()
# Test to create user # Test to create user
response = self.client.security.put_user( response = self.client.security.create_user(
self.USER_NAME, self.USER_NAME,
body={ body={
"password": "opensearchpy@123", "password": "opensearchpy@123",
@@ -127,7 +147,7 @@ class TestSecurityPlugin(TestCase):
user_content["password"] = "123@opensearchpy" user_content["password"] = "123@opensearchpy"
# Test to update user # Test to update user
response = self.client.security.put_user(self.USER_NAME, body=user_content) response = self.client.security.create_user(self.USER_NAME, body=user_content)
self.assertNotIn("errors", response) self.assertNotIn("errors", response)
self.assertEqual("OK", response.get("status")) self.assertEqual("OK", response.get("status"))