Skip to content

Commit

Permalink
apparently the collab rm api is "weird"
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmith4-godaddy committed Oct 25, 2024
1 parent bdd4d7e commit 1fcee84
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 143 deletions.
91 changes: 4 additions & 87 deletions src/API/Accounts/AccountsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,19 @@ class AccountsClient extends BaseApiClient
{
protected $apiName = 'accounts';

public const TYPE_ADMIN = 'admin';
public const TYPE_EVENT = 'event';
public const TYPE_CONFIG = 'config';
public const TYPE_ISSUE = 'issue';
public const TYPE_CREDENTIALS = 'credentials';
public const TYPE_CONTACT = 'contact';
public const TYPE_REPORT = 'report';

// old stuff

public function addSshKey(string $accessToken, int $accountId, string $sshKey)
public function getCollaboratorAccess($accessToken, $accountId)
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->post("accounts/{$accountId}/ssh/keys", [
'json' => [
'key' => $sshKey
],
]);
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))->get("accounts/{$accountId}/access");
}

// everything from here down was copied over from mgmt, need to pare it to only the required bits


// definitely in use :)
public function listAccountCollaborators($accessToken, $accountId, string $access = 'from')
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->get(
"accounts/{$accountId}/collaborators",
[
'query' => [
'access' => $access,
],
]
);
}

// ditto
public function removeCollaboratorsForApp($accessToken, $accountId, $appId)
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->delete("accounts/{$accountId}/collaborators/apps/{$appId}");
}

// doesn't work - the client token doesn't have privs
public function getAdmins($accessToken, $supportId = null)
{
$query = [];

if (!empty($supportId)) {
$query['query']['supportId'] = $supportId;
}

return $this->guzzle($this->getBearerTokenMiddleware($accessToken))->get('accounts/admins', $query);
}

// fun!
// This API is both for removing access from individual apps, as well
// as removing access for whole accounts. fun!
/**
* @param string $accessToken
* @param int|string $targetAccountId
Expand Down Expand Up @@ -105,45 +61,6 @@ public function getApiKeys(string $token, array $accountIds)
);
}

public function fetchIds(string $token, bool $includeNonBilling = false)
{
$options = [];
if ($includeNonBilling) {
$options['query'] = ['nonbilling' => 'true'];
}

return $this->guzzle($this->getBearerTokenMiddleware($token))
->get('accounts/ids', $options);
}

public function updateAccountLimits(string $token, int $accountId, array $limits = [])
{
return $this->guzzle($this->getBearerTokenMiddleware($token))
->patch(sprintf('accounts/%d/limits', $accountId), [
'json' => $limits,
]);
}

public function setCellId(string $token, int $accountId, string $cellId)
{
return $this->guzzle($this->getBearerTokenMiddleware($token))
->patch("accounts/{$accountId}/cell-id", [
'json' => ['cellId' => $cellId],
]);
}


public function authenticateUser(string $accessToken, string $username, string $password)
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->post('accounts/authenticate', [
'json' => [
'username' => $username,
'password' => $password,
],
]);
}

public function listSshPublicKeys(
string $accessToken,
string $accountId,
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Accounts/AddSshKeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
}

try {
$this->api->addSshKey($token, $accountId, $key);
$this->api->createSshPublicKey($token, $accountId, $key);
} catch (ClientException $e) {
$output->writeln('<error>Could not upload ssh key.</error>');
$output->writeln(
Expand Down
51 changes: 0 additions & 51 deletions src/Command/Accounts/ListAdminsCommand.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Command/Accounts/ListCollabsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$accountId = $input->getArgument('accountId');
$token = $this->token->token;

$r = $this->api->listAccountCollaborators($token, $accountId);
$r = $this->api->getCollaboratorAccess($token, $accountId);
$output->writeln(json_encode(json_decode($r->getBody()->getContents()), JSON_PRETTY_PRINT));

return 0;
Expand Down
9 changes: 6 additions & 3 deletions src/Command/Accounts/RemoveCollabCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class RemoveCollabCommand extends Command
*/
protected $api;

// TODO should this have the option to remove a collaborator from the whole account, not just an app?
// or is that another command? (boggle)

public function __construct(AuthApi $authApi, AccountsClient $apps, $name = 'account:collabs:remove')
{
$this->authClient = $authApi;
Expand All @@ -32,18 +35,18 @@ public function configure()
$this
->setDescription('Remove collaborator from account')
->addArgument('accountId', InputArgument::REQUIRED, 'Account ID')
->addArgument('appId', InputArgument::REQUIRED, 'App ID')
->addArgument('collabId', InputArgument::REQUIRED, 'Collab User ID')
;
$this->addOauthOptions();
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$accountId = $input->getArgument('accountId');
$appId = $input->getArgument('appId');
$collabId = $input->getArgument('collabId');
$token = $this->token->token;

$r = $this->api->removeAccess($token, $accountId, $appId);
$r = $this->api->removeAccess($token, $accountId, $collabId);
$output->writeln(json_encode(json_decode($r->getBody()->getContents()), JSON_PRETTY_PRINT));

return 0;
Expand Down

0 comments on commit 1fcee84

Please sign in to comment.