Skip to content

Commit

Permalink
give a default value if identity type is required (#1330)
Browse files Browse the repository at this point in the history
* give a default value if identity type is required

* fix rush lint
  • Loading branch information
BethanyZhou committed Apr 11, 2024
1 parent d340913 commit 030855d
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions powershell/cmdlets/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,10 +1181,13 @@ export class CmdletClass extends Class {

const preProcessManagedIdentityParameters = function* () {
yield $this.ManagedUserAssignedIdentityPreProcess($this);
yield '// calculate IdentityType';
if ($this.operation.details.csharp.virtualParameters?.body?.filter(p => p.name === 'IdentityType')[0]?.required) {
yield If(`null == ${$this.bodyParameter?.value}.IdentityType`, `${$this.bodyParameter?.value}.IdentityType = "None";`);
}
// if UserAssignedIdentity is a string array or string, use Length. Otherwise, use Count
yield If(`this.UserAssignedIdentity?.${!$this.flattenUserAssignedIdentity && $this.GetUserAssignedIdentityParameterTypeDefinition() === 'dictionary' ? 'Count' : 'Length'} > 0`,
function* () {
yield '// calculate IdentityType';
yield If(`"SystemAssigned".Equals(${$this.bodyParameter?.value}.IdentityType, StringComparison.InvariantCultureIgnoreCase)`, `${$this.bodyParameter?.value}.IdentityType = "SystemAssigned,UserAssigned";`);
yield Else(`${$this.bodyParameter?.value}.IdentityType = "UserAssigned";`);
});
Expand Down Expand Up @@ -1837,7 +1840,7 @@ export class CmdletClass extends Class {
set: operation.details.csharp.verb.toLowerCase() === 'new' ? toExpression(`${expandedBodyParameter.value}.${getVirtualPropertyName((<any>vParam.origin)) || vParam.origin.name} = value.IsPresent ? "SystemAssigned": null `) : undefined
});
enableSystemAssignedIdentity.description = 'Decides if enable a system assigned identity for the resource.';
enableSystemAssignedIdentity.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(enableSystemAssignedIdentity.description || '.')}"`)] }));
enableSystemAssignedIdentity.add(new Attribute(ParameterAttribute, { parameters: [new LiteralExpression(`Mandatory = ${vParam.required && operation.details.csharp.verb.toLowerCase() !== 'new' ? 'true' : 'false'}`), new LiteralExpression(`HelpMessage = "${escapeString(enableSystemAssignedIdentity.description || '.')}"`)] }));
if (length(vParam.alias) > 0) {
enableSystemAssignedIdentity.add(new Attribute(Alias, { parameters: vParam.alias.map(x => '"' + x + '"') }));
}
Expand Down

0 comments on commit 030855d

Please sign in to comment.