File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ import {
43
43
EnvironmentVariableAdmission ,
44
44
UserEnvironmentVariable ,
45
45
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb" ;
46
+ import { SCMToken } from "@gitpod/public-api/lib/gitpod/v1/scm_pb" ;
46
47
import { ContextURL } from "./context-url" ;
47
48
import { ApplicationError , ErrorCode , ErrorCodes } from "./messaging/error" ;
48
49
import {
@@ -57,6 +58,7 @@ import {
57
58
WorkspaceInfo ,
58
59
UserEnvVarValue ,
59
60
ProjectEnvVar ,
61
+ Token ,
60
62
} from "./protocol" ;
61
63
import {
62
64
OrgMemberInfo ,
@@ -542,4 +544,16 @@ export class PublicAPIConverter {
542
544
return "" ; // not allowed
543
545
}
544
546
}
547
+
548
+ toSCMToken ( t : Token ) : SCMToken {
549
+ return new SCMToken ( {
550
+ username : t . username ,
551
+ value : t . value ,
552
+ refreshToken : t . refreshToken ,
553
+ expiryDate : t . expiryDate ? Timestamp . fromDate ( new Date ( t . expiryDate ) ) : undefined ,
554
+ updateDate : t . updateDate ? Timestamp . fromDate ( new Date ( t . updateDate ) ) : undefined ,
555
+ scopes : t . scopes ,
556
+ idToken : t . idToken ,
557
+ } ) ;
558
+ }
545
559
}
Original file line number Diff line number Diff line change @@ -19,19 +19,24 @@ import {
19
19
ListSuggestedRepositoriesRequest ,
20
20
ListSuggestedRepositoriesResponse ,
21
21
} from "@gitpod/public-api/lib/gitpod/v1/scm_pb" ;
22
+ import { ctxUserId } from "../util/request-context" ;
23
+ import { ApplicationError , ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
22
24
23
25
@injectable ( )
24
26
export class ScmServiceAPI implements ServiceImpl < typeof ScmServiceInterface > {
25
27
constructor (
26
28
@inject ( PublicAPIConverter ) private readonly apiConverter : PublicAPIConverter ,
27
29
@inject ( ScmService ) private readonly scmService : ScmService ,
28
- ) {
29
- this . apiConverter ;
30
- this . scmService ;
31
- }
30
+ ) { }
32
31
33
32
async getSCMToken ( request : GetSCMTokenRequest , context : HandlerContext ) : Promise < GetSCMTokenResponse > {
34
- throw new ConnectError ( "unimplemented" , Code . Unimplemented ) ;
33
+ const userId = ctxUserId ( ) ;
34
+ try {
35
+ const token = await this . scmService . getToken ( userId , request ) ;
36
+ return new GetSCMTokenResponse ( { token : this . apiConverter . toSCMToken ( token ) } ) ;
37
+ } catch ( error ) {
38
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Token not found." ) ;
39
+ }
35
40
}
36
41
37
42
async guessTokenScopes (
You can’t perform that action at this time.
0 commit comments