@@ -306,7 +306,7 @@ export class Cluster extends OpenShiftItem {
306306 }
307307
308308 @vsCommand ( 'openshift.explorer.login.tokenLogin' )
309- static async tokenLogin ( userClusterUrl : string , skipConfirmation = false ) : Promise < string | null > {
309+ static async tokenLogin ( userClusterUrl : string , skipConfirmation = false , userToken ?: string ) : Promise < string | null > {
310310 let token : string ;
311311 const response = await Cluster . requestLoginConfirmation ( skipConfirmation ) ;
312312
@@ -328,21 +328,36 @@ export class Cluster extends OpenShiftItem {
328328 clusterURL = await Cluster . getUrl ( ) ;
329329 }
330330
331- const ocToken = await window . showInputBox ( {
332- value : token ,
333- prompt : 'Provide Bearer token for authentication to the API server' ,
334- ignoreFocusOut : true ,
335- password : true
336- } ) ;
337- if ( ! ocToken ) return null ;
338-
331+ let ocToken : string ;
332+ if ( ! userToken ) {
333+ ocToken = await window . showInputBox ( {
334+ value : token ,
335+ prompt : 'Provide Bearer token for authentication to the API server' ,
336+ ignoreFocusOut : true ,
337+ password : true
338+ } ) ;
339+ if ( ! ocToken ) return null ;
340+ } else {
341+ ocToken = userToken ;
342+ }
339343 return Progress . execFunctionWithProgress ( `Login to the cluster: ${ clusterURL } ` ,
340344 ( ) => Cluster . odo . execute ( Command . odoLoginWithToken ( clusterURL , ocToken . trim ( ) ) )
341345 . then ( ( result ) => Cluster . loginMessage ( clusterURL , result ) )
342346 . catch ( ( error ) => Promise . reject ( new VsCommandError ( `Failed to login to cluster '${ clusterURL } ' with '${ Filters . filterToken ( error . message ) } '!` , 'Failed to login to cluster' ) ) )
343347 ) ;
344348 }
345349
350+ @vsCommand ( 'openshift.explorer.login.clipboard' )
351+ static async loginUsingClipboardInfo ( ) : Promise < string | null > {
352+ const clipboard = await Cluster . readFromClipboard ( ) ;
353+ if ( ! Cluster . ocLoginCommandMatches ( clipboard ) ) {
354+ throw new VsCommandError ( 'Cannot parse login command in clipboard.' )
355+ }
356+ const url = Cluster . clusterURL ( clipboard ) ;
357+ const token = Cluster . getToken ( clipboard ) ;
358+ return Cluster . tokenLogin ( url , true , token ) ;
359+ }
360+
346361 static async loginMessage ( clusterURL : string , result : CliExitData ) : Promise < string | undefined > {
347362 if ( result . stderr === '' ) {
348363 Cluster . explorer . refresh ( ) ;
0 commit comments