Skip to content
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

Merged
merged 10 commits into from Sep 19, 2016
Merged

Conversation

ronan
Copy link
Contributor

@ronan ronan commented Sep 9, 2016

Requires: #1179

This PR:

  • Implements machine-token:list, machine-token:delete
  • Adds unit tests for above
  • Creates a new non-static Session object
  • Adds basis for DI of session object

Still todo:

  • Actual injection of session object using Robo container
  • Get behat tests working
  • Get output working (requires rebase onto robo-runner branch)

@pantheon-mentionbot
Copy link

@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);
Copy link
Contributor Author

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.


// Return the output data.
return new RowsOfFields($data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay!

@ronan ronan force-pushed the AL-538-machine-tokens-list branch 2 times, most recently from bfdcfe6 to cab83b1 Compare September 13, 2016 15:42
@ronan
Copy link
Contributor Author

ronan commented Sep 13, 2016

@TeslaDethray I think this is more or less ready to go except the Behat tests won't pass until the auth:login command is merged. And also until we can have a way of auto-loading the new FeatureContext.php class. Not sure how to do that.

Do we want to block this until we can get the Behat tests working? Or merge and iterate?

@TeslaDethray
Copy link
Contributor

The new FeatureContext.php should be loaded whenever you run the default_10 suite. @ronan

@ronan
Copy link
Contributor Author

ronan commented Sep 14, 2016

@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 behat-10.yml file and using that instead of behat.yml which seems much simpler. I still can't get my behat tests to authenticate though. I'll keep digging but I might be out of my depth a bit.

@TeslaDethray
Copy link
Contributor

@ronan Would it be possible to split the wonderful work you've done with the Session here into a separate PR?

@ronan
Copy link
Contributor Author

ronan commented Sep 14, 2016

Yeah. that'll probably help unstick this. I'll have a new pr in a few mins

@ronan
Copy link
Contributor Author

ronan commented Sep 14, 2016

I got behat tests working but this requires:

And a rebase

@greg-1-anderson
Copy link
Member

Those PRs all look mergable to me.

@coveralls
Copy link

coveralls commented Sep 15, 2016

Coverage Status

Coverage remained the same at 14.038% when pulling a264d57 on AL-538-machine-tokens-list into 8dde1f0 on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 14.038% when pulling a264d57 on AL-538-machine-tokens-list into 8dde1f0 on master.

@ronan
Copy link
Contributor Author

ronan commented Sep 15, 2016

Ok so this is passing now. All it's waiting for is guidance on the preferred way to implement the y/n delete confirmation

@TeslaDethray ^

@greg-1-anderson
Copy link
Member

There is an example of how to ask for missing arguments in #1206; however, interact isn't really the right answer for confirmation messages.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage remained the same at 14.038% when pulling 8d10b09 on AL-538-machine-tokens-list into 57a0568 on master.


$this->log()->notice('Deleting {token} ...', ['token' => $name]);
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Contributor

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);
Copy link
Contributor Author

@ronan ronan Sep 16, 2016

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:

  1. Catch and rethrow here with a regular, untranslatable exception
  2. Override the runner to output a "translated" version of the exception error.
  3. 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).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+1.4%) to 15.428% when pulling 18f73eb on AL-538-machine-tokens-list into 3af361d on master.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling 1df3b87 on AL-538-machine-tokens-list into e6e0e12 on master.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling 1df3b87 on AL-538-machine-tokens-list into e6e0e12 on master.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling 1df3b87 on AL-538-machine-tokens-list into e6e0e12 on master.

@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling f93a411 on AL-538-machine-tokens-list into 9415d9b on master.

@@ -94,17 +95,18 @@ public function delete($args, $assoc_args) {
'Deleting {name} ...',
array('name' => $name)
);
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling f76a18e on AL-538-machine-tokens-list into 9415d9b on master.

1 similar comment
@coveralls
Copy link

coveralls commented Sep 16, 2016

Coverage Status

Coverage increased (+0.07%) to 16.098% when pulling f76a18e on AL-538-machine-tokens-list into 9415d9b on master.

@TeslaDethray
Copy link
Contributor

+1

@ronan ronan merged commit cc0a0d7 into master Sep 19, 2016
@ronan ronan deleted the AL-538-machine-tokens-list branch September 19, 2016 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants