Skip to content

Commit b6d0f5b

Browse files
committed
add clients
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent 6c492ce commit b6d0f5b

5 files changed

Lines changed: 139 additions & 3 deletions

src/DurableClient.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,39 @@ public function grantEntityAccessToRole(EntityId $id, string $role, Operation $o
158158
{
159159
$this->entityClient->grantEntityAccessToRole($id, $role, $operation);
160160
}
161+
162+
public function revokeEntityAccessToUser(EntityId $id, string $user): void
163+
{
164+
$this->entityClient->revokeEntityAccessToUser($id, $user);
165+
}
166+
167+
public function revokeEntityAccessToRole(EntityId $id, string $role): void
168+
{
169+
$this->entityClient->revokeEntityAccessToRole($id, $role);
170+
}
171+
172+
public function shareOrchestrationOwnership(OrchestrationInstance $id, string $with): void
173+
{
174+
$this->orchestrationClient->shareOrchestrationOwnership($id, $with);
175+
}
176+
177+
public function grantOrchestrationAccessToUser(OrchestrationInstance $id, string $user, Operation $operation): void
178+
{
179+
$this->orchestrationClient->grantOrchestrationAccessToUser($id, $user, $operation);
180+
}
181+
182+
public function grantOrchestrationAccessToRole(OrchestrationInstance $id, string $role, Operation $operation): void
183+
{
184+
$this->orchestrationClient->grantOrchestrationAccessToRole($id, $role, $operation);
185+
}
186+
187+
public function revokeOrchestrationAccessToUser(OrchestrationInstance $id, string $user): void
188+
{
189+
$this->orchestrationClient->revokeOrchestrationAccessToUser($id, $user);
190+
}
191+
192+
public function revokeOrchestrationAccessToRole(OrchestrationInstance $id, string $role): void
193+
{
194+
$this->orchestrationClient->revokeOrchestrationAccessToRole($id, $role);
195+
}
161196
}

src/EntityClientInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ public function shareEntityOwnership(EntityId $id, string $with): void;
8787
public function grantEntityAccessToUser(EntityId $id, string $user, Operation $operation): void;
8888

8989
public function grantEntityAccessToRole(EntityId $id, string $role, Operation $operation): void;
90+
91+
public function revokeEntityAccessToUser(EntityId $id, string $user): void;
92+
93+
public function revokeEntityAccessToRole(EntityId $id, string $role): void;
9094
}

src/OrchestrationClientInterface.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@
2424

2525
namespace Bottledcode\DurablePhp;
2626

27+
use Bottledcode\DurablePhp\Events\Shares\Operation;
2728
use Bottledcode\DurablePhp\State\OrchestrationInstance;
2829
use Bottledcode\DurablePhp\State\Status;
30+
use Generator;
2931

3032
interface OrchestrationClientInterface
3133
{
3234
public function withAuth(string $token): void;
3335

3436
public function getStatus(OrchestrationInstance $instance): Status;
3537

36-
public function listInstances(/* todo */): \Generator;
38+
public function listInstances(/* todo */): Generator;
3739

3840
public function purge(OrchestrationInstance $instance): void;
3941

@@ -43,11 +45,21 @@ public function restart(OrchestrationInstance $instance): void;
4345

4446
public function resume(OrchestrationInstance $instance, string $reason): void;
4547

46-
public function startNew(string $name, array $args = [], string|null $id = null): OrchestrationInstance;
48+
public function startNew(string $name, array $args = [], ?string $id = null): OrchestrationInstance;
4749

4850
public function suspend(OrchestrationInstance $instance, string $reason): void;
4951

5052
public function terminate(OrchestrationInstance $instance, string $reason): void;
5153

5254
public function waitForCompletion(OrchestrationInstance $instance): void;
55+
56+
public function shareOrchestrationOwnership(OrchestrationInstance $id, string $with): void;
57+
58+
public function grantOrchestrationAccessToUser(OrchestrationInstance $id, string $user, Operation $operation): void;
59+
60+
public function grantOrchestrationAccessToRole(OrchestrationInstance $id, string $role, Operation $operation): void;
61+
62+
public function revokeOrchestrationAccessToUser(OrchestrationInstance $id, string $user): void;
63+
64+
public function revokeOrchestrationAccessToRole(OrchestrationInstance $id, string $role): void;
5365
}

