express-gateway icon indicating copy to clipboard operation
express-gateway copied to clipboard

Model schemas are strictly required even when auth policies are not used.

Open kevinswiber opened this issue 6 years ago • 2 comments

https://github.com/ExpressGateway/express-gateway/blob/2b0e5e746970e30f91ec9bb367a670e073d87eeb/lib/config/index.js#L11

EG is using a singleton config object. It attempts to load models early, even if no auth policies are used. This means users MUST include models no matter what.

Consider relaxing this requirement and look at lazy-loading based on runtime needs.

kevinswiber avatar Jun 22 '18 19:06 kevinswiber

Are the models exclusively used by the Admin Server or are they also tied policies or other parts of they system?

If the former case, then this seems like a simple case of removing config.loadModels(); from config/index.js and adding the following to config.js:

  loadConfig (type) {
    // ...load config object
    if (type === 'gateway' && config.admin) {
      this.loadModels();
    }
    //...
  }

As well ad addressing the dereferencePromise in services/consumers/credentials/credential.service.js which assumes that the models exist.

const dereferencePromise = refParser.dereference(config.models.credentials).then(derefSchema => mergeAllOf(derefSchema));

Would that work?

jtsampson avatar Jun 23 '18 18:06 jtsampson

This is going to require some work on our side. @jtsampson you correctly identified two spots where changing the strategy from eager to lazy loading would break, but I'm almost sure there would be other places.

I think the first place where we should start changing the code is the one that is looping through the policies array — and see if we can avoid to load there.

Perhaps (perhaps) — that array is completely useless as we can discovery the policies to load by ourselves. Once this'll be scheduled, I'll have a further look into.

XVincentX avatar Jun 25 '18 10:06 XVincentX