Skip to content

Commit c6dbe7c

Browse files
committed
fixup: move API mappting to protocol
1 parent 2a0a56a commit c6dbe7c

File tree

2 files changed

+75
-64
lines changed

2 files changed

+75
-64
lines changed

components/dashboard/src/service/json-rpc-authprovider-client.ts

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,24 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { Code, ConnectError, PromiseClient } from "@connectrpc/connect";
87
import { PartialMessage } from "@bufbuild/protobuf";
8+
import { Code, ConnectError, PromiseClient } from "@connectrpc/connect";
99
import { AuthProviderService } from "@gitpod/public-api/lib/gitpod/v1/authprovider_connect";
1010
import {
1111
CreateAuthProviderRequest,
12-
GetAuthProviderRequest,
13-
ListAuthProvidersRequest,
14-
ListAuthProviderDescriptionsRequest,
15-
UpdateAuthProviderRequest,
16-
DeleteAuthProviderRequest,
1712
CreateAuthProviderResponse,
18-
ListAuthProvidersResponse,
13+
DeleteAuthProviderRequest,
14+
DeleteAuthProviderResponse,
15+
GetAuthProviderRequest,
1916
GetAuthProviderResponse,
17+
ListAuthProviderDescriptionsRequest,
2018
ListAuthProviderDescriptionsResponse,
19+
ListAuthProvidersRequest,
20+
ListAuthProvidersResponse,
21+
UpdateAuthProviderRequest,
2122
UpdateAuthProviderResponse,
22-
DeleteAuthProviderResponse,
23-
AuthProvider,
24-
AuthProviderType,
25-
OAuth2Config,
2623
} from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
27-
import { AuthProviderEntry } from "@gitpod/gitpod-protocol";
24+
import { converter } from "./public-api";
2825
import { getGitpodService } from "./service";
2926

