New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Adds machine token commands for 1.0 #1182
Conversation
@ronan, thanks for your PR! By analyzing the blame information on this pull request, we identified @TeslaDethray to be a potential reviewer |
// Find the token. Will throw an exception if it doesn't exist. | ||
$machine_token = $user->machine_tokens->get($machine_token_id); | ||
if (empty($machine_token)) { | ||
throw new \Exception(vsprintf('There are no machine tokens with the id %s.', [$machine_token_id]), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TeslaDethray: Is this the right way to handle command failures? Do we want to use more specific Exceptions (TerminusNotFoundException
for example).
I'm not in love with gluing the id into the error message before adding it to the Exception for language translation and management reasons but this is fine for now I guess.
2e5d912
to
2fd9ece
Compare
|
||
// Return the output data. | ||
return new RowsOfFields($data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yay!
bfdcfe6
to
cab83b1
Compare
@TeslaDethray I think this is more or less ready to go except the Behat tests won't pass until the Do we want to block this until we can get the Behat tests working? Or merge and iterate? |
The new FeatureContext.php should be loaded whenever you run the default_10 suite. @ronan |
@TeslaDethray Not in my experience. The global autoload seems to load up the old one: https://github.com/pantheon-systems/terminus/blob/master/tests/config/behat.yml#L2 Not sure what I'm doing wrong here. I did get it to work by making a |
@ronan Would it be possible to split the wonderful work you've done with the Session here into a separate PR? |
Yeah. that'll probably help unstick this. I'll have a new pr in a few mins |
cab83b1
to
34cd341
Compare
I got behat tests working but this requires:
And a rebase |
Those PRs all look mergable to me. |
afee69c
to
6305f0f
Compare
37f7115
to
a264d57
Compare
1 similar comment
Ok so this is passing now. All it's waiting for is guidance on the preferred way to implement the y/n delete confirmation |
There is an example of how to ask for missing arguments in #1206; however, |
|
||
$this->log()->notice('Deleting {token} ...', ['token' => $name]); | ||
$response = $machine_token->delete(); | ||
if ($response['status_code'] == 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be leaking the response status code out of the model here. I'd rather have delete()
throw an exception (which the command could simply let fall through to the runner for simplicity). That change will probably break the old stuff though so I don't know if I should proceed or leave it as is and try and clean it up later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By "break the old stuff" I mean "require a change to the old stuff" I woudn't leave the existing code in a broken state obviously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This status-code check must've persisted for some time because it's not necessary anymore. We can just remove it.
|
||
// Find the token. Will throw an exception if it doesn't exist. | ||
$machine_token = $user->machine_tokens->get($machine_token_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I'm letting the exception thrown by get()
fall through and get caught by the runner. This works fine (and saves a few lines of code) but the Robo runner isn't familiar with our translatable exceptions. That means the output when there is an error here is:
[error] Could not find {model} "{id}"
We have 3 options:
- Catch and rethrow here with a regular, untranslatable exception
- Override the runner to output a "translated" version of the exception error.
- Change TerminusException to do the replacement itself so that
getMessage()
always returns a valid error message
I favor #3. We'll have to revisit it a bit when we actually start looking at translating error messages, but it should be backwards compatible with the old Terminus runner and forwards compatible with the new one (while not prematurely interpolating error strings).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also favor approach approach 3.
@@ -94,17 +95,18 @@ public function delete($args, $assoc_args) { | |||
'Deleting {name} ...', | |||
array('name' => $name) | |||
); | |||
$response = $machine_token->delete(); | |||
if ($response['status_code'] == 200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How good of you to fix the original, too! 💐
@@ -17,15 +19,17 @@ public function __construct($attributes, array $options = []) { | |||
|
|||
/** | |||
* Deletes machine token | |||
* | |||
* @return array | |||
* @return null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be @return void
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stack Exchange / PHPDoc wiki page says to omit @return if the return type is void.
http://stackoverflow.com/questions/2061550/phpdoc-return-void-necessary
I have no objection if we knowingly wish to diverge from the standard, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't pass the linter without a @return
tag so I'll add @return void
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@greg-1-anderson This repo is already divergent.
@ronan Since PHP always returns null in the absence of a return, the difference between @return void
and @return null
is that void
denotes to users that its return value will be of no use to them. null
is used in conjunction with other possible return types, e.g. @return null|string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TeslaDethray I dig. Change made.
1 similar comment
+1 |
Requires: #1179This PR:
machine-token:list
,machine-token:delete
Still todo:
Get output working (requires rebase onto robo-runner branch)