Skip to content

Commit 2ca1b06

Browse files
dagorozisra-felwyunchi-ms
authored
fix parsing bug (#13142)
* fix parsing bug * add default values Co-authored-by: Yeming Liu <[email protected]> Co-authored-by: Yunchi Wang <[email protected]>
1 parent d3bdc9e commit 2ca1b06

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed parsing bug
2122
* Updated ARM template What-If cmdlets to remove preview message from results
2223
* Fixed an issue where template deployment cmdlets crash if `-WhatIf` is set at a higher scope [#13038]
2324
* Fixed an issue where template deployment cmdlets does not preserve case for template parameters

src/Resources/Resources/RoleAssignments/NewAzureRoleAssignmentCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public class NewAzureRoleAssignmentCommand : ResourcesBaseCmdlet
184184
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ScopeWithSPN,
185185
HelpMessage = "Condition to be applied to the RoleAssignment.")]
186186
[ValidateNotNullOrEmpty]
187-
public string Condition { get; set; }
187+
public string Condition { get; set; } = null;
188188

189189
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.Empty,
190190
HelpMessage = "Version of the condition.")]
@@ -207,7 +207,7 @@ public class NewAzureRoleAssignmentCommand : ResourcesBaseCmdlet
207207
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.ScopeWithSPN,
208208
HelpMessage = "Version of the condition.")]
209209
[ValidateNotNullOrEmpty]
210-
public string ConditionVersion { get; set; }
210+
public string ConditionVersion { get; set; } = null;
211211

212212
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ParameterSet.RoleIdWithScopeAndObjectId,
213213
HelpMessage = "Role Id the principal is assigned to.")]
@@ -245,7 +245,7 @@ public override void ExecuteCmdlet()
245245
this.ResourceType = RoleAssignment.ObjectType;
246246
this.Scope = RoleAssignment.Scope;
247247
Guid guid = Guid.Empty;
248-
Guid.TryParse(RoleAssignment.RoleDefinitionId,out guid);
248+
Guid.TryParse(RoleAssignment.RoleDefinitionId, out guid);
249249
this.RoleDefinitionId = guid;
250250
this.Description = RoleAssignment.Description;
251251
this.Condition = RoleAssignment.Condition;
@@ -271,7 +271,9 @@ public override void ExecuteCmdlet()
271271
}
272272

273273
}
274-
double _conditionVersion = double.Parse((ConditionVersion ?? "2.0"));
274+
// ensure that if ConditionVersion is empty in any way, it becomes null
275+
ConditionVersion = string.IsNullOrEmpty(ConditionVersion) ? null : string.IsNullOrWhiteSpace(ConditionVersion) ? null : ConditionVersion;
276+
double _conditionVersion = double.Parse(ConditionVersion ?? "2.0");
275277
if (_conditionVersion < 2.0)
276278
{
277279
WriteExceptionError(new ArgumentException("Argument -ConditionVersion must be greater or equal than 2.0"));

0 commit comments

Comments
 (0)