Skip to content

Commit

Permalink
LCH-6382: Add ability to specify origin uuid.
Browse files Browse the repository at this point in the history
  • Loading branch information
saxumVermes committed Jun 19, 2023
1 parent 27940ab commit 3c01641
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/ContentHubClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public function __construct(

// Setting up the headers.
$config['headers']['Content-Type'] = 'application/json';
$config['headers']['X-Acquia-Plexus-Client-Id'] = $settings->getUuid();
if ($settings->getUuid()) {
$config['headers']['X-Acquia-Plexus-Client-Id'] = $settings->getUuid();
}
$config['headers']['User-Agent'] = $user_agent_string;

// Add the authentication handler.
Expand Down Expand Up @@ -163,11 +165,11 @@ public function definition($endpoint = '') {
public static function register(
LoggerInterface $logger,
EventDispatcherInterface $dispatcher,
$name,
$url,
$api_key,
$secret,
$api_version = 'v2'
array $client_details,
string $url,
string $api_key,
string $secret,
string $api_version = 'v2'
) {
$config = [
'base_uri' => self::makeBaseURL($url, $api_version),
Expand All @@ -177,14 +179,21 @@ public static function register(
],
'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
$key = ObjectFactory::getAuthenticationKey($api_key, $secret);
$middleware = ObjectFactory::getHmacAuthMiddleware($key);
$config['handler']->push($middleware);
$client = ObjectFactory::getGuzzleClient($config);
$options['body'] = json_encode(['name' => $name]);
$options['body'] = json_encode($body);
try {
$response = $client->post('register', $options);
$values = self::getResponseJson($response);
Expand Down Expand Up @@ -1413,4 +1422,9 @@ public function isFeatured(): bool {
return $remote['featured'] ?? FALSE;
}

public function getRemoteConfig(): array {
// Fetches it from /settings/client/:uuid.
return [];
}

}

0 comments on commit 3c01641

Please sign in to comment.