-
-
Notifications
You must be signed in to change notification settings - Fork 275
feat: add user metadata support for RLS policies #825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e7c7d51
f0e0e49
9a734ca
5f19dea
ad022ac
3109ebf
79e96c0
e10e404
5a1791e
81778d8
6c895b8
9fc37d0
573b34f
cd3ec31
f8d78d9
208b479
6afe8c4
0f181c2
8be7f15
150920e
b4676ca
2dd0938
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE storage.s3_multipart_uploads ADD COLUMN IF NOT EXISTS metadata jsonb NULL; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { FastifyInstance } from 'fastify' | ||
| import { FromSchema } from 'json-schema-to-ts' | ||
| import { getConfig } from '../../../config' | ||
| import { parseUserMetadata } from '../../../storage/uploader' | ||
| import { createDefaultSchema } from '../../routes-helper' | ||
| import { AuthenticatedRequest } from '../../types' | ||
| import { ROUTE_OPERATIONS } from '../operations' | ||
|
|
@@ -20,6 +21,9 @@ const getSignedUploadURLHeadersSchema = { | |
| type: 'object', | ||
| properties: { | ||
| 'x-upsert': { type: 'string' }, | ||
| 'x-metadata': { type: 'string' }, | ||
| 'content-type': { type: 'string' }, | ||
| 'content-length': { type: 'string' }, | ||
| authorization: { type: 'string' }, | ||
| }, | ||
| required: ['authorization'], | ||
|
|
@@ -69,10 +73,29 @@ export default async function routes(fastify: FastifyInstance) { | |
|
|
||
| const urlPath = `${bucketName}/${objectName}` | ||
|
|
||
| let userMetadata: Record<string, unknown> | undefined | ||
|
|
||
| const customMd = request.headers['x-metadata'] | ||
|
|
||
| if (typeof customMd === 'string') { | ||
| // TODO: parseUserMetadata casts to Record<string, string> but values could be anything; | ||
| // validation should be added in a follow-up | ||
| userMetadata = parseUserMetadata(customMd) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this parser returns This is an existing helper, feel free to add a TODO to be addressed later
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looked into supabase-js and s3 part of this, type is wrong but handling is correct and we return
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing to note is that when it's set when content-type is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added TODO |
||
| } | ||
|
|
||
| const contentType = request.headers['content-type'] | ||
| const contentLengthHeader = request.headers['content-length'] | ||
| const contentLength = contentLengthHeader ? Number(contentLengthHeader) : undefined | ||
|
|
||
| const signedUpload = await request.storage | ||
| .from(bucketName) | ||
| .signUploadObjectUrl(objectName, urlPath as string, uploadSignedUrlExpirationTime, owner, { | ||
| upsert: request.headers['x-upsert'] === 'true', | ||
| userMetadata, | ||
| metadata: { | ||
| mimetype: contentType, | ||
| contentLength, | ||
| }, | ||
| }) | ||
|
|
||
| return response.status(200).send({ url: signedUpload.url, token: signedUpload.token }) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't we need
x-metadataas well since we try to read below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, added