-
-
Notifications
You must be signed in to change notification settings - Fork 0
Release v4.0.0 #6
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
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8857fde
refactor(error): implement consistent error handling system
phukon e6aa7a9
feat: add input validation for key import
phukon cc840e3
chore(release): 4.0.0-next.1 [skip ci]
semantic-release-bot feca926
docs: update README
phukon f43b4d3
Merge branch 'next' of https://github.com/phukon/gitkeykit into next
phukon 377cc34
fix: correct typo in README and ensure async key import handling
phukon 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 +1,42 @@ | ||
| import { readFileSync } from "fs"; | ||
| import { execSync } from "child_process"; | ||
| import { GitKeyKitCodes, GitKeyKitError } from "../gitkeykitCodes"; | ||
| import createLogger from "../utils/logger"; | ||
|
|
||
| export function importKey(key: string): boolean { | ||
| const logger = createLogger("commands:import"); | ||
|
|
||
| /** | ||
| * Imports a GPG key from a file | ||
| * @param keyPath Path to the key file | ||
| * @throws {GitKeyKitError} If key import fails | ||
| */ | ||
| export async function importKey(keyPath: string): Promise<void> { | ||
| try { | ||
| execSync(`gpg --import ${key}`, { stdio: "inherit" }); | ||
| return true; // Indicate success | ||
| } catch (error: any) { | ||
| throw new Error(`Error importing key: ${(error as Error).message}`); | ||
| let keyContent: string; | ||
| try { | ||
| keyContent = readFileSync(keyPath, "utf-8"); | ||
| } catch (error) { | ||
| throw new GitKeyKitError(`Failed to read key file: ${keyPath}`, GitKeyKitCodes.KEY_IMPORT_ERROR, error); | ||
| } | ||
|
|
||
| if (!keyContent.includes("-----BEGIN PGP PRIVATE KEY BLOCK-----")) { | ||
| throw new GitKeyKitError("Invalid key file format: Missing PGP private key block", GitKeyKitCodes.KEY_IMPORT_ERROR); | ||
| } | ||
|
|
||
| try { | ||
| execSync("gpg --import", { | ||
| input: keyContent, | ||
| stdio: ["pipe", "inherit", "inherit"], | ||
| }); | ||
|
|
||
| logger.green("GPG key imported successfully"); | ||
| } catch (error) { | ||
| throw new GitKeyKitError("Failed to import GPG key", GitKeyKitCodes.KEY_IMPORT_ERROR, error); | ||
| } | ||
| } catch (error) { | ||
| if (error instanceof GitKeyKitError) { | ||
| throw error; | ||
| } | ||
| throw new GitKeyKitError("Unexpected error during key import", GitKeyKitCodes.KEY_IMPORT_ERROR, error); | ||
| } | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.