3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
12 use Civi\Cxn\Rpc\Message\AppMetasMessage
;
13 use Civi\Cxn\Rpc\Message\GarbledMessage
;
16 * The CxnApp API provides a pseudo-entity for exploring the list
17 * of published applications. It is a read-only API which
18 * downloads and validates the application list from civicrm.org.
20 * At time of writing, this API only supports simple filtering on
21 * equality. If you'd like more advanced filters, consider updating
22 * _civicrm_api3_basic_array_get() and api_v3_UtilsTest::testBasicArrayGet.
24 * NOTE: SyntaxConformanceTest is disabled for CxnApp. As a rough
25 * equivalent, see api_v3_UtilsTest::testBasicArrayGet.
29 * Adjust metadata for "register" action.
34 function _civicrm_api3_cxn_app_get_spec(&$spec) {
37 'type' => CRM_Utils_Type
::T_TEXT
,
38 'title' => ts('Certificate'),
39 'description' => 'PEM-encoded certificate',
43 'type' => CRM_Utils_Type
::T_STRING
,
44 'title' => ts('Application GUID'),
45 'description' => 'Application GUID',
47 'size' => CRM_Utils_Type
::HUGE
,
51 'type' => CRM_Utils_Type
::T_STRING
,
52 'title' => ts('Registration URL'),
53 'description' => 'An endpoint to notify when performing registration',
55 'size' => CRM_Utils_Type
::HUGE
,
59 'type' => CRM_Utils_Type
::T_TEXT
,
60 'title' => ts('Description'),
61 'description' => 'Description',
63 //$spec['perm'] = array(
65 // 'type' => CRM_Utils_Type::T_TEXT,
66 // 'title' => ts('Permissions'),
67 // 'description' => 'Permissions expected for the service (struct)',
72 * Get a list of applications available for connections.
74 * @param array $params
76 * @throws API_Exception
77 * @throws CRM_Core_Exception
78 * @throws \Civi\Cxn\Rpc\Exception\InvalidMessageException
80 function civicrm_api3_cxn_app_get($params) {
81 // You should not change CIVICRM_CXN_APPS_URL in production; this is for local development.
82 $url = defined('CIVICRM_CXN_APPS_URL') ? CIVICRM_CXN_APPS_URL
: \Civi\Cxn\Rpc\Constants
::OFFICIAL_APPMETAS_URL
;
84 list ($headers, $blob, $code) = CRM_Cxn_CiviCxnHttp
::singleton()->send('GET', $url, '');
86 throw new API_Exception("Failed to download application list.");
89 $agent = new \Civi\Cxn\Rpc\
Agent(NULL, NULL);
90 $agent->setCertValidator(CRM_Cxn_BAO_Cxn
::createCertificateValidator());
91 $message = $agent->decode([AppMetasMessage
::NAME
, GarbledMessage
::NAME
], $blob);
93 if ($message instanceof AppMetasMessage
) {
94 return _civicrm_api3_basic_array_get('CxnApp', $params, $message->getData(), 'appId',
95 ['appId', 'appUrl', 'desc', 'appCert', 'perm']);
97 elseif ($message instanceof GarbledMessage
) {
98 return civicrm_api3_create_error('Received garbled response', [
99 'garbled_message' => $message->getData(),
103 return civicrm_api3_create_error("Unrecognized message");