1+ import * as core from '@actions/core' ;
2+
3+ import Utils from './Utils' ;
4+ import PowerShellToolRunner from './PowerShellToolRunner' ;
5+ import ScriptBuilder from './ScriptBuilder' ;
6+ import { Constants } from './Constants' ;
7+
8+ export class ServicePrincipalLogin implements IAzurePowerShellSession {
9+ static readonly environment : string = Constants . environment ;
10+ static readonly scopeLevel : string = Constants . scopeLevel ;
11+ static readonly scheme : string = Constants . scheme ;
12+ servicePrincipalId : string ;
13+ servicePrincipalKey : string ;
14+ tenantId : string ;
15+ subscriptionId : string ;
16+
17+ constructor ( servicePrincipalId : string , servicePrincipalKey : string , tenantId : string , subscriptionId : string ) {
18+ this . servicePrincipalId = servicePrincipalId ;
19+ this . servicePrincipalKey = servicePrincipalKey ;
20+ this . tenantId = tenantId ;
21+ this . subscriptionId = subscriptionId ;
22+ }
23+
24+ async initialize ( ) {
25+ Utils . setPSModulePath ( ) ;
26+ const azLatestVersion : string = await Utils . getLatestModule ( Constants . moduleName ) ;
27+ core . debug ( `Az Module version used: ${ azLatestVersion } ` ) ;
28+ Utils . setPSModulePath ( `${ Constants . prefix } ${ azLatestVersion } ` ) ;
29+ }
30+
31+ async login ( ) {
32+ PowerShellToolRunner . init ( ) ;
33+ const scriptBuilder : ScriptBuilder = new ScriptBuilder ( ) ;
34+ const script : string = scriptBuilder . getScript ( ServicePrincipalLogin . scheme , this . tenantId , this . servicePrincipalId , this . servicePrincipalKey ,
35+ this . subscriptionId , ServicePrincipalLogin . environment , ServicePrincipalLogin . scopeLevel ) ;
36+ PowerShellToolRunner . executePowerShellCommand ( script ) ;
37+ }
38+
39+ }
0 commit comments