Skip to content

IotHub Commandlets #3156

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

Closed
wants to merge 15 commits into from
Closed

IotHub Commandlets #3156

wants to merge 15 commits into from

Conversation

rkmanda
Copy link
Member

@rkmanda rkmanda commented Oct 29, 2016

Description


This checklist is used to make sure that common guidelines for a pull request are followed. You can find a more complete discussion of PowerShell cmdlet best practices here.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.
  • The pull request does not introduce breaking changes (unless a major version change occurs in the assembly and module).

Testing Guidelines

  • Pull request includes test coverage for the included changes.
  • 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 locations or existing resources.

Cmdlet Signature Guidelines

  • New cmdlets that make changes or have side effects should implement ShouldProcess and have SupportShouldProcess=true specified in the cmdlet attribute. You can find more information on ShouldProcess here.
  • Cmdlet specifies OutputType attribute if any output is produced - if the cmdlet produces no output, it should implement a PassThrough parameter.

Cmdlet Parameter Guidelines

  • 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.
  • Cmdlet parameter sets should be mutually exclusive - each parameter set must have at least one mandatory parameter not in other parameter sets.

rkmanda added 15 commits October 7, 2016 15:48
…o dev

# Conflicts:
#	src/ResourceManager/IotHub/Commands.IotHub.Test/Commands.IotHub.Test.csproj
#	src/ResourceManager/IotHub/Commands.IotHub/Commands.IotHub.csproj
#	src/ResourceManager/IotHub/Commands.IotHub/Common/IotHubBaseCmdlet.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSAccessRights.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSCapabilities.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSCloudToDeviceProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSDiagnosticCategory.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSEventHubProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSFeedbackProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSIotHub.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSIotHubProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSIotHubSku.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSIotHubSkuInfo.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSMessagingEndpointProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSOperationMonitoringLevel.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSOperationsMonitoringProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSSBAccessRights.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSSharedAccessAuthorizationRule.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSSharedAccessSignatureAuthorizationRule.cs
#	src/ResourceManager/IotHub/Commands.IotHub/Models/PSStorageEndpointProperties.cs
#	src/ResourceManager/IotHub/Commands.IotHub/packages.config
@azurecla
Copy link

Hi @rkmanda, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!


It looks like you're working at Microsoft (rmanda). If you're full-time, we DON'T require a contribution license agreement.



If you are a vendor, DO please sign the electronic contribution license agreement. It will take 2 minutes and there's no faxing! https://cla.azure.com.

TTYL, AZPRBOT;

@azuresdkci
Copy link

Can one of the admins verify this patch?

@markcowl
Copy link
Member

markcowl commented Nov 3, 2016

@azuresdkci add to whitelist

@markcowl
Copy link
Member

markcowl commented Nov 3, 2016

@rkmanda Since this is your first cmdlet release, please schedule a cmldte design review with our team

@markcowl markcowl changed the title IotHub Commandlets [Hold]: IotHub Commandlets Nov 3, 2016
@markcowl markcowl changed the title [Hold]: IotHub Commandlets IotHub Commandlets Nov 12, 2016
@markcowl
Copy link
Member

@rkmanda please fix build failures.

@cormacpayne
Copy link
Member

@rkmanda can you address the comment above?

Copy link
Member

@cormacpayne cormacpayne left a comment

Choose a reason for hiding this comment

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

@rkmanda a few extra comments:

  • There are a few cmdlets that have ResourceGroupName and Name as positional parameters, and the rest of the mandatory parameters do not have positions. Please resolve this issue and keep in mind that you should have at most four positional parameters in a cmdlet
  • All of the cmdlets that make changes implement SupportsShouldProcess, however, you didn't implement the prompt in the cmdlet execution code in any of the cmdlets except for one. Please resolve this issue.

@{

# Version number of this module.
ModuleVersion = '0.0.01'
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda why not 0.0.1?

// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda this needs to match your module version, 0.0.1

// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda this needs to be the same as the module version, 0.0.1

public string Name { get; set; }

[Parameter(
Mandatory = true,
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda is there a reason why the first two parameters have a position and the last two do not? Currently these are the two scenarios you support:

Add-AzureRmIotHubEventHubConsumerGroup -ResourceGroupName "rgname" -Name "name" -EventHubEndpointName "endpoint" -EventHubConsumerGroupName "groupname"
Add-AzureRmIotHubEventHubConsumerGroup "rgname" "name" -EventHubEndpointName "endpoint" -EventHubConsumerGroupName "groupname"

The first scenario is great, but I think the second scenario should be fixed so that all of the parameters have a position (since they are all mandatory). This would allow users to do the following:

Add-AzureRmIotHubEventHubConsumerGroup "rgname" "name" "endpoint" "groupname"

Let me know what you think

Copy link
Member Author

Choose a reason for hiding this comment

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

The only motivation for pattern 2 was a guideline I remember reading on one of the docs which suggested making the rg name and name positional . It makes sense to make the others positional too . SO I will make that change


public override void ExecuteCmdlet()
{
this.IotHubClient.IotHubResource.CreateEventHubConsumerGroup(this.ResourceGroupName, this.Name, this.EventHubEndpointName, this.EventHubConsumerGroupName);
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda this cmdlet implements SupportsShouldProcess, but the execution of the cmdlet is not wrapped in the if-statement containing the ShouldProcess prompt.

View this document for more information.

[OutputType(typeof(PSSharedAccessSignatureAuthorizationRule), typeof(List<PSSharedAccessSignatureAuthorizationRule>))]
public class GetAzureRmIotHubConnectionString : IotHubBaseCmdlet
{
const string GetIotHubConnectionStringParameterSet = "GetIotHubConnectionString";
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda why do you need two parameter sets if the only difference between the two is the KeyName parameter? Why not make it optional and then you can get rid of the switch statement and just do

if (KeyName == null)
{
    IEnumerable<SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name);
    this.WriteObject(IotHubUtils.ToPSIotHubConnectionStrings(authPolicies, hostName), true);
}
else
{
    SharedAccessSignatureAuthorizationRule authPolicy = this.IotHubClient.IotHubResource.GetKeysForKeyName(this.ResourceGroupName, this.Name, this.KeyName);
    this.WriteObject(authPolicy.ToPSIotHubConnectionString(hostName), false);
}


[Parameter(
ParameterSetName = GetIotHubJobParameterSet,
Mandatory = false,
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda this will not work; the following command will throw an error because PowerShell will be unable to determine which parameter set you are using:

Get-AzureRmIotHubJob -ResourceGroupName "rgname" -Name "name"

I would recommend getting rid of the parameter sets and keeping this parameter optional. Then use the same solution suggested for GetAzureRmIotHubConnectionString


[Parameter(
ParameterSetName = GetIotHubKeyParameterSet,
Mandatory = true,
Copy link
Member

Choose a reason for hiding this comment

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

@rkmanda same comment as GetAzureRmIotHubConnectionString

public class NewAzureRmIotHub : IotHubBaseCmdlet
{
[Parameter(
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.

@rkmanda I would recommend getting rid of positional parameters for this cmdlet

@cormacpayne
Copy link
Member

@rkmanda you will also need to add a reference to your test project after this line: https://github.com/Azure/azure-powershell/blob/dev/AzurePowershell.Test.targets#L87

@markcowl
Copy link
Member

@rkmanda need to fix the build break and respond to comments

@rkmanda
Copy link
Member Author

rkmanda commented Nov 18, 2016

Just back from a vacation. :) Thanks for the comments. Will be working on this early next week.

@markcowl
Copy link
Member

@rkmanda. Please open a new PR when you are ready to respond to comments

@markcowl markcowl closed this Nov 23, 2016
@rkmanda rkmanda mentioned this pull request Dec 5, 2016
13 tasks
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.

5 participants