Skip to content

Commit

Permalink
Throw error if current operation is mi operation but cannot be replac…
Browse files Browse the repository at this point in the history
…ed by get+put (Azure#1371)

* Throw error if current operation is mi operation but cannot be replaced by get+put

* throw error

* disable-transform-identity-type-for-operation
  • Loading branch information
BethanyZhou committed Sep 6, 2024
1 parent 14856fe commit 0ba58e5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions powershell/plugins/create-commands-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ export /* @internal */ class Inferrer {
};
const disableGetPut = await this.state.getValue('disable-getput', false);
const disableTransformIdentityType = await this.state.getValue('disable-transform-identity-type', false);
const disableTransformIdentityTypeForOperation = await this.state.getValue('disable-transform-identity-type-for-operation', []);
const optsToExclude = new Array<string>();
if (disableTransformIdentityTypeForOperation) {
for (const item of values(disableTransformIdentityTypeForOperation)) {
optsToExclude.push(item);
}
}
this.state.message({ Channel: Channel.Debug, Text: 'detecting high level commands...' });
for (const operationGroup of values(model.operationGroups)) {
let hasPatch = false;
Expand Down Expand Up @@ -206,11 +213,15 @@ export /* @internal */ class Inferrer {
|| !hasPatch && putOperation && this.IsManagedIdentityOperation(putOperation))) {
await this.addVariants(putOperation.parameters, putOperation, this.createCommandVariant('create', [operationGroup.$key], [], this.state.model), '', this.state, [getOperation], CommandType.ManagedIdentityUpdate);
} else if (!disableTransformIdentityType && !supportsCombineGetPutOperation && hasPatch && patchOperation && this.IsManagedIdentityOperation(patchOperation)) {
if (!optsToExclude.includes(patchOperation.operationId ?? '')) {
const transformIdentityTypeErrorMessage = `Parameter IdentityType in operation '${patchOperation.operationId}' can not be transformed as the best practice design. See https://github.com/Azure/azure-powershell/blob/main/documentation/development-docs/design-guidelines/managed-identity-best-practices.md#frequently-asked-question to mitigate this issue.`;
this.state.message({ Channel: Channel.Error, Text: transformIdentityTypeErrorMessage });
throw new Error(transformIdentityTypeErrorMessage);
}
// bez: add patch operation back and disable transforming identity type
for (const variant of await this.inferCommandNames(patchOperation, operationGroup.$key, this.state)) {
await this.addVariants(patchOperation.parameters, patchOperation, variant, '', this.state);
}
await this.state.setValue('disable-transform-identity-type', true);
} else if (!disableGetPut && !hasPatch && supportsCombineGetPutOperation) {
/* generate variants for Update(Get+Put) for subjects only if:
- there is a get operation
Expand All @@ -222,11 +233,16 @@ export /* @internal */ class Inferrer {
await this.addVariants(putOperation.parameters, putOperation, this.createCommandVariant('create', [operationGroup.$key], [], this.state.model), '', this.state, [getOperation], CommandType.GetPut);
}
} else if (this.isAzure && !disableTransformIdentityType && patchOperation && this.IsManagedIdentityOperation(patchOperation)) {
if (!optsToExclude.includes(patchOperation.operationId ?? '')) {
const transformIdentityTypeErrorMessage = `Parameter IdentityType in operation '${patchOperation.operationId}' can not be transformed as the best practice design. See https://github.com/Azure/azure-powershell/blob/main/documentation/development-docs/design-guidelines/managed-identity-best-practices.md#frequently-asked-question to mitigate this issue.`;
this.state.message({ Channel: Channel.Error, Text: transformIdentityTypeErrorMessage });
throw new Error(transformIdentityTypeErrorMessage);
}

// bez: add variants back and disable transforming identity type as no put or get
for (const variant of await this.inferCommandNames(patchOperation, operationGroup.$key, this.state)) {
await this.addVariants(patchOperation.parameters, patchOperation, variant, '', this.state);
}
await this.state.setValue('disable-transform-identity-type', true);
}
}
// for (const operation of values(model.http.operations)) {
Expand Down

0 comments on commit 0ba58e5

Please sign in to comment.