@@ -4,12 +4,13 @@ import fs from 'fs';
44import net from 'net' ;
55import packageJson from 'package.json' ;
66import path from 'path' ;
7+ import { ValidBasicAuthSiteData } from 'src/atlclients/clientManager' ;
78import { downloadAndUnzip } from 'src/rovo-dev/util/downloadFile' ;
89import { getFsPromise } from 'src/rovo-dev/util/fsPromises' ;
910import { waitFor } from 'src/rovo-dev/util/waitFor' ;
1011import { Disposable , Event , EventEmitter , ExtensionContext , Terminal , Uri , window , workspace } from 'vscode' ;
1112
12- import { DetailedSiteInfo , isBasicAuthInfo , ProductJira } from '../atlclients/authInfo' ;
13+ import { DetailedSiteInfo } from '../atlclients/authInfo' ;
1314import { Container } from '../container' ;
1415import { RovoDevApiClient } from './client' ;
1516import { RovoDevDisabledReason , RovoDevEntitlementCheckFailedDetail } from './rovoDevWebviewProviderMessages' ;
@@ -107,58 +108,7 @@ async function getOrAssignPortForWorkspace(): Promise<number> {
107108 throw new Error ( 'unable to find an available port.' ) ;
108109}
109110
110- /**
111- * Placeholder implementation for Rovo Dev CLI credential storage
112- */
113- async function getCloudCredentials ( ) : Promise <
114- { username : string ; key : string ; host : string ; isValid : boolean ; isStaging : boolean } | undefined
115- > {
116- try {
117- const sites = Container . siteManager . getSitesAvailable ( ProductJira ) ;
118-
119- const promises = sites . map ( async ( site ) => {
120- // *.atlassian.net are PROD cloud sites
121- // *.jira-dev.com are Staging cloud sites
122- if ( ! site . host . endsWith ( '.atlassian.net' ) && ! site . host . endsWith ( '.jira-dev.com' ) ) {
123- return undefined ;
124- }
125-
126- const authInfo = await Container . credentialManager . getAuthInfo ( site ) ;
127- if ( ! isBasicAuthInfo ( authInfo ) ) {
128- return undefined ;
129- }
130-
131- // verify the credentials work
132- let isValid : boolean ;
133- try {
134- await Container . clientManager . jiraClient ( site ) ;
135- isValid = true ;
136- } catch {
137- isValid = false ;
138- }
139-
140- return {
141- username : authInfo . username ,
142- key : authInfo . password ,
143- host : site . host ,
144- isValid,
145- isStaging : site . host . endsWith ( '.jira-dev.com' ) ,
146- } ;
147- } ) ;
148-
149- const results = ( await Promise . all ( promises ) ) . filter ( ( result ) => result !== undefined ) ;
150-
151- // give priority to staging sites
152- return results . filter ( ( x ) => x . isStaging ) [ 0 ] || results [ 0 ] ;
153- } catch ( error ) {
154- RovoDevLogger . error ( error , 'Error fetching cloud credentials for Rovo Dev' ) ;
155- return undefined ;
156- }
157- }
158-
159- type CloudCredentials = NonNullable < Awaited < ReturnType < typeof getCloudCredentials > > > ;
160-
161- function areCredentialsEqual ( cred1 ?: CloudCredentials , cred2 ?: CloudCredentials ) {
111+ function areCredentialsEqual ( cred1 ?: ValidBasicAuthSiteData , cred2 ?: ValidBasicAuthSiteData ) {
162112 if ( cred1 === cred2 ) {
163113 return true ;
164114 }
@@ -167,7 +117,11 @@ function areCredentialsEqual(cred1?: CloudCredentials, cred2?: CloudCredentials)
167117 return false ;
168118 }
169119
170- return cred1 . host === cred2 . host && cred1 . key === cred2 . key && cred1 . username === cred2 . username ;
120+ return (
121+ cred1 . host === cred2 . host &&
122+ cred1 . authInfo . password === cred2 . authInfo . password &&
123+ cred1 . authInfo . username === cred2 . authInfo . username
124+ ) ;
171125}
172126
173127export interface RovoDevProcessNotStartedState {
@@ -239,7 +193,7 @@ export abstract class RovoDevProcessManager {
239193 return this . _onStateChanged . event ;
240194 }
241195
242- private static currentCredentials : CloudCredentials | undefined ;
196+ private static currentCredentials : ValidBasicAuthSiteData | undefined ;
243197
244198 /** This lock ensures this class is async-safe, preventing repeated invocations
245199 * of `initializeRovoDev` or `refreshRovoDevCredentials` to launch multiple processes
@@ -324,7 +278,7 @@ export abstract class RovoDevProcessManager {
324278
325279 private static async internalInitializeRovoDev (
326280 context : ExtensionContext ,
327- credentials : CloudCredentials | undefined ,
281+ credentials : ValidBasicAuthSiteData | undefined ,
328282 forceNewInstance ?: boolean ,
329283 ) {
330284 if ( ! workspace . workspaceFolders ?. length ) {
@@ -403,7 +357,7 @@ export abstract class RovoDevProcessManager {
403357 this . failIfRovoDevInstanceIsRunning ( ) ;
404358 }
405359
406- const credentials = await getCloudCredentials ( ) ;
360+ const credentials = await Container . clientManager . getCloudPrimarySite ( ) ;
407361 await this . internalInitializeRovoDev ( context , credentials , forceNewInstance ) ;
408362 } finally {
409363 this . asyncLocked = false ;
@@ -419,7 +373,7 @@ export abstract class RovoDevProcessManager {
419373 this . asyncLocked = true ;
420374
421375 try {
422- const credentials = await getCloudCredentials ( ) ;
376+ const credentials = await Container . clientManager . getCloudPrimarySite ( ) ;
423377 if ( areCredentialsEqual ( credentials , this . currentCredentials ) ) {
424378 return ;
425379 }
@@ -451,7 +405,7 @@ export abstract class RovoDevProcessManager {
451405
452406 private static async startRovoDev (
453407 context : ExtensionContext ,
454- credentials : CloudCredentials ,
408+ credentials : ValidBasicAuthSiteData ,
455409 rovoDevURIs : RovoDevURIs ,
456410 ) {
457411 // skip if there is no workspace folder open
@@ -495,7 +449,7 @@ class RovoDevTerminalInstance extends Disposable {
495449 }
496450
497451 public async start (
498- credentials : CloudCredentials ,
452+ credentials : ValidBasicAuthSiteData ,
499453 setState : ( newState : RovoDevProcessState ) => void ,
500454 ) : Promise < void > {
501455 if ( this . started ) {
@@ -538,9 +492,9 @@ class RovoDevTerminalInstance extends Disposable {
538492 iconPath : this . rovoDevIconUri ,
539493 env : {
540494 USER : process . env . USER || process . env . USERNAME ,
541- USER_EMAIL : credentials . username ,
495+ USER_EMAIL : credentials . authInfo . username ,
542496 ROVODEV_SANDBOX_ID : Container . appInstanceId ,
543- ...( credentials . key ? { USER_API_TOKEN : credentials . key } : { } ) ,
497+ ...( credentials . authInfo . password ? { USER_API_TOKEN : credentials . authInfo . password } : { } ) ,
544498 } ,
545499 } ) ;
546500
0 commit comments