Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rgzr committed Dec 26, 2017
2 parents 49c908d + 2292bce commit 2d913fc
Show file tree
Hide file tree
Showing 24 changed files with 997 additions and 108 deletions.
133 changes: 132 additions & 1 deletion API.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Versions

## 1.8.x
### Modified:
* `user.list` return value elements include a new field `createdAt` with a timestamp of user creation

### New:
* `user.rename`
* `*.count` methods
* `sync.list`
* `topic.list`
* `depth` and `filter` parameters for `*.list` methods

## 1.7.x
* `user.getEffectiveTags`

Expand Down Expand Up @@ -88,6 +99,7 @@
* [sys.login](#syslogin)
* [sys.node.list](#sysnodelist)
* [sys.session.list](#syssessionlist)
* [sys.session.count](#syssessioncount)
* [sys.session.kick](#syssessionkick)
* [sys.session.reload](#syssessionreload)
* [Pipes](#pipes)
Expand All @@ -98,6 +110,8 @@
* [Sync](#sync)
* [sync.lock](#synclock)
* [sync.unlock](#syncunlock)
* [sync.list](#synclist)
* [sync.count](#synccount)
* [Tasks](#tasks)
* [task.push](#taskpush)
* [task.pull](#taskpull)
Expand All @@ -106,14 +120,19 @@
* [task.reject](#taskreject)
* [task.cancel](#taskcancel)
* [task.list](#tasklist)
* [task.count](#taskccount)
* [Topics](#topics)
* [topic.sub](#topicsub)
* [topic.unsub](#topicunsub)
* [topic.pub](#topicpub)
* [topic.list](#topiclist)
* [topic.count](#topiccount)
* [Users](#users)
* [user.create](#usercreate)
* [user.delete](#userdelete)
* [user.rename](#userrename)
* [user.list](#userlist)
* [user.count](#usercount)
* [user.setTags](#usersettags)
* [user.delTags](#userdeltags)
* [user.getTags](#usergettags)
Expand Down Expand Up @@ -190,12 +209,28 @@ List the active sessions for an user prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Username prefix to list from
* `"depth": <Number>` - *Optional* - Filter the sessions listed to the passed depth relative to the passed prefix. Defaults to -1 (no filtering)
* `"filter": <String>` - *Optional* - Filter the sessions by user based on the passed RE2 regexp
* `"limit": <Number>` - *Optional* - Limit the number of results. Defaults to 100
* `"skip": <Number>` - *Optional* - Skips a number of results. Defaults to 0

### Result:
"result": [{"sessions":[{"creationTime":"2016-08-30T12:39:16.39Z","connid":"687c3b7baf4b9471","nodeid":"687c3b7b","protocol":"tcp","remoteAddress":"172.17.0.1:51398"},{"creationTime":"2016-08-30T12:39:21.283Z","id":"687c3b7b407bcce2","nodeid":"687c3b7b","protocol":"tcp","remoteAddress":"172.17.0.1:51402"}],"user":"root","n":2}, ...]

## sys.session.count
Count the active sessions for an user prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Username prefix to count from
* `"filter": <String>` - *Optional* - Filter the sessions by user based on the passed RE2 regexp
* `"subprefixes": <Boolean>` - *Optional* - Return a detailed count for each subprefix. Defaults to false

### Result (without subprefixes):
"result": {"count": 55}

### Result (with subprefixes):
"result": [{"prefix": "root", "count": 12}, {"prefix": "root.sub1", "count": "10"}, {"prefix": "root.sub2", "count": 2}]

## sys.session.kick
Terminates any connection which session id matches the prefix.

Expand Down Expand Up @@ -284,6 +319,33 @@ Frees a lock, cluster-wide.
### Result:
"result": { "ok": true }

## sync.list
List the active locks for a prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Lock prefix to list from
* `"depth": <Number>` - *Optional* - Filter the locks listed to the passed depth relative to the passed prefix. Defaults to -1 (no filtering)
* `"filter": <String>` - *Optional* - Filter the locks by prefix based on the passed RE2 regexp
* `"limit": <Number>` - *Optional* - Limit the number of results. Defaults to 100
* `"skip": <Number>` - *Optional* - Skips a number of results. Defaults to 0

### Result:
"result": [{"id": "lock.1", "owner": "root"}, {"id": "lock.2", "owner": "test"}]

## sync.count
Count the active locks for a prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Prefix to count from
* `"filter": <String>` - *Optional* - Filter the locks by prefix based on the passed RE2 regexp
* `"subprefixes": <Boolean>` - *Optional* - Return a detailed count for each subprefix. Defaults to false

### Result (without subprefixes):
"result": {"count": 55}

### Result (with subprefixes):
"result": [{"prefix": "root", "count": 12}, {"prefix": "root.sub1", "count": "10"}, {"prefix": "root.sub2", "count": 2}]

# Tasks

## task.push
Expand Down Expand Up @@ -366,12 +428,28 @@ List tasks happening inside a prefix and its properties

### Parameters:
* `"prefix": <String>` - Path prefix
* `"depth": <Number>` - *Optional* - Filter the tasks listed to the passed depth relative to the passed prefix. Defaults to -1 (no filtering)
* `"filter": <String>` - *Optional* - Filter the tasks by prefix based on the passed RE2 regexp
* `"limit": <Number>` - *Optional* - Limit the number of results. Defaults to 100
* `"skip": <Number>` - *Optional* - Skips a number of results. Defaults to 0

### Result:
"result": [{"id":"687c3b7bfbcdae7cb774d215cf923252f3fb","state":"waiting","path":"test.","priority":0,"ttl":0,"detached":false,"user":"root","method":"","params":null,"targetSession":"","result":null,"errCode":null,"errString":"","errObject":null,"tags":null,"creationTime":"2016-08-31T09:44:16.316Z","deadline":"2016-08-31T09:45:16.316Z"}, ...]

## task.count
Count the active tasks (with push and pull count) for a prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Prefix to count from
* `"filter": <String>` - *Optional* - Filter the tasks by prefix based on the passed RE2 regexp
* `"subprefixes": <Boolean>` - *Optional* - Return a detailed count for each subprefix. Defaults to false

### Result (without subprefixes):
"result": {"count": 55, "pushCount": 25, "pullCount": 30}

### Result (with subprefixes):
"result": [{"prefix": "root", "count": 12, "pushCount": 6, "pullCount": 6}, {"prefix": "root.sub1", "count": "10", "pushCount": 2, "pullCount": 8}, {"prefix": "root.sub2", "count": 2, "pushCount": 0, "pullCount": 2}]


# Topics

Expand Down Expand Up @@ -406,6 +484,32 @@ Publish data to a topic.
### Result:
"result": { "ok": true }

## topic.list
List the active topic subscriptions for a prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Topic prefix to list from
* `"depth": <Number>` - *Optional* - Filter the topics listed to the passed depth relative to the passed prefix. Defaults to -1 (no filtering)
* `"filter": <String>` - *Optional* - Filter the topics by prefix based on the passed RE2 regexp
* `"limit": <Number>` - *Optional* - Limit the number of results. Defaults to 100
* `"skip": <Number>` - *Optional* - Skips a number of results. Defaults to 0

### Result:
"result": [{"topic": "some.topic", "subscribers": 3}, {"topic": "some.other.topic", "subscribers": 5}]

## topic.count
Count the active topic subscriptions for a topic prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Topic prefix to count from
* `"filter": <String>` - *Optional* - Filter the topics by prefix based on the passed RE2 regexp
* `"subprefixes": <Boolean>` - *Optional* - Return a detailed count for each subprefix. Defaults to false

### Result (without subprefixes):
"result": {"count": 55}

### Result (with subprefixes):
"result": [{"prefix": "root", "count": 12}, {"prefix": "root.sub1", "count": "10"}, {"prefix": "root.sub2", "count": 2}]

# Users

Expand All @@ -428,16 +532,43 @@ Delete an existent user
### Result:
"result": { "ok": true }

## user.rename
Change the username of a user

### Parameters:
* `"user": <String>` - Username of the user
* `"new": <String>` - New username

### Result:
"result": { "ok": true }


## user.list
Lists users which username starts with a prefix

### Parameters:
* `"prefix": <String>` - Prefix where the tags will take effect
* `"depth": <Number>` - *Optional* - Filter the users listed to the passed depth relative to the passed prefix. Defaults to -1 (no filtering)
* `"filter": <String>` - *Optional* - Filter the users by prefix based on the passed RE2 regexp
* `"limit": <Number>` - *Optional* - Limit the number of results. Defaults to 100
* `"skip": <Number>` - *Optional* - Skips a number of results. Defaults to 0

### Result:
"result": [{"blacklist":["172.17.*"],"maxsessions":42,"tags":{test":{"@admin":true}},"templates":["template1","auth-token"],"user":"test","whitelist":["172.17.0.1"]},]
"result": [{"blacklist":["172.17.*"],"maxsessions":42,"tags":{test":{"@admin":true}},"templates":["template1","auth-token"],"user":"test","whitelist":["172.17.0.1"],"createdAt":"2016-08-31T09:45:16.316Z"}]

## user.count
Count the users on a prefix on the cluster.

### Parameters:
* `"prefix": <String>` - Username prefix to count from
* `"filter": <String>` - *Optional* - Filter the users by prefix based on the passed RE2 regexp
* `"subprefixes": <Boolean>` - *Optional* - Return a detailed count for each subprefix. Defaults to false

### Result (without subprefixes):
"result": {"count": 55}

### Result (with subprefixes):
"result": [{"prefix": "root", "count": 12}, {"prefix": "root.sub1", "count": "10"}, {"prefix": "root.sub2", "count": 2}]


## user.setTags
Expand Down
2 changes: 1 addition & 1 deletion connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"time"
"unsafe"

"github.com/Sirupsen/logrus"
"github.com/jaracil/ei"
. "github.com/jaracil/nexus/log"
"github.com/jaracil/smartio"
"github.com/nayarsystems/nxgo/nxcore"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
r "gopkg.in/gorethink/gorethink.v3"
)
Expand Down
27 changes: 26 additions & 1 deletion database.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,30 @@ func dbBootstrap() error {
return err
}
Log.Println("Creating root user")
ud := UserData{User: "root", Salt: safeId(16), Tags: map[string]map[string]interface{}{".": {"@admin": true}}}
ud := UserData{User: "root", Salt: safeId(16), Tags: map[string]map[string]interface{}{".": {"@admin": true}}, CreatedAt: time.Now()}
ud.Pass, err = HashPass("root", ud.Salt)
_, err = r.Table("users").Insert(&ud).RunWrite(db)
if err != nil {
return err
}

}
cur, err = r.Table("users").IndexList().Run(db)
usersIndexList := make([]string, 0)
err = cur.All(&usersIndexList)
cur.Close()
if err != nil {
return err
}
if !inStrSlice(usersIndexList, "blockedBy") {
Log.Println("Creating blockedBy index on users sessions")
_, err := r.Table("users").IndexCreateFunc("blockedBy", func(row r.Term) interface{} {
return row.Field("blockedBy")
}).RunWrite(db)
if err != nil {
return err
}
}
if !inStrSlice(tablelist, "sessions") {
Log.Println("Creating sessions table")
_, err := r.TableCreate("sessions").RunWrite(db)
Expand Down Expand Up @@ -152,6 +168,15 @@ func dbBootstrap() error {
if err != nil {
return err
}
if !inStrSlice(tasksIndexlist, "path") {
Log.Println("Creating path index on tasks table")
_, err := r.Table("tasks").IndexCreateFunc("path", func(row r.Term) interface{} {
return row.Field("path")
}).RunWrite(db)
if err != nil {
return err
}
}
if !inStrSlice(tasksIndexlist, "pspc") {
Log.Println("Creating pspc index on tasks table")
_, err := r.Table("tasks").IndexCreateFunc("pspc", func(row r.Term) interface{} {
Expand Down
26 changes: 16 additions & 10 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package: github.com/jaracil/nexus
import:
- package: github.com/Sirupsen/logrus
version: ~0.11.4
- package: github.com/sirupsen/logrus
version: ~1.0.4
- package: github.com/armon/go-proxyproto
- package: github.com/dancannon/gorethink
version: ~3.0.1
- package: gopkg.in/gorethink/gorethink.v3
version: ~3.0.5
- package: github.com/jaracil/ei
- package: github.com/jaracil/smartio
- package: github.com/jessevdk/go-flags
version: ~1.2.0
version: ~1.3.0
- package: github.com/nayarsystems/nxgo
version: ~1.7.0
subpackages:
- nxcore
- package: github.com/rifflock/lfshook
version: ~1.5.0
version: ~2.1.0
- package: github.com/shirou/gopsutil
version: ~2.17.2
version: ~2.17.11
subpackages:
- load
- package: github.com/tylerb/graceful
Expand All @@ -27,4 +27,4 @@ import:
- package: golang.org/x/net
subpackages:
- context
- websocket
- websocket
2 changes: 1 addition & 1 deletion hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/Sirupsen/logrus"
"github.com/sirupsen/logrus"
"github.com/jaracil/ei"
. "github.com/jaracil/nexus/log"
r "gopkg.in/gorethink/gorethink.v3"
Expand Down
Loading

0 comments on commit 2d913fc

Please sign in to comment.