EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
Add getSecret formula function (#3481)
Usame Beşir2ddfa39966a8
diff --git a/application/Espo/Core/Formula/Functions/ExtGroup/SecretGroup/GetType.php b/application/Espo/Core/Formula/Functions/ExtGroup/SecretGroup/GetType.phpnew file mode 100644index 0000000000..d9e735bf15--- /dev/null+++ b/application/Espo/Core/Formula/Functions/ExtGroup/SecretGroup/GetType.php@@ -0,0 +1,56 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2025 EspoCRM, Inc.+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Formula\Functions\ExtGroup\SecretGroup;++use Espo\Core\Formula\EvaluatedArgumentList;+use Espo\Core\Formula\Exceptions\BadArgumentType;+use Espo\Core\Formula\Exceptions\TooFewArguments;+use Espo\Core\Formula\Func;+use Espo\Tools\AppSecret\SecretProvider;++class GetType implements Func+{+ public function __construct(private SecretProvider $secretProvider) {}++ public function process(EvaluatedArgumentList $arguments): mixed+ {+ if (count($arguments) < 1) {+ throw TooFewArguments::create(1);+ }++ $string = $arguments[0];++ if (!is_string($string)) {+ throw BadArgumentType::create(1, 'string');+ }++ return $this->secretProvider->get($string);+ }+}diff --git a/application/Espo/Resources/metadata/app/formula.json b/application/Espo/Resources/metadata/app/formula.jsonindex a4ca0eeb6b..1e9c3b8ce0 100644--- a/application/Espo/Resources/metadata/app/formula.json+++ b/application/Espo/Resources/metadata/app/formula.json@@ -631,6 +631,11 @@"insertText": "ext\\oauth\\getAccessToken(ID)","returnType": "string","unsafe": true+ },+ {+ "name": "ext\\appSecret\\get",+ "insertText": "ext\\appSecret\\get(STRING)",+ "returnType": "string"}],"functionClassNameMap": {@@ -642,6 +647,7 @@"ext\\acl\\checkScope": "Espo\\Core\\Formula\\Functions\\ExtGroup\\AclGroup\\CheckScopeType","ext\\acl\\getLevel": "Espo\\Core\\Formula\\Functions\\ExtGroup\\AclGroup\\GetLevelType","ext\\acl\\getPermissionLevel": "Espo\\Core\\Formula\\Functions\\ExtGroup\\AclGroup\\GetPermissionLevelType",+ "ext\\appSecret\\get": "Espo\\Core\\Formula\\Functions\\ExtGroup\\SecretGroup\\GetType","util\\base64Encode": "Espo\\Core\\Formula\\Functions\\UtilGroup\\Base64EncodeType","util\\base64Decode": "Espo\\Core\\Formula\\Functions\\UtilGroup\\Base64DecodeType","ext\\oauth\\getAccessToken": "Espo\\Core\\Formula\\Functions\\ExtGroup\\OauthGroup\\GetAccessTokenType"