Node.js : 在 consul kv get 中传递令牌
Node.js : Pass token in consul kv get
我正在使用 consul 在我的 Node.js 项目中获取一些配置。
我能够使用下面给出的代码访问 consul 键值对。
import consul from 'consul';
(new consul()).kv.get('config', (err, result) => {
if (err) throw err;
console.log("result", result);
});
(使用 npm“领事”)
现在,我已经使用 ACL 保护了 consul 并创建了 3 个令牌:
master_token,一个具有写入权限的令牌和一个具有读取权限的令牌
由于领事现在受 ACL 保护,上面提到的代码显示“权限被拒绝”
如何在 kv.get 方法中传递此令牌以验证我的请求?
提前致谢。
初始化 consul 客户端时,您可以使用 defaults
选项来定义应随每个查询发送的令牌。
import consul from 'consul';
var defaultRequestOptions = {
token: '43d8f1cb-3c73-44a2-a1d6-c4fe1b9b1537'
};
(new consul({defaults: defaultRequestOptions})).kv.get('config', (err, result) => {
if (err) throw err;
console.log("result", result);
});
有关可用默认选项的完整列表,请参阅 Common Method Call Options。
我正在使用 consul 在我的 Node.js 项目中获取一些配置。
我能够使用下面给出的代码访问 consul 键值对。
import consul from 'consul';
(new consul()).kv.get('config', (err, result) => {
if (err) throw err;
console.log("result", result);
});
(使用 npm“领事”)
现在,我已经使用 ACL 保护了 consul 并创建了 3 个令牌: master_token,一个具有写入权限的令牌和一个具有读取权限的令牌
由于领事现在受 ACL 保护,上面提到的代码显示“权限被拒绝” 如何在 kv.get 方法中传递此令牌以验证我的请求?
提前致谢。
初始化 consul 客户端时,您可以使用 defaults
选项来定义应随每个查询发送的令牌。
import consul from 'consul';
var defaultRequestOptions = {
token: '43d8f1cb-3c73-44a2-a1d6-c4fe1b9b1537'
};
(new consul({defaults: defaultRequestOptions})).kv.get('config', (err, result) => {
if (err) throw err;
console.log("result", result);
});
有关可用默认选项的完整列表,请参阅 Common Method Call Options。