【问题标题】:google-cloud client library key file as jsongoogle-cloud 客户端库密钥文件为 json
【发布时间】:2020-12-14 21:46:11
【问题描述】:

我正在尝试使用@google-cloud 客户端库通过服务帐户进行身份验证。有没有办法将密钥文件内容作为 JSON 对象而不是文件路径传递?我不想将密钥文件存储在服务器上,而是使用秘密管理器服务,将密钥文件加载到内存中并根据需要使用它。 该库似乎只采用关键文件路径:

const storage = new Storage({projectId:projectId, keyFilename: keyPath});

【问题讨论】:

    标签: node.js google-cloud-platform google-cloud-storage


    【解决方案1】:

    在构造函数中使用credentials参数:storageOptions

    var sa_data = fs.readFileSync(keyPath);
    var sa_json = JSON.parse(sa_data)
    
    const storage = new Storage({
      credentials: sa_json
    });
    

    【讨论】:

    • 谢谢,这正是我需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2018-06-03
    • 2019-01-07
    相关资源
    最近更新 更多