src/RemoteEntityClient.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,28 @@ public function grantEntityAccessToRole(EntityId $id, string $role, Operation $o
200200
throw new Exception('Failed to grant access');
201201
}
202202
}
203+
204+
public function revokeEntityAccessToUser(EntityId $id, string $user): void
205+
{
206+
$req = new Request("{$this->apiHost}/entity/{$id->name}/{$id->id}/grant/user/{$user}", 'DELETE');
207+
if ($this->userToken) {
208+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
209+
}
210+
$result = $this->client->request($req);
211+
if ($result->getStatus() !== 200) {
212+
throw new Exception('Failed to grant access');
213+
}
214+
}
215+
216+
public function revokeEntityAccessToRole(EntityId $id, string $role): void
217+
{
218+
$req = new Request("{$this->apiHost}/entity/{$id->name}/{$id->id}/grant/role/{$role}", 'DELETE');
219+
if ($this->userToken) {
220+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
221+
}
222+
$result = $this->client->request($req);
223+
if ($result->getStatus() !== 200) {
224+
throw new Exception('Failed to grant access');
225+
}
226+
}
203227
}

src/RemoteOrchestrationClient.php

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Amp\Http\Client\HttpClient;
2828
use Amp\Http\Client\Request;
2929
use Amp\Http\Client\SocketException;
30+
use Bottledcode\DurablePhp\Events\Shares\Operation;
3031
use Bottledcode\DurablePhp\Proxy\SpyProxy;
3132
use Bottledcode\DurablePhp\State\Ids\StateId;
3233
use Bottledcode\DurablePhp\State\OrchestrationInstance;
@@ -147,7 +148,7 @@ public function startNew(string $name, array $args = [], ?string $id = null): Or
147148
throw new Exception($result->getBody()->buffer());
148149
}
149150

150-
return (new StateId($result->getHeader('X-Id')))->toOrchestrationInstance();
151+
return StateId::fromString($result->getHeader('X-Id'))->toOrchestrationInstance();
151152
}
152153

153154
#[Override]
@@ -192,4 +193,64 @@ public function withAuth(string $token): void
192193
{
193194
$this->userToken = $token;
194195
}
196+
197+
public function shareOrchestrationOwnership(OrchestrationInstance $id, string $with): void
198+
{
199+
$req = new Request("{$this->apiHost}/orchestration/{$id->instanceId}/{$id->executionId}/share/{$with}", 'PUT');
200+
if ($this->userToken) {
201+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
202+
}
203+
$result = $this->client->request($req);
204+
if ($result->getStatus() !== 200) {
205+
throw new Exception('Failed to share ownership');
206+
}
207+
}
208+
209+
public function grantOrchestrationAccessToUser(OrchestrationInstance $id, string $user, Operation $operation): void
210+
{
211+
$req = new Request("{$this->apiHost}/orchestration/{$id->instanceId}/{$id->executionId}/grant/user/{$user}/{$operation->value}", 'PUT');
212+
if ($this->userToken) {
213+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
214+
}
215+
$result = $this->client->request($req);
216+
if ($result->getStatus() !== 200) {
217+
throw new Exception('Failed to grant access');
218+
}
219+
}
220+
221+
public function grantOrchestrationAccessToRole(OrchestrationInstance $id, string $role, Operation $operation): void
222+
{
223+
$req = new Request("{$this->apiHost}/orchestration/{$id->instanceId}/{$id->executionId}/grant/role/{$role}/{$operation->value}", 'PUT');
224+
if ($this->userToken) {
225+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
226+
}
227+
$result = $this->client->request($req);
228+
if ($result->getStatus() !== 200) {
229+
throw new Exception('Failed to grant access');
230+
}
231+
}
232+
233+
public function revokeOrchestrationAccessToUser(OrchestrationInstance $id, string $user): void
234+
{
235+
$req = new Request("{$this->apiHost}/orchestration/{$id->instanceId}/{$id->executionId}/grant/user/{$user}", 'DELETE');
236+
if ($this->userToken) {
237+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
238+
}
239+
$result = $this->client->request($req);
240+
if ($result->getStatus() !== 200) {
241+
throw new Exception('Failed to grant access');
242+
}
243+
}
244+
245+
public function revokeOrchestrationAccessToRole(OrchestrationInstance $id, string $role): void
246+
{
247+
$req = new Request("{$this->apiHost}/orchestration/{$id->instanceId}/{$id->executionId}/grant/role/{$role}", 'DELETE');
248+
if ($this->userToken) {
249+
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
250+
}
251+
$result = $this->client->request($req);
252+
if ($result->getStatus() !== 200) {
253+
throw new Exception('Failed to grant access');
254+
}
255+
}
195256
}

0 commit comments

Comments
 (0)