@@ -34,21 +34,59 @@ class ServicePrincipalLogin {
3434 initialize ( ) {
3535 return __awaiter ( this , void 0 , void 0 , function * ( ) {
3636 Utils_1 . default . setPSModulePath ( ) ;
37- const azLatestVersion = yield Utils_1 . default . getLatestModule ( Constants_1 . default . moduleName ) ;
37+ const script = new ScriptBuilder_1 . default ( ) . getLatestModuleScript ( Constants_1 . default . moduleName ) ;
38+ const outputJson = yield this . getLatestModule ( script ) ;
39+ const azLatestVersion = outputJson . Constants . AzPSVersion ;
40+ if ( ! ( Constants_1 . default . Success in outputJson ) || ! Utils_1 . default . isValidVersion ( azLatestVersion ) ) {
41+ throw new Error ( `Invalid AzPSVersion: ${ azLatestVersion } ` ) ;
42+ }
3843 core . debug ( `Az Module version used: ${ azLatestVersion } ` ) ;
3944 Utils_1 . default . setPSModulePath ( `${ Constants_1 . default . prefix } ${ azLatestVersion } ` ) ;
4045 } ) ;
4146 }
47+ getLatestModule ( script ) {
48+ return __awaiter ( this , void 0 , void 0 , function * ( ) {
49+ let output = "" ;
50+ const options = {
51+ listeners : {
52+ stdout : ( data ) => {
53+ output += data . toString ( ) ;
54+ }
55+ }
56+ } ;
57+ yield PowerShellToolRunner_1 . default . init ( ) ;
58+ yield PowerShellToolRunner_1 . default . executePowerShellCommand ( script , options ) ;
59+ return JSON . parse ( output . trim ( ) ) ;
60+ } ) ;
61+ }
4262 login ( ) {
4363 return __awaiter ( this , void 0 , void 0 , function * ( ) {
64+ let output = "" ;
65+ const options = {
66+ listeners : {
67+ stdout : ( data ) => {
68+ output += data . toString ( ) ;
69+ }
70+ }
71+ } ;
72+ const args = {
73+ servicePrincipalId : this . servicePrincipalId ,
74+ servicePrincipalKey : this . servicePrincipalKey ,
75+ subscriptionId : this . subscriptionId ,
76+ environment : ServicePrincipalLogin . environment ,
77+ scopeLevel : ServicePrincipalLogin . scopeLevel
78+ } ;
79+ const script = new ScriptBuilder_1 . default ( ) . getAzPSLoginScript ( ServicePrincipalLogin . scheme , this . tenantId , args ) ;
4480 yield PowerShellToolRunner_1 . default . init ( ) ;
45- const scriptBuilder = new ScriptBuilder_1 . default ( ) ;
46- const script = scriptBuilder . getScript ( ServicePrincipalLogin . scheme , this . tenantId , this . servicePrincipalId , this . servicePrincipalKey , this . subscriptionId , ServicePrincipalLogin . environment , ServicePrincipalLogin . scopeLevel ) ;
47- PowerShellToolRunner_1 . default . executePowerShellCommand ( script ) ;
81+ yield PowerShellToolRunner_1 . default . executePowerShellCommand ( script , options ) ;
82+ const outputJson = JSON . parse ( output . trim ( ) ) ;
83+ if ( ! ( Constants_1 . default . Success in outputJson ) ) {
84+ throw new Error ( `Azure PowerShell login failed with error: ${ outputJson . Constants . Error } ` ) ;
85+ }
4886 } ) ;
4987 }
5088}
5189exports . ServicePrincipalLogin = ServicePrincipalLogin ;
52- ServicePrincipalLogin . environment = Constants_1 . default . environment ;
53- ServicePrincipalLogin . scopeLevel = Constants_1 . default . scopeLevel ;
54- ServicePrincipalLogin . scheme = Constants_1 . default . scheme ;
90+ ServicePrincipalLogin . environment = Constants_1 . default . AzureCloud ;
91+ ServicePrincipalLogin . scopeLevel = Constants_1 . default . Subscription ;
92+ ServicePrincipalLogin . scheme = Constants_1 . default . ServicePrincipal ;
0 commit comments