Skip to content

Commit b1eaece

Browse files
authored
[BUGS-5401] Look for status code in ssh-key:add response. (#2406)
* Look for status code in ssh-key:add response. * Print a human friendly message for ed25519 ssh key. * Fix coding standards.
1 parent dd2016b commit b1eaece

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Collections/SSHKeys.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function addKey($key_file)
4444
'method' => 'post',
4545
]
4646
);
47-
return (array)$response['data'];
47+
return $response;
4848
}
4949

5050
/**

src/Commands/SSHKey/AddCommand.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,22 @@ class AddCommand extends TerminusCommand
2424
*/
2525
public function add($file)
2626
{
27-
$this->session()->getUser()->getSSHKeys()->addKey($file);
27+
$response = $this->session()->getUser()->getSSHKeys()->addKey($file);
28+
if ($response['status_code'] !== 200) {
29+
$this->log()->error($this->getMessageToLog($response['data']));
30+
return;
31+
}
2832
$this->log()->notice('Added SSH key from file {file}.', compact('file'));
2933
}
34+
35+
/**
36+
* Get a (maybe) human friendly message to show to the user.
37+
*/
38+
private function getMessageToLog($response_data)
39+
{
40+
if (trim($response_data) === "SSH validation failed: Unknown SSH key type 'ssh-ed25519'.") {
41+
return "SSH keys of type 'ed25519' are not yet supported. Please use a different key type.";
42+
}
43+
return $response_data;
44+
}
3045
}

0 commit comments

Comments
 (0)