|
27 | 27 | use Amp\Http\Client\HttpClient; |
28 | 28 | use Amp\Http\Client\Request; |
29 | 29 | use Amp\Http\Client\SocketException; |
| 30 | +use Bottledcode\DurablePhp\Events\Shares\Operation; |
30 | 31 | use Bottledcode\DurablePhp\Proxy\SpyProxy; |
31 | 32 | use Bottledcode\DurablePhp\State\Ids\StateId; |
32 | 33 | use Bottledcode\DurablePhp\State\OrchestrationInstance; |
@@ -147,7 +148,7 @@ public function startNew(string $name, array $args = [], ?string $id = null): Or |
147 | 148 | throw new Exception($result->getBody()->buffer()); |
148 | 149 | } |
149 | 150 |
|
150 | | - return (new StateId($result->getHeader('X-Id')))->toOrchestrationInstance(); |
| 151 | + return StateId::fromString($result->getHeader('X-Id'))->toOrchestrationInstance(); |
151 | 152 | } |
152 | 153 |
|
153 | 154 | #[Override] |
@@ -192,4 +193,64 @@ public function withAuth(string $token): void |
192 | 193 | { |
193 | 194 | $this->userToken = $token; |
194 | 195 | } |
| 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 | + } |
195 | 256 | } |
0 commit comments