Throw error if current operation is mi operation but cannot be replaced by get+put (#1371)

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

* throw error

* disable-transform-identity-type-for-operation
This commit is contained in:
Beisi Zhou 2024-09-06 14:54:40 +08:00 коммит произвёл GitHub
Родитель 14856fe9d4
Коммит 0ba58e59a5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 20 добавлений и 4 удалений

Просмотреть файл

@ -4456,7 +4456,7 @@ packages:
dev: false
file:projects/powershell.tgz:
resolution: {integrity: sha512-/cTXzGUZTDhTv00X96g/ev5R8DhTdsQMIKOfHnwTU5XV+VHjonfZkNAE/F4J6Nx+PlUMQDOpu2l8WODdTfbxZQ==, tarball: file:projects/powershell.tgz}
resolution: {integrity: sha512-g+2G98k1uy6WYWIz2YpqovxGt8rcL0RxWA6Zx8iROMAxurDEnhto1UzalzXAuGu7QSqy7suBvPQGATb0Y77W9A==, tarball: file:projects/powershell.tgz}
name: '@rush-temp/powershell'
version: 0.0.0
dependencies:
@ -4492,7 +4492,7 @@ packages:
dev: false
file:projects/typespec-powershell.tgz:
resolution: {integrity: sha512-nJTut+dJB/qoOsof76bauP5BhxsrcPuz+QkxF3JSf+bQhhmk+SGESqigrJpvNCH1uj1w7rzg69TvWdPR9ihl1g==, tarball: file:projects/typespec-powershell.tgz}
resolution: {integrity: sha512-FEyIs94S0ytHp2gxuA2ZcEN7YOzvAPKpxNgNDEOEb3aK5brakvfUK/qW8UZaFgd2zA6+pPehphG/XlHsvshnDw==, tarball: file:projects/typespec-powershell.tgz}
name: '@rush-temp/typespec-powershell'
version: 0.0.0
dependencies:

Просмотреть файл

@ -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;
@ -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
@ -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)) {