Skip to content

Commit a6e79bc

Browse files
committed
WIP getSCMToken
1 parent 4086665 commit a6e79bc

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

components/gitpod-protocol/src/public-api-converter.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
EnvironmentVariableAdmission,
4444
UserEnvironmentVariable,
4545
} from "@gitpod/public-api/lib/gitpod/v1/envvar_pb";
46+
import { SCMToken } from "@gitpod/public-api/lib/gitpod/v1/scm_pb";
4647
import { ContextURL } from "./context-url";
4748
import { ApplicationError, ErrorCode, ErrorCodes } from "./messaging/error";
4849
import {
@@ -57,6 +58,7 @@ import {
5758
WorkspaceInfo,
5859
UserEnvVarValue,
5960
ProjectEnvVar,
61+
Token,
6062
} from "./protocol";
6163
import {
6264
OrgMemberInfo,
@@ -542,4 +544,16 @@ export class PublicAPIConverter {
542544
return ""; // not allowed
543545
}
544546
}
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+
}
545559
}

components/server/src/api/scm-service-api.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,24 @@ import {
1919
ListSuggestedRepositoriesRequest,
2020
ListSuggestedRepositoriesResponse,
2121
} 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";
2224

2325
@injectable()
2426
export class ScmServiceAPI implements ServiceImpl<typeof ScmServiceInterface> {
2527
constructor(
2628
@inject(PublicAPIConverter) private readonly apiConverter: PublicAPIConverter,
2729
@inject(ScmService) private readonly scmService: ScmService,
28-
) {
29-
this.apiConverter;
30-
this.scmService;
31-
}
30+
) {}
3231

3332
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+
}
3540
}
3641

3742
async guessTokenScopes(

0 commit comments

Comments
 (0)