Skip to content

Commit 25b4523

Browse files
getLicenseDetails
1 parent 66f067a commit 25b4523

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/main/license/JwtClaims.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Represents license-related information extracted from the JWT token
3+
*/
4+
export class JwtClaims {
5+
tenantName: string;
6+
dastEnabled: boolean;
7+
allowedEngines: string[];
8+
9+
constructor(tenantName: string, dastEnabled: boolean, allowedEngines: string[]) {
10+
this.tenantName = tenantName;
11+
this.dastEnabled = dastEnabled;
12+
this.allowedEngines = allowedEngines;
13+
}
14+
15+
/**
16+
* Creates a JwtClaims instance from a JSON object
17+
*/
18+
static fromJson(json: any): JwtClaims {
19+
return new JwtClaims(
20+
json.tenantName || '',
21+
json.dastEnabled || false,
22+
json.allowedEngines || []
23+
);
24+
}
25+
}

src/main/wrapper/CxConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum CxConstants {
2121
CMD_REMEDIATION = "remediation",
2222
SUB_CMD_REMEDIATION_SCA = "sca",
2323
SUB_CMD_TENANT = "tenant",
24+
SUB_CMD_LICENSE = "license",
2425
KICS_REMEDIATION_RESULTS_FILE = "--results-file",
2526
KICS_REMEDIATION_KICS_FILE = "--kics-files",
2627
KICS_REMEDIATION_SIMILARITY_IDS = "--similarity-ids",

src/main/wrapper/CxWrapper.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import * as os from "os";
99
import CxBFL from "../bfl/CxBFL";
1010
import path = require('path');
1111
import { getTrimmedMapValue } from "./utils";
12+
import { JwtClaims } from "../license/JwtClaims";
13+
14+
export { JwtClaims } from "../license/JwtClaims";
1215

1316
type ParamTypeMap = Map<CxParamType, string>;
1417

@@ -651,4 +654,25 @@ export class CxWrapper {
651654
}
652655
return r;
653656
}
654-
}
657+
658+
/**
659+
* Gets license details from the JWT token
660+
*/
661+
async getLicenseDetails(): Promise<JwtClaims | null> {
662+
const commands: string[] = [
663+
CxConstants.CMD_UTILS,
664+
CxConstants.SUB_CMD_LICENSE,
665+
CxConstants.FORMAT,
666+
CxConstants.FORMAT_JSON
667+
];
668+
commands.push(...this.initializeCommands(false));
669+
670+
const exec = new ExecutionService();
671+
const output = await exec.executeCommands(this.config.pathToExecutable, commands);
672+
673+
if (output.exitCode === 0 && output.payload) {
674+
return JwtClaims.fromJson(output.payload);
675+
}
676+
return null;
677+
}
678+
}

0 commit comments

Comments
 (0)