File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed
Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ import * as os from "os";
99import CxBFL from "../bfl/CxBFL" ;
1010import path = require( 'path' ) ;
1111import { getTrimmedMapValue } from "./utils" ;
12+ import { JwtClaims } from "../license/JwtClaims" ;
13+
14+ export { JwtClaims } from "../license/JwtClaims" ;
1215
1316type 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+ }
You can’t perform that action at this time.
0 commit comments