Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
vernemq
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
stack
vernemq
Commits
69c2caad
Commit
69c2caad
authored
Oct 11, 2018
by
Chavee Issariyapat
Browse files
Options
Browse Files
Download
Plain Diff
merge from master
parents
7ac5ed06
a6ab5fd5
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
32 additions
and
38 deletions
+32
-38
authhook/.gitignore
+1
-0
authhook/auth_on_publish.js
+2
-9
authhook/auth_on_subscribe.js
+1
-1
authhook/config/custom-environment-variables.json
+11
-4
authhook/index.js
+8
-8
authhook/on_deliver.js
+1
-2
authhook/on_unsubscribe.js
+3
-4
authhook/test/getTopicTest.js
+2
-3
authhook/utils/router.js
+3
-7
No files found.
authhook/.gitignore
View file @
69c2caad
.DS_Store
node_modules/
config/*.json
authhook/auth_on_publish.js
View file @
69c2caad
...
...
@@ -6,11 +6,6 @@ var LRU = require("lru-cache"),
maxAge
:
1000
*
60
*
5
});
// for testing
// function authCheck(client_id, username, topic, callback) {
// callback(true);
// }
module
.
exports
=
function
(
options
=
{})
{
return
function
(
req
,
res
,
next
)
{
...
...
@@ -43,8 +38,7 @@ module.exports = function (options = {}) {
var
output
=
{};
GGID
.
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
function
(
group
)
{
var
_ftopic
=
require
(
'./utils/getTopic'
).
rewriteTopic
(
topic
,
'pub'
,
group
,
req
.
body
.
client_id
,
output
);
// get topic where concat with groupID
var
_ftopic
=
require
(
'./utils/router'
).
rewriteTopic
(
topic
,
'pub'
,
group
,
req
.
body
.
client_id
,
output
);
// get topic where concat with groupID
response
=
{
'result'
:
'ok'
,
'modifiers'
:
{
...
...
@@ -72,4 +66,4 @@ module.exports = function (options = {}) {
next
();
}
}
}
\ No newline at end of file
}
authhook/auth_on_subscribe.js
View file @
69c2caad
...
...
@@ -38,7 +38,7 @@ module.exports = function (options = {}) {
GGID
.
getGroupID
(
req
.
body
.
username
,
req
.
body
.
client_id
,
function
(
group
)
{
console
.
log
(
group
);
var
_ftopic
=
require
(
'./utils/
getTopic
'
).
rewriteTopic
(
topic
,
'sub'
,
group
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_ftopic
=
require
(
'./utils/
router
'
).
rewriteTopic
(
topic
,
'sub'
,
group
,
req
.
body
.
client_id
)
// get topic where concat with groupID
var
_topic
=
[{
// setTopic for response
'topic'
:
_ftopic
,
'qos'
:
0
...
...
authhook/config/custom-environment-variables.json
View file @
69c2caad
{
"authserv_host"
:
"AUTH_SERVICE_HOST"
,
"authserv_port"
:
"AUTH_SERVICE_PORT"
,
"authserv_host"
:
"AUTH_SERVICE_HOST"
,
"authserv_port"
:
"AUTH_SERVICE_PORT"
,
"device_registry_host"
:
"DEVICE_REGISTRY_HOST"
,
"device_registry_port"
:
"DEVICE_REGISTRY_PORT"
"device_registry_host"
:
"DEVICE_REGISTRY_HOST"
,
"device_registry_port"
:
"DEVICE_REGISTRY_PORT"
,
"auth_on_register_debug"
:
"AUTH_ON_REGISTER_DEBUG"
,
"auth_on_publish_debug"
:
"AUTH_ON_PUBLISH_DEBUG"
,
"auth_on_subscribe_debug"
:
"AUTH_ON_SUBSCRIBE_DEBUG"
,
"on_publish_debug"
:
"ON_PUBLISH_DEBUG"
,
"on_deliver_debug"
:
"ON_DELIVER_DEBUG"
,
"on_unsubscribe_debug"
:
"ON_UNSUBSCRIBE_DEBUG"
}
authhook/index.js
View file @
69c2caad
process
.
env
[
"NODE_ENV"
]
=
"development"
;
process
.
env
[
"NODE_CONFIG_DIR"
]
=
__dirname
+
"/config/"
;
var
auth_on_register_debug
=
process
.
env
[
"AUTH_ON_REGISTER_DEBUG"
]
||
false
;
var
auth_on_publish_debug
=
process
.
env
[
"AUTH_ON_PUBLISH_DEBUG"
]
||
true
;
var
auth_on_subscribe_debug
=
process
.
env
[
"AUTH_ON_SUBSCRIBE_DEBUG"
]
||
true
;
var
on_publish_debug
=
process
.
env
[
"ON_PUBLISH_DEBUG"
]
||
true
;
var
on_deliver_debug
=
process
.
env
[
"ON_DELIVER_DEBUG"
]
||
true
;
var
on_unsubscribe_debug
=
process
.
env
[
"ON_UNSUBSCRIBE_DEBUG"
]
||
true
;
var
config
=
require
(
'config'
);
var
auth_on_register_debug
=
config
.
get
(
'auth_on_register_debug'
);
var
auth_on_publish_debug
=
config
.
get
(
'auth_on_publish_debug'
);
var
auth_on_subscribe_debug
=
config
.
get
(
'auth_on_subscribe_debug'
);
var
on_publish_debug
=
config
.
get
(
'on_publish_debug'
);
var
on_deliver_debug
=
config
.
get
(
'on_deliver_debug'
);
var
on_unsubscribe_debug
=
config
.
get
(
'on_unsubscribe_debug'
);
var
restify
=
require
(
'restify'
);
var
auth_on_register
=
require
(
'./auth_on_register'
)({
debug
:
auth_on_register_debug
});
...
...
authhook/on_deliver.js
View file @
69c2caad
...
...
@@ -21,4 +21,4 @@ module.exports = function(options = {}) {
var
topic
=
topics
.
split
(
'/!'
)[
1
]
return
topics
.
split
(
'/!'
)[
0
]
+
topic
.
substring
(
topic
.
indexOf
(
'/'
),
topic
.
length
)
}
}
\ No newline at end of file
}
authhook/on_unsubscribe.js
View file @
69c2caad
...
...
@@ -18,10 +18,10 @@ module.exports = function(options = {}) {
}
else
{
var
GGID
=
require
(
'./utils/getGroupID'
);
GGID
.
getGroupID
(
token
,
client_id
,
function
(
group
)
{
if
(
group
)
{
var
_ftopic
=
require
(
'./utils/
getTopic
'
).
rewriteTopic
(
topic
,
'unsub'
,
group
,
client_id
)
var
_ftopic
=
require
(
'./utils/
router
'
).
rewriteTopic
(
topic
,
'unsub'
,
group
,
client_id
)
response
=
{
"result"
:
"ok"
,
"topics"
:
[
_ftopic
]
...
...
@@ -39,4 +39,4 @@ module.exports = function(options = {}) {
});
}
}
}
\ No newline at end of file
}
authhook/test/getTopicTest.js
View file @
69c2caad
var
assert
=
require
(
'assert'
)
var
getTopic
=
require
(
'../utils/
getTopic'
).
get
Topic
var
getTopic
=
require
(
'../utils/
router'
).
rewrite
Topic
describe
(
'GetTopic'
,
()
=>
{
describe
(
'realtime msg'
,
()
=>
{
...
...
@@ -49,4 +49,4 @@ describe('GetTopic', () => {
})
})
})
})
\ No newline at end of file
})
authhook/utils/
getTopic
.js
→
authhook/utils/
router
.js
View file @
69c2caad
...
...
@@ -2,19 +2,16 @@ var modify = require('./modify');
function
rewriteTopic
(
topic
,
op
,
groupid
,
clientid
,
output
)
{
var
chunk
=
topic
.
split
(
'/'
);
console
.
log
(
groupid
);
switch
(
chunk
[
0
])
{
case
'@msg'
:
return
modify
.
insertWordIntoTopic
(
topic
,
'!'
+
groupid
,
1
);
case
'@shadow'
:
if
(
chunk
[
1
]
==
'
write'
||
chunk
[
1
]
==
'read
'
)
{
if
(
chunk
[
1
]
==
'
set'
||
chunk
[
1
]
==
'get
'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
''
+
clientid
,
2
);
}
else
if
(
chunk
[
1
]
==
'
set'
||
chunk
[
1
]
==
'get
'
)
{
else
if
(
chunk
[
1
]
==
'
write'
||
chunk
[
1
]
==
'read
'
)
{
output
.
verb
=
chunk
[
1
];
return
modify
.
insertWordIntoTopic
(
topic
,
groupid
,
2
);
}
...
...
@@ -44,4 +41,4 @@ console.log(groupid);
}
}
module
.
exports
.
rewriteTopic
=
rewriteTopic
\ No newline at end of file
module
.
exports
.
rewriteTopic
=
rewriteTopic
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment