From 55e0561e880857f3a3b373d3208817232fe782bb Mon Sep 17 00:00:00 2001 From: Peter Pajor Date: Mon, 3 Jul 2023 12:55:33 +0200 Subject: [PATCH] LCH-6545: Add app id to the client constructor. --- src/ContentHubClient.php | 24 ++++++++++++------------ src/ObjectFactory.php | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/ContentHubClient.php b/src/ContentHubClient.php index 32f63225..9e7f9657 100644 --- a/src/ContentHubClient.php +++ b/src/ContentHubClient.php @@ -77,7 +77,8 @@ public function __construct( HmacAuthMiddleware $middleware, EventDispatcherInterface $dispatcher, array $config = [], - $api_version = 'v2' + string $app_id = '', + string $api_version = 'v2' ) { $this->logger = $logger; $this->settings = $settings; @@ -106,6 +107,10 @@ public function __construct( $config['headers']['X-Acquia-Plexus-Client-Id'] = $settings->getUuid(); } $config['headers']['User-Agent'] = $user_agent_string; + if (!$app_id) { + throw new \Exception('Content Hub App ID must be specified'); + } + $config['headers']['X-Acquia-Plexus-App-Id'] = $app_id; // Add the authentication handler. // @see https://github.com/acquia/http-hmac-spec @@ -165,10 +170,11 @@ public function definition($endpoint = '') { public static function register( LoggerInterface $logger, EventDispatcherInterface $dispatcher, - array $client_details, + string $name, string $url, string $api_key, string $secret, + string $app_id, string $api_version = 'v2' ) { $config = [ @@ -176,16 +182,11 @@ public static function register( 'headers' => [ 'Content-Type' => 'application/json', 'User-Agent' => ContentHubDescriptor::userAgent(), + 'X-Acquia-Plexus-App-Id' => $app_id, ], 'handler' => ObjectFactory::getHandlerStack(), ]; - $name = $client_details['name']; - $uuid = $client_details['uuid'] ?? ''; $body = ['name' => $name]; - if ($uuid) { - $body['originUUID'] = $uuid; - } - // Add the authentication handler. // @see https://github.com/acquia/http-hmac-spec @@ -203,7 +204,7 @@ public static function register( 'base_url' => $settings->getUrl(), ]; $client = ObjectFactory::getCHClient($logger, $settings, - $settings->getMiddleware(), $dispatcher, $config); + $settings->getMiddleware(), $dispatcher, $config, $app_id); // @todo remove this once shared secret is returned on the register // endpoint. // We need the shared secret to be fully functional, so an additional @@ -215,7 +216,7 @@ public static function register( $settings->getUuid(), $settings->getApiKey(), $settings->getSecretKey(), $settings->getUrl(), $remote['shared_secret']); return ObjectFactory::getCHClient($logger, $settings, - $settings->getMiddleware(), $dispatcher, $config); + $settings->getMiddleware(), $dispatcher, $config, $app_id); } catch (\Exception $exception) { if ($exception instanceof BadResponseException) { @@ -1423,8 +1424,7 @@ public function isFeatured(): bool { } public function getRemoteConfig(): array { - // Fetches it from /settings/client/:uuid. - return []; + return $this::getResponseJson($this->get('settings/client')) ?? []; } } diff --git a/src/ObjectFactory.php b/src/ObjectFactory.php index af526cb4..49551d27 100644 --- a/src/ObjectFactory.php +++ b/src/ObjectFactory.php @@ -122,10 +122,11 @@ public static function getCHClient( // phpcs:ignore HmacAuthMiddleware $middleware, EventDispatcherInterface $dispatcher, array $config, + string $app_id, string $api_version = 'v2' ): ContentHubClient { return new ContentHubClient($logger, $settings, $middleware, - $dispatcher, $config, $api_version); + $dispatcher, $config, $app_id, $api_version); } /**