kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: signed-integrity now has "json" output mode, and it is default (ref. #66)
rodzic
4d80cbe743
commit
b226bf3012
|
@ -167,14 +167,14 @@ let getFileIntegrity = async (path, algos) => {
|
|||
* paths - paths to files for which integrity files are to be generated
|
||||
* keyfile - path of the file containing the private key to use
|
||||
* algos - array of SubtleCrypto.digest-compatible hashing algorithms (default: ["SHA-256"])
|
||||
* output - whether to output the signed integrity data to "files" or "text" (default)
|
||||
* output - whether to output the signed integrity data to "files", or as "text" or "json" (default)
|
||||
* extension - file extension to use when saving integrity files (default: ".integrity")
|
||||
*/
|
||||
let genSignedIntegrity = async (
|
||||
paths,
|
||||
keyfile,
|
||||
algos=["SHA-256"],
|
||||
output='files',
|
||||
output='json',
|
||||
extension='.integrity') => {
|
||||
|
||||
// load the key
|
||||
|
@ -200,7 +200,7 @@ let genSignedIntegrity = async (
|
|||
)
|
||||
|
||||
// initialize the result
|
||||
let result = ''
|
||||
let result = {}
|
||||
|
||||
// do the thing for each path
|
||||
for (const path of paths) {
|
||||
|
@ -239,16 +239,21 @@ let genSignedIntegrity = async (
|
|||
let jwt = header + '.' + payload + '.' + signature
|
||||
|
||||
// do we want output to text or files
|
||||
if (output == 'text') {
|
||||
result += `${path}: ${jwt}\n`
|
||||
} else {
|
||||
result[path] = jwt
|
||||
if (output == 'files') {
|
||||
// write it out to {path}.extension
|
||||
Deno.writeTextFileSync(path + extension, jwt)
|
||||
}
|
||||
}
|
||||
|
||||
// return whatever we have to return
|
||||
return result;
|
||||
if (output == 'json') {
|
||||
return JSON.stringify(result);
|
||||
} else if (output == 'text') {
|
||||
return Object.keys(result).map(p=>`${p}: ${result[p]}`).join('\n') + '\n'
|
||||
} else if (output == 'files') {
|
||||
return "created integrity files:\n" + Object.keys(result).map(p=>`- ${p}${extension}`).join('\n') + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
// this never changes
|
||||
|
@ -289,8 +294,8 @@ const pluginActions = {
|
|||
default: "SHA-256"
|
||||
},
|
||||
output: {
|
||||
description: "output mode: 'files' or 'text'",
|
||||
default: 'text',
|
||||
description: "output mode: 'files', 'text', or 'json'",
|
||||
default: 'json',
|
||||
string: true
|
||||
},
|
||||
extension: {
|
||||
|
|
Ładowanie…
Reference in New Issue