55
66import { KubernetesObject } from '@kubernetes/client-node' ;
77import { Cluster as KcuCluster , Context as KcuContext } from '@kubernetes/client-node/dist/config_types' ;
8- import * as fs from 'fs/promises' ;
9- import * as YAML from 'js-yaml' ;
8+ import * as https from 'https' ;
109import { ExtensionContext , QuickInputButtons , QuickPickItem , QuickPickItemButtonEvent , ThemeIcon , Uri , commands , env , window , workspace } from 'vscode' ;
1110import { CommandText } from '../base/command' ;
1211import { CliChannel } from '../cli' ;
@@ -17,14 +16,13 @@ import * as NameValidator from '../openshift/nameValidator';
1716import { TokenStore } from '../util/credentialManager' ;
1817import { Filters } from '../util/filters' ;
1918import { inputValue , quickBtn } from '../util/inputValue' ;
20- import { KubeConfigUtils , getKubeConfigFiles } from '../util/kubeUtils' ;
19+ import { KubeConfigUtils } from '../util/kubeUtils' ;
2120import { LoginUtil } from '../util/loginUtil' ;
2221import { Platform } from '../util/platform' ;
2322import { Progress } from '../util/progress' ;
2423import { VsCommandError , vsCommand } from '../vscommand' ;
2524import { OpenShiftTerminalManager } from '../webview/openshift-terminal/openShiftTerminal' ;
2625import OpenShiftItem , { clusterRequired } from './openshiftItem' ;
27- import * as https from 'https' ;
2826
2927export interface QuickPickItemExt extends QuickPickItem {
3028 name : string ,
@@ -1006,9 +1004,6 @@ export class Cluster extends OpenShiftItem {
10061004
10071005 try {
10081006 await Oc . Instance . loginWithToken ( clusterURL , ocToken , abortController ) ;
1009- if ( Cluster . isOpenShiftSandbox ( clusterURL ) ) {
1010- await Cluster . installPipelineUserContext ( ) ;
1011- }
10121007 return Cluster . loginMessage ( clusterURL ) ;
10131008 } catch ( error ) {
10141009 if ( abortController ?. signal . aborted ) return null ;
@@ -1041,7 +1036,8 @@ export class Cluster extends OpenShiftItem {
10411036 apiEndpointUrl : string ,
10421037 oauthRequestTokenUrl : string ,
10431038 ) : Promise < string | null > {
1044- const clipboard = await Cluster . readFromClipboard ( ) ;
1039+ // for whatever reason the token is padded with spaces at the beginning and end when copied from the website
1040+ const clipboard = ( await Cluster . readFromClipboard ( ) ) . trim ( ) ;
10451041 if ( ! clipboard ) {
10461042 const choice = await window . showErrorMessage (
10471043 'Cannot parse token in clipboard. Please click `Get token` button below, copy token into clipboard and press `Login to Sandbox` button again.' ,
@@ -1055,44 +1051,6 @@ export class Cluster extends OpenShiftItem {
10551051 return Cluster . tokenLogin ( apiEndpointUrl , true , clipboard ) ;
10561052 }
10571053
1058- static async installPipelineUserContext ( ) : Promise < void > {
1059- const kcu = new KubeConfigUtils ( ) ;
1060- const kcFiles = getKubeConfigFiles ( ) ;
1061- if ( kcFiles . length === 0 ) {
1062- throw new Error ( 'Could not locate Kube Config when trying to replace OpenShift Sandbox token with a longer-lived token' ) ;
1063- }
1064- const kcPath = kcFiles [ 0 ] ;
1065- const kcActual = YAML . load ( ( await fs . readFile ( kcPath ) ) . toString ( 'utf-8' ) ) as {
1066- users : { name : string ; user : { token : string } } [ ] ;
1067- contexts : {
1068- context : { cluster : string ; user : string ; namespace : string } ;
1069- name : string ;
1070- } [ ] ;
1071- 'current-context' : string ;
1072- clusters : object [ ] ;
1073- } ;
1074-
1075- const currentCtx = kcu . getCurrentContext ( ) ;
1076- const currentCtxObj = kcActual . contexts . find ( ctx => ctx . name === currentCtx ) ;
1077- const sandboxUser = currentCtxObj . context . user ;
1078- const sandboxUserObj = kcActual . users . find ( user => user . name === sandboxUser ) ;
1079-
1080- const serviceAccounts = await Oc . Instance . getKubernetesObjects ( 'ServiceAccount' ) ;
1081- const pipelineServiceAccount = serviceAccounts . find ( serviceAccount => serviceAccount . metadata . name === 'pipeline' ) ;
1082- if ( ! pipelineServiceAccount ) {
1083- return ;
1084- }
1085- const secrets = await Oc . Instance . getKubernetesObjects ( 'Secret' ) ;
1086- const pipelineTokenSecret = secrets . find ( ( secret ) => secret . metadata . name . startsWith ( 'pipeline-token' ) ) as any ;
1087- const pipelineToken = Buffer . from ( pipelineTokenSecret . data . token , 'base64' ) . toString ( ) ;
1088-
1089- sandboxUserObj . user = {
1090- token : pipelineToken
1091- }
1092-
1093- await fs . writeFile ( kcPath , YAML . dump ( kcActual , { lineWidth : Number . POSITIVE_INFINITY } ) ) ;
1094- }
1095-
10961054 static async loginUsingClipboardInfo ( dashboardUrl : string ) : Promise < string | null > {
10971055 const clipboard = await Cluster . readFromClipboard ( ) ;
10981056 if ( ! NameValidator . ocLoginCommandMatches ( clipboard ) ) {
0 commit comments