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

On-board Location Based Services #5716

Closed
wants to merge 22 commits into from
Closed

On-board Location Based Services #5716

wants to merge 22 commits into from

Conversation

jp94
Copy link
Contributor

@jp94 jp94 commented Mar 1, 2018


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • The PR has modified HISTORY.rst describing any customer-facing, functional changes. Note that this does not include changes only to help content. (see Modifying change log).

Command Guidelines

  • Each command and parameter has a meaningful description.
  • Each new command has a test.

(see Authoring Command Modules)

@promptws
Copy link

promptws commented Mar 1, 2018

View a preview at https://prompt.ws/r/Azure/azure-cli/5716
This is an experimental preview for @microsoft users.

@tjprescott
Copy link
Member

PR being submitted for code review only.

Copy link
Member

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

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

Overall LGTM. A couple comments and questions.



# pylint: disable=line-too-long
def get_account(client, resource_group_name, account_name):
Copy link
Member

Choose a reason for hiding this comment

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

This can be simply reflected from the SDK.

:raises:
:class:`ErrorException<azure.mgmt.locationbasedservices.models.ErrorException>`
or :class:`ErrorException<knack.util.CLIError>`
"""
Copy link
Member

Choose a reason for hiding this comment

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

There are a few ways of supplying help text to the CLI. The docstring for a custom method is the only method that is actively discouraged. It would make more sense to put this in the help.py file so it is easier for people to find if they need to edit it (a docs feature) and because that system has more capabilities. If you just want to reuse help text across commands, then use the help kwarg in params.py.

if out.response.status_code == 404:
raise CLIError("The resource 'Microsoft.LocationBasedServices/accounts/" + account_name +
"' under resource group '" + resource_group_name + "' was not found.")
return out.output
Copy link
Member

Choose a reason for hiding this comment

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

If you did need to have a custom command for this, it should return:

return client.get(resource_group_name, account_name)

if not agree: # ... in order to pass ScenarioTest
response = prompt_y_n('I confirm that I have read and agree to the Microsoft Azure Preview Terms.')
if not response:
raise CLIError('You must agree to the Microsoft Azure Preview Terms to create an account.')
Copy link
Member

Choose a reason for hiding this comment

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

This is generally not used anywhere else for create commands. Is there a particular reason LBS would be different?

# Retrieve ClientRawResponse from get call
out = client.get(resource_group_name, account_name, raw=True)
# Handle 404 error
if out.response.status_code == 404:
Copy link
Member

Choose a reason for hiding this comment

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

Many show commands use error_handler=empty_on_404 kwarg in their command registrations specifically to avoid printing an error message.
This would be a very non-standard way of handling this error. My suggestions:

  1. follow suit with other commands and use empty_on_404
  2. Do nothing and see if the default error does what you want.
  3. Only if the error in 2 is inadequate or results in a stack trace, what a small error handler that accepts the incoming exception, processes it, and raise a CLIError.

@jp94
Copy link
Contributor Author

jp94 commented Mar 21, 2018

  • Removed custom get_account. Now uses default get function from the SDK.
  • Removed Public Preview Terms prompt.
  • Removed docs on custom.py Already supplied on _help.py.

Note on custom get_account

Our default behavior does not return anything (like empty_on_404).
Referring to az storage account show --name nonexistentaccount, I raised a CLIError instead.
az cognitiveservices --name nonexistentaccount does the same, but with a traceback.

All three behaviors are due to the way how RestAPI specs (Swagger) file is defined.
Our RestAPI specs will be updated by next actual PR, so this code was only a placeholder.

My team suggested that we show 404 errors.
But if CLI convention follows otherwise, I can do that, as noted with other modules using empty_on_404. Please let me know which would be an appropriate response.

Note Public Preview Terms prompt

Our service is currently on a Public Preview, but our actual PR will occur on our General Availability.
This prompt was added as a placeholder until General Availability.

@tjprescott
Copy link
Member

Hi @jp94 on the 404, here are some options:

  1. vm show: returns nothing by using empty_on_404. This is (obviously) acceptable and may become the expected standard for the CLI.
  2. storage account show: returns a CLIError. This is less common but currently acceptable.
  3. cognitiveservices account show: stack trace. This is NOT accepted. Anything that throws a strack trace is considered a bug.

Officially the recommendation is to go with option 1 as it allows you to distinguish between "the command succeeded and the thing isn't there (which you can see by the output)" and "the command failed".

@jp94
Copy link
Contributor Author

jp94 commented Mar 21, 2018

Cool. I will use empty_on_404 when we submit the actual PR.

@jp94 jp94 closed this Mar 21, 2018
@jp94 jp94 mentioned this pull request May 7, 2018
2 tasks
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.

4 participants