-
Notifications
You must be signed in to change notification settings - Fork 17
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
chore: eject pg-compose #1403
Merged
Merged
chore: eject pg-compose #1403
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5d4f962
chore: eject pg-compose
bchrobot 74c0d4c
fix: remove duplicate code
bchrobot c63c7e7
fix: add secrets migration
bchrobot f13da46
Merge branch 'main' into chore-eject-pg-compose
bchrobot 25a5c73
fix: secrets initial migration
bchrobot 532d7b6
fix: fix secret management
bchrobot 48f8f47
chore: move remaining van tasks
bchrobot e04914a
style: explicitly type job helpers
bchrobot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,49 @@ | ||
import Cryptr from "cryptr"; | ||
import type { Pool, PoolClient } from "pg"; | ||
|
||
import { config } from "../../config"; | ||
import { withClient } from "../utils"; | ||
|
||
export const cryptr = new Cryptr(config.SESSION_SECRET); | ||
|
||
export const setSecret = async ( | ||
client: PoolClient, | ||
ref: string, | ||
secret: string | ||
) => { | ||
const encryptedSecret = cryptr.encrypt(secret); | ||
await client.query( | ||
` | ||
insert into graphile_secrets.secrets (ref, encrypted_secret) | ||
values ($1, $2) | ||
on conflict (ref) do update set encrypted_secret = EXCLUDED.encrypted_secret | ||
`, | ||
[ref, encryptedSecret] | ||
); | ||
}; | ||
|
||
export const setSecretPool = (pool: Pool, ref: string, secret: string) => | ||
withClient(pool, (client) => setSecret(client, ref, secret)); | ||
|
||
export const getSecret = async (client: PoolClient, ref: string) => { | ||
const { | ||
rows: [secret] | ||
} = await client.query<{ encrypted_secret: string }>( | ||
` | ||
select encrypted_secret | ||
from graphile_secrets.secrets | ||
where ref = $1 | ||
`, | ||
[ref] | ||
); | ||
|
||
if (secret) { | ||
return cryptr.decrypt(secret.encrypted_secret); | ||
} | ||
return undefined; | ||
}; | ||
|
||
export const getSecretPool = (pool: Pool, ref: string) => | ||
withClient(pool, (client) => getSecret(client, ref)); | ||
|
||
export default cryptr; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question: What URL is this? Is it something okay being in a public repo?
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.
No issue with it being in a public repo. It's unclear if it's a required option for the export request so it just points at a webhook catcher (that is turned off currently).
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.
Cool. Sounds good!