Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kongfig apply command uses default localhost instead of host parameter value #118

Open
theoskolnik opened this issue Feb 16, 2018 · 3 comments

Comments

@theoskolnik
Copy link

When trying to apply kongfig to an API in Kong, the apply command explicitly sets a host parameter; however, the error shows a request being made to http://localhost:8001. Seems like the host is getting lost somewhere.

kongfig apply --header='apikey: KEY’ --host=api.domain/admin --https --path=./kongfig.yml
Loading config ./kongfig.yml
Apply config to api.domain/admin
FetchError: request to http://localhost:8001/apis?offset=Mg%3D%3D&size=100 failed, reason: connect ECONNREFUSED 127.0.0.1:8001
 FetchError: request to http://localhost:8001/apis?offset=Mg%3D%3D&size=100 failed, reason: connect ECONNREFUSED 127.0.0.1:8001
    at ClientRequest.<anonymous> (/var/go/.nvm/versions/node/v7.4.0/lib/node_modules/kongfig/node_modules/node-fetch/index.js:133:11)
    at emitOne (events.js:96:13)
    at ClientRequest.emit (events.js:188:7)
    at Socket.socketErrorListener (_http_client.js:309:9)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at emitErrorNT (net.js:1281:8)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

The kongfig.yml:

apis:
- attributes:
    https_only: true
    upstream_url: https://some-upstream-url
    uris: /reference-api-dev
  name: reference-api-dev
  plugins:
  - attributes:
      config.whitelist: team
    name: acl
  - attributes:
      config:
        key_names: integration
    name: key-auth

kongfig --version: 1.3.0

npm --version: 4.0.5

The error is coming from node-fetch, a transitive dependency of kongfig's isomorphic-fetch; however I'm not sure if the host is getting set to localhost even before it reaches that call.

npm show kongfig dependencies
 
{ 'babel-polyfill': '^6.2.0',
  colors: '^1.1.2',
  commander: '^2.9.0',
  invariant: '^2.2.2',
  'isomorphic-fetch': '^2.2.0',
  'js-yaml': '^3.4.6',
  minimist: '^1.2.0',
  'object-assign': '^4.0.1',
  pad: '^1.1.0',
  prettyjson: '^1.1.3',
  semver: '^5.3.0' }
@theoskolnik
Copy link
Author

After some investigation, we figured out that this is a pagination issue. When Kongfig runs an apply, it will also make a GET request to admin_domain/apis when there are over 100 APIs registered in Kong (which is the default limit for paginated results in json data). The json response returns a "next" token with the hostname; in our case, we are not getting back admin_domain, but are instead getting back localhost:8001.

We've unsuccessfully tried a number of ways to preserve the scheme, hostname, and path in the next token; at this point, we would like to make the pagination limit configurable in this line of code.

@CyExy, is this a change you'd be willing to accept a pull request for?

@CyExy
Copy link
Contributor

CyExy commented Feb 22, 2018

Sorry, it took so long to get back to you; I think we should be able to fix the issue by overriding the host for the next link when --host has been given. Would that work for you?

@CyExy
Copy link
Contributor

CyExy commented Feb 28, 2018

@theoskolnik please could you test this PR #123

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants