Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hc-service-client

Package Overview
Dependencies
Maintainers
5
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hc-service-client

Service Client Extension for Honeybee

  • 1.3.0-alpha.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

ServiceClient

hc-service-client

本项目支持两种用法,如下介绍为在honeybee extension中使用的方法。

直接使用ServiceClient请参考: 这里 !!!

在honeycomb extension中的例子
{
  extension: {
    serviceClient: {
      module: 'hc-service-client',
      config: {
        otm: {
          endpoint: 'http://otm.com/v2',
          accessKeySecret: 'xxx',
          headerExtension: ['otm']
        },
        azk: {
          endpoint: 'http://algorithm.com/',
          accessKeySecret: 'xxx',
          workApp: 'test',
          headerExtension: ['azk']
        },
        brain: {
          endpoint: 'http://brain_domain.com/',
          accessKeySecret: 'xxx',
          headerExtension: [
            function (req, serviceCfg) {
              return {
                'X-Access-User': req.session.id
              };
            }
          ]
        }
      }
    }
  }
}

配置详情如下。

配置

hc-service-client的配置结构:

{
  [serviceCode]: {
    endpoint,
    accessKeyId,
    accessKeySecret,
    signatureApproach,
    headerExtension,
    disableFileSignature,
    headers,
    timeout
  }
}
optionsdescdefault
endpoint远程的endpoint必填
accessKeyId调用的用户标志anonymous
accessKeySecret调用的签名密钥,原token/systemToken必填
signatureApproach签名方式 enum: [systemCall, userAuth]默认 systemCall
disableFileSignature禁用文件签名false
headerExtension根据环境动态修改header的扩展[]
headers使用serviceClient的默认发送headers,优先级高于headerExtension{}
timeout请求的超时时间(单位ms)60000
signatureHeader签名请求头,默认 systemCall -> signature, userAuth -> Authorization
responseWrapper处理返回结果的function默认函数,返回结果result.code!== 'SUCCESS'时作为错误处理,否则将result.data作为结果返回,详见SERVICE_CLIENT文档responseWrapper参数介绍
headerExtension

其他参数介绍见 这里

headerExtension是一个数组,数组中元素支持动态扩展header,

支持

  • 函数, function (req, serviceCfg) ,返回 header
  • object,直接写header内容
  • 内置扩展, 'otm' 、 'azk' 、'gateway'

如:

{
  otm: {
    endpoint: 'http://xxx',
    accessKeyId: 'DonaldTrump',
    accessKeySecret: config.systemToken,
    headerExtension: [
      function (req, serviceCfg) {
        return {
          'X-Access-TenantCode': req.session.tenant || serviceCfg.defaultTenant
        };
      },
      {
        'X-Access-WorkApp': 'city_brain'
      },
      'otm'
    ]
  }
}

如上配置,三个类型返回的header会merge到一起,再最终请求时带上。

用法
const otm = req.getService('otm');
otm.get('/api/workspaces', {}, (err, data) => {});
const azk = req.getService('azk');
azk.get('/api/workspaces', {}, (err, data) => {});

Keywords

FAQs

Package last updated on 07 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc