File tree Expand file tree Collapse file tree 3 files changed +54
-4
lines changed
components/server/src/api Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ import { APITeamsService as TeamsServiceAPI } from "./teams";
41
41
import { APIUserService as UserServiceAPI } from "./user" ;
42
42
import { WorkspaceServiceAPI } from "./workspace-service-api" ;
43
43
import { AuthProviderServiceAPI } from "./auth-provider-service-api" ;
44
+ import { Unauthenticated } from "./unauthenticated" ;
44
45
45
46
decorate ( injectable ( ) , PublicAPIConverter ) ;
46
47
@@ -213,10 +214,14 @@ export class API {
213
214
} ;
214
215
215
216
const apply = async < T > ( ) : Promise < T > => {
216
- const subjectId = await self . verify ( context ) ;
217
- await rateLimit ( subjectId ) ;
218
- context . user = await self . ensureFgaMigration ( subjectId ) ;
219
-
217
+ const unauthenticated = Unauthenticated . get ( target , prop ) ;
218
+ if ( unauthenticated ) {
219
+ // TODO(at) add a low rate limit
220
+ } else {
221
+ const subjectId = await self . verify ( context ) ;
222
+ await rateLimit ( subjectId ) ;
223
+ context . user = await self . ensureFgaMigration ( subjectId ) ;
224
+ }
220
225
return Reflect . apply ( target [ prop as any ] , target , args ) ;
221
226
} ;
222
227
if ( grpc_type === "unary" || grpc_type === "client_stream" ) {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License.AGPL.txt in the project root for license information.
5
+ */
6
+
7
+ import * as chai from "chai" ;
8
+ import { Unauthenticated } from "./unauthenticated" ;
9
+
10
+ const expect = chai . expect ;
11
+
12
+ class Foo {
13
+ @Unauthenticated ( )
14
+ async fooUnauthenticated ( ) { }
15
+
16
+ async foo ( ) { }
17
+ }
18
+
19
+ describe ( "Unauthenticated decorator" , function ( ) {
20
+ const foo = new Foo ( ) ;
21
+
22
+ it ( "function is decorated" , function ( ) {
23
+ expect ( Unauthenticated . get ( foo , "fooUnauthenticated" ) ) . to . be . true ;
24
+ } ) ;
25
+ it ( "function is not decorated" , function ( ) {
26
+ expect ( Unauthenticated . get ( foo , "foo" ) ) . to . be . false ;
27
+ } ) ;
28
+ } ) ;
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3
+ * Licensed under the GNU Affero General Public License (AGPL).
4
+ * See License.AGPL.txt in the project root for license information.
5
+ */
6
+
7
+ const UNAUTHENTICATED_METADATA_KEY = Symbol ( "Unauthenticated" ) ;
8
+
9
+ export function Unauthenticated ( ) {
10
+ return Reflect . metadata ( UNAUTHENTICATED_METADATA_KEY , true ) ;
11
+ }
12
+
13
+ export namespace Unauthenticated {
14
+ export function get ( target : Object , properyKey : string | symbol ) : boolean {
15
+ return ! ! Reflect . getMetadata ( UNAUTHENTICATED_METADATA_KEY , target , properyKey ) ;
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments