-
Notifications
You must be signed in to change notification settings - Fork 4k
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
IotHub Commandlets #3156
Conversation
…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
Hi @rkmanda, I'm your friendly neighborhood Azure Pull Request Bot (You can call me AZPRBOT). Thanks for your contribution!
TTYL, AZPRBOT; |
Can one of the admins verify this patch? |
@azuresdkci add to whitelist |
@rkmanda Since this is your first cmdlet release, please schedule a cmldte design review with our team |
@rkmanda please fix build failures. |
@rkmanda can you address the comment above? |
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.
@rkmanda a few extra comments:
- There are a few cmdlets that have
ResourceGroupName
andName
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' |
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.
@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")] |
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.
@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")] |
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.
@rkmanda this needs to be the same as the module version, 0.0.1
public string Name { get; set; } | ||
|
||
[Parameter( | ||
Mandatory = true, |
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.
@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
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.
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); |
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.
@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"; |
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.
@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, |
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.
@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, |
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.
@rkmanda same comment as GetAzureRmIotHubConnectionString
public class NewAzureRmIotHub : IotHubBaseCmdlet | ||
{ | ||
[Parameter( | ||
Position = 0, |
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.
@rkmanda I would recommend getting rid of positional parameters for this cmdlet
@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 |
@rkmanda need to fix the build break and respond to comments |
Just back from a vacation. :) Thanks for the comments. Will be working on this early next week. |
@rkmanda. Please open a new PR when you are ready to respond to comments |
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
Testing Guidelines
Cmdlet Signature Guidelines
ShouldProcess
and haveSupportShouldProcess=true
specified in the cmdlet attribute. You can find more information onShouldProcess
here.OutputType
attribute if any output is produced - if the cmdlet produces no output, it should implement aPassThrough
parameter.Cmdlet Parameter Guidelines