-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix permissions for serverless functions (#6555)
Fixes #6525 (@martmull fyi it was not related to AWS but linked to the fact that we recently enforced passing a token to access files)
- Loading branch information
1 parent
67c4125
commit 4157a67
Showing
7 changed files
with
105 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...server/src/engine/metadata-modules/serverless-function/serverless-function.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common'; | ||
|
||
import { Observable, map } from 'rxjs'; | ||
|
||
import { FileService } from 'src/engine/core-modules/file/services/file.service'; | ||
|
||
@Injectable() | ||
export class ServerlessFunctionInterceptor implements NestInterceptor { | ||
constructor(private readonly fileService: FileService) {} | ||
|
||
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { | ||
return next.handle().pipe( | ||
map(async (data) => { | ||
if (data.edges && Array.isArray(data.edges)) { | ||
return { | ||
...data, | ||
edges: Promise.all( | ||
data.edges.map((item) => ({ | ||
...item, | ||
node: this.processItem(item.node), | ||
})), | ||
), | ||
}; | ||
} else { | ||
return this.processItem(data); | ||
} | ||
}), | ||
); | ||
} | ||
|
||
private async processItem(item: any): Promise<any> { | ||
if (item && item.sourceCodeFullPath) { | ||
const workspaceId = item.workspace?.id || item.workspaceId; | ||
|
||
if (!workspaceId) { | ||
return item; | ||
} | ||
|
||
const signedPayload = await this.fileService.encodeFileToken({ | ||
serverlessFunctionId: item.id, | ||
workspace_id: workspaceId, | ||
}); | ||
|
||
return { | ||
...item, | ||
sourceCodeFullPath: `${item.sourceCodeFullPath}?token=${signedPayload}`, | ||
}; | ||
} | ||
|
||
return item; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters