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)) {
|
for (const [argname, argconfig] of Object.entries(argdef)) {
|
||||||
|
if (argname == '_') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ( ("collect" in argconfig) && (argconfig.collect === true) ) {
|
if ( ("collect" in argconfig) && (argconfig.collect === true) ) {
|
||||||
plugin_args_config.collect.push(argname)
|
plugin_args_config.collect.push(argname)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,19 @@ let binToBase64 = (binary_data) => {
|
||||||
|
|
||||||
|
|
||||||
let getFileIntegrity = async (path, algos) => {
|
let getFileIntegrity = async (path, algos) => {
|
||||||
|
|
||||||
|
var result = []
|
||||||
|
|
||||||
|
// open the file and get some info on it
|
||||||
const file = await Deno.open(
|
const file = await Deno.open(
|
||||||
path,
|
path,
|
||||||
{ read: true }
|
{ read: true }
|
||||||
);
|
);
|
||||||
const fileInfo = await file.stat();
|
const fileInfo = await file.stat();
|
||||||
|
|
||||||
var result = []
|
|
||||||
|
|
||||||
// are we working with a file?
|
// are we working with a file?
|
||||||
if (fileInfo.isFile) {
|
if (fileInfo.isFile) {
|
||||||
|
|
||||||
//console.log(`+-- reading: ${path}`)
|
//console.log(`+-- reading: ${path}`)
|
||||||
|
|
||||||
// initialize
|
// initialize
|
||||||
|
@ -77,7 +79,11 @@ let getFileIntegrity = async (path, algos) => {
|
||||||
}
|
}
|
||||||
//console.log(`+-- file done: ${path}`)
|
//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
|
// putting this in a try-catch block as the file
|
||||||
// is apparently being auto-closed?
|
// is apparently being auto-closed?
|
||||||
// https://issueantenna.com/repo/denoland/deno/issues/15442
|
// https://issueantenna.com/repo/denoland/deno/issues/15442
|
||||||
|
@ -114,7 +120,12 @@ let getIntegrity = async (paths, algos=["SHA-256"], output="json") => {
|
||||||
|
|
||||||
var result = {}
|
var result = {}
|
||||||
for (const p of paths) {
|
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') {
|
if (output == 'json') {
|
||||||
|
@ -138,10 +149,8 @@ const pluginActions = {
|
||||||
run: getIntegrity,
|
run: getIntegrity,
|
||||||
description: "calculate subresource integrity hashes for provided files",
|
description: "calculate subresource integrity hashes for provided files",
|
||||||
arguments: {
|
arguments: {
|
||||||
path: {
|
_: {
|
||||||
description: "array of strings, paths to individual pieces of content",
|
description: "paths to individual pieces of content"
|
||||||
collect: true,
|
|
||||||
string: true
|
|
||||||
},
|
},
|
||||||
algorithm: {
|
algorithm: {
|
||||||
description: "array of SubtleCrypto.digest-compatible algorithm names to use to calculate digests (default: \"SHA-256\")",
|
description: "array of SubtleCrypto.digest-compatible algorithm names to use to calculate digests (default: \"SHA-256\")",
|
||||||
|
|
Ładowanie…
Reference in New Issue