Skip to content

Commit

Permalink
rename servicePrincipalKey to servicePrincipalSecret
Browse files Browse the repository at this point in the history
  • Loading branch information
YanaXu committed Oct 17, 2023
1 parent 3caf02d commit bd9b473
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions __tests__/LoginConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("LoginConfig Test", () => {
expect(loginConfig.allowNoSubscriptionsLogin).toBeFalsy();
expect(loginConfig.authType).toBe("SERVICE_PRINCIPAL");
expect(loginConfig.servicePrincipalId).toBe("client-id");
expect(loginConfig.servicePrincipalKey).toBe("client-secret");
expect(loginConfig.servicePrincipalSecret).toBe("client-secret");
expect(loginConfig.tenantId).toBe("tenant-id");
expect(loginConfig.subscriptionId).toBe("subscription-id");
});
Expand Down Expand Up @@ -157,7 +157,7 @@ describe("LoginConfig Test", () => {
expect(loginConfig.allowNoSubscriptionsLogin).toBeTruthy();
expect(loginConfig.authType).toBe("SERVICE_PRINCIPAL");
expect(loginConfig.servicePrincipalId).toBe("client-id-aa");
expect(loginConfig.servicePrincipalKey).toBeNull();
expect(loginConfig.servicePrincipalSecret).toBeNull();
expect(loginConfig.tenantId).toBe("tenant-id-aa");
expect(loginConfig.subscriptionId).toBe("subscription-id-aa");
});
Expand Down Expand Up @@ -251,7 +251,7 @@ describe("LoginConfig Test", () => {
expect(loginConfig.allowNoSubscriptionsLogin).toBeTruthy();
expect(loginConfig.authType).toBe("IDENTITY");
expect(loginConfig.servicePrincipalId).toBe("");
expect(loginConfig.servicePrincipalKey).toBeNull();
expect(loginConfig.servicePrincipalSecret).toBeNull();
expect(loginConfig.tenantId).toBe("");
expect(loginConfig.subscriptionId).toBe("");
});
Expand Down
2 changes: 1 addition & 1 deletion __tests__/PowerShell/AzPSLogin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jest.setTimeout(30000);
beforeAll(() => {
var loginConfig = new LoginConfig();
loginConfig.servicePrincipalId = "servicePrincipalID";
loginConfig.servicePrincipalKey = "servicePrinicipalkey";
loginConfig.servicePrincipalSecret = "servicePrincipalSecret";
loginConfig.tenantId = "tenantId";
loginConfig.subscriptionId = "subscriptionId";
azpsLogin = new AzPSLogin(loginConfig);
Expand Down
4 changes: 2 additions & 2 deletions src/Cli/AzureCliLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class AzureCliLogin {
"--username", this.loginConfig.servicePrincipalId,
"--tenant", this.loginConfig.tenantId
];
if (this.loginConfig.servicePrincipalKey) {
if (this.loginConfig.servicePrincipalSecret) {
await this.loginWithSecret(args);
}
else {
Expand Down Expand Up @@ -100,7 +100,7 @@ export class AzureCliLogin {

async loginWithSecret(args: string[]) {
core.info("Note: Azure/login action also supports OIDC login mechanism. Refer https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication for more details.")
args.push(`--password=${this.loginConfig.servicePrincipalKey}`);
args.push(`--password=${this.loginConfig.servicePrincipalSecret}`);
await this.callCliLogin(args, 'service principal with secret');
}

Expand Down
6 changes: 3 additions & 3 deletions src/PowerShell/AzPSScriptBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class AzPSScriptBuilder {
commands += `Add-AzEnvironment -Name '${loginConfig.environment}' -ARMEndpoint '${loginConfig.resourceManagerEndpointUrl}' | out-null;`;
}
if (loginConfig.authType === LoginConfig.AUTH_TYPE_SERVICE_PRINCIPAL) {
if (loginConfig.servicePrincipalKey) {
if (loginConfig.servicePrincipalSecret) {
commands += AzPSScriptBuilder.loginWithSecret(loginConfig);
loginMethodName = 'service principal with secret';
} else {
Expand Down Expand Up @@ -66,8 +66,8 @@ export default class AzPSScriptBuilder {
}

private static loginWithSecret(loginConfig: LoginConfig): string {
let servicePrincipalKey: string = loginConfig.servicePrincipalKey.split("'").join("''");
let loginCmdlet = `$psLoginSecrets = ConvertTo-SecureString '${servicePrincipalKey}' -AsPlainText -Force; `;
let servicePrincipalSecret: string = loginConfig.servicePrincipalSecret.split("'").join("''");
let loginCmdlet = `$psLoginSecrets = ConvertTo-SecureString '${servicePrincipalSecret}' -AsPlainText -Force; `;
loginCmdlet += `$psLoginCredential = New-Object System.Management.Automation.PSCredential('${loginConfig.servicePrincipalId}', $psLoginSecrets); `;

let cmdletSuffix = "-Credential $psLoginCredential";
Expand Down
10 changes: 5 additions & 5 deletions src/common/LoginConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class LoginConfig {

authType: string;
servicePrincipalId: string;
servicePrincipalKey: string;
servicePrincipalSecret: string;
tenantId: string;
subscriptionId: string;
resourceManagerEndpointUrl: string;
Expand All @@ -34,7 +34,7 @@ export class LoginConfig {
this.authType = core.getInput('auth-type').toUpperCase();

this.servicePrincipalId = core.getInput('client-id', { required: false });
this.servicePrincipalKey = null;
this.servicePrincipalSecret = null;
this.tenantId = core.getInput('tenant-id', { required: false });
this.subscriptionId = core.getInput('subscription-id', { required: false });

Expand All @@ -44,7 +44,7 @@ export class LoginConfig {
this.federatedToken = null;

this.mask(this.servicePrincipalId);
this.mask(this.servicePrincipalKey);
this.mask(this.servicePrincipalSecret);
}

private readParametersFromCreds() {
Expand All @@ -65,11 +65,11 @@ export class LoginConfig {

core.debug('Reading creds in JSON...');
this.servicePrincipalId = this.servicePrincipalId ? this.servicePrincipalId : secrets.getSecret("$.clientId", false);
this.servicePrincipalKey = secrets.getSecret("$.clientSecret", false);
this.servicePrincipalSecret = secrets.getSecret("$.clientSecret", false);
this.tenantId = this.tenantId ? this.tenantId : secrets.getSecret("$.tenantId", false);
this.subscriptionId = this.subscriptionId ? this.subscriptionId : secrets.getSecret("$.subscriptionId", false);
this.resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
if (!this.servicePrincipalId || !this.servicePrincipalKey || !this.tenantId || !this.subscriptionId) {
if (!this.servicePrincipalId || !this.servicePrincipalSecret || !this.tenantId || !this.subscriptionId) {
throw new Error("Not all parameters are provided in 'creds'. Double-check if all keys are defined in 'creds': 'clientId', 'clientSecret', 'subscriptionId', 'tenantId'.");
}
}
Expand Down

0 comments on commit bd9b473

Please sign in to comment.