]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add tenant indentifier list endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Tue, 18 Apr 2023 07:57:54 +0000 (09:57 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 20 Apr 2023 10:00:26 +0000 (12:00 +0200)
gui/baculum/protected/API/Pages/API/PluginM365TenantList.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

diff --git a/gui/baculum/protected/API/Pages/API/PluginM365TenantList.php b/gui/baculum/protected/API/Pages/API/PluginM365TenantList.php
new file mode 100644 (file)
index 0000000..c4164ef
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+
+use Baculum\Common\Modules\Errors\ClientError;
+use Baculum\Common\Modules\Errors\PluginError;
+use Baculum\Common\Modules\Errors\PluginM365Error;
+
+/**
+ * List Microsoft 365 plugin tenant identifiers.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class PluginM365TenantList extends BaculumAPIServer {
+
+       public function get() {
+               $misc = $this->getModule('misc');
+               $client = null;
+               $clientid = $this->Request->contains('id') ? (int)$this->Request['id'] : 0;
+               $result = $this->getModule('bconsole')->bconsoleCommand(
+                       $this->director,
+                       ['.client'],
+                       null,
+                       true
+               );
+               if ($result->exitcode === 0) {
+                       $client_val = $this->getModule('client')->getClientById($clientid);
+                       if (is_object($client_val) && in_array($client_val->name, $result->output)) {
+                               $client = $client_val->name;
+                       } else {
+                               $this->output = ClientError::MSG_ERROR_CLIENT_DOES_NOT_EXISTS;
+                               $this->error = ClientError::ERROR_CLIENT_DOES_NOT_EXISTS;
+                               return;
+                       }
+               } else {
+                       $this->output = PluginError::MSG_ERROR_WRONG_EXITCODE;
+                       $this->error = PluginError::ERROR_WRONG_EXITCODE;
+                       return;
+               }
+
+               $tenants = $this->getModule('fd_plugin_cfg')->getConfig('m365', $client);
+
+               $this->output = array_keys($tenants);
+               $this->error = PluginM365Error::ERROR_NO_ERRORS;
+       }
+}
index 49710576ae7d0923252a03e838fa1d7e75cdf55a..2f12e9a181644bac0cba02737ffa736a73253c82 100644 (file)
        <url ServiceParameter="PluginM365EmailAttachmentList" pattern="api/v2/plugins/m365/{id}/{tenantid}/emails/attachments/" parameters.id="\d+" parameters.tenantid="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="PluginM365EmailJobList" pattern="api/v2/plugins/m365/{id}/{tenantid}/jobs/" parameters.id="\d+" parameters.tenantid="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="PluginM365MailboxList" pattern="api/v2/plugins/m365/{id}/{tenantid}/mailboxes/" parameters.id="\d+" parameters.tenantid="[a-zA-Z0-9:.\-_ ]+" />
+       <url ServiceParameter="PluginM365TenantList" pattern="api/v2/plugins/m365/{id}/tenants/" parameters.id="\d+" />
        <!-- vSphere Plugin -->
        <url ServiceParameter="PluginVSphereListServers" pattern="api/v2/plugins/vsphere/{id}/servers" parameters.id="\d+" />
        <url ServiceParameter="PluginVSphereListHosts" pattern="api/v2/plugins/vsphere/{id}/hosts" parameters.id="\d+" />
index 7c0f91876ced36c1af20ecff9d3e8086f1b4381a..8e9f7a67559c5f87e61f7c93b3f4d4e6dfd4d0d5 100644 (file)
                                ]
                        }
                },
+               "/api/v2/plugins/m365/{clientid}/tenants": {
+                       "get": {
+                               "tags": ["plugins"],
+                               "summary": "Microsoft 365 plugin tenant identifier list",
+                               "description": "Get Microsoft 365 tenant identifier list.",
+                               "responses": {
+                                       "200": {
+                                               "description": "List of Microsoft 365 tenant identifiers.",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Tenant identifier"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/ClientId"
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/plugins/m365/{clientid}/users": {
                        "get": {
                                "tags": ["plugins"],
                                                                                "error": {
                                                                                        "type": "integer",
                                                                                        "description": "Error code",
-                                                                                       "enum": [0, 1, 4, 5, 6, 7, 11, 1000]
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
                                                                                }
                                                                        }
                                                                }
                                                                                "error": {
                                                                                        "type": "integer",
                                                                                        "description": "Error code",
-                                                                                       "enum": [0, 1, 4, 5, 6, 7, 11, 1000]
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
                                                                                }
                                                                        }
                                                                }
                                                                                "error": {
                                                                                        "type": "integer",
                                                                                        "description": "Error code",
-                                                                                       "enum": [0, 1, 4, 5, 6, 7, 11, 1000]
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
                                                                                }
                                                                        }
                                                                }
                                                                                "error": {
                                                                                        "type": "integer",
                                                                                        "description": "Error code",
-                                                                                       "enum": [0, 1, 4, 5, 6, 7, 11, 1000]
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
                                                                                }
                                                                        }
                                                                }
                                                                                "error": {
                                                                                        "type": "integer",
                                                                                        "description": "Error code",
-                                                                                       "enum": [0, 1, 4, 5, 6, 7, 11, 1000]
+                                                                                       "enum": [0, 1, 4, 5, 6, 7, 10, 11, 1000]
                                                                                }
                                                                        }
                                                                }