-
Notifications
You must be signed in to change notification settings - Fork 521
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
feat: create recoverable keys from dashboard #2783
Open
harshsbhat
wants to merge
9
commits into
unkeyed:main
Choose a base branch
from
harshsbhat:create-recoverable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+423
−253
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24bf8a4
create recoverable keys
harshsbhat 3b36e6c
lint
harshsbhat 3a66720
Add console.error
harshsbhat f3f5fa4
bot request
harshsbhat d0756a1
Merge remote-tracking branch 'origin/main' into create-recoverable
harshsbhat 8bfc8aa
bot requests
harshsbhat 7741652
pnpm lock file added
harshsbhat be6d6e9
[autofix.ci] apply automated fixes
autofix-ci[bot] 6783bb6
Merge branch 'main' into create-recoverable
harshsbhat 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { insertAuditLogs } from "@/lib/audit"; | ||
import { db, schema } from "@/lib/db"; | ||
import { env } from "@/lib/env"; | ||
import { TRPCError } from "@trpc/server"; | ||
import { newId } from "@unkey/id"; | ||
import { newKey } from "@unkey/keys"; | ||
import { type EncryptRequest, type RequestContext, Vault } from "@unkey/vault"; | ||
import { z } from "zod"; | ||
import { auth, t } from "../../trpc"; | ||
|
||
|
@@ -32,6 +34,7 @@ export const createKey = t.procedure | |
}) | ||
.optional(), | ||
enabled: z.boolean().default(true), | ||
recoverEnabled: z.boolean().optional(), | ||
environment: z.string().optional(), | ||
}), | ||
) | ||
|
@@ -108,7 +111,38 @@ export const createKey = t.procedure | |
enabled: input.enabled, | ||
environment: input.environment, | ||
}); | ||
|
||
if (input.recoverEnabled && keyAuth.storeEncryptedKeys) { | ||
const vault = new Vault(env().AGENT_URL, env().AGENT_TOKEN); | ||
const encryptReq: EncryptRequest = { | ||
keyring: workspace.id, | ||
data: key, | ||
}; | ||
const requestId = crypto.randomUUID(); | ||
const context: RequestContext = { requestId }; | ||
const vaultRes = await vault.encrypt(context, encryptReq).catch((err) => { | ||
console.error(err); | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: "Encryption Failed. Please contact support using [email protected]", | ||
}); | ||
}); | ||
await tx | ||
.insert(schema.encryptedKeys) | ||
.values({ | ||
keyId: keyId, | ||
workspaceId: workspace.id, | ||
encrypted: vaultRes.encrypted, | ||
encryptionKeyId: vaultRes.keyId, | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
throw new TRPCError({ | ||
code: "INTERNAL_SERVER_ERROR", | ||
message: | ||
"We are unable to store encrypted the key. Please contact support using [email protected]", | ||
}); | ||
}); | ||
} | ||
await insertAuditLogs(tx, { | ||
workspaceId: workspace.id, | ||
actor: { type: "user", id: ctx.user.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
Oops, something went wrong.
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.
💡 Codebase verification
Workspace pattern doesn't include the vault package location
The build failure is occurring because the vault package is located at
internal/vault/
but the workspace configuration in the root package.json only includes"apps/*"
and"packages/*"
patterns. The vault package needs to be moved to thepackages/
directory or the workspace pattern needs to be updated to include theinternal/*
pattern.internal/vault/
topackages/vault/
OR
"internal/*"
to the workspaces array in the root package.json🔗 Analysis chain
Verify the workspace dependency setup.
The build failure mentioned in the PR comments suggests that the
@unkey/vault
module is not being found. Please ensure that:Let's verify the workspace setup with the following script:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 419
Script:
Length of output: 2340