diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index 7f53c2ff1..5b3747261 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -37,6 +37,7 @@ use OpenSearch\Namespaces\IndicesNamespace; use OpenSearch\Namespaces\IngestNamespace; use OpenSearch\Namespaces\NodesNamespace; +use OpenSearch\Namespaces\SecurityNamespace; use OpenSearch\Namespaces\SnapshotNamespace; use OpenSearch\Namespaces\SqlNamespace; use OpenSearch\Namespaces\TasksNamespace; @@ -134,6 +135,11 @@ class Client */ protected $searchableSnapshots; + /** + * @var SecurityNamespace + */ + protected $security; + /** * @var SslNamespace */ @@ -167,6 +173,7 @@ public function __construct(Transport $transport, callable $endpoint, array $reg $this->dataFrameTransformDeprecated = new DataFrameTransformDeprecatedNamespace($transport, $endpoint); $this->monitoring = new MonitoringNamespace($transport, $endpoint); $this->searchableSnapshots = new SearchableSnapshotsNamespace($transport, $endpoint); + $this->security = new SecurityNamespace($transport, $endpoint); $this->ssl = new SslNamespace($transport, $endpoint); $this->sql = new SqlNamespace($transport, $endpoint); @@ -1382,6 +1389,12 @@ public function searchableSnapshots(): SearchableSnapshotsNamespace { return $this->searchableSnapshots; } + + public function security(): SecurityNamespace + { + return $this->security; + } + public function ssl(): SslNamespace { return $this->ssl; diff --git a/src/OpenSearch/ClientBuilder.php b/src/OpenSearch/ClientBuilder.php index 15e515d87..ed8d9a8cb 100644 --- a/src/OpenSearch/ClientBuilder.php +++ b/src/OpenSearch/ClientBuilder.php @@ -620,8 +620,8 @@ public function build(): Client $registeredNamespaces = []; foreach ($this->registeredNamespacesBuilders as $builder) { /** - * @var NamespaceBuilderInterface $builder -*/ + * @var NamespaceBuilderInterface $builder + */ $registeredNamespaces[$builder->getName()] = $builder->getObject($this->transport, $this->serializer); } diff --git a/src/OpenSearch/Endpoints/Security/ChangePassword.php b/src/OpenSearch/Endpoints/Security/ChangePassword.php new file mode 100644 index 000000000..72a1960a1 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/ChangePassword.php @@ -0,0 +1,39 @@ +action_group)) { + throw new RuntimeException('Missing parameter for the endpoint security.create_action_group'); + } + + return "/_plugins/_security/api/actiongroups/$this->action_group"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $action_group + * @return CreateActionGroup + */ + public function setActionGroup(?string $action_group): CreateActionGroup + { + $this->action_group = $action_group; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/CreateRole.php b/src/OpenSearch/Endpoints/Security/CreateRole.php new file mode 100644 index 000000000..b53a94e15 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/CreateRole.php @@ -0,0 +1,60 @@ +role)) { + throw new RuntimeException('Missing parameter for the endpoint security.create_role'); + } + + return "/_plugins/_security/api/roles/$this->role"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $role + * @return CreateRole + */ + public function setRole(?string $role): CreateRole + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php b/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php new file mode 100644 index 000000000..a138d6d1d --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php @@ -0,0 +1,60 @@ +role)) { + throw new RuntimeException('Missing parameter for the endpoint security.create_role_mapping'); + } + + return "/_plugins/_security/api/rolesmapping/$this->role"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $role + * @return CreateRoleMapping + */ + public function setRole(?string $role): CreateRoleMapping + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/CreateTenant.php b/src/OpenSearch/Endpoints/Security/CreateTenant.php new file mode 100644 index 000000000..99da6088b --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/CreateTenant.php @@ -0,0 +1,56 @@ +tenant)) { + throw new RuntimeException('Missing parameter for the endpoint security.create_tenant'); + } + + return "/_plugins/_security/api/tenants/$this->tenant"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $tenant + * @return CreateTenant + */ + public function setTenant(?string $tenant): CreateTenant + { + $this->tenant = $tenant; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/CreateUser.php b/src/OpenSearch/Endpoints/Security/CreateUser.php new file mode 100644 index 000000000..d6990bc13 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/CreateUser.php @@ -0,0 +1,61 @@ +username)) { + throw new RuntimeException('Missing parameter for the endpoint security.create_user'); + } + + return "/_plugins/_security/api/internalusers/$this->username"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $username + * @return CreateUser + */ + public function setUsername(?string $username): CreateUser + { + $this->username = $username; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php b/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php new file mode 100644 index 000000000..412901f5e --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php @@ -0,0 +1,56 @@ +action_group)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_action_group'); + } + + return "/_plugins/_security/api/actiongroups/$this->action_group"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $action_group + * @return DeleteActionGroup + */ + public function setActionGroup(?string $action_group): DeleteActionGroup + { + $this->action_group = $action_group; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteDistinguishedNames.php b/src/OpenSearch/Endpoints/Security/DeleteDistinguishedNames.php new file mode 100644 index 000000000..38bc2a2d0 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteDistinguishedNames.php @@ -0,0 +1,56 @@ +cluster_name)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_distinguished_names'); + } + + return "/_plugins/_security/api/nodesdn/$this->cluster_name"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $cluster_name + * @return DeleteDistinguishedNames + */ + public function setClusterName(?string $cluster_name): DeleteDistinguishedNames + { + $this->cluster_name = $cluster_name; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteRole.php b/src/OpenSearch/Endpoints/Security/DeleteRole.php new file mode 100644 index 000000000..6d1824bb6 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteRole.php @@ -0,0 +1,56 @@ +role)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_role'); + } + + return "/_plugins/_security/api/roles/$this->role"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $role + * @return DeleteRole + */ + public function setRole(?string $role): DeleteRole + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php b/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php new file mode 100644 index 000000000..81d237c48 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php @@ -0,0 +1,56 @@ +role)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_role_mapping'); + } + + return "/_plugins/_security/api/rolesmapping/$this->role"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $role + * @return DeleteRoleMapping + */ + public function setRole(?string $role): DeleteRoleMapping + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteTenant.php b/src/OpenSearch/Endpoints/Security/DeleteTenant.php new file mode 100644 index 000000000..81b3b9495 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteTenant.php @@ -0,0 +1,56 @@ +tenant)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_tenant'); + } + + return "/_plugins/_security/api/tenants/$this->tenant"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $tenant + * @return DeleteTenant + */ + public function setTenant(?string $tenant): DeleteTenant + { + $this->tenant = $tenant; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/DeleteUser.php b/src/OpenSearch/Endpoints/Security/DeleteUser.php new file mode 100644 index 000000000..b5b6580d9 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/DeleteUser.php @@ -0,0 +1,56 @@ +username)) { + throw new RuntimeException('Missing parameter for the endpoint security.delete_user'); + } + + return "/_plugins/_security/api/internalusers/$this->username"; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + /** + * @param string|null $username + * @return DeleteUser + */ + public function setUsername(?string $username): DeleteUser + { + $this->username = $username; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/FlushCache.php b/src/OpenSearch/Endpoints/Security/FlushCache.php new file mode 100644 index 000000000..834d082e5 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/FlushCache.php @@ -0,0 +1,36 @@ +action_group ? "/{$this->action_group}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $action_group + * @return GetActionGroups + */ + public function setActionGroup(?string $action_group): GetActionGroups + { + $this->action_group = $action_group; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/GetCertificates.php b/src/OpenSearch/Endpoints/Security/GetCertificates.php new file mode 100644 index 000000000..bec2a9445 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/GetCertificates.php @@ -0,0 +1,36 @@ +cluster_name ? "/{$this->cluster_name}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $cluster_name + * @return GetDistinguishedNames + */ + public function setClusterName(?string $cluster_name): GetDistinguishedNames + { + $this->cluster_name = $cluster_name; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/GetRoleMappings.php b/src/OpenSearch/Endpoints/Security/GetRoleMappings.php new file mode 100644 index 000000000..a260ec995 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/GetRoleMappings.php @@ -0,0 +1,51 @@ +role ? "/{$this->role}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $role + * @return GetRoleMappings + */ + public function setRole(?string $role): GetRoleMappings + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/GetRoles.php b/src/OpenSearch/Endpoints/Security/GetRoles.php new file mode 100644 index 000000000..3ad4acce1 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/GetRoles.php @@ -0,0 +1,51 @@ +role ? "/{$this->role}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $role + * @return GetRoles + */ + public function setRole(?string $role): GetRoles + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/GetTenants.php b/src/OpenSearch/Endpoints/Security/GetTenants.php new file mode 100644 index 000000000..9a2487978 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/GetTenants.php @@ -0,0 +1,51 @@ +tenant ? "/{$this->tenant}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $tenant + * @return GetTenants + */ + public function setTenant(?string $tenant): GetTenants + { + $this->tenant = $tenant; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/GetUsers.php b/src/OpenSearch/Endpoints/Security/GetUsers.php new file mode 100644 index 000000000..a3d64269e --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/GetUsers.php @@ -0,0 +1,51 @@ +username ? "/{$this->username}" : ''); + } + + public function getMethod(): string + { + return 'GET'; + } + + /** + * @param string|null $username + * @return GetUsers + */ + public function setUsername(?string $username): GetUsers + { + $this->username = $username; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/Health.php b/src/OpenSearch/Endpoints/Security/Health.php new file mode 100644 index 000000000..cd1c9127a --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/Health.php @@ -0,0 +1,36 @@ +action_group ? "/{$this->action_group}" : ''); + } + + public function getMethod(): string + { + return 'PATCH'; + } + + /** + * @param string|null $action_group + * @return PatchActionGroups + */ + public function setActionGroup(?string $action_group): PatchActionGroups + { + $this->action_group = $action_group; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/PatchConfig.php b/src/OpenSearch/Endpoints/Security/PatchConfig.php new file mode 100644 index 000000000..57ae8bd84 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/PatchConfig.php @@ -0,0 +1,36 @@ +role ? "/{$this->role}" : ''); + } + + public function getMethod(): string + { + return 'PATCH'; + } + + /** + * @param string|null $role + * @return PatchRoleMappings + */ + public function setRole(?string $role): PatchRoleMappings + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/PatchRoles.php b/src/OpenSearch/Endpoints/Security/PatchRoles.php new file mode 100644 index 000000000..a9b40a1ae --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/PatchRoles.php @@ -0,0 +1,51 @@ +role ? "/{$this->role}" : ''); + } + + public function getMethod(): string + { + return 'PATCH'; + } + + /** + * @param string|null $role + * @return PatchRoles + */ + public function setRole(?string $role): PatchRoles + { + $this->role = $role; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/PatchTenants.php b/src/OpenSearch/Endpoints/Security/PatchTenants.php new file mode 100644 index 000000000..8a4de9257 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/PatchTenants.php @@ -0,0 +1,51 @@ +tenant ? "/{$this->tenant}" : ''); + } + + public function getMethod(): string + { + return 'PATCH'; + } + + /** + * @param string|null $tenant + * @return PatchTenants + */ + public function setTenant(?string $tenant): PatchTenants + { + $this->tenant = $tenant; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/PatchUsers.php b/src/OpenSearch/Endpoints/Security/PatchUsers.php new file mode 100644 index 000000000..af4ae7740 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/PatchUsers.php @@ -0,0 +1,52 @@ +username ? "/{$this->username}" : ''); + } + + public function getMethod(): string + { + return 'PATCH'; + } + + /** + * @param string|null $username + * @return PatchUsers + */ + public function setUsername(?string $username): PatchUsers + { + $this->username = $username; + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Security/UpdateConfig.php b/src/OpenSearch/Endpoints/Security/UpdateConfig.php new file mode 100644 index 000000000..b5eeaab82 --- /dev/null +++ b/src/OpenSearch/Endpoints/Security/UpdateConfig.php @@ -0,0 +1,38 @@ +cluster_name)) { + throw new RuntimeException('Missing parameter for the endpoint security.update_distinguished_names'); + } + + return "/_plugins/_security/api/nodesdn/{$this->cluster_name}"; + } + + public function getMethod(): string + { + return 'PUT'; + } + + /** + * @param string|null $cluster_name + * @return UpdateDistinguishedNames + */ + public function setClusterName(?string $cluster_name): UpdateDistinguishedNames + { + $this->cluster_name = $cluster_name; + return $this; + } +} diff --git a/src/OpenSearch/Namespaces/SecurityNamespace.php b/src/OpenSearch/Namespaces/SecurityNamespace.php new file mode 100644 index 000000000..5cbd88573 --- /dev/null +++ b/src/OpenSearch/Namespaces/SecurityNamespace.php @@ -0,0 +1,554 @@ +endpoints; + $endpoint = $endpointBuilder('Security\ChangePassword'); + $endpoint->setBody([ + 'current_password' => $this->extractArgument($params, 'current_password'), + 'password' => $this->extractArgument($params, 'password'), + ]); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['action_group'] = (string) The name of the action group to create + * $params['allowed_actions'] = (array) list of allowed actions + * + * @param array $params Associative array of parameters + * @return array + */ + public function createActionGroup(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateActionGroup'); + $endpoint->setBody([ + 'allowed_actions' => $this->extractArgument($params, 'allowed_actions'), + ]); + $endpoint->setActionGroup($this->extractArgument($params, 'action_group')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role to create + * $params['cluster_permissions'] = (array) + * $params['index_permissions'] = (array) + * $params['tenant_permissions'] = (array) + * + * @param array $params Associative array of parameters + * @return array + */ + public function createRole(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateRole'); + $endpoint->setBody([ + 'cluster_permissions' => $this->extractArgument($params, 'cluster_permissions'), + 'index_permissions' => $this->extractArgument($params, 'index_permissions'), + 'tenant_permissions' => $this->extractArgument($params, 'tenant_permissions'), + ]); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role mapping to create + * $params['backend_roles'] = (array) + * $params['hosts'] = (array) + * $params['users'] = (array) + * + * @param array $params Associative array of parameters + * @return array + */ + public function createRoleMapping(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateRoleMapping'); + $endpoint->setBody([ + 'backend_roles' => $this->extractArgument($params, 'backend_roles'), + 'hosts' => $this->extractArgument($params, 'hosts'), + 'users' => $this->extractArgument($params, 'users'), + ]); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['tenant'] = (string) The name of the tenant to create + * $params['description'] = (string) + * + * @param array $params Associative array of parameters + * @return array + */ + public function createTenant(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateTenant'); + $endpoint->setBody([ + 'description' => $this->extractArgument($params, 'description'), + ]); + $endpoint->setTenant($this->extractArgument($params, 'tenant')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['username'] = (string) The username to give the created user + * $params['password'] = (string) + * $params['opendistro_security_roles'] = (array) + * $params['backend_roles'] = (array) + * $params['attributes'] = (array) + * + * @param array $params Associative array of parameters + * @return array + */ + public function createUser(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\CreateUser'); + $endpoint->setBody([ + 'password' => $this->extractArgument($params, 'password'), + 'opendistro_security_roles' => $this->extractArgument($params, 'opendistro_security_roles'), + 'backend_roles' => $this->extractArgument($params, 'backend_roles'), + 'attributes' => $this->extractArgument($params, 'attributes'), + ]); + $endpoint->setUsername($this->extractArgument($params, 'username')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['action_group'] = (string) The name of the action group to delete + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteActionGroup(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteActionGroup'); + $endpoint->setActionGroup($this->extractArgument($params, 'action_group')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['cluster_name'] = (string) The name of the cluster to delete distinguished names from + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteDistinguishedNames(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteDistinguishedNames'); + $endpoint->setClusterName($this->extractArgument($params, 'cluster_name')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role to delete + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteRole(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteRole'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role mapping to delete + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteRoleMapping(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteRoleMapping'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['tenant'] = (string) The name of the tenant to delete + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteTenant(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteTenant'); + $endpoint->setTenant($this->extractArgument($params, 'tenant')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['username'] = (string) The username of the user to delete + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteUser(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\DeleteUser'); + $endpoint->setUsername($this->extractArgument($params, 'username')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * @param array $params Associative array of parameters + * @return array + */ + public function flushCache(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\FlushCache'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * @param array $params Associative array of parameters + * @return array + */ + public function getAccount(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetAccount'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['action_group'] = (string) The name of the action group to fetch, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getActionGroups(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetActionGroups'); + $endpoint->setActionGroup($this->extractArgument($params, 'action_group')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * @param array $params Associative array of parameters + * @return array + */ + public function getCertificates(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetCertificates'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * @param array $params Associative array of parameters + * @return array + */ + public function getConfig(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetConfig'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['cluster_name'] = (string) The name of the cluster to get distinguished names for, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getDistinguishedNames(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetDistinguishedNames'); + $endpoint->setClusterName($this->extractArgument($params, 'cluster_name')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role to get mappings for, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getRoleMappings(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetRoleMappings'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role fetch, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getRoles(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetRoles'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['tenant'] = (string) The name of the tenant to fetch, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getTenants(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetTenants'); + $endpoint->setTenant($this->extractArgument($params, 'tenant')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['username'] = (string) The username of the user to fetch, omit to fetch all (optional) + * + * @param array $params Associative array of parameters + * @return array + */ + public function getUsers(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\GetUsers'); + $endpoint->setUsername($this->extractArgument($params, 'username')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * @param array $params Associative array of parameters + * @return array + */ + public function health(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\Health'); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['action_group'] = (string) The name of the action group to update, omit to patch multiple (optional) + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchActionGroups(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchActionGroups'); + $endpoint->setActionGroup($this->extractArgument($params, 'action_group')); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchConfig(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchConfig'); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role mappings to update, omit to patch multiple (optional) + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchRoleMappings(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchRoleMappings'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['role'] = (string) The name of the role to update, omit to patch multiple (optional) + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchRoles(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchRoles'); + $endpoint->setRole($this->extractArgument($params, 'role')); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['tenant'] = (string) The name of the tenant to update, omit to patch multiple (optional) + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchTenants(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchTenants'); + $endpoint->setTenant($this->extractArgument($params, 'tenant')); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['username'] = (string) The username of the user to update, omit to patch multiple (optional) + * $params['ops'] = (array) List of operations to execute + * + * @param array $params Associative array of parameters + * @return array + */ + public function patchUsers(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\PatchUsers'); + $endpoint->setUsername($this->extractArgument($params, 'username')); + $endpoint->setBody($this->extractArgument($params, 'ops') ?? []); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['dynamic'] = (array) array of config options + * + * @param array $params Associative array of parameters + * @return array + */ + public function updateConfig(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\UpdateConfig'); + $endpoint->setBody([ + 'dynamic' => $this->extractArgument($params, 'dynamic'), + ]); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } + + /** + * $params['cluster_name'] = (string) name of cluster to add or update distinguished names for + * $params['nodes_dn'] = (array) distinguished names to add to cluster + * + * @param array $params Associative array of parameters + * @return array + */ + public function updateDistinguishedNames(array $params = []) + { + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Security\UpdateDistinguishedNames'); + $endpoint->setBody([ + 'nodes_dn' => $this->extractArgument($params, 'nodes_dn'), + ]); + $endpoint->setClusterName($this->extractArgument($params, 'cluster_name')); + $endpoint->setParams($params); + + return $this->performRequest($endpoint); + } +} diff --git a/tests/Namespaces/SecurityNamespaceTest.php b/tests/Namespaces/SecurityNamespaceTest.php new file mode 100644 index 000000000..496cde367 --- /dev/null +++ b/tests/Namespaces/SecurityNamespaceTest.php @@ -0,0 +1,1116 @@ +transport = $this->createMock(Transport::class); + $this->client = ClientBuilder::create() + ->setTransport($this->transport) + ->setSSLVerification(false) + ->build(); + } + + /** + * @return array + */ + public function methodProvider(): array + { + return array_map(function (ReflectionMethod $method) { + return [$method->name]; + }, array_filter( + (new ReflectionClass(SecurityNamespace::class))->getMethods(), + function (ReflectionMethod $method) { + return $method->class === SecurityNamespace::class; + } + )); + } + + /** + * @dataProvider methodProvider + */ + public function testWithInvalidParams(string $methodName): void + { + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('"invalid" is not a valid parameter.'); + + $this->client->security()->$methodName([ + 'invalid' => 'abc', + ]); + } + + public function testChangePassword(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/account', [], [ + 'password' => 'abc', + 'current_password' => 'abc', + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->changePassword([ + 'password' => 'abc', + 'current_password' => 'abc' + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateActionGroup(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/actiongroups/my_test_action_group', [], [ + 'allowed_actions' => ['indices:data/read*'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->createActionGroup([ + 'action_group' => 'my_test_action_group', + 'allowed_actions' => ['indices:data/read*'] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateActionGroupThrowsWithoutActionGroup(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.create_action_group'); + + $this->client->security()->createActionGroup([ + 'allowed_actions' => ['indices:data/read*'] + ]); + } + + public function testCreateRole(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/roles/my_test_role', [], [ + 'cluster_permissions' => [ + 'cluster_composite_ops', + 'indices_monitor' + ], + 'index_permissions' => [ + [ + 'index_patterns' => [ + 'movies*' + ], + 'dls' => '', + 'fls' => [], + 'masked_fields' => [], + 'allowed_actions' => [ + 'read' + ] + ] + ], + 'tenant_permissions' => [ + [ + 'tenant_patterns' => [ + 'human_resources' + ], + 'allowed_actions' => [ + 'kibana_all_read' + ] + ] + ] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->createRole([ + 'role' => 'my_test_role', + 'cluster_permissions' => [ + 'cluster_composite_ops', + 'indices_monitor' + ], + 'index_permissions' => [ + [ + 'index_patterns' => [ + 'movies*' + ], + 'dls' => '', + 'fls' => [], + 'masked_fields' => [], + 'allowed_actions' => [ + 'read' + ] + ] + ], + 'tenant_permissions' => [ + [ + 'tenant_patterns' => [ + 'human_resources' + ], + 'allowed_actions' => [ + 'kibana_all_read' + ] + ] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateRoleThrowsWithoutRole(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.create_role'); + + $this->client->security()->createRole([ + 'cluster_permissions' => [], + 'index_permissions' => [ + [ + 'index_patterns' => [ + 'test_index*' + ], + ] + ], + 'tenant_permissions' => [], + ]); + } + + public function testCreateRoleMapping(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], [ + 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], + 'hosts' => ['*.starfleetintranet.com'], + 'users' => ['worf'], + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->createRoleMapping([ + 'role' => 'my_test_role_mapping', + 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], + 'hosts' => ['*.starfleetintranet.com'], + 'users' => ['worf'], + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateRoleMappingThrowsWithoutRole(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.create_role_mapping'); + + $this->client->security()->createRoleMapping([ + 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], + 'hosts' => ['*.starfleetintranet.com'], + 'users' => ['worf'], + ]); + } + + public function testCreateTenant(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/tenants/my_test_tenant', [], [ + 'description' => 'My test tenant' + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->createTenant([ + 'tenant' => 'my_test_tenant', + 'description' => 'My test tenant' + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateTenantThrowsWithoutRole(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.create_tenant'); + + $this->client->security()->createTenant([ + 'description' => 'My test tenant' + ]); + } + + public function testCreateUser(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/internalusers/my_test_username', [], [ + 'password' => 'kirkpass', + 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], + 'backend_roles' => ['captains', 'starfleet'], + 'attributes' => [ + 'attribute1' => 'value1', + 'attribute2' => 'value2' + ] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->createUser([ + 'username' => 'my_test_username', + 'password' => 'kirkpass', + 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], + 'backend_roles' => ['captains', 'starfleet'], + 'attributes' => [ + 'attribute1' => 'value1', + 'attribute2' => 'value2' + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testCreateUserThrowsWithoutUsername(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.create_user'); + + $this->client->security()->createUser([ + 'password' => 'kirkpass', + 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], + 'backend_roles' => ['captains', 'starfleet'], + 'attributes' => [ + 'attribute1' => 'value1', + 'attribute2' => 'value2' + ] + ]); + } + + public function testDeleteActionGroup(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteActionGroup([ + 'action_group' => 'my_test_action_group', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteActionGroupThrowsWithoutActionGroupName(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_action_group'); + + $this->client->security()->deleteActionGroup(); + } + + public function testDeleteDistinguishedNames(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteDistinguishedNames([ + 'cluster_name' => 'my_test_cluster', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteDistinguishedNamesThrowsWithoutRoleName(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_distinguished_names'); + + $this->client->security()->deleteDistinguishedNames(); + } + + public function testDeleteRole(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/roles/my_test_role', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteRole([ + 'role' => 'my_test_role', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteRoleThrowsWithoutRole(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_role'); + + $this->client->security()->deleteRole(); + } + + public function testDeleteRoleMapping(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteRoleMapping([ + 'role' => 'my_test_role_mapping', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteRoleMappingThrowsWithoutRoleMappingName(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_role_mapping'); + + $this->client->security()->deleteRoleMapping(); + } + + public function testDeleteTenant(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/tenants/my_test_tenant', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteTenant([ + 'tenant' => 'my_test_tenant', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteTenantThrowsWithoutTenantName(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_tenant'); + + $this->client->security()->deleteTenant(); + } + + public function testDeleteUser(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/internalusers/my_test_user', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $result = $this->client->security()->deleteUser([ + 'username' => 'my_test_user', + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $result); + } + + public function testDeleteUserThrowsWithoutUsername(): void + { + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('Missing parameter for the endpoint security.delete_user'); + + $this->client->security()->deleteUser(); + } + + public function testFlushCache(): void + { + $this->transport->method('performRequest') + ->with('DELETE', '/_plugins/_security/api/cache', [], null); + + $this->client->security()->flushCache(); + } + + public function testGetAccount(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/account', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getAccount(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetActionGroups(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getActionGroups([ + 'action_group' => 'my_test_action_group', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetActionGroupsWithoutActionGroupName(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/actiongroups', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getActionGroups(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetCertificates(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_opendistro/_security/api/ssl/certs', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getCertificates(); + + static::assertSame([ + 'resource' => ['test_resource'], + ], $response); + } + + public function testGetConfig(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/securityconfig', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getConfig(); + + static::assertSame([ + 'resource' => ['test_resource'], + ], $response); + } + + public function testGetDistinguishedNames(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getDistinguishedNames([ + 'cluster_name' => 'my_test_cluster', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetDistinguishedNamesWithoutClusterName(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/nodesdn', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getDistinguishedNames(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetRoleMappings(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/rolesmapping/my_test_role', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getRoleMappings([ + 'role' => 'my_test_role', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetRoleMappingsWithoutRoleName(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/rolesmapping', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getRoleMappings(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetRoles(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/roles/my_test_role', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getRoles([ + 'role' => 'my_test_role', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetRolesWithoutActionGroupName(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/roles', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getRoles(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetTenants(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/tenants/my_test_tenant', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getTenants([ + 'tenant' => 'my_test_tenant', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetTenantsWithoutTenantName(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/tenants', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getTenants(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetUsers(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/internalusers/my_test_user', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getUsers([ + 'username' => 'my_test_user', + ]); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testGetUsersWithoutUsername(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/api/internalusers', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'resource' => ['test_resource'], + ]); + + $response = $this->client->security()->getUsers(); + + static::assertSame([ + 'resource' => ['test_resource'] + ], $response); + } + + public function testHealth(): void + { + $this->transport->method('performRequest') + ->with('GET', '/_plugins/_security/health', [], null); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->health(); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchActionGroups(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/actiongroups/my_test_action_group', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchActionGroups([ + 'action_group' => 'my_test_action_group', + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchActionGroupsWithoutActionGroupName(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/actiongroups', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchActionGroups([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchConfig(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/securityconfig', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchConfig([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchRoleMappings(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchRoleMappings([ + 'role' => 'my_test_role_mapping', + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchRoleMappingsWithoutRoleMappingName(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/rolesmapping', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchRoleMappings([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchRoles(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/roles/my_test_role', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchRoles([ + 'role' => 'my_test_role', + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchRolesWithoutRoleName(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/roles', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchRoles([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchTenants(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/tenants/my_test_tenant', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchTenants([ + 'tenant' => 'my_test_tenant', + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchTenantsWithoutRoleName(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/tenants', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchTenants([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchUsers(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/internalusers/my_test_user', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchUsers([ + 'username' => 'my_test_user', + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testPatchUsersWithoutUsername(): void + { + $this->transport->method('performRequest') + ->with('PATCH', '/_plugins/_security/api/internalusers', [], [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->patchUsers([ + 'ops' => [ + ['op' => 'remove', 'path' => '/index_permissions/0/dls'] + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testUpdateConfig(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/securityconfig/config', [], [ + 'dynamic' => [ + 'filtered_alias_mode' => 'warn', + ] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->updateConfig([ + 'dynamic' => [ + 'filtered_alias_mode' => 'warn', + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } + + public function testUpdateDistinguishedNames(): void + { + $this->transport->method('performRequest') + ->with('PUT', '/_plugins/_security/api/securityconfig/config', [], [ + 'dynamic' => [ + 'filtered_alias_mode' => 'warn', + ] + ]); + $this->transport->method('resultOrFuture') + ->willReturn([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ]); + + $response = $this->client->security()->updateConfig([ + 'dynamic' => [ + 'filtered_alias_mode' => 'warn', + ] + ]); + + static::assertSame([ + 'status' => 'OK', + 'message' => 'Stubbed response' + ], $response); + } +}