Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
Support Authentication Policy
Browse files Browse the repository at this point in the history
  • Loading branch information
LianwMS committed Jun 17, 2020
1 parent 130e1d3 commit c1e5cbd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/plugins/azgenerator/CodeModelAz.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface CodeModelAz {
Extension_TestScenario: any;
Extension_ClientSubscriptionBound: boolean;
Extension_ClientBaseUrlBound: boolean;
Extension_ClientAuthenticationPolicy: string;
Extension_Mode: string;

SelectFirstCommandGroup(): boolean;
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/azgenerator/CodeModelAzImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class CodeModelCliImpl implements CodeModelAz {
private _configuredScenario: boolean;
private _clientSubscriptionBound: boolean;
private _clientBaseUrlBound: boolean;
private _clientAuthenticationPolicy: string;

async init() {
this.options = await this.session.getValue('az');
Expand All @@ -58,6 +59,7 @@ export class CodeModelCliImpl implements CodeModelAz {
this.substack = new Array<[Parameter[], number]>();
this._clientBaseUrlBound = this.options['client-base-url-bound'];
this._clientSubscriptionBound = this.options['client-subscription-bound'];
this._clientAuthenticationPolicy = this.options['client-authentication-policy'];
//this.sortOperationByAzCommand();
}

Expand Down Expand Up @@ -452,6 +454,10 @@ export class CodeModelCliImpl implements CodeModelAz {
return this._clientBaseUrlBound;
}

public get Extension_ClientAuthenticationPolicy(): string {
return this._clientAuthenticationPolicy;
}

//=================================================================================================================
// Command Groups
//
Expand Down
40 changes: 24 additions & 16 deletions src/plugins/azgenerator/TemplateAzureCliClientFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { CodeModelAz } from "./CodeModelAz"
import { HeaderGenerator } from "./Header";
import { isNullOrUndefined } from "util";

export function GenerateAzureCliClientFactory(model: CodeModelAz) : string[] {
export function GenerateAzureCliClientFactory(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
var output: string[] = header.getLines();
model.SelectFirstCommandGroup();
Expand All @@ -17,23 +17,31 @@ export function GenerateAzureCliClientFactory(model: CodeModelAz) : string[] {
output.push(" from azure.cli.core.commands.client_factory import get_mgmt_service_client");
output.push(" from ..vendored_sdks." + model.PythonOperationsName + " import " + model.PythonMgmtClient);

if (!isNullOrUndefined(model.Extension_ClientSubscriptionBound) || !isNullOrUndefined(model.Extension_ClientBaseUrlBound))
{
output.push(" return get_mgmt_service_client(cli_ctx, " + model.PythonMgmtClient + ",");
output.push(" subscription_bound=" + (model.Extension_ClientSubscriptionBound ? "True" : "False") + ",");
output.push(" base_url_bound=" + (model.Extension_ClientBaseUrlBound ? "True" : "False") + ")");
if (!isNullOrUndefined(model.Extension_ClientAuthenticationPolicy)) {
output.push(" from azure.core.pipeline.policies import " + model.Extension_ClientAuthenticationPolicy);
}
else
{
output.push(" return get_mgmt_service_client(cli_ctx, " + model.PythonMgmtClient + ")");

// Start handle arguments
output.push(" return get_mgmt_service_client(cli_ctx,");
output.push(" " + model.PythonMgmtClient);
if (!isNullOrUndefined(model.Extension_ClientSubscriptionBound)) {
output.push(output.pop() + ",");
output.push(" subscription_bound=" + (model.Extension_ClientSubscriptionBound ? "True" : "False"));
}
if (!isNullOrUndefined(model.Extension_ClientBaseUrlBound)) {
output.push(output.pop() + ",");
output.push(" base_url_bound=" + (model.Extension_ClientBaseUrlBound ? "True" : "False"));
}
if (!isNullOrUndefined(model.Extension_ClientAuthenticationPolicy)) {
output.push(output.pop() + ",");
output.push(" authentication_policy=" + model.Extension_ClientAuthenticationPolicy + "()");
}
output.push(output.pop()+ ")");
// End

if (model.SelectFirstCommandGroup())
{
do
{
if (model.GetModuleOperationName() != "")
{
if (model.SelectFirstCommandGroup()) {
do {
if (model.GetModuleOperationName() != "") {
output.push("");
output.push("");

Expand All @@ -42,7 +50,7 @@ export function GenerateAzureCliClientFactory(model: CodeModelAz) : string[] {
}
} while (model.SelectNextCommandGroup());
}

output.push("");

return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
def cf_attestation_cl(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from ..vendored_sdks.attestation import AttestationManagementClient
return get_mgmt_service_client(cli_ctx, AttestationManagementClient)
return get_mgmt_service_client(cli_ctx,
AttestationManagementClient)


def cf_operation(cli_ctx, *_):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
def cf_datafactory_cl(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from ..vendored_sdks.datafactory import DFAZManagementClient
return get_mgmt_service_client(cli_ctx, DFAZManagementClient)
return get_mgmt_service_client(cli_ctx,
DFAZManagementClient)


def cf_factory(cli_ctx, *_):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
def cf_managed_network_cl(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from ..vendored_sdks.managednetwork import ManagedNetworkManagementClient
return get_mgmt_service_client(cli_ctx, ManagedNetworkManagementClient)
return get_mgmt_service_client(cli_ctx,
ManagedNetworkManagementClient)


def cf_mn(cli_ctx, *_):
Expand Down

0 comments on commit c1e5cbd

Please sign in to comment.