From 7e618a23d0f428d2985456094ca0d7c00baeca45 Mon Sep 17 00:00:00 2001
From: ToshY <31921460+ToshY@users.noreply.github.com>
Date: Sun, 17 Nov 2024 19:18:31 +0100
Subject: [PATCH] added edge scripting secrets
---
docs/edge-scripting-api.md | 55 ++++++++
phpmd.baseline.xml | 1 +
src/EdgeScriptingAPI.php | 126 +++++++++++++++++-
src/Model/API/EdgeScripting/Secret/.gitkeep | 0
.../API/EdgeScripting/Secret/AddSecret.php | 41 ++++++
.../API/EdgeScripting/Secret/DeleteSecret.php | 29 ++++
.../API/EdgeScripting/Secret/ListSecrets.php | 29 ++++
.../API/EdgeScripting/Secret/UpdateSecret.php | 40 ++++++
.../API/EdgeScripting/Secret/UpsertSecret.php | 41 ++++++
.../EdgeScripting/Variable/UpsertVariable.php | 2 +-
10 files changed, 362 insertions(+), 2 deletions(-)
delete mode 100644 src/Model/API/EdgeScripting/Secret/.gitkeep
create mode 100644 src/Model/API/EdgeScripting/Secret/AddSecret.php
create mode 100644 src/Model/API/EdgeScripting/Secret/DeleteSecret.php
create mode 100644 src/Model/API/EdgeScripting/Secret/ListSecrets.php
create mode 100644 src/Model/API/EdgeScripting/Secret/UpdateSecret.php
create mode 100644 src/Model/API/EdgeScripting/Secret/UpsertSecret.php
diff --git a/docs/edge-scripting-api.md b/docs/edge-scripting-api.md
index eaa5002..e3d901a 100644
--- a/docs/edge-scripting-api.md
+++ b/docs/edge-scripting-api.md
@@ -212,6 +212,61 @@ $edgeScriptingApi->deleteVariable(
);
```
+### Secret
+
+#### [List Secrets](https://docs.bunny.net/reference/listedgescriptsecretsendpoint_listedgescriptsecrets)
+
+```php
+$edgeScriptingApi->listSecrets(
+ id: 1,
+);
+```
+
+#### [Add Secret](https://docs.bunny.net/reference/addedgescriptsecretendpoint_addedgescriptsecret)
+
+```php
+$edgeScriptingApi->addSecret(
+ id: 1,
+ body: [
+ 'Name' => 'VerySecretKey',
+ 'Secret' => 'V2UncmUgbm8gc3RyYW5nZXJzIHRvIGxvdmUKWW91IGtub3cgdGhlIHJ1bGVzIGFuZCBzbyBkbyBJIChEbyBJKQpBIGZ1bGwgY29tbWl0bWVudCdzIHdoYXQgSSdtIHRoaW5raW5nIG9mCllvdSB3b3VsZG4ndCBnZXQgdGhpcyBmcm9tIGFueSBvdGhlciBndXk=',
+ ],
+);
+```
+
+#### [Update Secret](https://docs.bunny.net/reference/updateedgescriptsecretendpoint_updateedgescriptsecret)
+
+```php
+$edgeScriptingApi->updateSecret(
+ id: 1,
+ secretId: 2,
+ body: [
+ 'Secret' => 'TmV2ZXIgZ29ubmEgZ2l2ZSB5b3UgdXAKTmV2ZXIgZ29ubmEgbGV0IHlvdSBkb3duCk5ldmVyIGdvbm5hIHJ1biBhcm91bmQgYW5kIGRlc2VydCB5b3UKTmV2ZXIgZ29ubmEgbWFrZSB5b3UgY3J5Ck5ldmVyIGdvbm5hIHNheSBnb29kYnllCk5ldmVyIGdvbm5hIHRlbGwgYSBsaWUgYW5kIGh1cnQgeW91',
+ ],
+);
+```
+
+#### [Upsert Secret](https://docs.bunny.net/reference/upsertedgescriptsecretendpoint_upsertedgescriptsecret)
+
+```php
+$edgeScriptingApi->upsertSecret(
+ id: 1,
+ body: [
+ 'Name' => 'VerySecretKey',
+ 'Secret' => 'SSBqdXN0IHdhbm5hIHRlbGwgeW91IGhvdyBJJ20gZmVlbGluZwpHb3R0YSBtYWtlIHlvdSB1bmRlcnN0YW5k',
+ ],
+);
+```
+
+#### [Delete Secret](https://docs.bunny.net/reference/deleteedgescriptsecretendpoint_deletesecret)
+
+```php
+$edgeScriptingApi->deleteSecret(
+ id: 1,
+ secretId: 2,
+);
+```
+
## Reference
* [Edge Scripting API](https://docs.bunny.net/reference/getedgescriptcodeendpoint_getcode)
diff --git a/phpmd.baseline.xml b/phpmd.baseline.xml
index 4cf4760..5956290 100644
--- a/phpmd.baseline.xml
+++ b/phpmd.baseline.xml
@@ -6,6 +6,7 @@
+
diff --git a/src/EdgeScriptingAPI.php b/src/EdgeScriptingAPI.php
index 85ea9ff..26d99e9 100644
--- a/src/EdgeScriptingAPI.php
+++ b/src/EdgeScriptingAPI.php
@@ -22,6 +22,11 @@
use ToshY\BunnyNet\Model\API\EdgeScripting\EdgeScript\UpdateEdgeScript;
use ToshY\BunnyNet\Model\API\EdgeScripting\Code\GetCode;
use ToshY\BunnyNet\Model\API\EdgeScripting\Code\SetCode;
+use ToshY\BunnyNet\Model\API\EdgeScripting\Secret\AddSecret;
+use ToshY\BunnyNet\Model\API\EdgeScripting\Secret\DeleteSecret;
+use ToshY\BunnyNet\Model\API\EdgeScripting\Secret\ListSecrets;
+use ToshY\BunnyNet\Model\API\EdgeScripting\Secret\UpdateSecret;
+use ToshY\BunnyNet\Model\API\EdgeScripting\Secret\UpsertSecret;
use ToshY\BunnyNet\Model\API\EdgeScripting\Variable\AddVariable;
use ToshY\BunnyNet\Model\API\EdgeScripting\Variable\DeleteVariable;
use ToshY\BunnyNet\Model\API\EdgeScripting\Variable\GetVariable;
@@ -199,7 +204,6 @@ public function listEdgeScripts(array $query = []): BunnyClientResponseInterface
);
}
-
/**
* @throws ClientExceptionInterface
* @throws Exception\BunnyClientResponseException
@@ -358,4 +362,124 @@ public function upsertVariable(
body: BodyContentHelper::getBody($body),
);
}
+
+ /**
+ * @throws ClientExceptionInterface
+ * @throws Exception\BunnyClientResponseException
+ * @throws Exception\JSONException
+ * @throws Exception\InvalidTypeForKeyValueException
+ * @throws Exception\InvalidTypeForListValueException
+ * @throws Exception\ParameterIsRequiredException
+ * @return BunnyClientResponseInterface
+ * @param int $id
+ * @param array $body
+ */
+ public function addSecret(
+ int $id,
+ array $body,
+ ): BunnyClientResponseInterface {
+ $endpoint = new AddSecret();
+
+ ParameterValidator::validate($body, $endpoint->getBody());
+
+ return $this->client->request(
+ endpoint: $endpoint,
+ parameters: [$id],
+ body: BodyContentHelper::getBody($body),
+ );
+ }
+
+ /**
+ * @throws ClientExceptionInterface
+ * @throws Exception\BunnyClientResponseException
+ * @throws Exception\JSONException
+ * @throws Exception\InvalidTypeForKeyValueException
+ * @throws Exception\InvalidTypeForListValueException
+ * @throws Exception\ParameterIsRequiredException
+ * @param int $id
+ * @return BunnyClientResponseInterface
+ */
+ public function listSecrets(int $id): BunnyClientResponseInterface
+ {
+ $endpoint = new ListSecrets();
+
+ return $this->client->request(
+ endpoint: $endpoint,
+ parameters: [$id],
+ );
+ }
+
+ /**
+ * @throws ClientExceptionInterface
+ * @throws Exception\BunnyClientResponseException
+ * @throws Exception\JSONException
+ * @throws Exception\InvalidTypeForKeyValueException
+ * @throws Exception\InvalidTypeForListValueException
+ * @throws Exception\ParameterIsRequiredException
+ * @param array $body
+ * @return BunnyClientResponseInterface
+ * @param int $id
+ */
+ public function upsertSecret(
+ int $id,
+ array $body,
+ ): BunnyClientResponseInterface {
+ $endpoint = new UpsertSecret();
+
+ ParameterValidator::validate($body, $endpoint->getBody());
+
+ return $this->client->request(
+ endpoint: $endpoint,
+ parameters: [$id],
+ body: BodyContentHelper::getBody($body),
+ );
+ }
+
+ /**
+ * @throws ClientExceptionInterface
+ * @throws Exception\BunnyClientResponseException
+ * @throws Exception\JSONException
+ * @param int $secretId
+ * @return BunnyClientResponseInterface
+ * @param int $id
+ */
+ public function deleteSecret(
+ int $id,
+ int $secretId,
+ ): BunnyClientResponseInterface {
+ $endpoint = new DeleteSecret();
+
+ return $this->client->request(
+ endpoint: $endpoint,
+ parameters: [$id, $secretId],
+ );
+ }
+
+ /**
+ * @throws ClientExceptionInterface
+ * @throws Exception\BunnyClientResponseException
+ * @throws Exception\JSONException
+ * @throws Exception\InvalidTypeForKeyValueException
+ * @throws Exception\InvalidTypeForListValueException
+ * @throws Exception\ParameterIsRequiredException
+ * @param int $secretId
+ * @param array $body
+ * @return BunnyClientResponseInterface
+ * @param int $id
+ */
+ public function updateSecret(
+ int $id,
+ int $secretId,
+ array $body,
+ ): BunnyClientResponseInterface {
+ $endpoint = new UpdateSecret();
+
+ ParameterValidator::validate($body, $endpoint->getBody());
+
+ return $this->client->request(
+ endpoint: $endpoint,
+ parameters: [$id, $secretId],
+ body: BodyContentHelper::getBody($body),
+ );
+ }
}
diff --git a/src/Model/API/EdgeScripting/Secret/.gitkeep b/src/Model/API/EdgeScripting/Secret/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/src/Model/API/EdgeScripting/Secret/AddSecret.php b/src/Model/API/EdgeScripting/Secret/AddSecret.php
new file mode 100644
index 0000000..253b784
--- /dev/null
+++ b/src/Model/API/EdgeScripting/Secret/AddSecret.php
@@ -0,0 +1,41 @@
+