-
Notifications
You must be signed in to change notification settings - Fork 33
Feature/form configure api #112
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
Changes from all commits
2c3b7d7
0123366
f8f3d15
cc2e859
ebb4412
4c31ab2
387bc13
71bbe0a
8aed8f6
9e620ed
3b610da
630e769
5fdeea5
f2f010e
5496830
b4495a9
1685d5c
a5ede2c
cccd18e
4957107
6f63b99
34f49d6
898b570
9a04225
34c4cca
0bae7b4
242c61c
fa9fc81
761db3b
ba4ccfe
d6af71d
7114292
20726cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| Meteor.subscribe('apiUmbrellaUsers'); | ||
| Meteor.subscribe('apiBackends'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <template name="apiBackends"> | ||
| <div class="row"> | ||
| <div class="col-lg-6 col-lg-offset-3"> | ||
| {{#autoForm collection="ApiBackends" doc=this id="apiBackends"}} | ||
| {{> afQuickField name='name'}} | ||
| <h4>Host</h4> | ||
| <hr /> | ||
| <div class="row"> | ||
| <div class="col-lg-3"> | ||
| {{> afQuickField name='backend_protocol' options="allowed"}} | ||
| </div> | ||
| <div class="col-lg-6"> | ||
| {{> afQuickField name='backend_host'}} | ||
| </div> | ||
| <div class="col-lg-3"> | ||
| {{> afQuickField name='backend_port'}} | ||
| </div> | ||
| </div> | ||
| {{> afQuickField name='server'}} | ||
| <!-- TODO: show fields inline | ||
| <form> | ||
| <div class="form-inline"> | ||
| {{> afQuickField name='matching'}} | ||
| </div> | ||
| </form> | ||
| --> | ||
| {{> afQuickField name='matching'}} | ||
| <h4>Global Request Settings</h4> | ||
| {{> afQuickField name='append_query_string'}} | ||
| {{> afQuickField name='set_headers'}} | ||
| {{> afQuickField name='http_basic_auth'}} | ||
| {{> afQuickField name='require_https' options="allowed"}} | ||
| {{> afQuickField name='api_key_verification_level' options="allowed"}} | ||
| {{> afQuickField name='required_roles' options="allowed"}} | ||
| <h5>Pass API Key to Backend (deprecated)</h5> | ||
| {{> afQuickField name='pass_api_key_header'}} | ||
| {{> afQuickField name='pass_api_key_query_param'}} | ||
| {{> afQuickField name='rate_limit_mode' options="allowed"}} | ||
| {{/autoForm}} | ||
| </div> | ||
| </div> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,269 @@ | ||
| ApiBackends = new Mongo.Collection('apiBackends'); | ||
|
|
||
| ApiBackendsSchema = new SimpleSchema({ | ||
| id: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| name: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| sort_order: { | ||
| type: Number, | ||
| optional: true | ||
| }, | ||
| backend_protocol: { | ||
| type: String, | ||
| optional: true, | ||
| allowedValues: [ | ||
| 'http', | ||
| 'https' | ||
| ], | ||
| label: 'Backend protocol' | ||
| }, | ||
| backend_host: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| backend_port: { | ||
| type: Number, | ||
| optional: true | ||
| }, | ||
| frontend_host: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| balance_algorithm: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any pre-defined strings for the balance algorithm? E.g. 'round-robin'. |
||
| type: String, | ||
| optional: true | ||
| }, | ||
| server: { | ||
| type: [Object], | ||
| optional: true, | ||
| label: 'Host' | ||
| }, | ||
| "server.$.backend_host": { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| "server.$.backend_port": { | ||
| type: String, | ||
| optional: true, | ||
| regEx: /^[0-9]{2,5}$/ | ||
| }, | ||
| matching: { | ||
| type: [Object], | ||
| optional: true, | ||
| }, | ||
| "matching.$.frontend_prefix": { | ||
| label: 'Frontend Prefix', | ||
| optional: true, | ||
| type: String | ||
| }, | ||
| "matching.$.backend_prefix": { | ||
| label: 'Backend Prefix', | ||
| optional: true, | ||
| type: String, | ||
| regEx: /^[a-z0-9A-Z_]{3,15}$/ | ||
| }, | ||
| duration: { | ||
| type: Number, | ||
| optional: true, | ||
| label: 'Duration' | ||
| }, | ||
| accuracy:{ | ||
| type: Number, | ||
| optional: true | ||
| }, | ||
| limit_by: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| limit: { | ||
| type: Number, | ||
| optional: true | ||
| }, | ||
| distributed: { | ||
| type: Boolean, | ||
| optional: true | ||
| }, | ||
| response_headers: { | ||
| type: Boolean, | ||
| optional: true | ||
| }, | ||
| matcher_type: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| http_method: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label may be needed here, as HTTP is all uppercase. |
||
| type: String, | ||
| optional: true | ||
| }, | ||
| frontend_matcher: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| backend_replacement: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| matcher: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| http_method: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label may be needed here, as HTTP is all uppercase. |
||
| type: String, | ||
| optional: true | ||
| }, | ||
| from: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| to: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| set_headers: { | ||
| type: String, | ||
| optional: true, | ||
| min: 20, | ||
| max: 1000, | ||
| autoform: { | ||
| rows: 2 | ||
| }, | ||
| label: 'Set Headers' | ||
| }, | ||
| append_query_string: { | ||
| type: String, | ||
| optional: true, | ||
| label: 'Append Query String Parameters' | ||
| }, | ||
| http_basic_auth: { | ||
| type: String, | ||
| optional: true, | ||
| label: 'HTTP Basic Authentication' | ||
| }, | ||
| require_https: { | ||
| type: String, | ||
| optional: true, | ||
| allowedValues: [ | ||
| 'Inherit (default - optional)', | ||
| 'Optional - HTTPS is optional', | ||
| 'Required - HTTPS is mandatory' | ||
| ], | ||
| label: 'HTTPS Requirements' | ||
| }, | ||
| require_https_transition_start_at: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label may be needed here, as HTTPS is all uppercase. |
||
| type: Date, | ||
| optional: true | ||
| }, | ||
| disable_api_key: { | ||
| type: Boolean, | ||
| optional: true | ||
| }, | ||
| api_key_verification_level: { | ||
| type: String, | ||
| optional: true, | ||
| allowedValues: [ | ||
| 'Inherit (default - required)', | ||
| 'Required - API keys are mandatory', | ||
| 'Disabled - API keys are optional' | ||
| ], | ||
| label: 'API Key Checks' | ||
| }, | ||
| api_key_verification_transition_start_at: { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Label needed. |
||
| type: Date, | ||
| optional: true | ||
| }, | ||
| required_roles: { | ||
| type: Array, | ||
| minCount: 1, | ||
| maxCount: 3, | ||
| optional: true, | ||
| label: 'Required Roles', | ||
| autoform: { | ||
| options: [ | ||
| { | ||
| label: 'api-umbrella-contact-form', | ||
| value: 'api-umbrella-contact-form' | ||
| }, | ||
| { | ||
| label: 'api-umbrella-key-creator', | ||
| value: 'api-umbrella-key-creator' | ||
| }, | ||
| { | ||
| label: 'write_access', | ||
| value: 'write_access' | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "required_roles.$": { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| rate_limit_mode: { | ||
| type: String, | ||
| optional: true, | ||
| allowedValues: [ | ||
| 'Default rate limits', | ||
| 'Custom rate limits', | ||
| 'Unlimited requests' | ||
| ], | ||
| label: 'Rate limit' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent capitalization of first letters. Choose a method for the schema and use it consistently. |
||
| }, | ||
| anonymous_rate_limit_behavior: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| authenticated_rate_limit_behavior: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| pass_api_key_header: { | ||
| type: Boolean, | ||
| optional: true, | ||
| defaultValue: false, | ||
| label: 'Via HTTP header' | ||
| }, | ||
| pass_api_key_query_param: { | ||
| type: Boolean, | ||
| optional: true, | ||
| defaultValue: false, | ||
| label: 'Via GET query parameter' | ||
| }, | ||
| error_templates: { | ||
| // type: [Object] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup needed. |
||
| type: String, | ||
| optional: true | ||
| }, | ||
| error_data: { | ||
| // type: [Object] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleanup. |
||
| type: String, | ||
| optional: true | ||
| }, | ||
| created_at: { | ||
| type: Date, | ||
| optional: true | ||
| }, | ||
| created_by: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| updated_at: { | ||
| type: Date, | ||
| optional: true | ||
| }, | ||
| updated_by: { | ||
| type: String, | ||
| optional: true | ||
| }, | ||
| version: { | ||
| type: Number, | ||
| optional: true | ||
| } | ||
| }); | ||
|
|
||
| ApiBackends.attachSchema(ApiBackendsSchema); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| Meteor.methods({ | ||
| "syncApiBackends":function () { | ||
| // Check if API Umbrella settings are available | ||
| if (Meteor.settings.api_umbrella) { | ||
| // Get API Backends from API Umbrella instance | ||
| var response = apiUmbrellaWeb.adminApi.v1.apiBackends.getApiBackends(); | ||
| var apiBackends = response.data.data; | ||
|
|
||
| _.each(apiBackends, function (item) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider renaming 'item' to 'backend' in order to be more explicit. |
||
| // Get existing API Backend | ||
| var existingApiBackend = ApiBackends.findOne({'id': item.id}); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If using 'backend' instead of 'item', replace 'item.id' with 'backend.id'. This will improve readability. |
||
|
|
||
| // If API Backend doesn't exist in collection, insert into collection | ||
| if (! existingApiBackend ) { | ||
| ApiBackends.insert(item); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If using 'backend' instead of 'item', replace 'item' with 'backend' here. |
||
| }; | ||
| }); | ||
| }; | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Meteor.publish('apiBackends', function () { | ||
| return ApiBackends.find(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will need to reconsider these subscriptions, as they publish all data to all clients.