Skip to content

Commit

Permalink
abandon jsonpath
Browse files Browse the repository at this point in the history
  • Loading branch information
MoChilia committed Feb 22, 2024
1 parent 07910cc commit c3add9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
2 changes: 1 addition & 1 deletion __tests__/LoginConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
24 changes: 5 additions & 19 deletions src/common/LoginConfig.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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'.");
}
Expand Down Expand Up @@ -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];
}

0 comments on commit c3add9c

Please sign in to comment.