Skip to content

Commit

Permalink
Add security plugin client
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Cawser <[email protected]>
  • Loading branch information
Robin Cawser authored and shyim committed Feb 8, 2022
1 parent d6345b5 commit 7343d32
Show file tree
Hide file tree
Showing 35 changed files with 3,230 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/OpenSearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -134,6 +135,11 @@ class Client
*/
protected $searchableSnapshots;

/**
* @var SecurityNamespace
*/
protected $security;

/**
* @var SslNamespace
*/
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/OpenSearch/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
39 changes: 39 additions & 0 deletions src/OpenSearch/Endpoints/Security/ChangePassword.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Endpoints\AbstractEndpoint;

class ChangePassword extends AbstractEndpoint
{
public function getParamWhitelist(): array
{
return [
'current_password',
'password',
];
}

public function getURI(): string
{
return '/_plugins/_security/api/account';
}

public function getMethod(): string
{
return 'PUT';
}
}
59 changes: 59 additions & 0 deletions src/OpenSearch/Endpoints/Security/CreateActionGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class CreateActionGroup extends AbstractEndpoint
{
/**
* @var string|null
*/
protected $action_group;

public function getParamWhitelist(): array
{
return [
'allowed_actions'
];
}

public function getURI(): string
{
if (!isset($this->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;
}
}
60 changes: 60 additions & 0 deletions src/OpenSearch/Endpoints/Security/CreateRole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class CreateRole extends AbstractEndpoint
{
/**
* @var string|null
*/
protected $role;

public function getParamWhitelist(): array
{
return [
'cluster_permissions',
'index_permissions',
'tenant_permissions',
];
}

public function getURI(): string
{
if (!isset($this->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;
}
}
60 changes: 60 additions & 0 deletions src/OpenSearch/Endpoints/Security/CreateRoleMapping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class CreateRoleMapping extends AbstractEndpoint
{
/**
* @var string|null
*/
protected $role;

public function getParamWhitelist(): array
{
return [
'backend_roles',
'hosts',
'users',
];
}

public function getURI(): string
{
if (!isset($this->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;
}
}
56 changes: 56 additions & 0 deletions src/OpenSearch/Endpoints/Security/CreateTenant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class CreateTenant extends AbstractEndpoint
{
/**
* @var string|null
*/
protected $tenant;

public function getParamWhitelist(): array
{
return ['description'];
}

public function getURI(): string
{
if (!isset($this->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;
}
}
61 changes: 61 additions & 0 deletions src/OpenSearch/Endpoints/Security/CreateUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/**
* 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.
*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

namespace OpenSearch\Endpoints\Security;

use OpenSearch\Common\Exceptions\RuntimeException;
use OpenSearch\Endpoints\AbstractEndpoint;

class CreateUser extends AbstractEndpoint
{
/**
* @var string|null
*/
protected $username;

public function getParamWhitelist(): array
{
return [
'password',
'opendistro_security_roles',
'backend_roles',
'attributes',
];
}

public function getURI(): string
{
if (!isset($this->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;
}
}
Loading

0 comments on commit 7343d32

Please sign in to comment.