Skip to content

Commit

Permalink
read scope
Browse files Browse the repository at this point in the history
  • Loading branch information
kdudkov committed Nov 1, 2023
1 parent 28a5fb6 commit 915567d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/userctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func main() {
file := flag.String("file", "users.yml", "file")
user := flag.String("user", "", "user")
passwd := flag.String("password", "", "password")
scope := flag.String("scope", "", "scope")
scope := flag.String("scope", "test", "scope")

users := read(*file)

Expand Down
12 changes: 11 additions & 1 deletion internal/client/client_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ func (h *ConnClientHandler) CanSeeScope(scope string) bool {
if h.user == nil {
return true
}
return h.user.Scope == "" || scope == "broadcast" || h.user.Scope == scope
if h.user.Scope == "" || h.user.Scope == scope {
return true
}

for _, s := range h.user.ReadScope {
if s == scope {
return true
}
}

return false
}

func (h *ConnClientHandler) GetUids() map[string]string {
Expand Down
8 changes: 7 additions & 1 deletion internal/client/client_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestRoute(t *testing.T) {
h := NewConnClientHandler("test", nil, &HandlerConfig{Uid: "111", IsClient: true})
h.ver = 1
h.user = &model.User{Scope: "aaa"}
h.user = &model.User{Scope: "aaa", ReadScope: []string{"ccc", "ddd"}}

var msg *cot.CotMessage
var c *cotproto.TakMessage
Expand All @@ -28,6 +28,12 @@ func TestRoute(t *testing.T) {
assert.NotNil(t, c)
assert.Equal(t, "t-x-c-t", c.GetCotEvent().GetType())

msg = &cot.CotMessage{TakMessage: cot.MakePing("123"), Scope: "ddd"}
c, err = passMsg(h, msg)
assert.NoError(t, err)
assert.NotNil(t, c)
assert.Equal(t, "t-x-c-t", c.GetCotEvent().GetType())

msg = &cot.CotMessage{TakMessage: cot.MakePing("123"), Scope: "bbb"}
c, err = passMsg(h, msg)
assert.NoError(t, err)
Expand Down
15 changes: 8 additions & 7 deletions internal/model/user.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package model

type User struct {
Login string `yaml:"user"`
Callsign string `yaml:"callsign,omitempty"`
Team string `yaml:"team,omitempty"`
Role string `yaml:"role,omitempty"`
Typ string `yaml:"type,omitempty"`
Password string `yaml:"password"`
Scope string `yaml:"scope,omitempty"`
Login string `yaml:"user"`
Callsign string `yaml:"callsign,omitempty"`
Team string `yaml:"team,omitempty"`
Role string `yaml:"role,omitempty"`
Typ string `yaml:"type,omitempty"`
Password string `yaml:"password"`
Scope string `yaml:"scope,omitempty"`
ReadScope []string `yaml:"read_scope"`
}

0 comments on commit 915567d

Please sign in to comment.