public override void ExecuteCmdlet() { if (ShouldProcess(KeyName, Properties.Resources.AddIotHubKey)) { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.HubId); this.Name = IotHubUtils.GetIotHubName(this.HubId); } var psAuthRule = new PSSharedAccessSignatureAuthorizationRule() { KeyName = this.KeyName, PrimaryKey = this.PrimaryKey, SecondaryKey = this.SecondaryKey, Rights = this.Rights }; var authRule = IotHubUtils.ToSharedAccessSignatureAuthorizationRule(psAuthRule); IotHubDescription iothubDesc = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); IList <SharedAccessSignatureAuthorizationRule> authRules = (List <SharedAccessSignatureAuthorizationRule>) this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name).ToList(); authRules.Add(authRule); iothubDesc.Properties.AuthorizationPolicies = authRules; this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iothubDesc); IEnumerable <SharedAccessSignatureAuthorizationRule> updatedAuthRules = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSSharedAccessSignatureAuthorizationRules(updatedAuthRules), true); } }
public override void ExecuteCmdlet() { if (ShouldProcess(KeyName, Properties.Resources.RemoveIotHubKey)) { if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.HubId); this.Name = IotHubUtils.GetIotHubName(this.HubId); } IotHubDescription iothubDesc = this.IotHubClient.IotHubResource.Get(this.ResourceGroupName, this.Name); IList <SharedAccessSignatureAuthorizationRule> authRules = (List <SharedAccessSignatureAuthorizationRule>) this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name).ToList(); foreach (var authRule in authRules) { if (authRule.KeyName.Equals(this.KeyName, StringComparison.OrdinalIgnoreCase)) { authRules.Remove(authRule); break; } } iothubDesc.Properties.AuthorizationPolicies = authRules; this.IotHubClient.IotHubResource.CreateOrUpdate(this.ResourceGroupName, this.Name, iothubDesc); IEnumerable <SharedAccessSignatureAuthorizationRule> updatedAuthRules = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSSharedAccessSignatureAuthorizationRules(updatedAuthRules), true); } }
public override void ExecuteCmdlet() { if (KeyName != null) { SharedAccessSignatureAuthorizationRule authPolicy = this.IotHubClient.IotHubResource.GetKeysForKeyName(this.ResourceGroupName, this.Name, this.KeyName); this.WriteObject(IotHubUtils.ToPSSharedAccessSignatureAuthorizationRule(authPolicy), false); } else { IEnumerable <SharedAccessSignatureAuthorizationRule> authPolicies = this.IotHubClient.IotHubResource.ListKeys(this.ResourceGroupName, this.Name); this.WriteObject(IotHubUtils.ToPSSharedAccessSignatureAuthorizationRules(authPolicies), true); } }