diff --git a/__tests__/LoginConfig.test.ts b/__tests__/LoginConfig.test.ts index 0f75f42d3..a4933903a 100644 --- a/__tests__/LoginConfig.test.ts +++ b/__tests__/LoginConfig.test.ts @@ -96,7 +96,7 @@ describe("LoginConfig Test", () => { expect(loginConfig.servicePrincipalId).toBe("client-id"); expect(loginConfig.servicePrincipalSecret).toBe("client-secret"); expect(loginConfig.tenantId).toBe("tenant-id"); - expect(loginConfig.subscriptionId).toBe(""); + expect(loginConfig.subscriptionId).toBe(undefined); }); test('initialize with creds', async () => { diff --git a/src/common/LoginConfig.ts b/src/common/LoginConfig.ts index b7ede4965..d3a3e1c74 100644 --- a/src/common/LoginConfig.ts +++ b/src/common/LoginConfig.ts @@ -1,5 +1,4 @@ import * as core from '@actions/core'; -import jsonpath from 'jsonpath'; export class LoginConfig { static readonly AUTH_TYPE_SERVICE_PRINCIPAL = "SERVICE_PRINCIPAL"; @@ -64,11 +63,11 @@ export class LoginConfig { } core.debug('Reading creds in JSON...'); - this.servicePrincipalId = this.servicePrincipalId ? this.servicePrincipalId : getKey(secrets, "$.clientId"); - this.servicePrincipalSecret = getKey(secrets, "$.clientSecret"); - this.tenantId = this.tenantId ? this.tenantId : getKey(secrets, "$.tenantId"); - this.subscriptionId = this.subscriptionId ? this.subscriptionId : getKey(secrets, "$.subscriptionId"); - this.resourceManagerEndpointUrl = getKey(secrets, "$.resourceManagerEndpointUrl"); + this.servicePrincipalId = this.servicePrincipalId ? this.servicePrincipalId : secrets.clientId; + this.servicePrincipalSecret = secrets.clientSecret; + this.tenantId = this.tenantId ? this.tenantId : secrets.tenantId; + this.subscriptionId = this.subscriptionId ? this.subscriptionId : secrets.subscriptionId; + this.resourceManagerEndpointUrl = secrets.resourceManagerEndpointUrl; if (!this.servicePrincipalId || !this.servicePrincipalSecret || !this.tenantId) { throw new Error("Not all parameters are provided in 'creds'. Double-check if all keys are defined in 'creds': 'clientId', 'clientSecret', 'tenantId'."); } @@ -117,16 +116,3 @@ async function jwtParser(federatedToken: string) { let decodedPayload = JSON.parse(bufferObj.toString("utf8")); return [decodedPayload['iss'], decodedPayload['sub']]; } - -function getKey(json: JSON, key: string): string { - let value = jsonpath.query(json, key); - if (value.length == 0) { - core.debug("Cannot find key: " + key); - return ""; - } - else if (value.length > 1) { - core.debug("Multiple values found for key: " + key + ". Please give jsonPath which points to a single value."); - return ""; - } - return value[0]; -} \ No newline at end of file