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

Feature/plugins v3spec part1 connect #73 #381

Merged
merged 4 commits into from
Sep 7, 2017

Conversation

DrMegavolt
Copy link
Contributor

@DrMegavolt DrMegavolt commented Aug 23, 2017

Final v1.0 version

@codecov
Copy link

codecov bot commented Aug 23, 2017

Codecov Report

Merging #381 into master will decrease coverage by 0.17%.
The diff coverage is 84.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #381      +/-   ##
==========================================
- Coverage   91.46%   91.28%   -0.18%     
==========================================
  Files         197      204       +7     
  Lines        8349     8521     +172     
==========================================
+ Hits         7636     7778     +142     
- Misses        713      743      +30
Impacted Files Coverage Δ
lib/gateway/index.js 100% <100%> (ø) ⬆️
lib/index.js 100% <100%> (ø) ⬆️
test/plugins/condition.test.js 100% <100%> (ø)
test/plugins/gateway-ext.test.js 100% <100%> (ø)
test/routing/path-general.test.js 100% <100%> (+4.54%) ⬆️
lib/eventBus.js 100% <100%> (ø)
test/common/routing.helper.js 96.77% <100%> (-1.62%) ⬇️
lib/gateway/pipelines.js 92.68% <100%> (+0.43%) ⬆️
test/common/server-helper.js 96.55% <100%> (ø) ⬆️
test/plugins/policy.test.js 100% <100%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc1fc8e...23f3a79. Read the comment docs.

@DrMegavolt DrMegavolt changed the title Feature/plugins v3spec part1 Feature/plugins v3spec part1 connect #73 Aug 23, 2017
this.logger = logger;
this.settings = settings || {};
this.config = config;
this.policies = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of exposing the underlying data structure, what do you think about registration functions? manifest.registerPolicy instead of manifest.policies.push.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

lib/plugins.js Outdated
};
};

class PluginManifest {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the concept of "manifest" is a little strange in this context. I think of a manifest as a file living outside the code that contains metadata about the contents of the project, usually written in a config format like XML, JSON, or INI. I get that it's serving a similar purpose, but I look at this in code and think, "Gee, is this telling me I can actually put this manifest in a separate config file?" This might be a bias based on my past experiences. Not sure. Also, feels a tad more weird when we start assigning event handlers. Just thought I'd toss this out there. Would it make more sense to just call this... Plugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it looks weird to common approach like that
https://developer.chrome.com/extensions/manifest

the thing is that what it passes is not a plugin, because plugin is entire package itself.
It is something like container/ plugin manager / context.

I cannot name it pluginOptions because it will be confused with parameters and settings

@kevinswiber
Copy link
Member

Just to clarify, this PR doesn't include support for the following extensions:

  • Custom database entities
  • Services (or an internal service registry of any kind)
  • Consumer Management (custom auth methods)

Is that correct?

@DrMegavolt
Copy link
Contributor Author

and no CLI extensions as well

@@ -8,6 +8,9 @@ db:
cli:
url: http://localhost:9876

plugins:
# eg-example-plugin:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

express-gateway-plugin-example would be the package name, the actual plugin name would be example in the system.config.yml ?

for example:
express-gateway-plugin-oauth2 would be the npm module the entry within system.config.yml - oauth2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, make sense. and if user needs to install non convention package they will have 'package' word for that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section basically acts as a whitelist, yeah?

If so, why do we need a whitelist if the package has already been explicitly installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like concept installed vs enabled. Same idea as behind policies - have many registered(installed), but use only whitelisted(enabled).
It seems to be standard pattern for plugins. Because installation is typically complex process and enable\disable is 1 sec operation.

Atom\VS Code\Sublime all have that. Kong - same idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even ExpressJS - installed middleware, unless it is used in code doesn't exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. So it's not really a "whitelist" of allowed plugins; it's just a signal to enable. We could have discovery logic for finding a package listed here.

  1. Try wrapping the package name in express-gateway-${name}-plugin.
  2. If that fails, try ${name}.
  3. Error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point I've implemented the logic
read settings for ${name}
if contains package -> require('package')
else ensure name is prefixed with express-gateway-plugin- -> require(name)

So if you really want different name, np use package property

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Thanks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 sounds good to me, the plugins: is so that there is a known declaration and exposure to what global params are in place

simliarly in policies: you can have policies installed but unless you declare it, it can't be referenced in a pipeline

lib/plugins.js Outdated
registerAdminExtension (adminExtension) {
this.adminExtensions.push(adminExtension);
}
registerCliExtension (cliExtension) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For acronyms in JavaScript identifiers, I use all capital letters as the convention, taken from some built-ins like encodeURIComponent. Would you be willing to switch this to registerCLIExtension?

@DrMegavolt DrMegavolt force-pushed the feature/plugins-v3spec-part1 branch 3 times, most recently from 2657d10 to 77232c1 Compare September 6, 2017 10:28
support for admin extensions

support for express-gateway extensions like routes and middleware

loading plugin conditions

plugin: policy test and replacing direct policy registration for some tests with plugin based approach
@DrMegavolt DrMegavolt force-pushed the feature/plugins-v3spec-part1 branch from 77232c1 to 20288c9 Compare September 6, 2017 10:30
@DrMegavolt
Copy link
Contributor Author

@altsang @kevinswiber please take a look once again.

The main difference for last commit it is now possible to provide entire config to gateway entity itself. so it will be completely decoupled from config module.

it allows test code without having real config file loaded first
(Still some tests rely on config automatically loaded by gateway, so backward compatibility is preserved - gateway will do config loading if no config object provided)

Another difference is that previously it was a trick to load fake test policies, now it is possible to just use plugins for that. Some tests where refactored with this approach

@kevinswiber
Copy link
Member

kevinswiber commented Sep 6, 2017

Hmm. So I'm actually running into an issue trying to load plugins. The require call fails. Agh! Trying to figure it out now.

error: [EG:plugins] Failed to load plugin eg-example-plugin Error: Cannot find module 'eg-example-plugin'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Module.require (module.js:517:17)
    at require (internal/module.js:11:18)
    at Object.module.exports.load (/Users/kevin/projects/ExpressGateway/express-gateway/lib/plugins.js:22:20)
    at Main.run (/Users/kevin/projects/ExpressGateway/express-gateway/lib/index.js:23:35)
    at Object.<anonymous> (/private/tmp/asdfasdasd/my-gateway/server.js:7:4)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)

But I can require it just fine in server.js.

@kevinswiber
Copy link
Member

kevinswiber commented Sep 6, 2017

Just found this. I think we should use it. Looks like it can be an issue for people developing plugins. Let's circumvent it. It fixed the problem for me.

https://www.npmjs.com/package/parent-require

@DrMegavolt

@altsang
Copy link
Contributor

altsang commented Sep 7, 2017

Jared's stuff is solid 👍

@DrMegavolt
Copy link
Contributor Author

parent-require is integrated

@DrMegavolt DrMegavolt merged commit b63a379 into master Sep 7, 2017
@DrMegavolt DrMegavolt deleted the feature/plugins-v3spec-part1 branch September 7, 2017 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants