Skip to content

Commit

Permalink
Prepare to dockerize service
Browse files Browse the repository at this point in the history
Add configuration over config file and ENV/ops

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Feb 24, 2018
1 parent a319271 commit e6a3fb0
Show file tree
Hide file tree
Showing 26 changed files with 1,069 additions and 547 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ examples/tcp/persist.db
coverage.txt
vendor

persist.db
persist.db
plugins
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:1.10.0

ENV \
VOLANTMQ_WORK_DIR=/var/lib/volantmq \
VOLANTMQ_BUILD_FLAGS=""

# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added
RUN groupadd -r volantmq && useradd -r -d ${VOLANTMQ_WORK_DIR} -m -g volantmq volantmq

# Create environment directory
ENV PATH /usr/lib/rabbitmq/bin:$PATH

RUN mkdir ${VOLANTMQ_WORK_DIR}/{plugins,logs}

# default config uses mqtt:1883
EXPOSE 1883

CMD ["volantmq"]
117 changes: 78 additions & 39 deletions Gopkg.lock

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

22 changes: 22 additions & 0 deletions auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import vlAuth "github.com/VolantMQ/auth"

type internalAuth struct {
creds map[string]string
}

// nolint: golint
func (a internalAuth) Password(user, password string) vlAuth.Status {
if hash, ok := a.creds[user]; ok {
if password == hash {
return vlAuth.StatusAllow
}
}
return vlAuth.StatusDeny
}

// nolint: golint
func (a internalAuth) ACL(clientID, user, topic string, access vlAuth.AccessType) vlAuth.Status {
return vlAuth.StatusAllow
}
14 changes: 7 additions & 7 deletions auth/basic.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package auth

type Simple interface {
Password(u, p string) Status
}

type Anonymous interface {
Is() Status
}
//type Simple interface {
// Password(u, p string) Status
//}
//
//type Anonymous interface {
// Is() Status
//}
26 changes: 13 additions & 13 deletions auth/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package auth
import (
"errors"
"fmt"
"strings"

"github.com/VolantMQ/auth"
)

// Manager auth
type Manager struct {
p []Provider
p []auth.Provider
}

var providers = make(map[string]Provider)
var providers = make(map[string]auth.Provider)

// Register auth provider
func Register(name string, provider Provider) error {
func Register(name string, provider auth.Provider) error {
if name == "" && provider == nil {
return errors.New("invalid args")
}
Expand All @@ -34,11 +35,10 @@ func UnRegister(name string) {
}

// NewManager new auth manager
func NewManager(p string) (*Manager, error) {
func NewManager(p []string) (*Manager, error) {
m := Manager{}

list := strings.Split(p, ";")
for _, pa := range list {
for _, pa := range p {
pvd, ok := providers[pa]
if !ok {
return nil, fmt.Errorf("session: unknown provider %q", pa)
Expand All @@ -51,23 +51,23 @@ func NewManager(p string) (*Manager, error) {
}

// Password authentication
func (m *Manager) Password(user, password string) Status {
func (m *Manager) Password(user, password string) auth.Status {
for _, p := range m.p {
if status := p.Password(user, password); status == StatusAllow {
if status := p.Password(user, password); status == auth.StatusAllow {
return status
}
}

return StatusDeny
return auth.StatusDeny
}

// ACL check permissions
func (m *Manager) ACL(clientID, user, topic string, access AccessType) Status {
func (m *Manager) ACL(clientID, user, topic string, access auth.AccessType) auth.Status {
for _, p := range m.p {
if status := p.ACL(clientID, user, topic, access); status == StatusAllow {
if status := p.ACL(clientID, user, topic, access); status == auth.StatusAllow {
return status
}
}

return StatusDeny
return auth.StatusDeny
}
Loading

0 comments on commit e6a3fb0

Please sign in to comment.