Skip to content

Commit

Permalink
Add Connection Token to Data Assets
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Feb 6, 2024
1 parent 2893245 commit 2caec32
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions api/routes/data-asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export default async function router(schema: any, config: Config) {
res: 'res.ListAssets.json'
}, async (req: AuthRequest, res: Response) => {
try {
await Auth.is_auth(config.models, req);
await Auth.is_auth(config.models, req, {
resources: [{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }]
});

const data = await config.models.Data.from(parseInt(req.params.dataid))

Expand Down Expand Up @@ -65,7 +67,10 @@ export default async function router(schema: any, config: Config) {
let data;
try {
await Auth.is_auth(config.models, req, {
resources: [{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) }]
resources: [
{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) },
{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }
]
});

data = await config.models.Data.from(parseInt(req.params.dataid));
Expand Down Expand Up @@ -125,7 +130,10 @@ export default async function router(schema: any, config: Config) {
}, async (req: AuthRequest, res: Response) => {
try {
await Auth.is_auth(config.models, req, {
resources: [{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) }]
resources: [
{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) },
{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }
]
});

const data = await config.models.Data.from(parseInt(req.params.dataid));
Expand Down Expand Up @@ -154,7 +162,10 @@ export default async function router(schema: any, config: Config) {
}, async (req: AuthRequest, res: Response) => {
try {
await Auth.is_auth(config.models, req, {
resources: [{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) }]
resources: [
{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) },
{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }
]
});

await S3.del(`data/${req.params.dataid}/${req.params.asset}.${req.params.ext}`);
Expand All @@ -181,7 +192,10 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req, {
token: true,
resources: [{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) }]
resources: [
{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) },
{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }
]
});

const stream = await S3.get(`data/${req.params.dataid}/${req.params.asset}.${req.params.ext}`);
Expand All @@ -204,7 +218,10 @@ export default async function router(schema: any, config: Config) {
try {
await Auth.is_auth(config.models, req, {
token: true,
resources: [{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) }]
resources: [
{ access: AuthResourceAccess.DATA, id: parseInt(req.params.dataid) },
{ access: AuthResourceAccess.CONNECTION, id: parseInt(req.params.connectionid) }
]
});

const data = await config.models.Data.from(parseInt(req.params.dataid));
Expand Down

0 comments on commit 2caec32

Please sign in to comment.