3027
export class JsonRpcAuthProviderClient implements PromiseClient<typeof AuthProviderService> {
@@ -49,13 +46,13 @@ export class JsonRpcAuthProviderClient implements PromiseClient<typeof AuthProvi
4946
organizationId,
5047
});
5148
const response = new ListAuthProvidersResponse();
52-
response.list = result.map(toAuthProvider);
49+
response.list = result.map(converter.toAuthProvider);
5350
return response;
5451
}
5552
if (userId) {
5653
const result = await getGitpodService().server.getOwnAuthProviders();
5754
const response = new ListAuthProvidersResponse();
58-
response.list = result.map(toAuthProvider);
55+
response.list = result.map(converter.toAuthProvider);
5956
return response;
6057
}
6158
throw new ConnectError("either organizationId or userId are required", Code.InvalidArgument);
@@ -89,37 +86,3 @@ export class JsonRpcAuthProviderClient implements PromiseClient<typeof AuthProvi
8986
return new DeleteAuthProviderResponse();
9087
}
9188
}
92-
93-
function toAuthProvider(entry: AuthProviderEntry): AuthProvider {
94-
const ap = new AuthProvider();
95-
ap.verified = entry.status === "verified";
96-
ap.host = entry.host;
97-
ap.id = entry.id;
98-
ap.type = toAuthProviderType(entry.type);
99-
ap.oauth2Config = toOAuth2Config(entry);
100-
ap.scopes = entry.oauth?.scope?.split(entry.oauth?.scopeSeparator || " ") || [];
101-
ap.settingsUrl = entry.oauth.settingsUrl;
102-
return ap;
103-
}
104-
105-
function toOAuth2Config(entry: AuthProviderEntry): OAuth2Config {
106-
const config = new OAuth2Config();
107-
config.clientId = entry.oauth.clientId;
108-
config.clientSecret = entry.oauth.clientSecret;
109-
return config;
110-
}
111-
112-
function toAuthProviderType(type: string): AuthProviderType {
113-
switch (type) {
114-
case "GitHub":
115-
return AuthProviderType.GITHUB;
116-
case "GitLab":
117-
return AuthProviderType.GITLAB;
118-
case "Bitbucket":
119-
return AuthProviderType.BITBUCKET;
120-
case "BitbucketServer":
121-
return AuthProviderType.BITBUCKET_SERVER;
122-
default:
123-
return AuthProviderType.UNSPECIFIED; // not allowed
124-
}
125-
}

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

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import { Code, ConnectError } from "@connectrpc/connect";
87
import { Timestamp } from "@bufbuild/protobuf";
8+
import { Code, ConnectError } from "@connectrpc/connect";
9+
import { AuthProvider, AuthProviderType, OAuth2Config } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb";
10+
import {
11+
Organization,
12+
OrganizationMember,
13+
OrganizationRole,
14+
OrganizationSettings,
15+
} from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
916
import {
1017
AdmissionLevel,
1118
EditorReference,
@@ -20,37 +27,32 @@ import {
2027
WorkspacePort_Protocol,
2128
WorkspaceStatus,
2229
} from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
23-
import {
24-
Organization,
25-
OrganizationMember,
26-
OrganizationRole,
27-
OrganizationSettings,
28-
} from "@gitpod/public-api/lib/gitpod/v1/organization_pb";
30+
import { ContextURL } from "./context-url";
2931
import { ApplicationError, ErrorCode, ErrorCodes } from "./messaging/error";
3032
import {
33+
AuthProviderEntry as AuthProviderProtocol,
3134
CommitContext,
3235
EnvVarWithValue,
36+
Workspace as ProtocolWorkspace,
3337
WithEnvvarsContext,
3438
WithPrebuild,
3539
WorkspaceContext,
3640
WorkspaceInfo,
37-
Workspace as ProtocolWorkspace,
3841
} from "./protocol";
42+
import {
43+
OrgMemberInfo,
44+
OrgMemberRole,
45+
OrganizationSettings as OrganizationSettingsProtocol,
46+
Organization as ProtocolOrganization,
47+
} from "./teams-projects-protocol";
48+
import { TrustedValue } from "./util/scrubbing";
3949
import {
4050
ConfigurationIdeConfig,
4151
PortProtocol,
4252
WorkspaceInstance,
4353
WorkspaceInstanceConditions,
4454
WorkspaceInstancePort,
4555
} from "./workspace-instance";
46-
import { ContextURL } from "./context-url";
47-
import { TrustedValue } from "./util/scrubbing";
48-
import {
49-
Organization as ProtocolOrganization,
50-
OrgMemberInfo,
51-
OrgMemberRole,
52-
OrganizationSettings as OrganizationSettingsProtocol,
53-
} from "./teams-projects-protocol";
5456

5557
const applicationErrorCode = "application-error-code";
5658
const applicationErrorData = "application-error-data";
@@ -376,4 +378,50 @@ export class PublicAPIConverter {
376378
result.defaultWorkspaceImage = settings.defaultWorkspaceImage || undefined;
377379
return result;
378380
}
381+
382+
toAuthProvider(ap: AuthProviderProtocol): AuthProvider {
383+
const result = new AuthProvider({
384+
id: ap.id,
385+
host: ap.host,
386+
type: this.toAuthProviderType(ap),
387+
verified: ap.status === "verified",
388+
settingsUrl: ap.oauth?.settingsUrl,
389+
scopes: ap.oauth?.scope?.split(ap.oauth?.scopeSeparator || " ") || [],
390+
});
391+
if (ap.organizationId) {
392+
result.owner = {
393+
case: "organizationId",
394+
value: ap.organizationId,
395+
};
396+
} else {
397+
result.owner = {
398+
case: "ownerId",
399+
value: ap.ownerId,
400+
};
401+
}
402+
result.oauth2Config = this.toOAuth2Config(ap);
403+
return result;
404+
}
405+
406+
toOAuth2Config(ap: AuthProviderProtocol): OAuth2Config {
407+
return new OAuth2Config({
408+
clientId: ap.oauth?.clientId,
409+
clientSecret: ap.oauth?.clientSecret,
410+
});
411+
}
412+
413+
toAuthProviderType(ap: AuthProviderProtocol): AuthProviderType {
414+
switch (ap.type) {
415+
case "GitHub":
416+
return AuthProviderType.GITHUB;
417+
case "GitLab":
418+
return AuthProviderType.GITLAB;
419+
case "Bitbucket":
420+
return AuthProviderType.BITBUCKET;
421+
case "BitbucketServer":
422+
return AuthProviderType.BITBUCKET_SERVER;
423+
default:
424+
return AuthProviderType.UNSPECIFIED; // not allowed
425+
}
426+
}
379427
}

0 commit comments

Comments
 (0)