Action.py template based refactor (#804)

* action.py-template-based-refactor

* add unit test

* reserve work

* reserve work

* update getaction data

* reserve work

* reserve work

* fix some issues

* logic fixing and test

* fix scenario test

* template improve

* add back commands py unittest

* fix positional action and dictionary type

* add unit test

* fix test

* try-fix-windows-issue
This commit is contained in:
Qiaoqiao Zhang 2021-04-07 13:49:16 +08:00 коммит произвёл GitHub
Родитель a630f855c3
Коммит 1c7662d1e4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
46 изменённых файлов: 3023 добавлений и 1041 удалений

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

@ -15,13 +15,21 @@ export async function processRequest(host: Host): Promise<void> {
try {
const folder = AzConfiguration.getValue(CodeGenConstants.azOutputFolder);
const azextFolder = AzConfiguration.getValue(CodeGenConstants.azextFolder);
const fileName = path.join(
const azLinter = new AzLinter();
let fileName = path.join(
folder,
azextFolder,
PathConstants.generatedFolder,
PathConstants.commandsFile,
);
const azLinter = new AzLinter();
await azLinter.process(fileName);
fileName = path.join(
folder,
azextFolder,
PathConstants.generatedFolder,
PathConstants.actionFile,
);
await azLinter.process(fileName);
if (NeedPreparers().size > 0) {

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

@ -111,7 +111,7 @@ export interface CodeModelAz {
Extension_ClientAuthenticationPolicy: string;
Extension_Mode: string;
ResourceType: string | undefined;
isComplexSchema(type: string): boolean;
isComplexSchema(type: string, param: any): boolean;
SelectFirstCommandGroup(needRefer?: boolean): boolean;
SelectNextCommandGroup(needRefer?: boolean): boolean;
@ -225,7 +225,7 @@ export interface CodeModelAz {
Parameter_IsList(Parameter): boolean;
Parameter_IsListOfSimple(Parameter): boolean;
Parameter_IsPolyOfSimple(Parameter): boolean;
Schema_ActionName(Schema): string;
MethodParameter_ActionName: string;
Parameter_SetAzNameMapsTo(string, Parameter): void;
Parameter_InGlobal(Parameter): boolean;
Parameter_IsHidden(Parameter): boolean;
@ -290,5 +290,6 @@ export interface CodeModelAz {
inputProperties: Map<CodeModelTypes, RenderInput>,
dependencies: DataGraph,
);
GetActionData(): any[];
GetTestUniqueResource: boolean;
}

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

@ -95,6 +95,7 @@ export class CodeModelCliImpl implements CodeModelAz {
substack: Array<[Parameter[], number]>;
currentSubOptionIndex: number;
paramActionNameReference: Map<Schema, string>;
allActions: Map<Parameter, string>;
private _testScenario: any;
private _defaultTestScenario: any[];
private _configuredScenario: boolean;
@ -476,6 +477,7 @@ export class CodeModelCliImpl implements CodeModelAz {
private setParamAzUniqueNames() {
this.paramActionNameReference = new Map<Schema, string>();
this.allActions = new Map<Parameter, string>();
const nameActionReference: Map<string, ActionParam> = new Map<string, ActionParam>();
const pythonReserveWord = ['all', 'id', 'format', 'type', 'filter'];
if (this.SelectFirstCommandGroup()) {
@ -693,10 +695,15 @@ export class CodeModelCliImpl implements CodeModelAz {
preAction.action.schema,
preActionUniqueName,
);
this.allActions.set(
preAction.action,
preActionUniqueName,
);
this.paramActionNameReference.set(
param.schema,
actionUniqueName,
);
this.allActions.set(param, actionUniqueName);
nameActionReference.set(
preActionUniqueName,
preAction,
@ -712,6 +719,7 @@ export class CodeModelCliImpl implements CodeModelAz {
param.schema,
actionName,
);
this.allActions.set(param, actionName);
}
}
} while (this.SelectNextMethodParameter());
@ -753,6 +761,87 @@ export class CodeModelCliImpl implements CodeModelAz {
}
});
}
public GetActionData() {
const actions = [];
SchemaType.Array;
this.allActions.forEach((actionName: string, param: Parameter) => {
if (actionName === 'AddEventGridDataConnection') {
param;
}
const action = {
actionName: actionName,
actionType: 'KeyValue',
};
action.actionType = this.Parameter_IsPositional(param)
? 'Positional'
: action.actionType;
action.actionType = this.Parameter_IsShorthandSyntax(param)
? 'ShortHandSyntax'
: action.actionType;
action['mapsTo'] = this.Parameter_MapsTo(param);
action['type'] = this.Schema_Type(param.schema);
action['nameAz'] = this.Parameter_NameAz(param);
if (action['type'] === SchemaType.Array) {
action['baseClass'] = '_AppendAction';
} else {
action['baseClass'] = 'Action';
}
action['subProperties'] = [];
action['subPropertiesMapsTo'] = [];
action['subPropertiesNamePython'] = [];
action['subPropertiesNameAz'] = [];
action['constants'] = {};
const baseParam = param['polyBaseParam'];
const keyToMatch = baseParam?.schema?.discriminator?.property?.language.python?.name;
const valueToMatch = param.schema?.['discriminatorValue'];
const allSubParameters = [];
if (this.EnterSubMethodParameters(param) && this.SelectFirstMethodParameter(true)) {
do {
const tmpParam = this.SubMethodParameter;
allSubParameters.push(tmpParam);
const pythonName = this.Parameter_NamePython(tmpParam);
const mapsTo = this.Parameter_MapsTo(tmpParam);
const nameAz = this.Parameter_NameAz(tmpParam);
const subType = this.Parameter_Type(tmpParam);
if (
this.Parameter_Type(tmpParam) === SchemaType.Constant &&
!isNullOrUndefined(tmpParam.schema['value']?.['value'])
) {
action['constants'][
`'${pythonName}'`
] = `'${tmpParam.schema['value']['value']}'`;
} else if (tmpParam['readOnly']) {
continue;
} else if (
keyToMatch === pythonName &&
!isNullOrUndefined(keyToMatch) &&
!isNullOrUndefined(valueToMatch) &&
tmpParam['isDiscriminator']
) {
action['constants'][`'${keyToMatch}'`] = `'${valueToMatch}'`;
} else {
action['subProperties'].push({
namePython: pythonName,
nameAz: nameAz,
type: subType,
});
action['subPropertiesMapsTo'].push(mapsTo);
action['subPropertiesNamePython'].push(pythonName);
action['subPropertiesNameAz'].push(nameAz);
}
} while (this.SelectNextMethodParameter(true));
if (action['actionType'] === 'Positional') {
const keys = this.Parameter_PositionalKeys(param, allSubParameters);
action['subPropertiesNamePython'] = keys;
}
}
SchemaType.Dictionary;
actions.push(action);
this.ExitSubMethodParameters();
});
return actions;
}
//= ================================================================================================================
// Extension level information
// autorest.az will have support for multiple extensions from single swagger file.
@ -1660,11 +1749,12 @@ export class CodeModelCliImpl implements CodeModelAz {
param.language['az'].mapsto = newName;
}
public Schema_ActionName(schema: Schema = this.MethodParameter.schema) {
public get MethodParameter_ActionName() {
const schema = this.MethodParameter.schema;
if (this.paramActionNameReference.has(schema)) {
return this.paramActionNameReference.get(schema);
}
return null;
return undefined;
}
public get MethodParameter_Name(): string {
@ -1763,13 +1853,13 @@ export class CodeModelCliImpl implements CodeModelAz {
return this.Parameter_IsShorthandSyntax(this.MethodParameter);
}
public isComplexSchema(type: string): boolean {
public isComplexSchema(type: string, param: any): boolean {
if (
type === SchemaType.Array ||
type === SchemaType.Object ||
type === SchemaType.Dictionary ||
type === SchemaType.Any ||
this.MethodParameter.language['cli'].json === true
param?.language?.['cli']?.json === true
) {
return true;
} else {
@ -1862,22 +1952,22 @@ export class CodeModelCliImpl implements CodeModelAz {
) {
return false;
} else if (p['schema'].type === SchemaType.Array) {
if (this.isComplexSchema(p['schema']?.elementType?.type)) {
if (this.isComplexSchema(p['schema']?.elementType?.type, p['schema'])) {
return false;
}
for (const mp of values(p['schema']?.elementType?.properties)) {
if (this.isComplexSchema(mp['schema'].type)) {
if (this.isComplexSchema(mp['schema'].type, mp['schema'])) {
return false;
}
}
for (const parent of values(p['schema']?.elementType?.parents?.all)) {
for (const pp of values(parent['properties'])) {
if (this.isComplexSchema(pp['schema'].type)) {
if (this.isComplexSchema(pp['schema'].type, pp['schema'])) {
return false;
}
}
}
} else if (this.isComplexSchema(p['schema'].type)) {
} else if (this.isComplexSchema(p['schema'].type, p['schema'])) {
return false;
}
}
@ -1902,18 +1992,18 @@ export class CodeModelCliImpl implements CodeModelAz {
return false;
} else if (p['schema'].type === SchemaType.Array) {
for (const mp of values(p['schema']?.elementType?.properties)) {
if (this.isComplexSchema(mp['schema'].type)) {
if (this.isComplexSchema(mp['schema'].type, mp['schema'])) {
return false;
}
}
for (const parent of values(p['schema']?.elementType?.parents?.all)) {
for (const pp of values(parent['properties'])) {
if (this.isComplexSchema(pp['schema'].type)) {
if (this.isComplexSchema(pp['schema'].type, pp['schema'])) {
return false;
}
}
}
} else if (this.isComplexSchema(p['schema'].type)) {
} else if (this.isComplexSchema(p['schema'].type, p['schema'])) {
// objects.objects
return false;
}
@ -1935,7 +2025,7 @@ export class CodeModelCliImpl implements CodeModelAz {
if (mp['readOnly']) {
continue;
}
if (this.isComplexSchema(mp['schema'].type)) {
if (this.isComplexSchema(mp['schema'].type, mp['schema'])) {
return false;
}
}
@ -1944,12 +2034,12 @@ export class CodeModelCliImpl implements CodeModelAz {
if (pp['readOnly']) {
continue;
}
if (this.isComplexSchema(pp['schema'].type)) {
if (this.isComplexSchema(pp['schema'].type, pp['schema'])) {
return false;
}
}
}
} else if (this.isComplexSchema(p.type)) {
} else if (this.isComplexSchema(p.type, p)) {
// dicts.objects or dicts.dictionaries
return false;
}
@ -2006,7 +2096,7 @@ export class CodeModelCliImpl implements CodeModelAz {
private Parameter_IsSimpleArray(param: Parameter): boolean {
if (this.Parameter_Type(param) === SchemaType.Array) {
const elementType = param.schema['elementType'].type;
if (!this.isComplexSchema(elementType)) {
if (!this.isComplexSchema(elementType, param.schema)) {
return true;
}
}
@ -2018,7 +2108,7 @@ export class CodeModelCliImpl implements CodeModelAz {
return false;
}
if (this.isComplexSchema(this.Parameter_Type(param))) {
if (this.isComplexSchema(this.Parameter_Type(param), param)) {
return true;
}
return false;
@ -2110,7 +2200,7 @@ export class CodeModelCliImpl implements CodeModelAz {
if (schema.language['cli'].json === true) {
return true;
}
if (this.isComplexSchema(this.Schema_Type(schema))) {
if (this.isComplexSchema(this.Schema_Type(schema), schema)) {
return true;
}
return false;

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

@ -12,7 +12,6 @@ import { CliTopInit } from '../renders/CliTopInit';
import { CliMainDocSourceJsonMap } from '../renders/extraMain/CliMainDocSourceJsonMap';
import { CliMainRequirement } from '../renders/extraMain/CliMainRequirement';
import { CliMainSetupPy } from '../renders/extraMain/CliMainSetupPy';
import { GenerateAzureCliActions } from '../renders/generated/CliActions';
import { GenerateAzureCliClientFactory } from '../renders/generated/CliClientFactory';
import { CliCommands } from '../renders/generated/CliCommands';
import { GenerateAzureCliCustom } from '../renders/generated/CliCustom';
@ -26,6 +25,7 @@ import { CliTestStep, NeedPreparers } from '../renders/tests/CliTestStep';
import { GenerateMetaFile } from '../renders/CliMeta';
import { CliCmdletTest } from '../renders/tests/CliTestCmdlet';
import { SimpleTemplate } from '../renders/TemplateBase';
import { CliActions } from '../renders/generated/CliActions';
export class AzCoreFullGenerator extends GeneratorBase {
constructor(model: CodeModelAz) {
@ -53,9 +53,6 @@ export class AzCoreFullGenerator extends GeneratorBase {
files[
path.join(model.azOutputFolder, 'generated/_validators.py')
] = GenerateAzureCliValidators(model);
files[
path.join(model.azOutputFolder, 'generated/action.py')
] = GenerateAzureCliActions(model);
files[
path.join(model.azOutputFolder, 'generated/__init__.py')
] = GenerateNamespaceInit(model);
@ -74,6 +71,7 @@ export class AzCoreFullGenerator extends GeneratorBase {
files[
path.join(model.azOutputFolder, 'manual/__init__.py')
] = GenerateNamespaceInit(model);
await this.generateFullSingleAndAddtoOutput(new CliActions(model));
await this.generateFullSingleAndAddtoOutput(new CliCommands(model));
await this.generateFullSingleAndAddtoOutput(new CliTopAction(model));
await this.generateFullSingleAndAddtoOutput(new CliTopCustom(model));
@ -151,7 +149,7 @@ export class AzCoreFullGenerator extends GeneratorBase {
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.cmdletFolder,
PathConstants.conftestFile + '.njx',
PathConstants.conftestFile + PathConstants.njxFileExtension,
),
),
);

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

@ -16,7 +16,6 @@ import { CliTopHelp } from '../renders/CliTopHelp';
import { CliTopInit } from '../renders/CliTopInit';
import { CliMainRequirement } from '../renders/extraMain/CliMainRequirement';
import { CliMainSetupPy } from '../renders/extraMain/CliMainSetupPy';
import { GenerateAzureCliActions } from '../renders/generated/CliActions';
import { GenerateAzureCliClientFactory } from '../renders/generated/CliClientFactory';
import { CliCommands } from '../renders/generated/CliCommands';
import { GenerateAzureCliCustom } from '../renders/generated/CliCustom';
@ -31,6 +30,7 @@ import { GenerateMetaFile } from '../renders/CliMeta';
import { CliExtSetupPy } from '../renders/extraExt/CliExtSetupPy';
import { CliCmdletTest } from '../renders/tests/CliTestCmdlet';
import { SimpleTemplate } from '../renders/TemplateBase';
import { CliActions } from '../renders/generated/CliActions';
export class AzCoreIncrementalGenerator extends GeneratorBase {
constructor(model: CodeModelAz) {
@ -59,9 +59,6 @@ export class AzCoreIncrementalGenerator extends GeneratorBase {
this.files[
path.join(PathConstants.generatedFolder, PathConstants.validatorsFile)
] = GenerateAzureCliValidators(this.model);
this.files[
path.join(PathConstants.generatedFolder, PathConstants.actionFile)
] = GenerateAzureCliActions(this.model);
this.files[
path.join(PathConstants.generatedFolder, PathConstants.initFile)
] = GenerateNamespaceInit(this.model);
@ -81,6 +78,7 @@ export class AzCoreIncrementalGenerator extends GeneratorBase {
] = GenerateNamespaceInit(this.model);
}
await this.generateIncrementalSingleAndAddtoOutput(new CliActions(this.model));
await this.generateIncrementalSingleAndAddtoOutput(new CliCommands(this.model));
// Add Import and run method from generated folder (Init)
await this.generateIncrementalSingleAndAddtoOutput(new CliTopInit(this.model));
@ -177,7 +175,7 @@ export class AzCoreIncrementalGenerator extends GeneratorBase {
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.cmdletFolder,
PathConstants.conftestFile + '.njx',
PathConstants.conftestFile + PathConstants.njxFileExtension,
),
),
);

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

@ -14,7 +14,7 @@ import { CliReport } from '../renders/CliReport';
import { CliTopInit } from '../renders/CliTopInit';
import { CliTopMetadata } from '../renders/extraExt/CliExtMetadata';
import { CliExtSetupPy } from '../renders/extraExt/CliExtSetupPy';
import { GenerateAzureCliActions } from '../renders/generated/CliActions';
import { CliActions } from '../renders/generated/CliActions';
import { GenerateAzureCliClientFactory } from '../renders/generated/CliClientFactory';
import { CliCommands } from '../renders/generated/CliCommands';
import { GenerateAzureCliCustom } from '../renders/generated/CliCustom';
@ -52,9 +52,6 @@ export class AzExtensionFullGenerator extends GeneratorBase {
this.files[
path.join(this.azDirectory, 'generated/_validators.py')
] = GenerateAzureCliValidators(this.model);
this.files[path.join(this.azDirectory, 'generated/action.py')] = GenerateAzureCliActions(
this.model,
);
this.files[path.join(this.azDirectory, 'generated/__init__.py')] = GenerateNamespaceInit(
this.model,
);
@ -77,6 +74,7 @@ export class AzExtensionFullGenerator extends GeneratorBase {
] = GenerateNamespaceInit(this.model);
}
await this.generateFullSingleAndAddtoOutput(new CliActions(this.model));
await this.generateFullSingleAndAddtoOutput(new CliCommands(this.model));
await this.generateFullSingleAndAddtoOutput(new CliTopAction(this.model));
await this.generateFullSingleAndAddtoOutput(new CliTopCustom(this.model));
@ -140,7 +138,7 @@ export class AzExtensionFullGenerator extends GeneratorBase {
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.cmdletFolder,
PathConstants.conftestFile + '.njx',
PathConstants.conftestFile + PathConstants.njxFileExtension,
),
),
);

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

@ -16,7 +16,7 @@ import { CliReport } from '../renders/CliReport';
import { CliTopInit } from '../renders/CliTopInit';
import { CliTopMetadata } from '../renders/extraExt/CliExtMetadata';
import { CliExtSetupPy } from '../renders/extraExt/CliExtSetupPy';
import { GenerateAzureCliActions } from '../renders/generated/CliActions';
import { CliActions } from '../renders/generated/CliActions';
import { GenerateAzureCliClientFactory } from '../renders/generated/CliClientFactory';
import { CliCommands } from '../renders/generated/CliCommands';
import { GenerateAzureCliCustom } from '../renders/generated/CliCustom';
@ -54,9 +54,6 @@ export class AzExtensionIncrementalGenerator extends GeneratorBase {
this.files[
path.join(this.azDirectory, PathConstants.generatedFolder, PathConstants.validatorsFile)
] = GenerateAzureCliValidators(this.model);
this.files[
path.join(this.azDirectory, PathConstants.generatedFolder, PathConstants.actionFile)
] = GenerateAzureCliActions(this.model);
this.files[
path.join(this.azDirectory, PathConstants.generatedFolder, PathConstants.initFile)
] = GenerateNamespaceInit(this.model);
@ -78,6 +75,7 @@ export class AzExtensionIncrementalGenerator extends GeneratorBase {
] = GenerateNamespaceInit(this.model);
}
await this.generateIncrementalSingleAndAddtoOutput(new CliActions(this.model));
// Add Import and run method from generated folder (Init)
await this.generateIncrementalSingleAndAddtoOutput(new CliTopInit(this.model));
@ -160,7 +158,7 @@ export class AzExtensionIncrementalGenerator extends GeneratorBase {
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.cmdletFolder,
PathConstants.conftestFile + '.njx',
PathConstants.conftestFile + PathConstants.njxFileExtension,
),
),
);

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

@ -20,7 +20,10 @@ export class CliReport extends TemplateBase {
constructor(model: CodeModelAz) {
super(model);
this.relativePath = path.join(PathConstants.reportFile);
this.tmplPath = path.join(PathConstants.templateRootFolder, 'report.md.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.reportFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -12,7 +12,10 @@ export class CliExtHistory extends TemplateBase {
constructor(model: CodeModelAz) {
super(model);
this.relativePath = PathConstants.historyRstFile;
this.tmplPath = path.join(PathConstants.templateRootFolder, 'HISTORY.rst.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.historyRstFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -15,7 +15,8 @@ export class CliTopMetadata extends TemplateBase {
this.relativePath = path.join(model.AzextFolder, PathConstants.metadataFile);
this.tmplPath = path.join(
PathConstants.templateRootFolder,
'azext/azext_metadata.json.njx',
'azext',
PathConstants.metadataFile + PathConstants.njxFileExtension,
);
}

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

@ -12,7 +12,10 @@ export class CliExtSetupCfg extends TemplateBase {
constructor(model: CodeModelAz) {
super(model);
this.relativePath = PathConstants.setupCfgFile;
this.tmplPath = path.join(PathConstants.templateRootFolder, 'setup.cfg.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.setupCfgFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -16,7 +16,10 @@ export class CliExtSetupPy extends TemplateBase {
constructor(model: CodeModelAz) {
super(model);
this.relativePath = PathConstants.setupPyFile;
this.tmplPath = path.join(PathConstants.templateRootFolder, 'setup.py.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.setupPyFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -7,528 +7,41 @@ import { Parameter, SchemaType } from '@azure-tools/codemodel';
import { ToPythonString, ToMultiLine, isNullOrUndefined } from '../../../utils/helper';
import { CodeModelAz } from '../../CodeModelAz';
import { HeaderGenerator } from '../Header';
import { TemplateBase } from '../TemplateBase';
import * as path from 'path';
import { PathConstants } from '../../../utils/models';
let allActions: Map<string, boolean>;
export function GenerateAzureCliActions(model: CodeModelAz): string[] {
allActions = new Map<string, boolean>();
const header: HeaderGenerator = new HeaderGenerator();
header.disableProtectedAccess = true;
let output: string[] = [];
let outputCode: string[] = [];
if (model.SelectFirstCommandGroup()) {
do {
if (model.SelectFirstCommand()) {
do {
if (model.SelectFirstMethod()) {
do {
let baseParam = null;
if (model.SelectFirstMethodParameter()) {
do {
if (
baseParam &&
model.MethodParameter['polyBaseParam'] === baseParam
) {
const keyToMatch =
baseParam.schema?.discriminator?.property?.language
.python?.name;
const valueToMatch =
model.MethodParameter.schema?.['discriminatorValue'];
const subActionName = model.Schema_ActionName(
model.MethodParameter.schema,
);
if (
isNullOrUndefined(subActionName) ||
allActions.has(subActionName)
) {
continue;
}
if (model.MethodParameter_IsPositional) {
outputCode = outputCode.concat(
GetPositionalAction(
model,
subActionName,
model.MethodParameter,
),
);
} else if (model.MethodParameter_IsShorthandSyntax) {
outputCode = outputCode.concat(
GetShorthandSyntaxAction(
model,
subActionName,
model.MethodParameter,
),
);
} else {
outputCode = outputCode.concat(
GetAction(
model,
subActionName,
model.MethodParameter,
keyToMatch,
valueToMatch,
),
);
}
}
const actionName = model.Schema_ActionName(
model.MethodParameter.schema,
);
if (isNullOrUndefined(actionName)) {
if (model.Parameter_IsPolyOfSimple(model.MethodParameter)) {
baseParam = model.MethodParameter;
}
} else {
if (allActions.has(actionName)) {
continue;
}
if (model.MethodParameter_IsPositional) {
outputCode = outputCode.concat(
GetPositionalAction(
model,
actionName,
model.MethodParameter,
),
);
} else if (model.MethodParameter_IsShorthandSyntax) {
outputCode = outputCode.concat(
GetShorthandSyntaxAction(
model,
actionName,
model.MethodParameter,
),
);
} else {
outputCode = outputCode.concat(
GetAction(model, actionName, model.MethodParameter),
);
}
}
} while (model.SelectNextMethodParameter());
}
} while (model.SelectNextMethod());
}
} while (model.SelectNextCommand());
}
} while (model.SelectNextCommandGroup());
}
if (outputCode.length !== 0) {
header.addImport('argparse');
header.addFromImport('collections', ['defaultdict']);
header.addFromImport('knack.util', ['CLIError']);
output = header.getLines().concat(outputCode);
} else {
output = header.getLines();
}
output.push('');
return output;
}
function GetAction(
model: CodeModelAz,
actionName: string,
param: Parameter,
keyToMatch: string = null,
valueToMatch: string = null,
) {
const output: string[] = [];
allActions.set(actionName, true);
output.push('');
output.push('');
let baseAction = 'Action';
const paramType = param?.schema?.type;
if (paramType === SchemaType.Array) baseAction = '_Append' + baseAction;
output.push('class ' + actionName + '(argparse.' + baseAction + '):');
output.push(' def __call__(self, parser, namespace, values, option_string=None):');
output.push(' action = self.get_action(values, option_string)');
if (paramType === SchemaType.Array) {
output.push(
' super(' +
actionName +
', self).__call__(parser, namespace, action, option_string)',
export class CliActions extends TemplateBase {
constructor(model: CodeModelAz) {
super(model);
this.relativePath = path.join(
model.AzextFolder,
PathConstants.generatedFolder,
PathConstants.actionFile,
);
} else {
output.push(' namespace.' + model.Parameter_MapsTo(param) + ' = action');
}
output.push('');
output.push(' def get_action(self, values, option_string): # pylint: disable=no-self-use');
output.push(' try:');
output.push(' properties = defaultdict(list)');
output.push(" for (k, v) in (x.split('=', 1) for x in values):");
output.push(' properties[k].append(v)');
output.push(' properties = dict(properties)');
output.push(' except ValueError:');
output.push(
" raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))",
);
output.push(' d = {}');
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter(true)) {
do {
if (model.Parameter_DefaultValue(model.SubMethodParameter) !== undefined) {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = " +
ToPythonString(
model.Parameter_DefaultValue(model.SubMethodParameter),
model.Parameter_Type(model.SubMethodParameter),
),
);
}
} while (model.SelectNextMethodParameter(true));
}
model.ExitSubMethodParameters();
}
output.push(' for k in properties:');
output.push(' kl = k.lower()');
output.push(' v = properties[k]');
let foundProperties = false;
const preParamType = paramType;
const allPossibleKeys = [];
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter()) {
foundProperties = true;
let ifkv = 'if';
do {
if (model.SubMethodParameter['readOnly']) {
continue;
}
if (model.SubMethodParameter.schema?.type === SchemaType.Constant) {
continue;
}
if (
!isNullOrUndefined(keyToMatch) &&
!isNullOrUndefined(valueToMatch) &&
model.Parameter_NamePython(model.SubMethodParameter) === keyToMatch
) {
continue;
}
output.push(
' ' +
ifkv +
" kl == '" +
model.Parameter_NameAz(model.SubMethodParameter) +
"':",
);
allPossibleKeys.push(model.Parameter_NameAz(model.SubMethodParameter));
if (model.MethodParameter_IsArray) {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = v",
);
} else {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = v[0]",
);
}
ifkv = 'elif';
} while (model.SelectNextMethodParameter());
}
model.ExitSubMethodParameters();
}
if (allPossibleKeys.length > 0) {
output.push(' else:');
ToMultiLine(
" raise CLIError('Unsupported Key {} is provided for parameter " +
model.Parameter_MapsTo(param) +
'. All possible keys are: ' +
allPossibleKeys.join(', ') +
"'.format(k))",
output,
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.generatedFolder,
PathConstants.actionFile + PathConstants.njxFileExtension,
);
}
if (!foundProperties && preParamType === SchemaType.Dictionary) {
output.pop();
output.pop();
output.push(' v = properties[k]');
output.push(' d[k] = v[0]');
} else if (!foundProperties && model.MethodParameter_IsArray) {
output.pop();
output.pop();
output.push(' v = properties[k]');
output.push(' d[k] = v');
} else if (!isNullOrUndefined(keyToMatch) && !isNullOrUndefined(valueToMatch)) {
output.push(" d['" + keyToMatch + "'] = '" + valueToMatch + "'");
public async GetRenderData(): Promise<Record<string, unknown>> {
const data = { imports: [], pylints: [], actions: [] };
data.actions = this.model.GetActionData();
data['pylints'].push('# pylint: disable=protected-access', '# pylint: disable=no-self-use');
const result = { data: { imports: [], pylints: [] } };
result.data = data;
return result;
}
public async fullGeneration(): Promise<string[]> {
return this.render();
}
public async incrementalGeneration(): Promise<string[]> {
return this.render();
}
output.push(' return d');
return output;
}
function GetPositionalAction(
model: CodeModelAz,
actionName: string,
param: Parameter,
keyToMatch: string = null,
valueToMatch: string = null,
) {
let output: string[] = [];
allActions.set(actionName, true);
output.push('');
output.push('');
const keys = model.MethodParameter_PositionalKeys;
let baseAction = 'Action';
const paramType = param?.schema?.type;
if (paramType === SchemaType.Array) baseAction = '_Append' + baseAction;
output.push('class ' + actionName + '(argparse.' + baseAction + '):');
output.push(' def __call__(self, parser, namespace, values, option_string=None):');
output.push(' action = self.get_action(values, option_string)');
if (paramType === SchemaType.Array) {
output.push(' for item in action:');
output.push(
' super(' +
actionName +
', self).__call__(parser, namespace, item, option_string)',
);
} else {
output.push(' namespace.' + model.Parameter_MapsTo(param) + ' = action[0]');
}
output.push('');
output.push(' def get_action(self, values, option_string=None):');
if (isNullOrUndefined(keys) || keys.length <= 0) {
output.push(' pass');
return output;
}
output.push(' try:');
output.push(
' value_chunk_list = [values[x:x+' +
keys.length +
'] for x in range(0, len(values), ' +
keys.length +
')]',
);
output.push(' value_list = []');
output.push(' for chunk in value_chunk_list:');
output.push(' ' + keys.join(', ') + (keys.length === 1 ? ',' : '') + ' = chunk');
output.push(' value_list.append(');
output = output.concat(
generateConstructObject(
model,
' ',
keyToMatch,
valueToMatch,
false,
keys,
),
);
output.push(' )');
output.push(' return value_list');
output.push(' except ValueError:');
output.push(
" raise CLIError('usage error: {} NAME METRIC OPERATION VALUE'.format(option_string))",
);
return output;
}
function GetShorthandSyntaxAction(
model: CodeModelAz,
actionName: string,
param: Parameter,
keyToMatch: string = null,
valueToMatch: string = null,
) {
const output: string[] = [];
allActions.set(actionName, true);
output.push('');
output.push('');
let baseAction = 'Action';
const paramType = param?.schema?.type;
if (paramType === SchemaType.Array) baseAction = '_Append' + baseAction;
output.push('class ' + actionName + '(argparse.' + baseAction + '):');
output.push(' def __call__(self, parser, namespace, values, option_string=None):');
output.push(' action = self.get_action(values, option_string)');
if (paramType === SchemaType.Array) {
output.push(' for item in action:');
output.push(
' super(' +
actionName +
', self).__call__(parser, namespace, item, option_string)',
);
} else {
output.push(' namespace.' + model.Parameter_MapsTo(param) + ' = action');
}
output.push('');
output.push(' def get_action(self, values, option_string): # pylint: disable=no-self-use');
output.push(' ret = []');
output.push(' for item in values:');
output.push(' properties = defaultdict(list)');
output.push(' try:');
output.push(" for (k, v) in (x.split('=', 1) for x in item.split(',')):");
output.push(' properties[k].append(v)');
output.push(' properties = dict(properties)');
output.push(' except ValueError:');
output.push(
" raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))",
);
output.push(' d = {}');
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter(true)) {
do {
if (model.Parameter_DefaultValue(model.SubMethodParameter) !== undefined) {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = " +
ToPythonString(
model.Parameter_DefaultValue(model.SubMethodParameter),
model.Parameter_Type(model.SubMethodParameter),
),
);
}
} while (model.SelectNextMethodParameter(true));
}
model.ExitSubMethodParameters();
}
output.push(' for k in properties:');
output.push(' kl = k.lower()');
output.push(' v = properties[k]');
let foundProperties = false;
const preParamType = paramType;
const allPossibleKeys = [];
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter()) {
foundProperties = true;
let ifkv = 'if';
do {
if (model.SubMethodParameter['readOnly']) {
continue;
}
if (model.SubMethodParameter.schema?.type === SchemaType.Constant) {
continue;
}
if (
!isNullOrUndefined(keyToMatch) &&
!isNullOrUndefined(valueToMatch) &&
model.Parameter_NamePython(model.SubMethodParameter) === keyToMatch
) {
continue;
}
output.push(
' ' +
ifkv +
" kl == '" +
model.Parameter_NameAz(model.SubMethodParameter) +
"':",
);
allPossibleKeys.push(model.Parameter_NameAz(model.SubMethodParameter));
if (model.MethodParameter_IsArray) {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = v",
);
} else {
output.push(
" d['" +
model.Parameter_NamePython(model.SubMethodParameter) +
"'] = v[0]",
);
}
ifkv = 'elif';
} while (model.SelectNextMethodParameter());
}
model.ExitSubMethodParameters();
}
if (allPossibleKeys.length > 0) {
output.push(' else:');
ToMultiLine(
" raise CLIError('Unsupported Key {} is provided for parameter " +
model.Parameter_MapsTo(param) +
'. All possible keys are: ' +
allPossibleKeys.join(', ') +
"'.format(k))",
output,
);
}
if (!foundProperties && preParamType === SchemaType.Dictionary) {
output.pop();
output.pop();
output.push(' v = properties[k]');
output.push(' d[k] = v[0]');
} else if (!foundProperties && model.MethodParameter_IsArray) {
output.pop();
output.pop();
output.push(' v = properties[k]');
output.push(' d[k] = v');
} else if (!isNullOrUndefined(keyToMatch) && !isNullOrUndefined(valueToMatch)) {
output.push(" d['" + keyToMatch + "'] = '" + valueToMatch + "'");
}
output.push(' ret.append(d)');
if (model.MethodParameter_Type === SchemaType.Array) {
output.push(' return ret');
} else {
output.push(' return ret[0]');
}
return output;
}
function generateConstructObject(
model: CodeModelAz,
indent: string,
keyToMatch: string,
valueToMatch: string,
needReturn: boolean,
keys: string[],
) {
const output: string[] = [];
output.push(indent + (needReturn ? 'return ' : '') + '{');
let hasPair = false;
if (keys.length > 0) {
for (const key of keys) {
hasPair = true;
output.push(indent + " '" + key + "': " + key + ',');
}
} else {
if (model.EnterSubMethodParameters()) {
if (model.SelectFirstMethodParameter(true)) {
do {
if (model.SubMethodParameter['readOnly']) {
continue;
}
if (model.SubMethodParameter.schema?.type === SchemaType.Constant) {
continue;
}
if (
!isNullOrUndefined(keyToMatch) &&
!isNullOrUndefined(valueToMatch) &&
model.Parameter_NamePython(model.SubMethodParameter) === keyToMatch
) {
continue;
}
hasPair = true;
output.push(
indent +
' ' +
model.Parameter_NamePython(model.SubMethodParameter) +
' = ' +
model.Parameter_NamePython(model.SubMethodParameter) +
',',
);
} while (model.SelectNextMethodParameter(true));
}
model.ExitSubMethodParameters();
}
}
if (hasPair) {
output[output.length - 1] = output.last.substring(0, output.last.length - 1);
output.push(indent + '}');
} else {
output.pop();
}
return output;
}

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

@ -32,7 +32,11 @@ export class CliCommands extends TemplateBase {
PathConstants.generatedFolder,
PathConstants.commandsFile,
);
this.tmplPath = path.join(PathConstants.templateRootFolder, 'generated/commands.py.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.generatedFolder,
PathConstants.commandsFile + PathConstants.njxFileExtension,
);
}
pythonString(str: string): string {

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

@ -279,7 +279,10 @@ function ConstructMethodBodyParameter(model: CodeModelAz, needGeneric = false, r
);
} else if (!isNullOrUndefined(model.MethodParameter_DefaultValue)) {
if (
model.isComplexSchema(model.MethodParameter_Type) &&
model.isComplexSchema(
model.MethodParameter_Type,
model.MethodParameter,
) &&
defaultValue !== '{}'
) {
defaultValue = 'json.loads(' + defaultValue + ')';

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

@ -272,7 +272,7 @@ function getShorthandSyntaxAction(
}
let options: Parameter[] = [];
if (!isNullOrUndefined(model.Schema_ActionName(model.MethodParameter.schema))) {
if (!isNullOrUndefined(model.MethodParameter_ActionName)) {
if (baseParam && model.MethodParameter['polyBaseParam'] === baseParam) {
const keyToMatch = baseParam.schema?.['discriminator']?.property?.language.python?.name;
const valueToMatch = model.MethodParameter.schema?.['discriminatorValue'];
@ -375,7 +375,7 @@ function getPositionalActionHelp(
const positionalKeys = model.MethodParameter_PositionalKeys;
let options: Parameter[] = [];
if (!isNullOrUndefined(model.Schema_ActionName(model.MethodParameter.schema))) {
if (!isNullOrUndefined(model.MethodParameter_ActionName)) {
if (baseParam && model.MethodParameter['polyBaseParam'] === baseParam) {
const keyToMatch = baseParam.schema?.['discriminator']?.property?.language.python?.name;
const valueToMatch = model.MethodParameter.schema?.['discriminatorValue'];
@ -472,7 +472,7 @@ function getKeyValueActionHelp(
}
let options: Parameter[] = [];
if (!isNullOrUndefined(model.Schema_ActionName(model.MethodParameter.schema))) {
if (!isNullOrUndefined(model.MethodParameter_ActionName)) {
if (baseParam && model.MethodParameter['polyBaseParam'] === baseParam) {
const keyToMatch = baseParam.schema?.['discriminator']?.property?.language.python?.name;
const valueToMatch = model.MethodParameter.schema?.['discriminatorValue'];

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

@ -303,9 +303,7 @@ function getCommandBody(model: CodeModelAz, needGeneric = false, debug = false)
model.MethodParameter_IsList &&
model.MethodParameter_IsListOfSimple
) {
const actionName: string = model.Schema_ActionName(
model.MethodParameter.schema,
);
const actionName: string = model.MethodParameter_ActionName;
argument += ', action=' + actionName;
hasActions = true;
@ -343,11 +341,7 @@ function getCommandBody(model: CodeModelAz, needGeneric = false, debug = false)
}
if (model.MethodParameter_IsListOfSimple) {
let options = [];
if (
!isNullOrUndefined(
model.Schema_ActionName(model.MethodParameter.schema),
)
) {
if (!isNullOrUndefined(model.MethodParameter_ActionName)) {
if (
baseParam &&
model.MethodParameter['polyBaseParam'] === baseParam

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

@ -34,7 +34,7 @@ export class CliCmdletTest extends TemplateBase {
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.cmdletFolder,
`${testFileName}.njx`,
testFileName + PathConstants.njxFileExtension,
);
this.className = isNegativeTest ? 'NegativeTest' : 'PositiveTest';
}

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

@ -15,7 +15,11 @@ export class CliTestInit extends TemplateBase {
PathConstants.testFolder,
PathConstants.initFile,
);
this.tmplPath = path.join(PathConstants.templateRootFolder, 'tests/init.py.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.initFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -33,7 +33,12 @@ export class CliTestPrepare extends TemplateBase {
PathConstants.latestFolder,
PathConstants.preparersFile,
);
this.tmplPath = path.join(PathConstants.templateRootFolder, 'tests/latest/prepares.py.njx');
this.tmplPath = path.join(
PathConstants.templateRootFolder,
PathConstants.testFolder,
PathConstants.latestFolder,
PathConstants.preparersFile + PathConstants.njxFileExtension,
);
}
public async fullGeneration(): Promise<string[]> {

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

@ -7,6 +7,7 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
{% if data.actions.length != 0 %}
{% for pylint in data.pylints %}
{{pylint}}
{% endfor %}
@ -14,14 +15,21 @@
import argparse
from collections import defaultdict
from knack.util import CLIError
{% endif %}
class AddFactoryVstsConfiguration(argparse.Action):
{% for action in data.actions %}
{% if action.actionType == 'KeyValue' %}
class {{action.actionName}}(argparse.{{action.baseClass}}):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_vsts_configuration = action
{% if action.type == 'array' -%}
super({{action.actionName}}, self).__call__(parser, namespace, action, option_string)
{% else -%}
namespace.{{action.mapsTo}} = action
{%- endif %}
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -31,126 +39,114 @@ class AddFactoryVstsConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
{% if action.type != 'dictionary' or action.subProperties.length > 0 %}
kl = k.lower()
{% endif %}
v = properties[k]
if kl == 'project-name':
d['project_name'] = v[0]
elif kl == 'tenant-id':
d['tenant_id'] = v[0]
elif kl == 'account-name':
d['account_name'] = v[0]
elif kl == 'repository-name':
d['repository_name'] = v[0]
elif kl == 'collaboration-branch':
d['collaboration_branch'] = v[0]
elif kl == 'root-folder':
d['root_folder'] = v[0]
elif kl == 'last-commit-id':
d['last_commit_id'] = v[0]
d['type'] = 'FactoryVSTSConfiguration'
{% if action.type != 'dictionary' or action.subProperties.length > 0 %}
{% for subprop in action.subProperties %}
{% if loop.first %}if{% else %}elif{% endif %} kl == '{{subprop.nameAz}}':
{% if subprop.type == 'array' %}
d['{{subprop.namePython}}'] = v
{% else %}
d['{{subprop.namePython}}'] = v[0]
{% endif %}
{% endfor %}
{% if action.subProperties.length > 0 %}
else:
raise CLIError('Unsupported Key {} is provided for parameter {{action.nameAz}}. All possible keys are: {{ action.subPropertiesNameAz | join(', ') }}'.
format(k))
{% endif %}
{% else %}
{% if subprop.type == 'array' %}
d[k] = v
{% else %}
d[k] = v[0]
{% endif %}
{% endif %}
{% for key, value in action.constants %}
d[{{key}}] = {{value}}
{% endfor %}
return d
{% elif 'Positional' == action.actionType %}
class AddFactoryGitHubConfiguration(argparse.Action):
class {{action.actionName}}(argparse.{{action.baseClass}}):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_git_hub_configuration = action
{% if action.type == 'array' %}
for item in action:
super({{action.actionName}}, self).__call__(parser, namespace, item, option_string)
{% else %}
namespace.{{action.mapsTo}} = action[0]
{% endif %}
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string=None):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
value_chunk_list = [values[x:x+{{action.subProperties.length}}] for x in range(0, len(values), {{action.subProperties.length}})]
value_list = []
for chunk in value_chunk_list:
{{ action.subPropertiesNamePython | join(', ') }} = chunk
value_list.append(
{
{% for item in action.subPropertiesNamePython %}
'{{item}}': {{item}},
{% endfor %}
}
)
return value_list
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'host-name':
d['host_name'] = v[0]
elif kl == 'account-name':
d['account_name'] = v[0]
elif kl == 'repository-name':
d['repository_name'] = v[0]
elif kl == 'collaboration-branch':
d['collaboration_branch'] = v[0]
elif kl == 'root-folder':
d['root_folder'] = v[0]
elif kl == 'last-commit-id':
d['last_commit_id'] = v[0]
d['type'] = 'FactoryGitHubConfiguration'
return d
raise CLIError('usage error: {} NAME METRIC OPERATION VALUE'.format(option_string))
{% elif 'ShortHandSyntax' == action.actionType %}
class AddFolder(argparse.Action):
class {{action.actionName}}(argparse.{{action.baseClass}}):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.folder = action
{% if action.type == 'array' %}
for item in action:
super({{action.actionName}}, self).__call__(parser, namespace, item, option_string)
{% else %}
namespace.{{action.mapsTo}} = action[0]
{% endif %}
def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
def get_action(self, values, option_string):
ret = []
for item in values:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'name':
d['name'] = v[0]
return d
try:
for (k, v) in (x.split('=', 1) for x in item.split(',')):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
{% if action.type != 'dictionary' or action.subProperties.length > 0 %}
kl = k.lower()
{% endif %}
v = properties[k]
{% if action.type != 'dictionary' or action.subProperties.length > 0 %}
{% for subprop in action.subProperties %}
{% if loop.first %}if{% else %}elif{% endif %} kl == '{{subprop.nameAz}}':
{% if subprop.type == 'array' %}
d['{{subprop.namePython}}'] = v
{% else %}
d['{{subprop.namePython}}'] = v[0]
{% endif %}
{% endfor %}
{% if action.subProperties.length > 0 %}
else:
raise CLIError('Unsupported Key {} is provided for parameter {{action.nameAz}}. All possible keys are: {{ action.subPropertiesNameAz | join(', ') }}'.
format(k))
{% endif %}
{% else %}
{% if subprop.type == 'array' %}
d[k] = v
{% else %}
d[k] = v[0]
{% endif %}
{% endif %}
ret.append(d)
return ret
class AddFilters(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddFilters, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'operand':
d['operand'] = v[0]
elif kl == 'operator':
d['operator'] = v[0]
elif kl == 'values':
d['values'] = v
return d
class AddOrderBy(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddOrderBy, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'order-by':
d['order_by'] = v[0]
elif kl == 'order':
d['order'] = v[0]
return d
{% endif %}
{% endfor %}

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

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

@ -96,6 +96,8 @@ export class PathConstants {
public static incTestScenarioFile(rpName: string): string {
return 'test_' + rpName + '_scenario_incrementalGenerated.py';
}
public static readonly njxFileExtension = '.njx';
}
export enum CodeGenConstants {

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddKeys(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddKeys, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,43 +34,83 @@ class AddKeys(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'alg':
d['alg'] = v[0]
elif kl == 'crv':
d['crv'] = v[0]
elif kl == 'd':
d['d'] = v[0]
elif kl == 'dp':
d['dp'] = v[0]
elif kl == 'dq':
d['dq'] = v[0]
elif kl == 'e':
d['e'] = v[0]
elif kl == 'k':
d['k'] = v[0]
elif kl == 'kid':
d['kid'] = v[0]
elif kl == 'kty':
d['kty'] = v[0]
elif kl == 'n':
d['n'] = v[0]
elif kl == 'p':
d['p'] = v[0]
elif kl == 'q':
d['q'] = v[0]
elif kl == 'qi':
d['qi'] = v[0]
elif kl == 'use':
d['use'] = v[0]
elif kl == 'x':
d['x'] = v[0]
elif kl == 'x5-c':
d['x5_c'] = v
elif kl == 'y':
d['y'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter keys. All possible keys are: alg, crv, d, '
'dp, dq, e, k, kid, kty, n, p, q, qi, use, x, x5-c, y'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter keys. All possible keys are: alg, crv, d, dp, dq, e,'
' k, kid, kty, n, p, q, qi, use, x, x5-c, y'.format(k)
)
return d

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

@ -7,4 +7,3 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddSubstatuses(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddSubstatuses, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,21 +34,37 @@ class AddSubstatuses(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'code':
d['code'] = v[0]
elif kl == 'level':
d['level'] = v[0]
elif kl == 'display-status':
d['display_status'] = v[0]
elif kl == 'message':
d['message'] = v[0]
elif kl == 'time':
d['time'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter substatuses. All possible keys are: code, '
'level, display-status, message, time'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter substatuses. All possible keys are: code, level,'
' display-status, message, time'.format(k)
)
return d
@ -52,7 +73,7 @@ class AddStatuses(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddStatuses, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -62,19 +83,35 @@ class AddStatuses(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'code':
d['code'] = v[0]
elif kl == 'level':
d['level'] = v[0]
elif kl == 'display-status':
d['display_status'] = v[0]
elif kl == 'message':
d['message'] = v[0]
elif kl == 'time':
d['time'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter statuses. All possible keys are: code, '
'level, display-status, message, time'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter statuses. All possible keys are: code, level,'
' display-status, message, time'.format(k)
)
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -17,11 +22,12 @@ from knack.util import CLIError
class AddFactoryVstsConfiguration(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_vsts_configuration = action[0]
def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x:x+7] for x in range(0, len(values), 7)]
value_chunk_list = [values[x: x + 7] for x in range(0, len(values), 7)]
value_list = []
for chunk in value_chunk_list:
type, project_name, tenant_id, account_name, repository_name, root_folder, collaboration_branch = chunk
@ -33,7 +39,7 @@ class AddFactoryVstsConfiguration(argparse.Action):
'account_name': account_name,
'repository_name': repository_name,
'root_folder': root_folder,
'collaboration_branch': collaboration_branch
'collaboration_branch': collaboration_branch,
}
)
return value_list
@ -46,7 +52,7 @@ class AddFactoryGitHubConfiguration(argparse.Action):
action = self.get_action(values, option_string)
namespace.factory_git_hub_configuration = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -56,43 +62,63 @@ class AddFactoryGitHubConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'host-name':
d['host_name'] = v[0]
elif kl == 'account-name':
d['account_name'] = v[0]
elif kl == 'repository-name':
d['repository_name'] = v[0]
elif kl == 'collaboration-branch':
d['collaboration_branch'] = v[0]
elif kl == 'root-folder':
d['root_folder'] = v[0]
elif kl == 'last-commit-id':
d['last_commit_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter factory_git_hub_configuration. All '
'possible keys are: host-name, account-name, repository-name, collaboration-branch, '
'root-folder, last-commit-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter factory-git-hub-configuration. All possible keys are:'
' host-name, account-name, repository-name, collaboration-branch, root-folder, last-commit-id'
.format(k)
)
d['type'] = 'FactoryGitHubConfiguration'
return d
class AddFakeIdentity(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.fake_identity = action[0]
def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x:x+2] for x in range(0, len(values), 2)]
value_chunk_list = [values[x: x + 2] for x in range(0, len(values), 2)]
value_list = []
for chunk in value_chunk_list:
name, zones_inside = chunk
value_list.append(
{
'name': name,
'zones_inside': zones_inside
'zones_inside': zones_inside,
}
)
return value_list
@ -105,7 +131,7 @@ class AddReplicaSets(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddReplicaSets, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -115,13 +141,23 @@ class AddReplicaSets(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'location':
d['location'] = v[0]
elif kl == 'subnet-id':
d['subnet_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter replica_sets. All possible keys are: '
'location, subnet-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter replica-sets. All possible keys are: location,'
' subnet-id'.format(k)
)
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'name':
d['name'] = v[0]
elif kl == 'capacity':
d['capacity'] = v[0]
elif kl == 'tier':
d['tier'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: name, '
'capacity, tier'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: name, capacity, tier'
.format(k)
)
return d
@ -48,7 +65,7 @@ class AddTrustedExternalTenants(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddTrustedExternalTenants, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,13 +75,21 @@ class AddTrustedExternalTenants(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'value':
d['value'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter trusted_external_tenants. All possible '
'keys are: value'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter trusted-external-tenants. All possible keys are:'
' value'.format(k)
)
return d
@ -73,7 +98,7 @@ class AddOptimizedAutoscale(argparse.Action):
action = self.get_action(values, option_string)
namespace.optimized_autoscale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -83,19 +108,33 @@ class AddOptimizedAutoscale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'version':
d['version'] = v[0]
elif kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'minimum':
d['minimum'] = v[0]
elif kl == 'maximum':
d['maximum'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter optimized_autoscale. All possible keys '
'are: version, is-enabled, minimum, maximum'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter optimized-autoscale. All possible keys are: version,'
' is-enabled, minimum, maximum'.format(k)
)
return d
@ -104,7 +143,7 @@ class AddVirtualNetworkConfiguration(argparse.Action):
action = self.get_action(values, option_string)
namespace.virtual_network_configuration = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -114,18 +153,29 @@ class AddVirtualNetworkConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'subnet-id':
d['subnet_id'] = v[0]
elif kl == 'engine-public-ip-id':
d['engine_public_ip_id'] = v[0]
elif kl == 'data-management-public-ip-id':
d['data_management_public_ip_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter virtual_network_configuration. All '
'possible keys are: subnet-id, engine-public-ip-id, data-management-public-ip-id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter virtual-network-configuration. All possible keys are:'
' subnet-id, engine-public-ip-id, data-management-public-ip-id'.format(k)
)
return d
@ -134,7 +184,7 @@ class AddKeyVaultProperties(argparse.Action):
action = self.get_action(values, option_string)
namespace.key_vault_properties = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -144,17 +194,29 @@ class AddKeyVaultProperties(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'key-name':
d['key_name'] = v[0]
elif kl == 'key-version':
d['key_version'] = v[0]
elif kl == 'key-vault-uri':
d['key_vault_uri'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter key_vault_properties. All possible keys '
'are: key-name, key-version, key-vault-uri'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter key-vault-properties. All possible keys are:'
' key-name, key-version, key-vault-uri'.format(k)
)
return d
@ -163,7 +225,7 @@ class AddClustersValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddClustersValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -173,13 +235,21 @@ class AddClustersValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'language-extension-name':
d['language_extension_name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: '
'language-extension-name'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: language-extension-name'
.format(k)
)
return d
@ -188,7 +258,7 @@ class AddReadWriteDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_write_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -198,18 +268,31 @@ class AddReadWriteDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'soft-delete-period':
d['soft_delete_period'] = v[0]
elif kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_write_database. All possible keys '
'are: soft-delete-period, hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-write-database. All possible keys are:'
' soft-delete-period, hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadWrite'
return d
@ -218,7 +301,7 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_only_following_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -228,16 +311,27 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_only_following_database. All '
'possible keys are: hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-only-following-database. All possible keys are:'
' hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadOnlyFollowing'
return d
@ -246,7 +340,7 @@ class AddDatabasesValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddDatabasesValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -256,23 +350,41 @@ class AddDatabasesValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'role':
d['role'] = v[0]
elif kl == 'name':
d['name'] = v[0]
elif kl == 'type':
d['type'] = v[0]
elif kl == 'fqn':
d['fqn'] = v[0]
elif kl == 'email':
d['email'] = v[0]
elif kl == 'app-id':
d['app_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: role, name, '
'type, fqn, email, app-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: role, name, type, fqn,'
' email, app-id'.format(k)
)
return d
@ -281,7 +393,7 @@ class AddEventHubDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.event_hub_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -291,29 +403,52 @@ class AddEventHubDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'event-hub-resource-id':
d['event_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'event-system-properties':
d['event_system_properties'] = v
elif kl == 'compression':
d['compression'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter event_hub_data_connection. All possible '
'keys are: event-hub-resource-id, consumer-group, table-name, mapping-rule-name, '
'data-format, event-system-properties, compression, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter event-hub-data-connection. All possible keys are:'
' event-hub-resource-id, consumer-group, table-name, mapping-rule-name, data-format,'
' event-system-properties, compression, location'.format(k)
)
d['kind'] = 'EventHub'
return d
@ -322,7 +457,7 @@ class AddIotHubDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.iot_hub_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -332,29 +467,52 @@ class AddIotHubDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'iot-hub-resource-id':
d['iot_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'event-system-properties':
d['event_system_properties'] = v
elif kl == 'shared-access-policy-name':
d['shared_access_policy_name'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter iot_hub_data_connection. All possible '
'keys are: iot-hub-resource-id, consumer-group, table-name, mapping-rule-name, '
'data-format, event-system-properties, shared-access-policy-name, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter iot-hub-data-connection. All possible keys are:'
' iot-hub-resource-id, consumer-group, table-name, mapping-rule-name, data-format,'
' event-system-properties, shared-access-policy-name, location'.format(k)
)
d['kind'] = 'IotHub'
return d
@ -363,7 +521,7 @@ class AddEventGridDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.event_grid_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -373,30 +531,54 @@ class AddEventGridDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'storage-account-resource-id':
d['storage_account_resource_id'] = v[0]
elif kl == 'event-hub-resource-id':
d['event_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'ignore-first-record':
d['ignore_first_record'] = v[0]
elif kl == 'blob-storage-event-type':
d['blob_storage_event_type'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter event_grid_data_connection. All possible '
'keys are: storage-account-resource-id, event-hub-resource-id, consumer-group, '
'table-name, mapping-rule-name, data-format, ignore-first-record, '
'blob-storage-event-type, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter event-grid-data-connection. All possible keys are:'
' storage-account-resource-id, event-hub-resource-id, consumer-group, table-name,'
' mapping-rule-name, data-format, ignore-first-record, blob-storage-event-type, location'.format(k)
)
d['kind'] = 'EventGrid'
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'name':
d['name'] = v[0]
elif kl == 'capacity':
d['capacity'] = v[0]
elif kl == 'tier':
d['tier'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: name, '
'capacity, tier'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: name, capacity, tier'
.format(k)
)
return d
@ -48,7 +65,7 @@ class AddTrustedExternalTenants(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddTrustedExternalTenants, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,13 +75,21 @@ class AddTrustedExternalTenants(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'value':
d['value'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter trusted_external_tenants. All possible '
'keys are: value'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter trusted-external-tenants. All possible keys are:'
' value'.format(k)
)
return d
@ -73,7 +98,7 @@ class AddOptimizedAutoscale(argparse.Action):
action = self.get_action(values, option_string)
namespace.optimized_autoscale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -83,19 +108,33 @@ class AddOptimizedAutoscale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'version':
d['version'] = v[0]
elif kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'minimum':
d['minimum'] = v[0]
elif kl == 'maximum':
d['maximum'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter optimized_autoscale. All possible keys '
'are: version, is-enabled, minimum, maximum'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter optimized-autoscale. All possible keys are: version,'
' is-enabled, minimum, maximum'.format(k)
)
return d
@ -104,7 +143,7 @@ class AddVirtualNetworkConfiguration(argparse.Action):
action = self.get_action(values, option_string)
namespace.virtual_network_configuration = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -114,18 +153,29 @@ class AddVirtualNetworkConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'subnet-id':
d['subnet_id'] = v[0]
elif kl == 'engine-public-ip-id':
d['engine_public_ip_id'] = v[0]
elif kl == 'data-management-public-ip-id':
d['data_management_public_ip_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter virtual_network_configuration. All '
'possible keys are: subnet-id, engine-public-ip-id, data-management-public-ip-id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter virtual-network-configuration. All possible keys are:'
' subnet-id, engine-public-ip-id, data-management-public-ip-id'.format(k)
)
return d
@ -134,7 +184,7 @@ class AddKeyVaultProperties(argparse.Action):
action = self.get_action(values, option_string)
namespace.key_vault_properties = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -144,17 +194,29 @@ class AddKeyVaultProperties(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'key-name':
d['key_name'] = v[0]
elif kl == 'key-version':
d['key_version'] = v[0]
elif kl == 'key-vault-uri':
d['key_vault_uri'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter key_vault_properties. All possible keys '
'are: key-name, key-version, key-vault-uri'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter key-vault-properties. All possible keys are:'
' key-name, key-version, key-vault-uri'.format(k)
)
return d
@ -163,7 +225,7 @@ class AddClustersValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddClustersValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -173,13 +235,21 @@ class AddClustersValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'language-extension-name':
d['language_extension_name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: '
'language-extension-name'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: language-extension-name'
.format(k)
)
return d
@ -188,7 +258,7 @@ class AddReadWriteDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_write_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -198,18 +268,31 @@ class AddReadWriteDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'soft-delete-period':
d['soft_delete_period'] = v[0]
elif kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_write_database. All possible keys '
'are: soft-delete-period, hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-write-database. All possible keys are:'
' soft-delete-period, hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadWrite'
return d
@ -218,7 +301,7 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_only_following_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -228,16 +311,27 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_only_following_database. All '
'possible keys are: hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-only-following-database. All possible keys are:'
' hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadOnlyFollowing'
return d
@ -246,7 +340,7 @@ class AddDatabasesValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddDatabasesValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -256,23 +350,41 @@ class AddDatabasesValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'role':
d['role'] = v[0]
elif kl == 'name':
d['name'] = v[0]
elif kl == 'type':
d['type'] = v[0]
elif kl == 'fqn':
d['fqn'] = v[0]
elif kl == 'email':
d['email'] = v[0]
elif kl == 'app-id':
d['app_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: role, name, '
'type, fqn, email, app-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: role, name, type, fqn,'
' email, app-id'.format(k)
)
return d
@ -281,7 +393,7 @@ class AddEventHubDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.event_hub_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -291,29 +403,52 @@ class AddEventHubDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'event-hub-resource-id':
d['event_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'event-system-properties':
d['event_system_properties'] = v
elif kl == 'compression':
d['compression'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter event_hub_data_connection. All possible '
'keys are: event-hub-resource-id, consumer-group, table-name, mapping-rule-name, '
'data-format, event-system-properties, compression, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter event-hub-data-connection. All possible keys are:'
' event-hub-resource-id, consumer-group, table-name, mapping-rule-name, data-format,'
' event-system-properties, compression, location'.format(k)
)
d['kind'] = 'EventHub'
return d
@ -322,7 +457,7 @@ class AddIotHubDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.iot_hub_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -332,29 +467,52 @@ class AddIotHubDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'iot-hub-resource-id':
d['iot_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'event-system-properties':
d['event_system_properties'] = v
elif kl == 'shared-access-policy-name':
d['shared_access_policy_name'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter iot_hub_data_connection. All possible '
'keys are: iot-hub-resource-id, consumer-group, table-name, mapping-rule-name, '
'data-format, event-system-properties, shared-access-policy-name, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter iot-hub-data-connection. All possible keys are:'
' iot-hub-resource-id, consumer-group, table-name, mapping-rule-name, data-format,'
' event-system-properties, shared-access-policy-name, location'.format(k)
)
d['kind'] = 'IotHub'
return d
@ -363,7 +521,7 @@ class AddEventGridDataConnection(argparse.Action):
action = self.get_action(values, option_string)
namespace.event_grid_data_connection = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -373,30 +531,54 @@ class AddEventGridDataConnection(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'storage-account-resource-id':
d['storage_account_resource_id'] = v[0]
elif kl == 'event-hub-resource-id':
d['event_hub_resource_id'] = v[0]
elif kl == 'consumer-group':
d['consumer_group'] = v[0]
elif kl == 'table-name':
d['table_name'] = v[0]
elif kl == 'mapping-rule-name':
d['mapping_rule_name'] = v[0]
elif kl == 'data-format':
d['data_format'] = v[0]
elif kl == 'ignore-first-record':
d['ignore_first_record'] = v[0]
elif kl == 'blob-storage-event-type':
d['blob_storage_event_type'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter event_grid_data_connection. All possible '
'keys are: storage-account-resource-id, event-hub-resource-id, consumer-group, '
'table-name, mapping-rule-name, data-format, ignore-first-record, '
'blob-storage-event-type, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter event-grid-data-connection. All possible keys are:'
' storage-account-resource-id, event-hub-resource-id, consumer-group, table-name,'
' mapping-rule-name, data-format, ignore-first-record, blob-storage-event-type, location'.format(k)
)
d['kind'] = 'EventGrid'
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddTrustedExternalTenants(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddTrustedExternalTenants, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,13 +34,21 @@ class AddTrustedExternalTenants(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'value':
d['value'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter trusted_external_tenants. All possible '
'keys are: value'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter trusted-external-tenants. All possible keys are:'
' value'.format(k)
)
return d
@ -44,7 +57,7 @@ class AddOptimizedAutoscale(argparse.Action):
action = self.get_action(values, option_string)
namespace.optimized_autoscale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -54,19 +67,33 @@ class AddOptimizedAutoscale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'version':
d['version'] = v[0]
elif kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'minimum':
d['minimum'] = v[0]
elif kl == 'maximum':
d['maximum'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter optimized_autoscale. All possible keys '
'are: version, is-enabled, minimum, maximum'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter optimized-autoscale. All possible keys are: version,'
' is-enabled, minimum, maximum'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddVirtualNetworkConfiguration(argparse.Action):
action = self.get_action(values, option_string)
namespace.virtual_network_configuration = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,18 +112,29 @@ class AddVirtualNetworkConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'subnet-id':
d['subnet_id'] = v[0]
elif kl == 'engine-public-ip-id':
d['engine_public_ip_id'] = v[0]
elif kl == 'data-management-public-ip-id':
d['data_management_public_ip_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter virtual_network_configuration. All '
'possible keys are: subnet-id, engine-public-ip-id, data-management-public-ip-id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter virtual-network-configuration. All possible keys are:'
' subnet-id, engine-public-ip-id, data-management-public-ip-id'.format(k)
)
return d
@ -105,7 +143,7 @@ class AddKeyVaultProperties(argparse.Action):
action = self.get_action(values, option_string)
namespace.key_vault_properties = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -115,17 +153,29 @@ class AddKeyVaultProperties(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'key-name':
d['key_name'] = v[0]
elif kl == 'key-version':
d['key_version'] = v[0]
elif kl == 'key-vault-uri':
d['key_vault_uri'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter key_vault_properties. All possible keys '
'are: key-name, key-version, key-vault-uri'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter key-vault-properties. All possible keys are:'
' key-name, key-version, key-vault-uri'.format(k)
)
return d
@ -134,7 +184,7 @@ class AddClustersValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddClustersValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -144,13 +194,21 @@ class AddClustersValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'language-extension-name':
d['language_extension_name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: '
'language-extension-name'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: language-extension-name'
.format(k)
)
return d
@ -159,7 +217,7 @@ class AddReadWriteDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_write_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,18 +227,31 @@ class AddReadWriteDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'soft-delete-period':
d['soft_delete_period'] = v[0]
elif kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_write_database. All possible keys '
'are: soft-delete-period, hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-write-database. All possible keys are:'
' soft-delete-period, hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadWrite'
return d
@ -189,7 +260,7 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_only_following_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -199,16 +270,27 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_only_following_database. All '
'possible keys are: hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-only-following-database. All possible keys are:'
' hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadOnlyFollowing'
return d
@ -217,7 +299,7 @@ class AddDatabasesValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddDatabasesValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -227,21 +309,39 @@ class AddDatabasesValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'role':
d['role'] = v[0]
elif kl == 'name':
d['name'] = v[0]
elif kl == 'type':
d['type'] = v[0]
elif kl == 'fqn':
d['fqn'] = v[0]
elif kl == 'email':
d['email'] = v[0]
elif kl == 'app-id':
d['app_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: role, name, '
'type, fqn, email, app-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: role, name, type, fqn,'
' email, app-id'.format(k)
)
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddTrustedExternalTenants(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddTrustedExternalTenants, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,13 +34,21 @@ class AddTrustedExternalTenants(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'value':
d['value'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter trusted_external_tenants. All possible '
'keys are: value'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter trusted-external-tenants. All possible keys are:'
' value'.format(k)
)
return d
@ -44,7 +57,7 @@ class AddOptimizedAutoscale(argparse.Action):
action = self.get_action(values, option_string)
namespace.optimized_autoscale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -54,19 +67,33 @@ class AddOptimizedAutoscale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'version':
d['version'] = v[0]
elif kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'minimum':
d['minimum'] = v[0]
elif kl == 'maximum':
d['maximum'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter optimized_autoscale. All possible keys '
'are: version, is-enabled, minimum, maximum'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter optimized-autoscale. All possible keys are: version,'
' is-enabled, minimum, maximum'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddVirtualNetworkConfiguration(argparse.Action):
action = self.get_action(values, option_string)
namespace.virtual_network_configuration = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,18 +112,29 @@ class AddVirtualNetworkConfiguration(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'subnet-id':
d['subnet_id'] = v[0]
elif kl == 'engine-public-ip-id':
d['engine_public_ip_id'] = v[0]
elif kl == 'data-management-public-ip-id':
d['data_management_public_ip_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter virtual_network_configuration. All '
'possible keys are: subnet-id, engine-public-ip-id, data-management-public-ip-id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter virtual-network-configuration. All possible keys are:'
' subnet-id, engine-public-ip-id, data-management-public-ip-id'.format(k)
)
return d
@ -105,7 +143,7 @@ class AddKeyVaultProperties(argparse.Action):
action = self.get_action(values, option_string)
namespace.key_vault_properties = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -115,17 +153,29 @@ class AddKeyVaultProperties(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'key-name':
d['key_name'] = v[0]
elif kl == 'key-version':
d['key_version'] = v[0]
elif kl == 'key-vault-uri':
d['key_vault_uri'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter key_vault_properties. All possible keys '
'are: key-name, key-version, key-vault-uri'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter key-vault-properties. All possible keys are:'
' key-name, key-version, key-vault-uri'.format(k)
)
return d
@ -134,7 +184,7 @@ class AddClustersValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddClustersValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -144,13 +194,21 @@ class AddClustersValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'language-extension-name':
d['language_extension_name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: '
'language-extension-name'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: language-extension-name'
.format(k)
)
return d
@ -159,7 +217,7 @@ class AddReadWriteDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_write_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,18 +227,31 @@ class AddReadWriteDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'soft-delete-period':
d['soft_delete_period'] = v[0]
elif kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_write_database. All possible keys '
'are: soft-delete-period, hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-write-database. All possible keys are:'
' soft-delete-period, hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadWrite'
return d
@ -189,7 +260,7 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
action = self.get_action(values, option_string)
namespace.read_only_following_database = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -199,16 +270,27 @@ class AddReadOnlyFollowingDatabase(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'hot-cache-period':
d['hot_cache_period'] = v[0]
elif kl == 'location':
d['location'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter read_only_following_database. All '
'possible keys are: hot-cache-period, location'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter read-only-following-database. All possible keys are:'
' hot-cache-period, location'.format(k)
)
d['kind'] = 'ReadOnlyFollowing'
return d
@ -217,7 +299,7 @@ class AddDatabasesValue(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddDatabasesValue, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -227,21 +309,39 @@ class AddDatabasesValue(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'role':
d['role'] = v[0]
elif kl == 'name':
d['name'] = v[0]
elif kl == 'type':
d['type'] = v[0]
elif kl == 'fqn':
d['fqn'] = v[0]
elif kl == 'email':
d['email'] = v[0]
elif kl == 'app-id':
d['app_id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter value. All possible keys are: role, name, '
'type, fqn, email, app-id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter value. All possible keys are: role, name, type, fqn,'
' email, app-id'.format(k)
)
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddSubscriptions(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddSubscriptions, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,13 +34,20 @@ class AddSubscriptions(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter subscriptions. All possible keys are: id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter subscriptions. All possible keys are: id'.format(k)
)
return d
@ -44,7 +56,7 @@ class AddVirtualNetworks(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddVirtualNetworks, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -54,23 +66,31 @@ class AddVirtualNetworks(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter virtual_networks. All possible keys are: '
'id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter virtual-networks. All possible keys are: id'.format(k)
)
return d
class AddSubnets(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
for item in action:
super(AddSubnets, self).__call__(parser, namespace, item, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
ret = []
for item in values:
properties = defaultdict(list)
@ -82,13 +102,20 @@ class AddSubnets(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter subnets. All possible keys are: id'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter subnets. All possible keys are: id'.format(k)
)
ret.append(d)
return ret
@ -98,7 +125,7 @@ class AddHub(argparse.Action):
action = self.get_action(values, option_string)
namespace.hub = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -108,12 +135,21 @@ class AddHub(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter hub. All possible keys are: id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter hub-and-spoke-topology_hub. All possible keys are: id'
.format(k)
)
return d
@ -122,7 +158,7 @@ class AddSpokes(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddSpokes, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -132,12 +168,21 @@ class AddSpokes(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter spokes. All possible keys are: id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter hub-and-spoke-topology_spokes. All possible keys'
' are: id'.format(k)
)
return d
@ -146,7 +191,7 @@ class AddMesh(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddMesh, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -156,10 +201,19 @@ class AddMesh(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter mesh. All possible keys are: id'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter hub-and-spoke-topology_mesh. All possible keys'
' are: id'.format(k)
)
return d

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

@ -7,4 +7,3 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddAutoScale(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_scale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddAutoScale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'min-node-count':
d['min_node_count'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
elif kl == 'max-node-count':
d['max_node_count'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_scale. All possible keys are: '
'min-node-count, enabled, max-node-count'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-scale. All possible keys are: min-node-count,'
' enabled, max-node-count'.format(k)
)
return d
@ -48,7 +65,7 @@ class AddAutoPause(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_pause = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,15 +75,25 @@ class AddAutoPause(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'delay-in-minutes':
d['delay_in_minutes'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_pause. All possible keys are: '
'delay-in-minutes, enabled'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-pause. All possible keys are: delay-in-minutes,'
' enabled'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddLibraryRequirements(argparse.Action):
action = self.get_action(values, option_string)
namespace.library_requirements = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,15 +112,25 @@ class AddLibraryRequirements(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'content':
d['content'] = v[0]
elif kl == 'filename':
d['filename'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter library_requirements. All possible keys '
'are: content, filename'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter library-requirements. All possible keys are: content,'
' filename'.format(k)
)
return d
@ -102,7 +139,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -112,15 +149,24 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'tier':
d['tier'] = v[0]
elif kl == 'name':
d['name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.format(k)
)
return d
@ -129,7 +175,7 @@ class AddRecurringScans(argparse.Action):
action = self.get_action(values, option_string)
namespace.recurring_scans = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -138,19 +184,30 @@ class AddRecurringScans(argparse.Action):
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
d['email_subscription_admins'] = True
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'email-subscription-admins':
d['email_subscription_admins'] = v[0]
elif kl == 'emails':
d['emails'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter recurring_scans. All possible keys are: '
'is-enabled, email-subscription-admins, emails'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter recurring-scans. All possible keys are: is-enabled,'
' email-subscription-admins, emails'.format(k)
)
return d
@ -159,7 +216,7 @@ class AddBaselineResults(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddBaselineResults, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,13 +226,21 @@ class AddBaselineResults(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'result':
d['result'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter baseline_results. All possible keys are: '
'result'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter baseline-results. All possible keys are: result'
.format(k)
)
return d
@ -184,7 +249,7 @@ class AddDefaultDataLakeStorage(argparse.Action):
action = self.get_action(values, option_string)
namespace.default_data_lake_storage = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -194,15 +259,25 @@ class AddDefaultDataLakeStorage(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'account-url':
d['account_url'] = v[0]
elif kl == 'filesystem':
d['filesystem'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter default_data_lake_storage. All possible '
'keys are: account-url, filesystem'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter default-data-lake-storage. All possible keys are:'
' account-url, filesystem'.format(k)
)
return d
@ -211,7 +286,7 @@ class AddConnectivityEndpoints(argparse.Action):
action = self.get_action(values, option_string)
namespace.connectivity_endpoints = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -221,6 +296,9 @@ class AddConnectivityEndpoints(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
v = properties[k]
d[k] = v[0]
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddAutoScale(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_scale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddAutoScale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'min-node-count':
d['min_node_count'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
elif kl == 'max-node-count':
d['max_node_count'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_scale. All possible keys are: '
'min-node-count, enabled, max-node-count'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-scale. All possible keys are: min-node-count,'
' enabled, max-node-count'.format(k)
)
return d
@ -48,7 +65,7 @@ class AddAutoPause(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_pause = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,15 +75,25 @@ class AddAutoPause(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'delay-in-minutes':
d['delay_in_minutes'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_pause. All possible keys are: '
'delay-in-minutes, enabled'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-pause. All possible keys are: delay-in-minutes,'
' enabled'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddLibraryRequirements(argparse.Action):
action = self.get_action(values, option_string)
namespace.library_requirements = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,15 +112,25 @@ class AddLibraryRequirements(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'content':
d['content'] = v[0]
elif kl == 'filename':
d['filename'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter library_requirements. All possible keys '
'are: content, filename'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter library-requirements. All possible keys are: content,'
' filename'.format(k)
)
return d
@ -102,7 +139,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -112,15 +149,24 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'tier':
d['tier'] = v[0]
elif kl == 'name':
d['name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.format(k)
)
return d
@ -129,7 +175,7 @@ class AddRecurringScans(argparse.Action):
action = self.get_action(values, option_string)
namespace.recurring_scans = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -138,19 +184,30 @@ class AddRecurringScans(argparse.Action):
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
d['email_subscription_admins'] = True
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'email-subscription-admins':
d['email_subscription_admins'] = v[0]
elif kl == 'emails':
d['emails'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter recurring_scans. All possible keys are: '
'is-enabled, email-subscription-admins, emails'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter recurring-scans. All possible keys are: is-enabled,'
' email-subscription-admins, emails'.format(k)
)
return d
@ -159,7 +216,7 @@ class AddBaselineResults(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddBaselineResults, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,13 +226,21 @@ class AddBaselineResults(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'result':
d['result'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter baseline_results. All possible keys are: '
'result'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter baseline-results. All possible keys are: result'
.format(k)
)
return d
@ -184,7 +249,7 @@ class AddDefaultDataLakeStorage(argparse.Action):
action = self.get_action(values, option_string)
namespace.default_data_lake_storage = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -194,15 +259,25 @@ class AddDefaultDataLakeStorage(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'account-url':
d['account_url'] = v[0]
elif kl == 'filesystem':
d['filesystem'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter default_data_lake_storage. All possible '
'keys are: account-url, filesystem'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter default-data-lake-storage. All possible keys are:'
' account-url, filesystem'.format(k)
)
return d
@ -211,7 +286,7 @@ class AddConnectivityEndpoints(argparse.Action):
action = self.get_action(values, option_string)
namespace.connectivity_endpoints = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -221,6 +296,9 @@ class AddConnectivityEndpoints(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
v = properties[k]
d[k] = v[0]
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddAutoScale(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_scale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddAutoScale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'min-node-count':
d['min_node_count'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
elif kl == 'max-node-count':
d['max_node_count'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_scale. All possible keys are: '
'min-node-count, enabled, max-node-count'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-scale. All possible keys are: min-node-count,'
' enabled, max-node-count'.format(k)
)
return d
@ -48,7 +65,7 @@ class AddAutoPause(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_pause = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,15 +75,25 @@ class AddAutoPause(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'delay-in-minutes':
d['delay_in_minutes'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_pause. All possible keys are: '
'delay-in-minutes, enabled'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-pause. All possible keys are: delay-in-minutes,'
' enabled'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddLibraryRequirements(argparse.Action):
action = self.get_action(values, option_string)
namespace.library_requirements = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,15 +112,25 @@ class AddLibraryRequirements(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'content':
d['content'] = v[0]
elif kl == 'filename':
d['filename'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter library_requirements. All possible keys '
'are: content, filename'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter library-requirements. All possible keys are: content,'
' filename'.format(k)
)
return d
@ -102,7 +139,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -112,15 +149,24 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'tier':
d['tier'] = v[0]
elif kl == 'name':
d['name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.format(k)
)
return d
@ -129,7 +175,7 @@ class AddRecurringScans(argparse.Action):
action = self.get_action(values, option_string)
namespace.recurring_scans = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -138,19 +184,30 @@ class AddRecurringScans(argparse.Action):
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
d['email_subscription_admins'] = True
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'email-subscription-admins':
d['email_subscription_admins'] = v[0]
elif kl == 'emails':
d['emails'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter recurring_scans. All possible keys are: '
'is-enabled, email-subscription-admins, emails'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter recurring-scans. All possible keys are: is-enabled,'
' email-subscription-admins, emails'.format(k)
)
return d
@ -159,7 +216,7 @@ class AddBaselineResults(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddBaselineResults, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,13 +226,21 @@ class AddBaselineResults(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'result':
d['result'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter baseline_results. All possible keys are: '
'result'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter baseline-results. All possible keys are: result'
.format(k)
)
return d
@ -184,7 +249,7 @@ class AddDefaultDataLakeStorage(argparse.Action):
action = self.get_action(values, option_string)
namespace.default_data_lake_storage = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -194,15 +259,25 @@ class AddDefaultDataLakeStorage(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'account-url':
d['account_url'] = v[0]
elif kl == 'filesystem':
d['filesystem'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter default_data_lake_storage. All possible '
'keys are: account-url, filesystem'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter default-data-lake-storage. All possible keys are:'
' account-url, filesystem'.format(k)
)
return d
@ -211,7 +286,7 @@ class AddConnectivityEndpoints(argparse.Action):
action = self.get_action(values, option_string)
namespace.connectivity_endpoints = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -221,6 +296,9 @@ class AddConnectivityEndpoints(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
v = properties[k]
d[k] = v[0]
return d

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

@ -7,8 +7,13 @@
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
@ -19,7 +24,7 @@ class AddAutoScale(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_scale = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -29,17 +34,29 @@ class AddAutoScale(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'min-node-count':
d['min_node_count'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
elif kl == 'max-node-count':
d['max_node_count'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_scale. All possible keys are: '
'min-node-count, enabled, max-node-count'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-scale. All possible keys are: min-node-count,'
' enabled, max-node-count'.format(k)
)
return d
@ -48,7 +65,7 @@ class AddAutoPause(argparse.Action):
action = self.get_action(values, option_string)
namespace.auto_pause = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -58,15 +75,25 @@ class AddAutoPause(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'delay-in-minutes':
d['delay_in_minutes'] = v[0]
elif kl == 'enabled':
d['enabled'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter auto_pause. All possible keys are: '
'delay-in-minutes, enabled'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter auto-pause. All possible keys are: delay-in-minutes,'
' enabled'.format(k)
)
return d
@ -75,7 +102,7 @@ class AddLibraryRequirements(argparse.Action):
action = self.get_action(values, option_string)
namespace.library_requirements = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -85,15 +112,25 @@ class AddLibraryRequirements(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'content':
d['content'] = v[0]
elif kl == 'filename':
d['filename'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter library_requirements. All possible keys '
'are: content, filename'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter library-requirements. All possible keys are: content,'
' filename'.format(k)
)
return d
@ -102,7 +139,7 @@ class AddSku(argparse.Action):
action = self.get_action(values, option_string)
namespace.sku = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -112,15 +149,24 @@ class AddSku(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'tier':
d['tier'] = v[0]
elif kl == 'name':
d['name'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.
format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter sku. All possible keys are: tier, name'.format(k)
)
return d
@ -129,7 +175,7 @@ class AddRecurringScans(argparse.Action):
action = self.get_action(values, option_string)
namespace.recurring_scans = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -138,19 +184,30 @@ class AddRecurringScans(argparse.Action):
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
d['email_subscription_admins'] = True
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'is-enabled':
d['is_enabled'] = v[0]
elif kl == 'email-subscription-admins':
d['email_subscription_admins'] = v[0]
elif kl == 'emails':
d['emails'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter recurring_scans. All possible keys are: '
'is-enabled, email-subscription-admins, emails'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter recurring-scans. All possible keys are: is-enabled,'
' email-subscription-admins, emails'.format(k)
)
return d
@ -159,7 +216,7 @@ class AddBaselineResults(argparse._AppendAction):
action = self.get_action(values, option_string)
super(AddBaselineResults, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -169,13 +226,21 @@ class AddBaselineResults(argparse._AppendAction):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'result':
d['result'] = v
else:
raise CLIError('Unsupported Key {} is provided for parameter baseline_results. All possible keys are: '
'result'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter baseline-results. All possible keys are: result'
.format(k)
)
return d
@ -184,7 +249,7 @@ class AddDefaultDataLakeStorage(argparse.Action):
action = self.get_action(values, option_string)
namespace.default_data_lake_storage = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -194,15 +259,25 @@ class AddDefaultDataLakeStorage(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'account-url':
d['account_url'] = v[0]
elif kl == 'filesystem':
d['filesystem'] = v[0]
else:
raise CLIError('Unsupported Key {} is provided for parameter default_data_lake_storage. All possible '
'keys are: account-url, filesystem'.format(k))
raise CLIError(
'Unsupported Key {} is provided for parameter default-data-lake-storage. All possible keys are:'
' account-url, filesystem'.format(k)
)
return d
@ -211,7 +286,7 @@ class AddConnectivityEndpoints(argparse.Action):
action = self.get_action(values, option_string)
namespace.connectivity_endpoints = action
def get_action(self, values, option_string): # pylint: disable=no-self-use
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
@ -221,6 +296,9 @@ class AddConnectivityEndpoints(argparse.Action):
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
v = properties[k]
d[k] = v[0]
return d

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

@ -0,0 +1,219 @@
{
"data": {
"imports": [],
"pylints": [
"# pylint: disable=protected-access",
"# pylint: disable=no-self-use"
],
"actions": [
{
"actionName": "AddFactoryVstsConfiguration",
"actionType": "Positional",
"mapsTo": "factory_vsts_configuration",
"type": "object",
"nameAz": "factory-vsts-configuration",
"baseClass": "Action",
"subProperties": [
{
"namePython": "project_name",
"nameAz": "project-name",
"type": "string"
},
{
"namePython": "tenant_id",
"nameAz": "tenant-id",
"type": "string"
},
{
"namePython": "account_name",
"nameAz": "account-name",
"type": "string"
},
{
"namePython": "repository_name",
"nameAz": "repository-name",
"type": "string"
},
{
"namePython": "collaboration_branch",
"nameAz": "collaboration-branch",
"type": "string"
},
{
"namePython": "root_folder",
"nameAz": "root-folder",
"type": "string"
},
{
"namePython": "last_commit_id",
"nameAz": "last-commit-id",
"type": "string"
}
],
"subPropertiesMapsTo": [
"project_name",
"tenant_id",
"account_name",
"repository_name",
"collaboration_branch",
"root_folder",
"last_commit_id"
],
"subPropertiesNamePython": [
"type",
"project_name",
"tenant_id",
"account_name",
"repository_name",
"root_folder",
"collaboration_branch"
],
"subPropertiesNameAz": [
"project-name",
"tenant-id",
"account-name",
"repository-name",
"collaboration-branch",
"root-folder",
"last-commit-id"
],
"constants": {
"'type'": "'FactoryVSTSConfiguration'"
}
},
{
"actionName": "AddFactoryGitHubConfiguration",
"actionType": "KeyValue",
"mapsTo": "factory_git_hub_configuration",
"type": "object",
"nameAz": "factory-git-hub-configuration",
"baseClass": "Action",
"subProperties": [
{
"namePython": "host_name",
"nameAz": "host-name",
"type": "string"
},
{
"namePython": "account_name",
"nameAz": "account-name",
"type": "string"
},
{
"namePython": "repository_name",
"nameAz": "repository-name",
"type": "string"
},
{
"namePython": "collaboration_branch",
"nameAz": "collaboration-branch",
"type": "string"
},
{
"namePython": "root_folder",
"nameAz": "root-folder",
"type": "string"
},
{
"namePython": "last_commit_id",
"nameAz": "last-commit-id",
"type": "string"
}
],
"subPropertiesMapsTo": [
"host_name",
"account_name",
"repository_name",
"collaboration_branch",
"root_folder",
"last_commit_id"
],
"subPropertiesNamePython": [
"host_name",
"account_name",
"repository_name",
"collaboration_branch",
"root_folder",
"last_commit_id"
],
"subPropertiesNameAz": [
"host-name",
"account-name",
"repository-name",
"collaboration-branch",
"root-folder",
"last-commit-id"
],
"constants": {
"'type'": "'FactoryGitHubConfiguration'"
}
},
{
"actionName": "AddFakeIdentity",
"actionType": "Positional",
"mapsTo": "fake_identity",
"type": "object",
"nameAz": "fake-identity",
"baseClass": "Action",
"subProperties": [
{
"namePython": "name",
"nameAz": "name",
"type": "string"
},
{
"namePython": "zones_inside",
"nameAz": "zones-inside",
"type": "array"
}
],
"subPropertiesMapsTo": [
"name",
"zones_inside"
],
"subPropertiesNamePython": [
"name",
"zones_inside"
],
"subPropertiesNameAz": [
"name",
"zones-inside"
],
"constants": {}
},
{
"actionName": "AddReplicaSets",
"actionType": "KeyValue",
"mapsTo": "replica_sets",
"type": "array",
"nameAz": "replica-sets",
"baseClass": "_AppendAction",
"subProperties": [
{
"namePython": "location",
"nameAz": "location",
"type": "string"
},
{
"namePython": "subnet_id",
"nameAz": "subnet-id",
"type": "string"
}
],
"subPropertiesMapsTo": [
"location",
"subnet_id"
],
"subPropertiesNamePython": [
"location",
"subnet_id"
],
"subPropertiesNameAz": [
"location",
"subnet-id"
],
"constants": {}
}
]
}
}

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

@ -0,0 +1,163 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
class AddFactoryVstsConfiguration(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_vsts_configuration = action[0]
def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x: x + 7] for x in range(0, len(values), 7)]
value_list = []
for chunk in value_chunk_list:
type, project_name, tenant_id, account_name, repository_name, root_folder, collaboration_branch = chunk
value_list.append(
{
'type': type,
'project_name': project_name,
'tenant_id': tenant_id,
'account_name': account_name,
'repository_name': repository_name,
'root_folder': root_folder,
'collaboration_branch': collaboration_branch,
}
)
return value_list
except ValueError:
raise CLIError('usage error: {} NAME METRIC OPERATION VALUE'.format(option_string))
class AddFactoryGitHubConfiguration(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_git_hub_configuration = action
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'host-name':
d['host_name'] = v[0]
elif kl == 'account-name':
d['account_name'] = v[0]
elif kl == 'repository-name':
d['repository_name'] = v[0]
elif kl == 'collaboration-branch':
d['collaboration_branch'] = v[0]
elif kl == 'root-folder':
d['root_folder'] = v[0]
elif kl == 'last-commit-id':
d['last_commit_id'] = v[0]
else:
raise CLIError(
'Unsupported Key {} is provided for parameter factory-git-hub-configuration. All possible keys are:'
' host-name, account-name, repository-name, collaboration-branch, root-folder, last-commit-id'
.format(k)
)
d['type'] = 'FactoryGitHubConfiguration'
return d
class AddFakeIdentity(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.fake_identity = action[0]
def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x: x + 2] for x in range(0, len(values), 2)]
value_list = []
for chunk in value_chunk_list:
name, zones_inside = chunk
value_list.append(
{
'name': name,
'zones_inside': zones_inside,
}
)
return value_list
except ValueError:
raise CLIError('usage error: {} NAME METRIC OPERATION VALUE'.format(option_string))
class AddReplicaSets(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
super(AddReplicaSets, self).__call__(parser, namespace, action, option_string)
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'location':
d['location'] = v[0]
elif kl == 'subnet-id':
d['subnet_id'] = v[0]
else:
raise CLIError(
'Unsupported Key {} is provided for parameter replica-sets. All possible keys are: location,'
' subnet-id'.format(k)
)
return d

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

@ -0,0 +1,75 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
class AddFactoryGitHubConfiguration(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_git_hub_configuration = action
def get_action(self, values, option_string):
try:
properties = defaultdict(list)
for (k, v) in (x.split('=', 1) for x in values):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'host-name':
d['host_name'] = v[0]
elif kl == 'account-name':
d['account_name'] = v[0]
elif kl == 'repository-name':
d['repository_name'] = v[0]
elif kl == 'collaboration-branch':
d['collaboration_branch'] = v[0]
elif kl == 'root-folder':
d['root_folder'] = v[0]
elif kl == 'last-commit-id':
d['last_commit_id'] = v[0]
else:
raise CLIError(
'Unsupported Key {} is provided for parameter factory-git-hub-configuration. All possible keys are:'
' host-name, account-name, repository-name, collaboration-branch, root-folder, last-commit-id'
.format(k)
)
d['type'] = 'FactoryGitHubConfiguration'
return d

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

@ -0,0 +1,46 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from knack.util import CLIError
class AddFactoryVstsConfiguration(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
namespace.factory_vsts_configuration = action[0]
def get_action(self, values, option_string=None):
try:
value_chunk_list = [values[x: x + 7] for x in range(0, len(values), 7)]
value_list = []
for chunk in value_chunk_list:
type, project_name, tenant_id, account_name, repository_name, root_folder, collaboration_branch = chunk
value_list.append(
{
'type': type,
'project_name': project_name,
'tenant_id': tenant_id,
'account_name': account_name,
'repository_name': repository_name,
'root_folder': root_folder,
'collaboration_branch': collaboration_branch,
}
)
return value_list
except ValueError:
raise CLIError('usage error: {} NAME METRIC OPERATION VALUE'.format(option_string))

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

@ -0,0 +1,62 @@
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
# pylint: disable=protected-access
# pylint: disable=no-self-use
import argparse
from collections import defaultdict
from knack.util import CLIError
class AddSubnets(argparse._AppendAction):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string)
for item in action:
super(AddSubnets, self).__call__(parser, namespace, item, option_string)
def get_action(self, values, option_string):
ret = []
for item in values:
properties = defaultdict(list)
try:
for (k, v) in (x.split('=', 1) for x in item.split(',')):
properties[k].append(v)
properties = dict(properties)
except ValueError:
raise CLIError('usage error: {} [KEY=VALUE ...]'.format(option_string))
d = {}
for k in properties:
kl = k.lower()
v = properties[k]
if kl == 'id':
d['id'] = v[0]
elif kl == 'name':
d['name'] = v[0]
else:
raise CLIError(
'Unsupported Key {} is provided for parameter subnets. All possible keys are: id, name'.format(
k
)
)
ret.append(d)
return ret

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

@ -0,0 +1,270 @@
/* ---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*-------------------------------------------------------------------------------------------- */
import * as assert from 'assert';
import * as nunjucks from 'nunjucks';
import * as path from 'path';
import * as sourceMapSupport from 'source-map-support';
import { readFile, writeFile, rmFile } from '@azure-tools/async-io';
import { AzLinter } from '../../src/azlinter';
sourceMapSupport.install();
describe('renderActionPYTest', () => {
it('single positional action test', async () => {
const tmplPath = path.join(`${__dirname}`, '../../src/templates/generated/action.py.njx');
nunjucks.configure({ autoescape: false });
let result = nunjucks.render(tmplPath, {
data: {
pylints: ['# pylint: disable=protected-access', '# pylint: disable=no-self-use'],
actions: [
{
actionName: 'AddFactoryVstsConfiguration',
actionType: 'Positional',
mapsTo: 'factory_vsts_configuration',
type: 'object',
nameAz: 'factory-vsts-configuration',
baseClass: 'Action',
subProperties: [
{
namePython: 'type',
nameAz: 'type',
type: 'string',
},
{
namePython: 'project_name',
nameAz: 'project-name',
type: 'string',
},
{
namePython: 'tenant_id',
nameAz: 'tenant-id',
type: 'string',
},
{
namePython: 'account_name',
nameAz: 'account-name',
type: 'string',
},
{
namePython: 'repository_name',
nameAz: 'repository-name',
type: 'string',
},
{
namePython: 'root_folder',
nameAz: 'root-folder',
type: 'string',
},
{
namePython: 'collaboration_branch',
nameAz: 'collaboration-branch',
type: 'string',
},
],
subPropertiesMapsTo: [
'type',
'project_name',
'tenant_id',
'account_name',
'repository_name',
'root_folder',
'collaboration_branch',
],
subPropertiesNamePython: [
'type',
'project_name',
'tenant_id',
'account_name',
'repository_name',
'root_folder',
'collaboration_branch',
],
subPropertiesNameAz: [
'type',
'project-name',
'tenant-id',
'account-name',
'repository-name',
'root-folder',
'collaboration-branch',
],
},
],
},
});
const oriFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/ori_positional_action.py',
);
await writeFile(oriFile, result);
const azLinter = new AzLinter();
await azLinter.process(oriFile);
result = await readFile(oriFile);
const expectedFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/positional_action.py',
);
const expected = await readFile(expectedFile);
assert.deepStrictEqual(
result,
expected,
'render positional action in action.py is incorrect',
);
await rmFile(oriFile);
});
it('single key value action test', async () => {
const tmplPath = path.join(`${__dirname}`, '../../src/templates/generated/action.py.njx');
nunjucks.configure({ autoescape: false });
let result = nunjucks.render(tmplPath, {
data: {
pylints: ['# pylint: disable=protected-access', '# pylint: disable=no-self-use'],
actions: [
{
actionName: 'AddFactoryGitHubConfiguration',
actionType: 'KeyValue',
mapsTo: 'factory_git_hub_configuration',
type: 'object',
nameAz: 'factory-git-hub-configuration',
baseClass: 'Action',
subProperties: [
{
nameAz: 'host-name',
namePython: 'host_name',
type: 'string',
},
{
nameAz: 'account-name',
namePython: 'account_name',
type: 'string',
},
{
nameAz: 'repository-name',
namePython: 'repository_name',
type: 'string',
},
{
nameAz: 'collaboration-branch',
namePython: 'collaboration_branch',
type: 'string',
},
{
nameAz: 'root-folder',
namePython: 'root_folder',
type: 'string',
},
{
nameAz: 'last-commit-id',
namePython: 'last_commit_id',
type: 'string',
},
],
subPropertiesMapsTo: [
'host_name',
'account_name',
'repository_name',
'collaboration_branch',
'root_folder',
'last_commit_id',
],
subPropertiesNamePython: [
'host_name',
'account_name',
'repository_name',
'collaboration_branch',
'root_folder',
'last_commit_id',
],
subPropertiesNameAz: [
'host-name',
'account-name',
'repository-name',
'collaboration-branch',
'root-folder',
'last-commit-id',
],
constants: {
"'type'": "'FactoryGitHubConfiguration'",
},
},
],
},
});
const oriFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/ori_key_value_action.py',
);
await writeFile(oriFile, result);
const azLinter = new AzLinter();
await azLinter.process(oriFile);
result = await readFile(oriFile);
const expectedFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/key_value_action.py',
);
const expected = await readFile(expectedFile);
assert.deepStrictEqual(
result,
expected,
'render key value action in action.py is incorrect',
);
await rmFile(oriFile);
});
it('single shorthand syntax action test', async () => {
const tmplPath = path.join(`${__dirname}`, '../../src/templates/generated/action.py.njx');
nunjucks.configure({ autoescape: false });
let result = nunjucks.render(tmplPath, {
data: {
pylints: ['# pylint: disable=protected-access', '# pylint: disable=no-self-use'],
actions: [
{
actionName: 'AddSubnets',
actionType: 'ShortHandSyntax',
mapsTo: 'subnets',
type: 'array',
nameAz: 'subnets',
baseClass: '_AppendAction',
subProperties: [
{
nameAz: 'id',
namePython: 'id',
type: 'string',
},
{
nameAz: 'name',
namePython: 'name',
type: 'string',
},
],
subPropertiesMapsTo: ['id', 'name'],
subPropertiesNamePython: ['id', 'name'],
subPropertiesNameAz: ['id', 'name'],
constants: {},
},
],
},
});
const oriFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/ori_short_hand_syntax_action.py',
);
await writeFile(oriFile, result);
const azLinter = new AzLinter();
await azLinter.process(oriFile);
result = await readFile(oriFile);
const expectedFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/short_hand_syntax_action.py',
);
const expected = await readFile(expectedFile);
assert.deepStrictEqual(
result,
expected,
'render shorthand syntax action in action.py is incorrect',
);
await rmFile(oriFile);
});
});

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

@ -0,0 +1,110 @@
/* ---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*-------------------------------------------------------------------------------------------- */
import * as assert from 'assert';
import * as fs from 'fs';
import * as nunjucks from 'nunjucks';
import * as path from 'path';
import * as sourceMapSupport from 'source-map-support';
import { readFile, rmFile, writeFile } from '@azure-tools/async-io';
import { CodeModel } from '@azure-tools/codemodel';
import { AzConfiguration, CodeGenConstants, ExtensionMode } from '../../src/utils/models';
import { CliActions } from '../../src/generate/renders/generated/CliActions';
import { AzLinter } from '../../src/azlinter';
import { Entry } from '../../src/entry';
import { CodeModelCliImpl } from '../../src/generate/CodeModelAzImpl';
import { createTestSession } from '../utils/test-helper';
sourceMapSupport.install();
const resources = path.join(`${__dirname}`, '/../../test/unittest/');
const fileName = 'datafactory-az-modifier-after.yaml';
describe('getActionsRender', () => {
let model: CodeModelCliImpl;
async function init(extensionName: string, fileName: string): Promise<void> {
const cfg = {
az: {
extensions: extensionName,
},
};
if (!fs.existsSync(path.join(resources, 'input', fileName))) {
throw Error;
}
const session = await createTestSession<CodeModel>(cfg, path.join(resources, 'input'), [
fileName,
]);
const entry = new Entry(session);
await entry.init();
const codeModel = new CodeModelCliImpl(session);
codeModel.GenerateTestInit();
model = codeModel;
}
async function getActionsRenderData() {
await init('datafactory', fileName);
AzConfiguration.setValue(CodeGenConstants.extensionMode, ExtensionMode.Experimental);
AzConfiguration.setValue(CodeGenConstants.azextFolder, 'azext_datafactory_preview');
AzConfiguration.setValue(
CodeGenConstants.pythonNamespace,
'azext_datafactory_preview.vendored_sdks.azure_mgmt_datafactory',
);
const cliActionRender = new CliActions(model);
const data = await cliActionRender.GetRenderData();
return data;
}
function render(tmplPath: string, data: any) {
nunjucks.configure({ autoescape: false });
const result = nunjucks.render(tmplPath, data);
return result;
}
const originalWarn = console.warn.bind(console.warn);
beforeAll(() => {
console.warn = (msg) => msg.toString().includes('ShowInTest') && originalWarn(msg);
});
afterAll(() => {
console.warn = originalWarn;
});
it('getActionRenderDataTest1', async () => {
const expected = JSON.parse(
await readFile(path.join(resources, 'expected', 'data/actions.json')),
);
let data = await getActionsRenderData();
data = JSON.parse(JSON.stringify(data));
assert.deepStrictEqual(
data,
expected,
'Getting render data error from extension to methodParameter ',
);
});
it('getActionRenderDataTest2', async () => {
const tmplPath = path.join(`${__dirname}`, '../../src/templates/generated/action.py.njx');
const data = await getActionsRenderData();
let result = render(tmplPath, data);
const oriFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/ori_action.py',
);
await writeFile(oriFile, result);
const azLinter = new AzLinter();
await azLinter.process(oriFile);
result = await readFile(oriFile);
const expectedFile = path.join(
`${__dirname}`,
'../../test/unittest/expected/generated/action.py',
);
const expected = await readFile(expectedFile);
assert.deepStrictEqual(result, expected, 'render logic for action.py is incorrect');
await rmFile(oriFile);
});
});