kopia lustrzana https://gitlab.com/rysiekpl/libresilient
cli: we can support multiple files passed via glob expressions; basic-integrity cli uses that now
rodzic
3dd94f1c75
commit
b9d7d9f0eb
|
@ -79,6 +79,9 @@ let parsePluginActionArgs = (args, argdef) => {
|
|||
}
|
||||
|
||||
for (const [argname, argconfig] of Object.entries(argdef)) {
|
||||
if (argname == '_') {
|
||||
continue;
|
||||
}
|
||||
if ( ("collect" in argconfig) && (argconfig.collect === true) ) {
|
||||
plugin_args_config.collect.push(argname)
|
||||
}
|
||||
|
|
|
@ -27,17 +27,19 @@ let binToBase64 = (binary_data) => {
|
|||
|
||||
|
||||
let getFileIntegrity = async (path, algos) => {
|
||||
|
||||
|
||||
var result = []
|
||||
|
||||
// open the file and get some info on it
|
||||
const file = await Deno.open(
|
||||
path,
|
||||
{ read: true }
|
||||
);
|
||||
const fileInfo = await file.stat();
|
||||
|
||||
var result = []
|
||||
|
||||
// are we working with a file?
|
||||
if (fileInfo.isFile) {
|
||||
|
||||
//console.log(`+-- reading: ${path}`)
|
||||
|
||||
// initialize
|
||||
|
@ -77,7 +79,11 @@ let getFileIntegrity = async (path, algos) => {
|
|||
}
|
||||
//console.log(`+-- file done: ${path}`)
|
||||
|
||||
// we are not working with a file
|
||||
} else {
|
||||
result = false;
|
||||
}
|
||||
|
||||
// putting this in a try-catch block as the file
|
||||
// is apparently being auto-closed?
|
||||
// https://issueantenna.com/repo/denoland/deno/issues/15442
|
||||
|
@ -114,7 +120,12 @@ let getIntegrity = async (paths, algos=["SHA-256"], output="json") => {
|
|||
|
||||
var result = {}
|
||||
for (const p of paths) {
|
||||
result[p] = await getFileIntegrity(p, algos)
|
||||
// filter-out stuff we are not interested in
|
||||
// like directories etc
|
||||
var r = await getFileIntegrity(p, algos)
|
||||
if (r !== false) {
|
||||
result[p] = r
|
||||
}
|
||||
}
|
||||
|
||||
if (output == 'json') {
|
||||
|
@ -138,10 +149,8 @@ const pluginActions = {
|
|||
run: getIntegrity,
|
||||
description: "calculate subresource integrity hashes for provided files",
|
||||
arguments: {
|
||||
path: {
|
||||
description: "array of strings, paths to individual pieces of content",
|
||||
collect: true,
|
||||
string: true
|
||||
_: {
|
||||
description: "paths to individual pieces of content"
|
||||
},
|
||||
algorithm: {
|
||||
description: "array of SubtleCrypto.digest-compatible algorithm names to use to calculate digests (default: \"SHA-256\")",
|
||||
|
|
Ładowanie…
Reference in New Issue