1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AcquiaCloudApi\Endpoints; |
4
|
|
|
|
5
|
|
|
use AcquiaCloudApi\Connector\ClientInterface; |
6
|
|
|
use AcquiaCloudApi\Response\RolesResponse; |
7
|
|
|
use AcquiaCloudApi\Response\RoleResponse; |
8
|
|
|
use AcquiaCloudApi\Response\OperationResponse; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Client |
12
|
|
|
* @package AcquiaCloudApi\CloudApi |
13
|
|
|
*/ |
14
|
|
|
class Roles implements CloudApi |
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** @var ClientInterface The API client. */ |
18
|
|
|
protected $client; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Client constructor. |
22
|
|
|
* |
23
|
|
|
* @param ClientInterface $client |
24
|
|
|
*/ |
25
|
|
|
public function __construct(ClientInterface $client) |
26
|
|
|
{ |
27
|
|
|
$this->client = $client; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Show all roles in an organization. |
32
|
|
|
* |
33
|
|
|
* @param string $organizationUuid |
34
|
|
|
* @return RolesResponse |
35
|
|
|
*/ |
36
|
|
|
public function getAll($organizationUuid) |
37
|
|
|
{ |
38
|
|
|
return new RolesResponse( |
39
|
|
|
$this->client->request('get', "/organizations/${organizationUuid}/roles") |
|
|
|
|
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Return details about a specific role. |
45
|
|
|
* |
46
|
|
|
* @param string $roleUuid |
47
|
|
|
* @return RoleResponse |
48
|
|
|
*/ |
49
|
|
|
public function get($roleUuid) |
50
|
|
|
{ |
51
|
|
|
return new RoleResponse( |
52
|
|
|
$this->client->request('get', "/roles/${roleUuid}") |
|
|
|
|
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Create a new role. |
58
|
|
|
* |
59
|
|
|
* @param string $organizationUuid |
60
|
|
|
* @param string $name |
61
|
|
|
* @param array $permissions |
62
|
|
|
* @param null|string $description |
63
|
|
|
* @return OperationResponse |
64
|
|
|
*/ |
65
|
|
|
public function create($organizationUuid, $name, array $permissions, $description = null) |
66
|
|
|
{ |
67
|
|
|
$options = [ |
68
|
|
|
'form_params' => [ |
69
|
|
|
'name' => $name, |
70
|
|
|
'permissions' => $permissions, |
71
|
|
|
'description' => $description, |
72
|
|
|
], |
73
|
|
|
]; |
74
|
|
|
|
75
|
|
|
return new OperationResponse( |
76
|
|
|
$this->client->request('post', "/organizations/${organizationUuid}/roles", $options) |
|
|
|
|
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Update the permissions associated with a role. |
82
|
|
|
* |
83
|
|
|
* @param string $roleUuid |
84
|
|
|
* @param array $permissions |
85
|
|
|
* @return OperationResponse |
86
|
|
|
*/ |
87
|
|
|
public function update($roleUuid, array $permissions) |
88
|
|
|
{ |
89
|
|
|
$options = [ |
90
|
|
|
'form_params' => [ |
91
|
|
|
'permissions' => $permissions, |
92
|
|
|
], |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
return new OperationResponse( |
96
|
|
|
$this->client->request('put', "/roles/${roleUuid}", $options) |
|
|
|
|
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Delete a role. |
102
|
|
|
* |
103
|
|
|
* @param string $roleUuid |
104
|
|
|
* @return OperationResponse |
105
|
|
|
*/ |
106
|
|
|
public function delete($roleUuid) |
107
|
|
|
{ |
108
|
|
|
return new OperationResponse($this->client->request('delete', "/roles/${roleUuid}")); |
|
|
|
|
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|