yaml-crypt
Advanced tools
Comparing version 0.4.5 to 0.4.6
@@ -157,2 +157,6 @@ #!/usr/bin/env node | ||
}); | ||
parser.addArgument(["-f", "--force"], { | ||
action: "storeTrue", | ||
help: "Overwrite existing files" | ||
}); | ||
parser.addArgument(["file"], { | ||
@@ -563,3 +567,3 @@ nargs: "*", | ||
: file.substring(0, file.length - "-crypt".length); | ||
if (fs.existsSync(output)) { | ||
if (fs.existsSync(output) && !args.force) { | ||
throw new UsageError(`output file already exists: ${output}`); | ||
@@ -566,0 +570,0 @@ } |
@@ -5,15 +5,41 @@ export as namespace yamlcrypt; | ||
/** | ||
* Generates a random key to be used with the given algorithm | ||
* | ||
* @param algorithm One of "fernet" (default) or "branca" | ||
* @returns A generated key, as string, suitable for the given algorithm | ||
*/ | ||
export function generateKey(algorithm?: Algorithm): string; | ||
/** | ||
* Loads the YAML file as object from the specified path, | ||
* using decryption keys from the user's configuration file | ||
* | ||
* @param path File path | ||
* @param opts Options to use while loading (optional) | ||
* @returns A promise that resolves to the loaded YAML document, as object | ||
*/ | ||
export function loadFile(path: string, opts?: LoadFileOptions): Promise<any>; | ||
export interface LoadFileOptions { | ||
/** Default decryption and encryption keys */ | ||
config?: Config; | ||
/** Needs to be specified when the YAML file contains multiple documents */ | ||
loadAll?: boolean; | ||
} | ||
/** | ||
* Load the user's configuration file from disk | ||
* | ||
* @param opts Options to use while loading (optional) | ||
* @returns A promise that resolves to the configuration object | ||
*/ | ||
export function loadConfig(opts?: LoadConfigOptions): Promise<Config>; | ||
export interface LoadConfigOptions { | ||
/** Full path of the configuration file */ | ||
path?: string; | ||
/** Override user's HOME directory when loading */ | ||
home?: string; | ||
@@ -41,8 +67,38 @@ } | ||
export interface Yamlcrypt { | ||
/** | ||
* Encrypts the given YAML document | ||
* | ||
* @param str The YAML document (as string) to encrypt | ||
* @param opts Encryption options | ||
* @returns The encrypted document, as string | ||
*/ | ||
encrypt(str: string, opts?: EncryptOptions): string; | ||
/** | ||
* Encrypts all the given YAML documents (multiple documents | ||
* are separated by "---") | ||
* | ||
* @param str The YAML documents (as string) to encrypt | ||
* @param opts Encryption options | ||
* @returns The encrypted documents, as string | ||
*/ | ||
encryptAll(str: string, opts?: EncryptOptions): string; | ||
/** | ||
* Decrypts the given YAML document, returns the parsed object | ||
* | ||
* @param str The YAML document (as string) to decrypt | ||
* @param opts Decryption options | ||
* @returns The decrypted document, as object | ||
*/ | ||
decrypt(str: string, opts?: DecryptOptions): any; | ||
/** | ||
* Decrypts all the given YAML documents (separated by "---"), | ||
* returns an array of parsed objects | ||
* | ||
* @param str The YAML documents (as string) to decrypt | ||
* @param opts Decryption options | ||
* @returns Array of the decrypted documents | ||
*/ | ||
decryptAll(str: string, opts?: DecryptOptions): any[]; | ||
@@ -49,0 +105,0 @@ |
{ | ||
"name": "yaml-crypt", | ||
"version": "0.4.5", | ||
"version": "0.4.6", | ||
"description": "Encrypt and decrypt YAML documents", | ||
@@ -29,3 +29,3 @@ "license": "MIT", | ||
"fernet": "^0.3.1", | ||
"js-yaml": "^3.12.1", | ||
"js-yaml": "^3.12.2", | ||
"pkginfo": "^0.4.1", | ||
@@ -37,5 +37,5 @@ "tmp": "^0.0.33", | ||
"chai": "^4.1.2", | ||
"coveralls": "^3.0.0", | ||
"eslint": "^5.11.0", | ||
"mocha": "^5.1.0", | ||
"coveralls": "^3.0.3", | ||
"eslint": "^5.15.0", | ||
"mocha": "^6.0.2", | ||
"nyc": "^13.3.0", | ||
@@ -42,0 +42,0 @@ "prettier": "^1.15.3" |
@@ -148,2 +148,26 @@ const fs = require("fs"); | ||
it("should throw an error when the output file exists", () => { | ||
const tmpdir = tmp.dirSync(); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", `${tmpdir.name}/2.yaml-crypt`); | ||
fs.copyFileSync("./test/test-2.yaml", `${tmpdir.name}/2.yaml`); | ||
expect(() => | ||
runWithKeyFile( | ||
["-d", `${tmpdir.name}/2.yaml-crypt`], | ||
{}, | ||
{ stdout: new Out() } | ||
) | ||
).to.throw(/output file already exists/); | ||
}); | ||
it("should succeed when the output file exists and -f is given", () => { | ||
const tmpdir = tmp.dirSync(); | ||
fs.copyFileSync("./test/test-2.yaml-crypt", `${tmpdir.name}/2.yaml-crypt`); | ||
fs.copyFileSync("./test/test-2.yaml", `${tmpdir.name}/2.yaml`); | ||
runWithKeyFile( | ||
["-d", "--force", `${tmpdir.name}/2.yaml-crypt`], | ||
{}, | ||
{ stdout: new Out() } | ||
); | ||
}); | ||
it("should decrypt the given directory", () => { | ||
@@ -150,0 +174,0 @@ const tmpdir = tmp.dirSync(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72231
2019
Updatedjs-yaml@^3.12.2