@@ -2989,12 +2989,8 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2989
2989
traceAPIParams ( ctx , { params } ) ;
2990
2990
2991
2991
const user = await this . checkAndBlockUser ( "deleteOwnAuthProvider" ) ;
2992
- const ownProviders = await this . authProviderService . getAuthProvidersOfUser ( user . id ) ;
2993
- const authProvider = ownProviders . find ( ( p ) => p . id === params . id ) ;
2994
- if ( ! authProvider ) {
2995
- throw new ApplicationError ( ErrorCodes . NOT_FOUND , "User resource not found." ) ;
2996
- }
2997
- await this . authProviderService . deleteAuthProvider ( authProvider ) ;
2992
+
2993
+ await this . authProviderService . deleteAuthProviderOfUser ( user . id , params . id ) ;
2998
2994
}
2999
2995
3000
2996
async createOrgAuthProvider (
@@ -3018,36 +3014,19 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3018
3014
if ( ! newProvider . organizationId || ! uuidValidate ( newProvider . organizationId ) ) {
3019
3015
throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Invalid organizationId" ) ;
3020
3016
}
3021
-
3022
- await this . guardWithFeatureFlag ( "orgGitAuthProviders" , user , newProvider . organizationId ) ;
3023
-
3024
- await this . guardTeamOperation ( newProvider . organizationId , "update" ) ;
3025
- await this . auth . checkPermissionOnOrganization ( user . id , "write_git_provider" , newProvider . organizationId ) ;
3026
-
3027
3017
if ( ! newProvider . host ) {
3028
3018
throw new ApplicationError (
3029
3019
ErrorCodes . BAD_REQUEST ,
3030
3020
"Must provider a host value when creating a new auth provider." ,
3031
3021
) ;
3032
3022
}
3033
3023
3034
- try {
3035
- // on creating we're are checking for already existing runtime providers
3036
- const host = newProvider . host && newProvider . host . toLowerCase ( ) ;
3037
-
3038
- if ( ! ( await this . authProviderService . isHostReachable ( host ) ) ) {
3039
- log . debug ( `Host could not be reached.` , { entry, newProvider } ) ;
3040
- throw new Error ( "Host could not be reached." ) ;
3041
- }
3024
+ await this . guardWithFeatureFlag ( "orgGitAuthProviders" , user , newProvider . organizationId ) ;
3042
3025
3043
- const hostContext = this . hostContextProvider . get ( host ) ;
3044
- if ( hostContext ) {
3045
- const builtInExists = hostContext . authProvider . params . ownerId === undefined ;
3046
- log . debug ( `Attempt to override existing auth provider.` , { entry, newProvider, builtInExists } ) ;
3047
- throw new Error ( "Provider for this host already exists." ) ;
3048
- }
3026
+ await this . guardTeamOperation ( newProvider . organizationId , "update" ) ;
3049
3027
3050
- const result = await this . authProviderService . createOrgAuthProvider ( newProvider ) ;
3028
+ try {
3029
+ const result = await this . authProviderService . createOrgAuthProvider ( user . id , newProvider ) ;
3051
3030
return AuthProviderEntry . redact ( result ) ;
3052
3031
} catch ( error ) {
3053
3032
if ( ApplicationError . hasErrorCode ( error ) ) {
@@ -3081,10 +3060,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3081
3060
await this . guardWithFeatureFlag ( "orgGitAuthProviders" , user , providerUpdate . organizationId ) ;
3082
3061
3083
3062
await this . guardTeamOperation ( providerUpdate . organizationId , "update" ) ;
3084
- await this . auth . checkPermissionOnOrganization ( user . id , "write_git_provider" , providerUpdate . organizationId ) ;
3085
3063
3086
3064
try {
3087
- const result = await this . authProviderService . updateOrgAuthProvider ( providerUpdate ) ;
3065
+ const result = await this . authProviderService . updateOrgAuthProvider ( user . id , providerUpdate ) ;
3088
3066
return AuthProviderEntry . redact ( result ) ;
3089
3067
} catch ( error ) {
3090
3068
if ( ApplicationError . hasErrorCode ( error ) ) {
@@ -3106,10 +3084,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3106
3084
await this . guardWithFeatureFlag ( "orgGitAuthProviders" , user , params . organizationId ) ;
3107
3085
3108
3086
await this . guardTeamOperation ( params . organizationId , "get" ) ;
3109
- await this . auth . checkPermissionOnOrganization ( user . id , "read_git_provider" , params . organizationId ) ;
3110
3087
3111
3088
try {
3112
- const result = await this . authProviderService . getAuthProvidersOfOrg ( params . organizationId ) ;
3089
+ const result = await this . authProviderService . getAuthProvidersOfOrg ( user . id , params . organizationId ) ;
3113
3090
return result . map ( AuthProviderEntry . redact . bind ( AuthProviderEntry ) ) ;
3114
3091
} catch ( error ) {
3115
3092
if ( ApplicationError . hasErrorCode ( error ) ) {
@@ -3125,24 +3102,76 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
3125
3102
3126
3103
const user = await this . checkAndBlockUser ( "deleteOrgAuthProvider" ) ;
3127
3104
3105
+ // check for "orgGitAuthProviders" feature flag
3128
3106
const team = await this . getTeam ( ctx , params . organizationId ) ;
3129
3107
if ( ! team ) {
3130
3108
throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Invalid organizationId" ) ;
3131
3109
}
3132
-
3133
3110
await this . guardWithFeatureFlag ( "orgGitAuthProviders" , user , team . id ) ;
3134
3111
3135
3112
await this . guardTeamOperation ( params . organizationId || "" , "update" ) ;
3136
- await this . auth . checkPermissionOnOrganization ( user . id , "write_git_provider" , params . organizationId ) ;
3137
3113
3138
- // Find the matching auth provider we're attempting to delete
3139
- const orgProviders = await this . authProviderService . getAuthProvidersOfOrg ( team . id ) ;
3140
- const authProvider = orgProviders . find ( ( p ) => p . id === params . id && p . organizationId === params . organizationId ) ;
3114
+ await this . authProviderService . deleteAuthProviderOfOrg ( user . id , params . organizationId , params . id ) ;
3115
+ }
3116
+
3117
+ async getAuthProvider ( ctx : TraceContextWithSpan , id : string ) : Promise < AuthProviderEntry > {
3118
+ traceAPIParams ( ctx , { id } ) ;
3119
+
3120
+ const user = await this . checkAndBlockUser ( "getAuthProvider" ) ;
3121
+
3122
+ const result = await this . authProviderService . getAuthProvider ( user . id , id ) ;
3123
+ if ( ! result ) {
3124
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found." ) ;
3125
+ }
3126
+ return result ;
3127
+ }
3128
+
3129
+ /**
3130
+ * Delegates to `deleteOrgAuthProvider` or `deleteOwnAuthProvider` depending on the ownership
3131
+ * of the specified auth provider.
3132
+ */
3133
+ async deleteAuthProvider ( ctx : TraceContextWithSpan , id : string ) : Promise < void > {
3134
+ traceAPIParams ( ctx , { id } ) ;
3135
+
3136
+ const user = await this . checkAndBlockUser ( "deleteAuthProvider" ) ;
3137
+
3138
+ const authProvider = await this . authProviderService . getAuthProvider ( user . id , id ) ;
3141
3139
if ( ! authProvider ) {
3142
3140
throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found." ) ;
3143
3141
}
3144
3142
3145
- await this . authProviderService . deleteAuthProvider ( authProvider ) ;
3143
+ if ( authProvider . organizationId ) {
3144
+ return this . deleteOrgAuthProvider ( ctx , { id, organizationId : authProvider . organizationId } ) ;
3145
+ } else {
3146
+ return this . deleteOwnAuthProvider ( ctx , { id } ) ;
3147
+ }
3148
+ }
3149
+
3150
+ /**
3151
+ * Delegates to `updateOrgAuthProvider` or `updateOwnAuthProvider` depending on the ownership
3152
+ * of the specified auth provider.
3153
+ */
3154
+ async updateAuthProvider (
3155
+ ctx : TraceContextWithSpan ,
3156
+ id : string ,
3157
+ entry : AuthProviderEntry . UpdateEntry ,
3158
+ ) : Promise < AuthProviderEntry > {
3159
+ traceAPIParams ( ctx , { id } ) ;
3160
+
3161
+ const user = await this . checkAndBlockUser ( "updateAuthProvider" ) ;
3162
+
3163
+ const authProvider = await this . authProviderService . getAuthProvider ( user . id , id ) ;
3164
+ if ( ! authProvider ) {
3165
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found." ) ;
3166
+ }
3167
+
3168
+ if ( authProvider . organizationId ) {
3169
+ return this . updateOrgAuthProvider ( ctx , {
3170
+ entry : { ...entry , organizationId : authProvider . organizationId } ,
3171
+ } ) ;
3172
+ } else {
3173
+ return this . updateOwnAuthProvider ( ctx , { entry } ) ;
3174
+ }
3146
3175
}
3147
3176
3148
3177
async getOnboardingState ( ctx : TraceContext ) : Promise < GitpodServer . OnboardingState > {
0 commit comments