Skip to content

Commit

Permalink
[BUGS-5401] Look for status code in ssh-key:add response. (#2406)
Browse files Browse the repository at this point in the history
* Look for status code in ssh-key:add response.

* Print a human friendly message for ed25519 ssh key.

* Fix coding standards.
  • Loading branch information
kporras07 authored Nov 8, 2022
1 parent dd2016b commit b1eaece
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Collections/SSHKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function addKey($key_file)
'method' => 'post',
]
);
return (array)$response['data'];
return $response;
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/Commands/SSHKey/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,22 @@ class AddCommand extends TerminusCommand
*/
public function add($file)
{
$this->session()->getUser()->getSSHKeys()->addKey($file);
$response = $this->session()->getUser()->getSSHKeys()->addKey($file);
if ($response['status_code'] !== 200) {
$this->log()->error($this->getMessageToLog($response['data']));
return;
}
$this->log()->notice('Added SSH key from file {file}.', compact('file'));
}

/**
* Get a (maybe) human friendly message to show to the user.
*/
private function getMessageToLog($response_data)
{
if (trim($response_data) === "SSH validation failed: Unknown SSH key type 'ssh-ed25519'.") {
return "SSH keys of type 'ed25519' are not yet supported. Please use a different key type.";
}
return $response_data;
}
}

0 comments on commit b1eaece

Please sign in to comment.