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

Proxy42 integration to Platform #3740

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apinf_packages/apis/client/profile/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Counts } from 'meteor/tmeasday:publish-counts';

Template.apiSettings.helpers({
proxyIsConfigured () {
// Get count of Proxies
// Get count of Proxies (apinfUmbrella and proxy42)
const proxyCount = Counts.get('proxyCount');

// Check that a proxy is defined
Expand Down
4 changes: 2 additions & 2 deletions apinf_packages/apis/client/profile/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ Template.viewApi.onCreated(function () {

templateInstance.api = new ReactiveVar();

// Subscribe to public proxy details
// Subscribe to public proxy details: apinfUmbrella and proxy42
templateInstance.subscribe('proxyCount');
// Subscribe to public proxy details (particular type)
templateInstance.subscribe('publicProxyDetails', 'apiUmbrella');
templateInstance.subscribe('publicProxyDetails');
// Subscribe to Settings "supportsGraphql"
templateInstance.subscribe('singleSetting', 'supportsGraphql');
// Subscribe to development Features settings
Expand Down
9 changes: 5 additions & 4 deletions apinf_packages/core/lib/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,10 @@
"proxies_addProxy": "Add proxy",
"proxies_noProxiesFound": "No proxies found.",
"proxiesPage_title_proxies": "Proxies",
"proxy42BackendForm_proxyBasePath_title": "Proxy host URL, with ",
"proxy42BackendForm_proxyBasepath_label": "Proxy Base path",
"proxy42BackendForm_apiBasepath_label": "API Base path",
"proxy42BackendForm_apiPort_label": "API port",
"proxyBackendForm_advancedSettings_title": "Advanced settings",
"proxyBackendForm_apiBasePath_helpText": "Actual address of your API. Proxy request is mapped to this, endpoint from it is conveyed here.",
"proxyBackendForm_apiBasePath_helpText_example": "/my_api/v1/",
Expand Down Expand Up @@ -750,7 +754,6 @@
"proxyBackendForm_emqProxyForm_removeEmqUser_confirmButton": "Yes, remove",
"proxyBackendForm_emqProxyForm_removeEmqUser_cancelButton": "Cancel",
"proxyBackendForm_emqProxyForm_removeEmqUser_successMessage": "EMQ user successfully removed!",
"proxyBackendForm_IDPappID_additional_helpText": "IDP app id is an IDentity Provider application ID. This is needed for FIWARE component integration. So, if you have no idea what this means, leave it alone.",
"proxyBackendForm_IDPappID_helpText": "Identification of IDP application.",
"proxyBackendForm_proxyBasePath_title": "Proxy host URL, with ",
"proxyBackendForm_proxyBasePath_helpText": "API users send requests to this address (when completed with endpoint).",
Expand All @@ -760,8 +763,8 @@
"proxyBackendForm_redirect_helpText": "Redirect:",
"proxyBackendForm_request_header_helpText": "Headers to be added by Proxy into requests.",
"proxyBackendForm_request_helpText": "Request",
"proxyBackendForm_response_helpText": "Response",
"proxyBackendForm_requiredErrorMessage": "Please fill in the required fields",
"proxyBackendForm_response_helpText": "Response",
"proxyBackendForm_subsettings_additional_helpText_1": "'Sub settings' refer to sub URL settings. These are related to FIWARE integration, but they can be useful in some scenarios. If you want to restrict traffic based on HTTP verbs, require that some headers are present, these settings are your friends.",
"proxyBackendForm_subsettings_additional_helpText_2": "HTTP Methods: Here you can select the sub-URL, i.e. method, which settings altered are altered.",
"proxyBackendForm_subsettings_additional_helpText_3": "Regex: With this parameter you can filter the content of requests.",
Expand All @@ -773,8 +776,6 @@
"proxyBackendForm_deleteButton": "Reset Configuration",
"proxyBackendForm_deleteErrorMessage": "Delete failed on API Umbrella proxy",
"proxyBackendForm_frontendPrefixNotUnique": "Frontend prefix already exists. Select another one.",
"proxyBackendForm_publishErrorMessage": "Publish failed on API Umbrella proxy",
"proxyBackendForm_requiredErrorMessage": "Please fill in the required fields",
"proxyBackendForm_deleteSuccessMessage": "Successfully deleted proxy settings",
"proxyBackendForm_publish_failureMessage": "Failure on publishing apiUmbrella: ",
"proxyBackendForm_update_failureMessage": "Failure on proxy backend on apiUmbrella: ",
Expand Down
1 change: 1 addition & 0 deletions apinf_packages/proxies/client/form/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import _ from 'lodash';
const requiredFieldsForProxy = {
emqtt: ['proxyUrl', 'apiUrl', 'adminUsername', 'adminPassword', 'elasticsearch'],
apiUmbrella: ['url', 'apiKey', 'authToken', 'elasticsearch'],
proxy42: ['url'],
};

export default function validateSchema (proxyType, proxyFields) {
Expand Down
2 changes: 1 addition & 1 deletion apinf_packages/proxies/collection/registered_proxies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ This file is covered by the EUPL license.
You may obtain a copy of the licence at
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

export default ['apiUmbrella', 'emq'];
export default ['apiUmbrella', 'emq', 'proxy42'];
18 changes: 18 additions & 0 deletions apinf_packages/proxies/collection/schemas/proxy_42.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Copyright 2019 Apinf Oy
This file is covered by the EUPL license.
You may obtain a copy of the licence at
https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence-eupl-v11 */

// Meteor packages imports
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

export default {
proxy42: {
type: Object,
optional: true,
},
'proxy42.url': {
type: String,
regEx: SimpleSchema.RegEx.Url,
},
};
12 changes: 6 additions & 6 deletions apinf_packages/proxies/collection/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,28 @@ Meteor.publish('allProxies', function () {
if (Roles.userIsInRole(this.userId, ['admin'])) {
proxies = Proxies.find();
}

return proxies;
});

Meteor.publish('proxyCount', function () {
// Publish count of proxies
Counts.publish(this, 'proxyCount', Proxies.find({ type: 'apiUmbrella' }));
// Publish count of proxies (apinfUmbrella and proxy42)
Counts.publish(this, 'proxyCount', Proxies.find({ type: { $in: ['apiUmbrella', 'proxy42'] } }));
});

Meteor.publish('emqProxyCount', function () {
// Publish count of proxies
Counts.publish(this, 'emqProxyCount', Proxies.find({ type: 'emq' }));
});

Meteor.publish('publicProxyDetails', (type) => {
check(type, String);
Meteor.publish('publicProxyDetails', () => {
// Return all proxies with public data: name, url, type
return Proxies.find({ type }, {
return Proxies.find({ }, {
fields: {
_id: 1,
name: 1,
'apiUmbrella.url': 1,
emq: 1,
'proxy42.url': 1,
type: 1,
},
});
Expand Down
18 changes: 18 additions & 0 deletions apinf_packages/proxy_backends/client/form/autoform.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import requiredFieldsFilled from './required_fields';
AutoForm.hooks({
proxyBackendForm: {
formToModifier: (doc) => {
console.log('form-to-modifier');
if (doc.$set['apiUmbrella.sub_settings']) {
doc.$set['apiUmbrella.sub_settings'] = _.compact(doc.$set['apiUmbrella.sub_settings']);
}
Expand All @@ -45,11 +46,13 @@ AutoForm.hooks({
},
before: {
insert (proxyBackend) {
console.log('inserttiä puskee=');
// TODO: Refactor this method. It is too long and complex

// Get reference to autoform instance, for form submission callback
const form = this;

console.log('form=', form);
// Empty fields case, check doc exists & has apiUmbrella object
if (proxyBackend.type === 'apiUmbrella') {
// Make sure all required fields are filled
Expand Down Expand Up @@ -127,13 +130,27 @@ AutoForm.hooks({
aclRule.proxyId = proxyBackend.proxyId;
});

// Save proxy backend
form.result(proxyBackend);
} else if (proxyBackend.type === 'proxy42') {
console.log('proxy 42=', proxyBackend);
console.log('proxy 42 apiU=', proxyBackend.apiUmbrella);
console.log('proxy 42 sett=', proxyBackend.apiUmbrella.settings);
//console.log('proxy 42 apiumb=', proxyBackend.settings.apiUmbrella);

const settings = {
rate_limit_mode: 'unlimited',
};
proxyBackend.apiUmbrella.settings = settings;
console.log('proxy 42 talteen=', proxyBackend);
// Save proxy backend
form.result(proxyBackend);
}
// Autoform does not expect anything to be returned
return undefined;
},
update (updateDoc) {
console.log('updatea tehtään');
// TODO: Refactor this method. It is too long and complex

// Get reference to autoform instance, for form submission callback
Expand Down Expand Up @@ -349,6 +366,7 @@ AutoForm.hooks({
}
},
onError (formType, error) {
console.log('erreys sattui');
sAlert.error(error.message, { timeout: 'none' });
},
},
Expand Down
6 changes: 5 additions & 1 deletion apinf_packages/proxy_backends/client/form/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<!-- visible fields -->
<!-- Selector for proxy list if proxies are more one otherwise hidden field -->

{{# if oneProxy }}
{{> afQuickField name="proxyId" value=proxy._id type="hidden" }}
{{ else }}
Expand All @@ -31,6 +30,11 @@
{{> apiUmbrellaProxyForm proxy=proxy proxyHost=proxyHost api=api }}
{{/ if }}

<!-- Proxy 42 -->
{{# if equals proxy.type "proxy42" }}
{{> proxy42ProxyForm proxy=proxy proxyHost=proxyHost api=api }}
{{/ if }}

<!-- EMQ -->
{{# if equals proxy.type "emq" }}
{{> emqProxyForm }}
Expand Down
1 change: 0 additions & 1 deletion apinf_packages/proxy_backends/client/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ Template.proxyBackend.onCreated(() => {
} else {
// Get all proxies ordered by name
const proxies = Proxies.find({}, { sort: { name: 1 } }).fetch();

// Set current proxy ID as the first item of the proxies list
currentProxyId = proxies[0]._id;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<template name="proxy42ProxyForm">

<!-- TODO
- validation:
- regex for basepaths
- > 0 for port
-->

<!-- hidden fields, auto-value -->
{{> afQuickField name="type" type="hidden" value="proxy42" }}

<div class="api-settings">
<div class="form-group col-md-4" data-required="true" style="padding-left: 0 !important;">
<!-- Proxy base path (frontend prefix) -->
{{_ "proxy42BackendForm_proxyBasePath_title" }}
<label for="proxy-base-path-field" style="padding-left: 3px">
{{_ "proxy42BackendForm_proxyBasepath_label" }}
</label>

<div class="input-group">
<span class="input-group-addon" id="proxy-url" >
{{ proxy.proxy42.url }}
</span>

<input type="text"
id="proxy-base-path-field"
name="front_prefix"
class="form-control"
required
value={{ proxyBackend.frontPrefix }}
pattern={{ proxyPrefixPattern }}
>
</div>

<!-- validation messages -->
{{# if isProxyBasePathInvalid }}
<p class="text-danger">
{{{ afFieldMessage name='apiUmbrella.url_matches.0.frontend_prefix' }}}
</p>
{{/ if }}

<!-- help text -->
<p class="help-block">
{{_ "proxyBackendForm_proxyBasePath_helpText" }}&nbsp;<b>{{_ "general_example" }}</b><br />
{{ proxy.apiUmbrella.url }}<b>{{_ "proxyBackendForm_proxyBasePath_helpText_example" }}</b>{{_ "proxyBackendForm_apiBasePath_helpText_continued" }}
</p>
</div>

<!-- symbol for redirection -->
<div class="col-md-2" style="text-align: center;">
<!-- {{_ "proxyBackendForm_redirect_helpText" }} <br /> -->
<br />
<span style="font-weight: bold;">{{_ "proxyBackendForm_request_helpText" }}</span>
<span class="glyphicon glyphicon-arrow-right"></span><br />
<span class="glyphicon glyphicon-arrow-left"></span>
<span style="font-weight: bold;">{{_ "proxyBackendForm_response_helpText" }}</span>
</div>

<!-- API base path (backend prefix) -->
<div class="row">
<div class="form-group col-md-4" data-required="true" style="margin-bottom: 0;">

{{_ "proxyBackendForm_apiBasePath_title" }}
<label for="api-base-path-field" style="padding-left: 3px">
{{_ "proxy42BackendForm_apiBasepath_label" }}
</label>

<div class="input-group">
<!-- API url addon -->
<span class="input-group-addon" id="api-url">
{{ api.url }}
</span>

<input type="text"
id="api-base-path-field"
name="front_prefix"
class="form-control"
required
value={{ proxyBackend.backendPrefix }}
pattern={{ apiPrefixPattern }}
>
</div>

<!-- validation messages -->
{{# if afFieldIsInvalid name='apiUmbrella.url_matches.0.backend_prefix' }}
<p class="text-danger">
{{{ afFieldMessage name='apiUmbrella.url_matches.0.backend_prefix' }}}
</p>
{{/ if }}

<!-- help text -->
<p class="help-block">
{{_ "proxyBackendForm_apiBasePath_helpText" }}&nbsp;<b>{{_ "general_example" }}</b><br />
{{ api.url }}<b>{{_ "proxyBackendForm_apiBasePath_helpText_example" }}</b>{{_ "proxyBackendForm_apiBasePath_helpText_continued" }}
</p>
</div>

<!-- API port (servers.port) -->
<div class="form-group col-md-2" data-required="true">
<label for="api-port-field" id="api-port-field-label">
{{_ "proxy42BackendForm_apiPort_label" }}
</label>

<input type="text"
id="api-port-field"
name="api-port-field-label"
class="form-control"
required
value={{ proxyBackend.apiPort }}
>

<!-- validation messages -->
{{# if afFieldIsInvalid name="apiUmbrella.servers.0.port" }}
<p class="text-danger">
{{{ afFieldMessage name="apiUmbrella.servers.0.port" }}}
</p>
{{/ if }}

<!-- help text -->
<p class="help-block">
{{_ "proxyBackendForm_apiPort_helpText" }}
</p>
</div>
</div>

<hr style="color: rgba(59, 59, 88, 0.15);margin-right: -20px;margin-left: -20px;margin-bottom: 1em;margin-top: 0.5em;">
</div>
</template>
Loading