Skip to content

Commit 47cade7

Browse files
authored
Remove support for pre-"Auth" APIs (#1372)
* Remove support for pre-"Auth" APIs * Remove unnecessary auth_api_enabled
1 parent dbc0e6c commit 47cade7

13 files changed

+38
-121
lines changed

config-defaults.yaml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,16 +263,10 @@ api:
263263
# though a recommendation will be displayed.
264264
write_user_ssh_config: null
265265

266-
# Whether the Auth API is enabled.
267-
auth: true
268-
269-
# Whether the API supports project invitations (requires "auth").
270-
invitations: false
271-
272-
# Whether the Organizations API is enabled (requires "auth").
266+
# Whether the Organizations API is enabled.
273267
organizations: false
274268

275-
# Whether Centralized User Management is available (requires "auth" and "organizations").
269+
# Whether Centralized User Management is available (requires "organizations").
276270
centralized_permissions: false
277271

278272
# Whether the projects list should be fetched from the newer "extended-access" API instead of "/me".
@@ -283,7 +277,7 @@ api:
283277
# This can be null for no filtering, or a string or a list of strings.
284278
vendor_filter: null
285279

286-
# Whether the User Verification APIs (/me/verification and /users/ID/phonenumber) are enabled (requires "auth").
280+
# Whether the User Verification APIs (/me/verification and /users/ID/phonenumber) are enabled.
287281
user_verification: false
288282

289283
# Whether the Metrics API is enabled.

config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ api:
5151

5252
ssh_domain_wildcards: ['*.platform.sh']
5353

54-
invitations: true
5554
organizations: true
5655
centralized_permissions: true
5756
user_verification: true

src/Command/ApiCurlCommand.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ class ApiCurlCommand extends CommandBase
99
{
1010
protected $hiddenInList = true;
1111

12-
public function isEnabled() {
13-
if (!$this->config()->has('api.base_url')) {
14-
return false;
15-
}
16-
17-
return parent::isEnabled();
18-
}
19-
2012
protected function configure()
2113
{
2214
$this->setName('api:curl')
@@ -27,7 +19,7 @@ protected function configure()
2719

2820
protected function execute(InputInterface $input, OutputInterface $output)
2921
{
30-
$url = $this->config()->get('api.base_url');
22+
$url = $this->config()->getApiUrl();
3123

3224
// Initialize the API service so that it gets CommandBase's event listeners
3325
// (allowing for auto login).

src/Command/Auth/AuthInfoCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5151
}
5252

5353
// Exit early if it's the user ID.
54-
if ($property === 'id' && $this->api()->authApiEnabled()) {
54+
if ($property === 'id') {
5555
$userId = $this->api()->getMyUserId($input->getOption('refresh'));
5656
if ($userId === false) {
5757
$this->stdErr->writeln('The current session is not associated with a user ID');

src/Command/Auth/AuthTokenCommand.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@ protected function configure()
2929
. ' Take care not to expose the token in a shared program or system, or to send the token to the wrong API domain.'
3030
);
3131
$executable = $this->config()->get('application.executable');
32+
$apiUrl = $this->config()->getApiUrl();
3233
$examples = [
3334
'Print the payload for JWT-formatted tokens' => \sprintf('%s auth:token -W | cut -d. -f2 | base64 -d', $executable),
35+
'Use the token in a curl command' => \sprintf('curl -H"$(%s auth:token -HW)" %s/users/me', $executable, rtrim($apiUrl, '/')),
3436
];
35-
if ($apiUrl = $this->config()->getWithDefault('api.base_url', '')) {
36-
$examples['Use the token in a curl command'] = \sprintf('curl -H"$(%s auth:token -HW)" %s/users/me', $executable, rtrim($apiUrl, '/'));
37-
}
3837
$help .= "\n\n<comment>Examples:</comment>";
3938
foreach ($examples as $description => $example) {
4039
$help .= "\n\n$description:\n <info>$example</info>";

src/Command/Auth/VerifyPhoneNumberCommand.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@ protected function configure()
2121

2222
public function isEnabled()
2323
{
24-
$config = $this->config();
25-
if (!$config->getWithDefault('api.user_verification', false)
26-
|| !$config->getWithDefault('api.auth', false)
27-
|| !$config->getWithDefault('api.base_url', '')) {
24+
if (!$this->config()->getWithDefault('api.user_verification', false)) {
2825
return false;
2926
}
3027
return parent::isEnabled();

src/Command/CommandBase.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -923,12 +923,7 @@ protected function addHiddenOption($name, $shortcut = null, $mode = null, $descr
923923
protected function addProjectOption()
924924
{
925925
$this->addOption('project', 'p', InputOption::VALUE_REQUIRED, 'The project ID or URL');
926-
927-
if ($this->config()->getWithDefault('api.base_url', '') !== '') {
928-
$this->addHiddenOption('host', null, InputOption::VALUE_REQUIRED, 'Deprecated option, no longer used');
929-
} else {
930-
$this->addOption('host', null, InputOption::VALUE_REQUIRED, "The project's API hostname");
931-
}
926+
$this->addHiddenOption('host', null, InputOption::VALUE_REQUIRED, 'Deprecated option, no longer used');
932927

933928
return $this;
934929
}
@@ -1560,9 +1555,7 @@ final protected function validateInput(InputInterface $input, $envNotRequired =
15601555
$environmentId = null;
15611556

15621557
// Warn about using the deprecated --host option.
1563-
if ($this->config()->getWithDefault('api.base_url', '') !== '') {
1564-
$this->warnAboutDeprecatedOptions(['host']);
1565-
}
1558+
$this->warnAboutDeprecatedOptions(['host']);
15661559

15671560
// Identify the project.
15681561
if ($projectId !== null) {

src/Command/Organization/OrganizationCreateCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ private function getForm()
4646
'options' => $countryList,
4747
'asChoice' => false,
4848
'defaultCallback' => function () use ($countryList) {
49-
if ($this->api()->authApiEnabled()) {
50-
$userCountry = $this->api()->getUser()->country;
51-
if (isset($countryList[$userCountry])) {
52-
return $countryList[$userCountry];
53-
}
54-
return $userCountry ?: null;
49+
$userCountry = $this->api()->getUser()->country;
50+
if (isset($countryList[$userCountry])) {
51+
return $countryList[$userCountry];
5552
}
56-
return null;
53+
return $userCountry ?: null;
5754
},
5855
'normalizer' => function ($value) { return $this->normalizeCountryCode($value); },
5956
'validator' => function ($countryCode) use ($countryList) {

src/Command/Organization/OrganizationCurlCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
2222
{
2323
$organization = $this->validateOrganizationInput($input);
2424

25-
$apiUrl = Url::fromString($this->config()->get('api.base_url'));
25+
$apiUrl = Url::fromString($this->config()->getApiUrl());
2626
$absoluteUrl = $apiUrl->combine($organization->getUri())->__toString();
2727

2828
/** @var CurlCli $curl */

src/Command/User/UserAddCommand.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ protected function configure()
3030

3131
$this->addRoleOption();
3232

33-
if ($this->config()->getWithDefault('api.invitations', false)) {
34-
$this->addOption('force-invite', null, InputOption::VALUE_NONE, 'Send an invitation, even if one has already been sent');
35-
}
33+
$this->addOption('force-invite', null, InputOption::VALUE_NONE, 'Send an invitation, even if one has already been sent');
3634

3735
$this->addProjectOption();
3836
$this->addWaitOptions();
@@ -319,7 +317,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
319317
$this->stdErr->writeln('');
320318

321319
// If the user does not already exist on the project, then use the Invitations API.
322-
if (!$existingProjectAccess && $this->config()->getWithDefault('api.invitations', false)) {
320+
if (!$existingProjectAccess) {
323321
$this->stdErr->writeln('Inviting the user to the project...');
324322
$permissions = [];
325323
foreach ($desiredTypeRoles as $type => $role) {
@@ -343,14 +341,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
343341
}
344342

345343
// Make the desired changes at the project level.
346-
if (!$existingProjectAccess) {
347-
$this->stdErr->writeln("Adding the user to the project");
348-
$result = $project->addUser($email, $desiredProjectRole);
349-
$activities = $result->getActivities();
350-
/** @var ProjectAccess $projectAccess */
351-
$projectAccess = $result->getEntity();
352-
$userId = $projectAccess->id;
353-
} elseif ($existingProjectAccess->role !== $desiredProjectRole) {
344+
if ($existingProjectAccess->role !== $desiredProjectRole) {
354345
$this->stdErr->writeln("Setting the user's project role to: $desiredProjectRole");
355346
$result = $existingProjectAccess->update(['role' => $desiredProjectRole]);
356347
$activities = $result->getActivities();

src/Service/Api.php

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public function deleteAllSessions()
264264
*/
265265
private function getConnectorOptions() {
266266
$connectorOptions = [];
267-
$connectorOptions['api_url'] = $this->config->getWithDefault('api.base_url', '');
267+
$connectorOptions['api_url'] = $this->config->getApiUrl();
268268
if ($this->config->has('api.accounts_api_url')) {
269269
$connectorOptions['accounts'] = $this->config->get('api.accounts_api_url');
270270
}
@@ -312,7 +312,6 @@ private function getConnectorOptions() {
312312
return $this->onRefreshError($e);
313313
};
314314

315-
$connectorOptions['auth_api_enabled'] = $this->config->get('api.auth');
316315
$connectorOptions['centralized_permissions_enabled'] = $this->config->get('api.centralized_permissions');
317316

318317
return $connectorOptions;
@@ -641,20 +640,14 @@ public function getMyProjects($refresh = null)
641640
* Return the user's project with the given ID.
642641
*
643642
* @param string $id The project ID.
644-
* @param string|null $host The project's hostname. @deprecated no longer used if an api.base_url is configured.
643+
* @param string|null $host @deprecated no longer used
645644
* @param bool|null $refresh Whether to bypass the cache.
646645
*
647646
* @return Project|false
648647
*/
649648
public function getProject($id, $host = null, $refresh = null)
650649
{
651-
// Ignore the $host if an api.base_url is configured.
652-
$apiUrl = $this->config->getWithDefault('api.base_url', '');
653-
if ($apiUrl !== '') {
654-
$host = null;
655-
}
656-
657-
$cacheKey = sprintf('%s:project:%s:%s', $this->config->getSessionId(), $id, $host);
650+
$cacheKey = sprintf('%s:project:%s', $this->config->getSessionId(), $id);
658651
$cached = $this->cache->fetch($cacheKey);
659652

660653
if ($refresh || !$cached) {
@@ -679,10 +672,7 @@ public function getProject($id, $host = null, $refresh = null)
679672
$project = new Project($cached, $baseUrl, $guzzleClient);
680673
$this->debug('Loaded project from cache: ' . $id);
681674
}
682-
$apiUrl = $this->config->getWithDefault('api.base_url', '');
683-
if ($apiUrl) {
684-
$project->setApiUrl($apiUrl);
685-
}
675+
$project->setApiUrl($this->config->getApiUrl());
686676

687677
return $project;
688678
}
@@ -839,34 +829,14 @@ public function getEnvironmentTypes(Project $project, $refresh = null)
839829
* 'last_name': string,
840830
* 'display_name': string,
841831
* 'phone_number_verified': bool,
842-
* 'uuid'?: string
843832
* }
844833
*/
845834
public function getMyAccount($reset = false)
846835
{
847-
$info = ['id' => '', 'username' => '', 'email' => '', 'first_name' => '', 'last_name' => '', 'phone_number_verified' => false];
848-
if ($this->authApiEnabled()) {
849-
$user = $this->getUser(null, $reset);
850-
$info = array_merge($info, $user->getProperties());
851-
$info['display_name'] = trim($user->first_name . ' ' . $user->last_name);
852-
} else {
853-
$account = $this->getLegacyAccountInfo($reset);
854-
$info = [
855-
'id' => $account['id'],
856-
'username' => $account['username'],
857-
'email' => $account['mail'],
858-
'display_name' => $account['display_name'],
859-
];
860-
if (isset($account['display_name'])) {
861-
$parts = \explode(' ', $account['display_name'], 2);
862-
if (count($parts) === 2) {
863-
list($info['first_name'], $info['last_name']) = $parts;
864-
} else {
865-
$info['last_name'] = $account['display_name'];
866-
}
867-
}
868-
}
869-
return $info;
836+
$user = $this->getUser(null, $reset);
837+
return $user->getProperties() + [
838+
'display_name' => trim($user->first_name . ' ' . $user->last_name),
839+
];
870840
}
871841

872842
/**
@@ -900,16 +870,6 @@ public function getMyUserId($reset = false)
900870
return $this->getClient()->getMyUserId($reset);
901871
}
902872

903-
/**
904-
* Determines if the Auth API can be used, e.g. the getUser() method.
905-
*
906-
* @return bool
907-
*/
908-
public function authApiEnabled()
909-
{
910-
return $this->config->getWithDefault('api.auth', false) && $this->config->getWithDefault('api.base_url', '');
911-
}
912-
913873
/**
914874
* Get the logged-in user's SSH keys.
915875
*
@@ -921,7 +881,7 @@ public function getSshKeys($reset = false)
921881
{
922882
$data = $this->getLegacyAccountInfo($reset);
923883

924-
return SshKey::wrapCollection($data['ssh_keys'], rtrim($this->config->get('api.base_url'), '/') . '/', $this->getHttpClient());
884+
return SshKey::wrapCollection($data['ssh_keys'], rtrim($this->config->getApiUrl(), '/') . '/', $this->getHttpClient());
925885
}
926886

927887
/**
@@ -963,8 +923,6 @@ public function getAccount(ProjectAccess $access, $reset = false)
963923
*
964924
* This is from the /users API which deals with basic authentication-related data.
965925
*
966-
* @see Api::authApiEnabled()
967-
*
968926
* @param string|null $id
969927
* The user ID. Defaults to the current user.
970928
* @param bool $reset
@@ -973,9 +931,6 @@ public function getAccount(ProjectAccess $access, $reset = false)
973931
*/
974932
public function getUser($id = null, $reset = false)
975933
{
976-
if (!$this->config->getWithDefault('api.auth', false)) {
977-
throw new \BadMethodCallException('api.auth must be enabled for this method');
978-
}
979934
if ($id) {
980935
$cacheKey = 'user:' . $id;
981936
} else {

src/Service/Config.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,4 +679,14 @@ private function applyLocalDirectoryDefaults()
679679
}
680680
}
681681
}
682+
683+
/**
684+
* Returns the base API URL.
685+
*
686+
* @return string
687+
*/
688+
public function getApiUrl()
689+
{
690+
return (string) $this->get('api.base_url');
691+
}
682692
}

src/Service/SshDiagnostics.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,7 @@ public function diagnoseFailure($uri, Process $failedProcess)
216216

217217
$this->stdErr->writeln('The SSH connection failed because access requires MFA (multi-factor authentication).');
218218

219-
if (!$this->api->authApiEnabled()) {
220-
if ($this->config->has('api.mfa_setup_url')) {
221-
$this->stdErr->writeln(\sprintf(
222-
'Ensure that MFA is enabled on your account. Set it up at: <comment>%s</comment>',
223-
$this->config->get('api.mfa_setup_url')
224-
));
225-
$this->stdErr->writeln(\sprintf('Then log in again with: <comment>%s login -f</comment>', $executable));
226-
} else {
227-
$this->stdErr->writeln(\sprintf('Log in again with: <comment>%s login -f</comment>', $executable));
228-
}
229-
} elseif ($this->api->getUser()->mfa_enabled) {
219+
if ($this->api->getUser()->mfa_enabled) {
230220
$this->stdErr->writeln('MFA is currently enabled on your account, but reverification is required.');
231221
$this->stdErr->writeln(\sprintf('Log in again with: <comment>%s login -f</comment>', $executable));
232222
} else {

0 commit comments

Comments
 (0)