Skip to content

Commit

Permalink
add listAuthProviderDescriptions implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTugarev committed Nov 8, 2023
1 parent e977f50 commit fe7238f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ export class JsonRpcAuthProviderClient implements PromiseClient<typeof AuthProvi
async listAuthProviderDescriptions(
request: PartialMessage<ListAuthProviderDescriptionsRequest>,
): Promise<ListAuthProviderDescriptionsResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
const aps = await getGitpodService().server.getAuthProviders();
return new ListAuthProviderDescriptionsResponse({
descriptions: aps.map((ap) => converter.toAuthProviderDescription(ap)),
});
}

async updateAuthProvider(request: PartialMessage<UpdateAuthProviderRequest>): Promise<UpdateAuthProviderResponse> {
Expand Down
23 changes: 19 additions & 4 deletions components/gitpod-protocol/src/public-api-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

import { Timestamp } from "@bufbuild/protobuf";
import { Code, ConnectError } from "@connectrpc/connect";
import { AuthProvider, AuthProviderType, OAuth2Config } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
import {
AuthProvider,
AuthProviderDescription,
AuthProviderType,
OAuth2Config,
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
import {
Organization,
OrganizationMember,
Expand All @@ -31,6 +36,7 @@ import { ContextURL } from "./context-url";
import { ApplicationError, ErrorCode, ErrorCodes } from "./messaging/error";
import {
AuthProviderEntry as AuthProviderProtocol,
AuthProviderInfo,
CommitContext,
EnvVarWithValue,
Workspace as ProtocolWorkspace,
Expand Down Expand Up @@ -379,11 +385,20 @@ export class PublicAPIConverter {
return result;
}

toAuthProviderDescription(ap: AuthProviderInfo): AuthProviderDescription {
const result = new AuthProviderDescription({
id: ap.authProviderId,
host: ap.host,
type: this.toAuthProviderType(ap.authProviderType),
});
return result;
}

toAuthProvider(ap: AuthProviderProtocol): AuthProvider {
const result = new AuthProvider({
id: ap.id,
host: ap.host,
type: this.toAuthProviderType(ap),
type: this.toAuthProviderType(ap.type),
verified: ap.status === "verified",
settingsUrl: ap.oauth?.settingsUrl,
scopes: ap.oauth?.scope?.split(ap.oauth?.scopeSeparator || " ") || [],
Expand All @@ -410,8 +425,8 @@ export class PublicAPIConverter {
});
}

toAuthProviderType(ap: AuthProviderProtocol): AuthProviderType {
switch (ap.type) {
toAuthProviderType(type: string): AuthProviderType {
switch (type) {
case "GitHub":
return AuthProviderType.GITHUB;
case "GitLab":
Expand Down
18 changes: 15 additions & 3 deletions components/server/src/api/auth-provider-service-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
DeleteAuthProviderResponse,
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
import { AuthProviderService } from "../auth/auth-provider-service";
import { AuthProviderEntry } from "@gitpod/gitpod-protocol";
import { AuthProviderEntry, AuthProviderInfo } from "@gitpod/gitpod-protocol";
import { Unauthenticated } from "./unauthenticated";

@injectable()
export class AuthProviderServiceAPI implements ServiceImpl<typeof AuthProviderServiceInterface> {
Expand Down Expand Up @@ -105,11 +106,22 @@ export class AuthProviderServiceAPI implements ServiceImpl<typeof AuthProviderSe
return result;
}

/**
* Listing descriptions of auth providers doesn't require authentication.
*/
@Unauthenticated()
async listAuthProviderDescriptions(
request: ListAuthProviderDescriptionsRequest,
_request: ListAuthProviderDescriptionsRequest,
context: HandlerContext,
): Promise<ListAuthProviderDescriptionsResponse> {
throw new ConnectError("unimplemented", Code.Unimplemented);
const user = context.user;
const aps = user
? await this.authProviderService.getAuthProviderDescriptions(user)
: await this.authProviderService.getAuthProviderDescriptionsUnauthenticated();

return new ListAuthProviderDescriptionsResponse({
descriptions: aps.map((ap: AuthProviderInfo) => this.apiConverter.toAuthProviderDescription(ap)),
});
}

async updateAuthProvider(
Expand Down

0 comments on commit fe7238f

Please sign in to comment.