Skip to content

Add-AzureRmAccount - Add position to Credential, update parameter sets #3042

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

Merged
merged 2 commits into from
Oct 11, 2016

Conversation

cormacpayne
Copy link
Member

@cormacpayne cormacpayne commented Sep 30, 2016

Comments

Fix for issue #2048 and #1102

Add position for Credential parameter so that the following is allowed:

Add-AzureRmAccount (Get-Credential)

Updated the parameter sets so that SubscriptionId and SubscriptionName are mutually exclusive. Parameter sets were split into two:

  • SubscriptionId is included but not required
  • SubscriptionName is include and required

This allows for either parameter to be used in a parameter set, but not both.


This checklist is used to make sure that common issues in a pull request are covered by the creator. You can find a more complete discussion of PowerShell cmdlet best practices here.

Below in Overall Changes, check off the boxes that apply to your PR. For the categories that you did not check off, you can remove them from this body. Within each of the categories that you did select, make sure that you can check off all of the boxes.

For information on cleaning up the commits in your pull request, click here.

Overall Changes

General

  • Title of the PR is clear and informative
  • There are a small number of commits that each have an informative message
  • If it applies, references the bug/issue that the PR fixes
  • All files have the Microsoft copyright header
  • Cmdlets refer to management libraries through nuget references - no dlls are checked in
  • The PR does not introduce breaking changes (unless a major version change occurs in the assembly and module)

Tests

  • PR includes test coverage for the included changes
  • Tests must use xunit, and should either use Moq to mock management client calls, or use the scenario test framework
  • PowerShell scripts used in tests must not use hard-coded values for location
  • PowerShell scripts used in tests should do any necessary setup as part of the test or suite setup, and should not use hard-coded values for existing resources
  • Tests should not use App.config files for settings
  • Tests should use the built-in PowerShell functions for generating random names when unique names are necessary - this will store names in the test recording
  • Tests should use Start-Sleep to pause rather than Thread.Sleep

Parameters

  • Cmdlets should have no more than four positional parameters
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets
  • Parameter types should not expose types from the management library - complex parameter types should be defined in the module
  • Complex parameter types are discouraged - a parameter type should be simple types as often as possible. If complex types are used, they should be shallow and easily creatable from a constructor or another cmdlet
  • Parameters should be explicitly marked as Mandatory or not, and should contain a HelpMessage
  • No parameter is of type object.
    • Management cmdlets should have the following parameters and aliases:
      • ResourceGroupName with (optional) alias to ResourceGroup type string marked as [ValueFromPipelineByPropertyName]
      • Name with alias to ResourceName type string marked as [ValueFromPipelineByPropertyName]
      • Location (if appropriate) type string
      • Tag, type HashTable

@cormacpayne cormacpayne changed the title Add-AzureRmAccount - Add position to Credential, update parameter sets [HOLD] Add-AzureRmAccount - Add position to Credential, update parameter sets Sep 30, 2016
@cormacpayne cormacpayne changed the title [HOLD] Add-AzureRmAccount - Add position to Credential, update parameter sets Add-AzureRmAccount - Add position to Credential, update parameter sets Oct 4, 2016
Copy link
Member

@markcowl markcowl left a comment

Choose a reason for hiding this comment

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

This looks great. One required comment and a nit

private const string AccessTokenParameterSet = "AccessToken";
private const string SubscriptionNameParameterSet = "SubscriptionName";
private const string SubscriptionIdParameterSet = "SubscriptionId";
private const string UserParameterSetWithSubscriptionId = "UserWithSubscriptionId";
Copy link
Member

Choose a reason for hiding this comment

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

Need to update the DefaultParameterSetName in the Cmdlet attribute to match one of the actual parameter sets (UserWithSubscriptionId is the best bet)

[Parameter(ParameterSetName = SubscriptionIdParameterSet, Mandatory = false, HelpMessage = "Optional credential")]
[Parameter(ParameterSetName = SubscriptionNameParameterSet, Mandatory = false, HelpMessage = "Optional credential")]

[Parameter(ParameterSetName = UserParameterSetWithSubscriptionId, Mandatory = false, HelpMessage = "Optional credential", Position = 0)]
Copy link
Member

Choose a reason for hiding this comment

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

Note: if there wasn't another change to make I would not make this comment. Please break the Parameter attributes over multiple lines so they are not so difficult to read in the default code review pane.

@cormacpayne
Copy link
Member Author

@markcowl addressed code review comments

@zephrxx
Copy link

zephrxx commented Jun 22, 2018

Doesn't work for 2 factor auth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants