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/mqtt topic namespacing for emq #2887

Closed
wants to merge 12 commits into from

Conversation

saransh-dev
Copy link
Contributor

Fixed issue #2842

closes: #2842

Copy link
Member

@phanimahesh phanimahesh left a comment

Choose a reason for hiding this comment

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

I haven't tested this yet, these are comments from just looking at the diff.

.disabled-div{
pointer-events: none;
opacity: 0.4;
}
Copy link
Member

Choose a reason for hiding this comment

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

Consistent indentation please. And configure your editor to end files with newlines.

@@ -125,7 +126,7 @@ Meteor.methods({
id: rule.id,
allow: rule.allow,
access: rule.access,
topic: rule.topic,
topic: topicPrefix + rule.topic,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is a good idea. an enterprising user can make a request with invalid or someone else's topic prefix.

Please add a verification to ensure this is the same as saved topic prefix for this api, or even better, do not accept topic prefix as argument here. I'm asuming it would be possible to extract saved topic prefix from mongo directly on server and prepend it there.

Client side data should never be trusted blindly. Client uses topic prefix to display to users, and server should extract topic prefix from db and use it for its operations instead of trusting data that was through the client.

@@ -153,7 +154,7 @@ Meteor.methods({
proxyId: rule.proxyId,
allow: rule.allow,
access: rule.access,
topic: rule.topic,
topic: topicPrefix + rule.topic,
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

@@ -11,3 +11,5 @@ https://joinup.ec.europa.eu/community/eupl/og_page/european-union-public-licence
export const proxyBasePathRegEx = new RegExp(/^\/[\w\-\.\?\$\*\+\'\)\(/:#@!&,;=]+\/$/);
// eslint-disable-next-line no-useless-escape
export const apiBasePathRegEx = new RegExp(/^\/[\w\-\?\.\$\*\+\)\'\(/:#@!&,;=]*$/);
// allow only a-zA-Z0-9_ # +
export const topicPrefix = new RegExp(/^\/[\w+#]+\/$/);
Copy link
Member

Choose a reason for hiding this comment

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

+ and # are special in mqtt topics. Both characters must not be allowed in topic prefix.

Topic prefix regex should be /^\/[\w-]+\/$/

Topics, on the other hand, should probably be /^\/[\w-]+\/(([\w-]+|\+)\/)*([\w-]+|\+|#)$/
To explain, topics must start with a /, have atleast one "word" (topic prefix), followed by a /, and can be followed by:

  • an arbitrarily long string of words or + delimited by /
  • optionally ending in a #

The last character of a topic can not be /. The regex is a bit unwieldy, but I can not compress it further.

Copy link
Member

Choose a reason for hiding this comment

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

BTW the topic regex is for use after prepending the prefix. Without the prefix, it will reduce to /^(([\w-]+|\+)\/)*([\w-]+|\+|#)$/

@@ -28,6 +28,7 @@
"invalidDomainMessage": "Tarvitaan validi verkkotunnus",
"invalidEmailMessage": "Tarvitaan validi s\u00e4hk\u00f6postiosoite",
"invalidApiBasePathMessage": "T\u00e4ytyy alkaa kauttaviivalla ja p\u00e4\u00e4tty\u00e4 kauttaviivaan. Sallittuja merkkej\u00e4 ovat kirjaimet, numerot sek\u00e4 -.?$*+'()\/:#@!&,;=",
"invalidTopicPrefix": "On aloitettava ja päättyttävä /. Sallitut aakkosnumeeriset merkit ja + #",
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete Finnish text

@@ -1060,6 +1061,7 @@
"proxyBackendForm_apiPort_helpText": "Rajapintapalvelimen portin numero",
"proxyBackendForm_disableApiKey_helpText": "Salli k\u00e4ytt\u00e4jien kutsua rajapintaa ilman rajapinta-avainta.",
"proxyBackendForm_proxyBasePath_helpText": "Peruspolku jokaiseen v\u00e4lityspalvelinkutsuun. Esimerkiksi:",
"proxyBackendForm_topicPrefix_helpText": "Aiheen etuliite lisätään ennen kaikkia EMQ-aiheita.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Delete Finnish text

<!-- Rate limits -->
<div class="panel panel-default">
<div class="panel panel-default {{# unless proxyBackend.emq.settings.topicPrefix }} disabled-div {{/ unless}}">
Copy link
Contributor

Choose a reason for hiding this comment

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

Wrap part {{# unless proxyBackend.emq.settings.topicPrefix }} disabled-div {{/ unless}} in helper.
Read: http://blazejs.org/guide/spacebars.html#Attribute-Helpers

@@ -3,8 +3,35 @@
<!-- Hidden fields -->
{{> afQuickField name="type" type="hidden" value="emq" }}
<!-- End hidden fields -->

<!-- Topic prefix -->
{{#unless proxyBackend.emq.settings.topicPrefix}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add spacebar between # and word
Add spacebar before }}

</label>

{{> afFieldInput
name="emq.settings.topicPrefix"
Copy link
Contributor

Choose a reason for hiding this comment

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

Place it in one line


<!-- validation messages -->
{{# if afFieldIsInvalid name='emq.settings.topicPrefix' }}
<p class="text-danger">
Copy link
Contributor

Choose a reason for hiding this comment

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

<p> block must be nested

@marla-singer
Copy link
Contributor

@amardeep-deligence Don't generate one-type commits.

 Fixed git platform build errors 
 Fixed git platform build errors 
 Fixed git platform build errors Third Time 
 Fixed git platform build errors - Fourth attempt

These commits are unuseful, squash them
https://github.com/apinf/platform/blob/develop/CONTRIBUTING.md#git-rebase

@phanimahesh
Copy link
Member

phanimahesh commented Sep 7, 2017 via email

@marla-singer
Copy link
Contributor

@phanimahesh Did you test the functional work of this code?

Copy link
Member

@phanimahesh phanimahesh left a comment

Choose a reason for hiding this comment

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

Never merge into a feature branch. As it stands this branch can not be reviewed. Commits are present multiple times and changes in a commit don't appear in overall diff, even when I did not notice any later commit reverting them. Please do a proper rebase and push force with lease, compressing this into no more than 2-3 logical commits.

Also:

  • ACL rules must fit in a single line on desktop screens
  • Deleting all ACLs is a single accidental click away. Add a confirmation or undo option.

@@ -53,7 +53,7 @@ Meteor.methods({
if (err) reject(err);

// Expose only username and ID
const users = _.map(res.data, (user) => {
const users = _.map(res?res.data:[], (user) => {
Copy link
Member

Choose a reason for hiding this comment

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

Ideally this single line should be commit of its own.

@@ -130,7 +142,7 @@ Meteor.methods({
};
// Append ACL type & value
data[rule.fromType] = rule.fromValue;

return
Copy link
Member

Choose a reason for hiding this comment

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

?

@@ -158,7 +170,7 @@ Meteor.methods({
};
// Append ACL type & value
data[rule.fromType] = rule.fromValue;

return
Copy link
Member

Choose a reason for hiding this comment

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

?

// allow / then a-zA-Z0-9 then /
export const topicPrefixRegEx = new RegExp(/^\/[\w-]+\/$/);
// Must begin with alphanumeric. Allowed character is / and end with + or # delimited by /
export const topicRegEx = new RegExp(/^(([\w-]+|\+)\/)*([\w-]+|\+|#)$/);
Copy link
Member

Choose a reason for hiding this comment

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

This comment is incorrect. This should make it clear:

Topic is a string of segments joined by /. A segment is either:

  • a string of letters, numbers or literals - or _
  • Or just the literal +

In addition, the last segment can be a literal #.

{ 'emq.settings.acl.id': { $in: [rules && rules.length ? rules[0].id : ''] } },
{ fields: { 'emq.settings.topicPrefix': 1 } });
// set topicPrefix if available in db
if (emqProxyBackend && emqProxyBackend.emq.settings.topicPrefix) {
Copy link
Member

Choose a reason for hiding this comment

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

What happens if it is not available? User gets to set rules on arbitrary topics because enforced prefix will be ''? (see line 106)

Fixed git platform build errors

Fixed git platform build errors

Fixed git platform build errors Third Time
@bajiat
Copy link
Contributor

bajiat commented Sep 14, 2017

@marla-singer Can you review the code?

@phanimahesh Can you check that the PR fulfills the requirements for the enhancement issue?

@amardeep-deligence
Copy link
Contributor

@phanimahesh "Deleting all ACLs is a single accidental click away. Add a confirmation or undo option." is not done yet. Other features are ready to test.

@bajiat
Copy link
Contributor

bajiat commented Sep 19, 2017

@phanimahesh Can you create a separate issue for "Deleting all ACLs is a single accidental click away. Add a confirmation or undo option." ? Describe why it is needed in the issue and what needs to be done.

@amardeep-deligence
Copy link
Contributor

amardeep-deligence commented Sep 19, 2017

@bajiat @phanimahesh , I have implemented "confirmation before deleting ACLs" in this PR already

@amardeep-deligence
Copy link
Contributor

This PR may also close Issue- #2724

@bajiat
Copy link
Contributor

bajiat commented Sep 28, 2017

@amardeep-deligence and @phanimahesh What is the status of the PR? Have all the requested changes been made? If not, is there a reason?

@amardeep-deligence
Copy link
Contributor

@bajiat @phanimahesh @marla-singer @brylie this PR is ready for review.

@bajiat
Copy link
Contributor

bajiat commented Oct 17, 2017

@phanimahesh and @marla-singer What is the status of this PR? The PR was started 1,5 months ago. Are there pending changes or is the review for changes missing? Can this still be rebased or should it be started from scratch by cherrypicking the actual changes? I would like to have a resolution (decision on what is to be done) by 16:00 EEST today.

@marla-singer
Copy link
Contributor

@preriasusi What to do with this PR?

@phanimahesh
Copy link
Member

@marla-singer We are effectively reimplementing this entire view in the new dashboard you are working on, after considering more feedback. This can be closed for now, or after we have absorbed the relevant parts into the new dashboard.

@55 55 closed this Apr 23, 2018
@ghost ghost removed the Ready for review label Apr 23, 2018
@preriasusi preriasusi deleted the feature/mqtt-topic-namespacing-for-emq branch August 29, 2018 08:00
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.

MQTT topic namespacing for EMQ
7 participants