-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,301 additions
and
553 deletions.
There are no files selected for viewing
38 changes: 0 additions & 38 deletions
38
migrations/multitenant/0006-add-tenants-external-credentials.sql
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
migrations/tenant/0017-add_owner_id_column_deprecate_owner.sql
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,8 @@ | ||
alter table storage.objects add column if not exists owner_id text default null; | ||
alter table storage.buckets add column if not exists owner_id text default null; | ||
|
||
comment on column storage.objects.owner is 'Field is deprecated, use owner_id instead'; | ||
comment on column storage.buckets.owner is 'Field is deprecated, use owner_id instead'; | ||
|
||
ALTER TABLE storage.buckets | ||
DROP CONSTRAINT IF EXISTS buckets_owner_fkey; |
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,14 @@ | ||
CREATE TABLE bucket_credentials ( | ||
"id" uuid NOT NULL DEFAULT extensions.uuid_generate_v4(), | ||
name text NOT NULL unique, | ||
access_key text NULL, | ||
secret_key text NULL, | ||
role text null, | ||
region text not null, | ||
endpoint text NULL, | ||
force_path_style boolean NOT NULL default false, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
ALTER TABLE storage.buckets ADD COLUMN credential_id uuid DEFAULT NULL; | ||
ALTER TABLE storage.buckets ADD CONSTRAINT fk_bucket_credential FOREIGN KEY (credential_id) REFERENCES bucket_credentials(id); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import fastifyPlugin from 'fastify-plugin' | ||
import { RouteGenericInterface } from 'fastify/types/route' | ||
import { BucketWithCredentials } from '../../storage/schemas' | ||
import { StorageBackendError } from '../../storage' | ||
|
||
declare module 'fastify' { | ||
interface FastifyRequest<RouteGeneric extends RouteGenericInterface = RouteGenericInterface> { | ||
bucket: BucketWithCredentials | ||
} | ||
|
||
interface FastifyContextConfig { | ||
getParentBucketId?: ((request: FastifyRequest<any>) => string) | false | ||
} | ||
} | ||
|
||
export const parentBucket = fastifyPlugin(async (fastify) => { | ||
fastify.decorateRequest('bucket', undefined) | ||
fastify.addHook('preHandler', async (request) => { | ||
if (typeof request.routeConfig.getParentBucketId === 'undefined') { | ||
throw new Error( | ||
`getParentBucketId not defined in route ${request.routerPath} ${request.routerPath} config` | ||
) | ||
} | ||
|
||
if (request.routeConfig.getParentBucketId === false) { | ||
return | ||
} | ||
|
||
const bucketId = request.routeConfig.getParentBucketId(request) | ||
|
||
if (!bucketId) { | ||
throw new StorageBackendError('invalid_bucket', 400, 'bucket name is invalid or not provided') | ||
} | ||
|
||
const bucket = await request.db.asSuperUser().findBucketById(bucketId, '*', { | ||
includeCredentials: true, | ||
}) | ||
|
||
request.bucket = bucket | ||
}) | ||
}) |
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
Oops, something went wrong.