Skip to content
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

fix: Refactor pinning authorization logic to use user_tag table #1654

Merged
merged 1 commit into from
Mar 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ DAG_CARGO_PASSWORD=<db-password>



# Pinning services api, requires a PSA allow list for authoritzation
# this is the user id in the database
PSA_ALLOW=1
# Pinning services api, requires a user to have the HasPsaAccess user_tag.
```

Production vars should be set in Github Actions secrets.
Expand Down
1 change: 0 additions & 1 deletion packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ wrangler secret put CLUSTER_BASIC_AUTH_TOKEN --env production # Get from nft.sto
wrangler secret put CLUSTER_SERVICE --env production # Which cluster should be used. Options 'IpfsCluster' / 'IpfsCluster2' / 'IpfsCluster3'
wrangler secret put MAILCHIMP_API_KEY --env production # Get from mailchimp
wrangler secret put LOGTAIL_TOKEN --env production # Get from Logtail
wrangler secret put PSA_ALLOW --env production # CSV user ID list, get from 1password vault
wrangler secret put METAPLEX_AUTH_TOKEN --env production # User ID meteplex endpoint should use (not required for dev)
wrangler secret put S3_REGION --env production # e.g us-east-2 (not required for dev)
wrangler secret put S3_ACCESS_KEY_ID --env production # Get from Amazon S3 (not required for dev)
Expand Down
1 change: 0 additions & 1 deletion packages/api/src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ declare global {
const COMMITHASH: string
const MAINTENANCE_MODE: Mode
const METAPLEX_AUTH_TOKEN: string
const PSA_ALLOW: string
const S3_ENDPOINT: string
const S3_REGION: string
const S3_ACCESS_KEY_ID: string
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/utils/db-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ export class DBClient {
magic_link_id,
github_id,
did,
keys:auth_key_user_id_fkey(user_id,id,name,secret)
keys:auth_key_user_id_fkey(user_id,id,name,secret),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some kind of editor or linter support for this would be nice. No idea if that exists, you you need an eagle eye to catch this

tags:user_tag_user_id_fkey(user_id,id,tag,value)
`
)
.or(`magic_link_id.eq.${id},github_id.eq.${id},did.eq.${id}`)
// @ts-ignore
.filter('keys.deleted_at', 'is', null)
// @ts-ignore
.filter('tags.deleted_at', 'is', null)

const { data, error, status } = await select.single()

Expand Down
25 changes: 22 additions & 3 deletions packages/api/test/scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export async function createTestUser({
* @param {number} tag.user_id
* @param {string} tag.tag
* @param {string} tag.value
* @param {string=} tag.deleted_at
* @param {string} tag.inserted_at
* @param {string} tag.reason
*/
Expand Down Expand Up @@ -96,22 +97,40 @@ export async function createTestUserWithFixedToken({
secret: token,
userId: user.id,
})

await createUserTag({
user_id: user.id,
tag: 'HasPsaAccess',
value: 'true',
reason: '',
inserted_at: '2/22/2022',
inserted_at: new Date().toISOString(),
})

await createUserTag({
user_id: user.id,
tag: 'HasAccountRestriction',
value: 'false',
reason: '',
inserted_at: '2/22/2022',
inserted_at: new Date().toISOString(),
})

// Add some deleted tags to ensure our filtering works
await createUserTag({
user_id: user.id,
tag: 'HasPsaAccess',
value: 'false',
reason: '',
inserted_at: new Date().toISOString(),
deleted_at: new Date().toISOString(),
})
await createUserTag({
user_id: user.id,
tag: 'HasAccountRestriction',
value: 'true',
reason: '',
inserted_at: new Date().toISOString(),
deleted_at: new Date().toISOString(),
})

return { token, userId: user.id, githubId: user.github_id }
}

Expand Down