2

我目前正在创建一种病毒扫描功能。

我正在尝试做的事情:当文件上传到指定的 blob 存储容器时,会触发 Azure 函数。该功能将扫描文件中的病毒,如果干净,则将文件移动到另一个 blob 存储容器。

我创建了一个在创建 blob 时触发的 Azure 函数(即上传文件时),但我不知道如何将病毒扫描集成到混合中。

我尝试使用ClamAV.js,但无法正常工作。我不确定如何安装 ClamAV(守护程序),以便它可以被 Azure 函数使用,所以这可能是它无法正常工作的原因。另外,我不确定如何安装 npm 包(在 Azure 函数中),所以我必须将实际的 js 文件从包上传到函数,然后再导入。不确定这是否有效......

我曾尝试使用AttachmentScanner,但我无法在 Azure 函数中使用它(更具体地说,我无法让该函数发送 POST 请求)。

我面临的一个主要问题是我认为我无法解决:如何在 Azure 函数中使用 npm 包?我可以在某个地方安装它们吗?我可以只下载包并手动将 js 文件上传到 Azure Function 并以这种方式导入吗?

这是我使用 AttachmentScanner 的尝试:

module.exports = async function (context, myBlob) {
    var req = new XMLHttpRequest();
    req.open( "POST", "https://beta.attachmentscanner.com/requests", false );

    req.headers({
        "authorization": "bearer [OMITTED]",
        "content-type": "application/json"
    });

    req.type("json");
    req.send({
        "url": context.bindingData.uri //"http://www.attachmentscanner.com/eicar.com"
    });

    req.end(function (res) {
        if (res.error) throw new Error(res.error);

        context.log(req.responseText);
    });

    context.log("JavaScript blob trigger function processed blob \n Name:", context.bindingData.name, "\n Blob Size:", myBlob.length, "Bytes");
    context.log("context");
    context.log(context);
    context.log("myBlob");
    context.log(myBlob);
};

这会产生一个错误:Exception: ReferenceError: XMLHttpRequest is not defined

使用以下函数,我可以检测 blob 并打印有关它的信息:

module.exports = async function (context, myBlob) {    
    context.log("JavaScript blob trigger function processed blob \n Name:", context.bindingData.name, "\n Blob Size:", myBlob.length, "Bytes");
    context.log("context");
    context.log(context);
    context.log();
    context.log("myBlob");
    context.log(myBlob);
};

任何帮助表示赞赏!

4

1 回答 1

1

首先,我确定你不能将ClamAV安装到 Azure Functions 中,所以你需要创建一个 Linux VM 来安装它。

接下来,您可以按照Visual Studio CodeAzure CLIPythonLinux等官方快速入门教程在本地环境中安装Azure Functions Core Tool(适用于 Windows 或 Linux),为 Node.js 创建一个 func 项目并将其发布到 Azure。

最后,这是我自己的想法,以满足您的需求。您可以尝试使用带有 Blob 触发器的 Azure 函数来为需要扫描的 blob 生成带有 sas 令牌的 url。有一个代码示例Node.js Azure Function for generating SAS tokens,您可以参考它知道如何做。然后,通过带有 ClamAV.js 的 Node.js 服务器将带有 sas 令牌的 blob url 传递给 VM 中的 ClamAV,以使用 HTTP 流对其进行扫描。

当然,您可以将 ClamAV.js 与 Azure Functions 集成,但我认为长时间扫描大文件对于 Azure Functions 这样的无服务器架构并不是一个好主意。希望能帮助到你。

于 2019-04-12T06:16:47.780 回答