@@ -18,10 +18,7 @@ import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
18
18
import fetch from "node-fetch" ;
19
19
import { Authorizer } from "../authorization/authorizer" ;
20
20
import { ApplicationError , ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error" ;
21
- import { GitHubScope } from "../github/scopes" ;
22
- import { GitLabScope } from "../gitlab/scopes" ;
23
- import { BitbucketOAuthScopes } from "../bitbucket/bitbucket-oauth-scopes" ;
24
- import { BitbucketServerOAuthScopes } from "../bitbucket-server/bitbucket-server-oauth-scopes" ;
21
+ import { getRequiredScopes , getScopesOfProvider } from "./auth-provider-scopes" ;
25
22
26
23
@injectable ( )
27
24
export class AuthProviderService {
@@ -107,8 +104,8 @@ export class AuthProviderService {
107
104
hiddenOnDashboard : ap . hiddenOnDashboard ,
108
105
disallowLogin : ap . disallowLogin ,
109
106
description : ap . description ,
110
- scopes : this . toScopes ( ap ) ,
111
- requirements : this . toScopeRequirements ( ap ) ,
107
+ scopes : getScopesOfProvider ( ap ) ,
108
+ requirements : getRequiredScopes ( ap ) ,
112
109
} ;
113
110
114
111
const result : AuthProviderInfo [ ] = [ ] ;
@@ -131,52 +128,6 @@ export class AuthProviderService {
131
128
}
132
129
return result ;
133
130
}
134
- /**
135
- * This is extracted from auth provider handlers in order to avoid a
136
- * dependency to host contexts.
137
- *
138
- * TODO(at) these defaults of provider types needs to be centralized.
139
- */
140
- private toScopeRequirements ( entry : AuthProviderEntry ) {
141
- switch ( entry . type ) {
142
- case "GitHub" :
143
- return {
144
- default : GitHubScope . Requirements . DEFAULT ,
145
- publicRepo : GitHubScope . Requirements . PUBLIC_REPO ,
146
- privateRepo : GitHubScope . Requirements . PRIVATE_REPO ,
147
- } ;
148
- case "GitLab" :
149
- return {
150
- default : GitLabScope . Requirements . DEFAULT ,
151
- publicRepo : GitLabScope . Requirements . DEFAULT ,
152
- privateRepo : GitLabScope . Requirements . REPO ,
153
- } ;
154
- case "Bitbucket" :
155
- return {
156
- default : BitbucketOAuthScopes . Requirements . DEFAULT ,
157
- publicRepo : BitbucketOAuthScopes . Requirements . DEFAULT ,
158
- privateRepo : BitbucketOAuthScopes . Requirements . DEFAULT ,
159
- } ;
160
- case "BitbucketServer" :
161
- return {
162
- default : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
163
- publicRepo : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
164
- privateRepo : BitbucketServerOAuthScopes . Requirements . DEFAULT ,
165
- } ;
166
- }
167
- }
168
- private toScopes ( entry : AuthProviderEntry ) {
169
- switch ( entry . type ) {
170
- case "GitHub" :
171
- return GitHubScope . All ;
172
- case "GitLab" :
173
- return GitLabScope . All ;
174
- case "Bitbucket" :
175
- return BitbucketOAuthScopes . ALL ;
176
- case "BitbucketServer" :
177
- return BitbucketServerOAuthScopes . ALL ;
178
- }
179
- }
180
131
181
132
async getAuthProvidersOfUser ( user : User | string ) : Promise < AuthProviderEntry [ ] > {
182
133
const userId = User . is ( user ) ? user . id : user ;
0 commit comments