2

我正在按照教程Windows Azure SDK for Node.js - 计算管理来管理虚拟机。

azure account cert export我使用to下载了 pem 文件<Subscription GUID>.pem

该脚本当前包含:

var subscriptionId ="<Subscription GUID>";
var pem = "<Subscription GUID>.pem";

var computeManagementClient = computeManagement.createComputeManagementClient(computeManagement.createCertificateCloudCredentials({
    subscriptionId: subscriptionId,
    pem: fs.readFileSync(pem)
}));

当我从 Node.js 运行它时,它会产生错误:

C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:416
  throw new Error('Required argument ' + name + ' for function ' + func + ' is
        ^
Error: Required argument credentials.pem for function CertificateCloudCredentials is not defined
    at throwMissingArgument (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:416:9)
    at ArgumentValidator._.extend.string (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:426:7)
    at C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\services\credentials\certificateCloudCredentials.js:35:9
    at Object.validateArgs (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\util\validate.js:478:3)
    at new CertificateCloudCredentials (C:\Apps\azure\node_modules\azure-mgmt-compute\node_modules\azure-common\lib\services\credentials\certificateCloudCredentials.js:32:14)
    at Object.exports.createCertificateCloudCredentials (C:\Apps\azure\node_modules\azure-mgmt-compute\lib\compute.js:54:10)
    at Object.<anonymous> (C:\Apps\azure\setup.js:14:97)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
4

1 回答 1

6

问题在于pem: fs.readFileSync(pem). SDK 不会将节点缓冲区转换为字符串。Github 上有一个问题

直到toString在缓冲区上固定使用:

pem: fs.readFileSync(pem).toString()
于 2014-05-21T19:17:53.043 回答