Skip to content

Commit

Permalink
LCH-6545: Add app id to the client constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
saxumVermes committed Jul 3, 2023
1 parent 3c01641 commit 55e0561
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -165,27 +170,23 @@ 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 = [
'base_uri' => self::makeBaseURL($url, $api_version),
'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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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')) ?? [];
}

}
3 changes: 2 additions & 1 deletion src/ObjectFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 55e0561

Please sign in to comment.