Skip to content

Commit

Permalink
chore(veinmind-common): update conf service func field
Browse files Browse the repository at this point in the history
  • Loading branch information
d1nfinite committed Jun 13, 2022
1 parent c72d266 commit 3eccbd1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
3 changes: 1 addition & 2 deletions plugins/go/veinmind-sensitive/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ module github.com/chaitin/veinmind-tools/plugins/go/veinmind-sensitive

go 1.18

replace github.com/chaitin/veinmind-tools/veinmind-common/go v1.0.0 => ../../../veinmind-common/go

require (
github.com/BurntSushi/toml v0.3.1
github.com/chaitin/libveinmind v1.1.0
github.com/chaitin/veinmind-tools/veinmind-common/go v1.0.0
github.com/chaitin/veinmind-tools/veinmind-common/go v0.0.0-20220613062319-ac5c6e55bfe4
github.com/stretchr/testify v1.7.0
)

Expand Down
17 changes: 15 additions & 2 deletions veinmind-common/go/service/conf/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ import (
"testing"
)

func TestDefaultClient(t *testing.T) {
func TestDefaultClient(t *testing.T) {
c := DefaultConfClient()
_, err := c.Pull(Sensitive)
_, err := c.Pull(Sensitive)
assert.Error(t, err)
}

func TestNewConfService(t *testing.T) {
s, err := NewConfService()
if err != nil {
t.Error(err)
}

s.Store(Sensitive, []byte{0x01})
b, err := s.Pull(Sensitive)
if err != nil {
t.Error(err)
}

assert.Equal(t, b, []byte{0x01})
}
28 changes: 17 additions & 11 deletions veinmind-common/go/service/conf/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,35 @@ import (
const Namespace = "github.com/chaitin/veinmind-tools/veinmind-common/go/service/conf"

type ConfService struct {
store map[string][]byte
store map[PluginConfNS][]byte
}

type confClient struct {
ctx context.Context
group *errgroup.Group
Pull func(ns PluginConfNS) ([]byte, error)
ctx context.Context
group *errgroup.Group
Pull func(ns PluginConfNS) ([]byte, error)
}

func (c *ConfService) Pull(pluginName string) ([]byte, error){
if b, ok := c.store[pluginName]; ok {
func NewConfService() (*ConfService, error) {
c := new(ConfService)
c.store = make(map[PluginConfNS][]byte)
return c, nil
}

func (c *ConfService) Pull(ns PluginConfNS) ([]byte, error) {
if b, ok := c.store[ns]; ok {
return b, nil
}else{
} else {
return nil, errors.New("conf: plugin conf doesn't exist")
}
}

func (c *ConfService) Store(pluginName string, b []byte) error {
c.store[pluginName] = b
func (c *ConfService) Store(ns PluginConfNS, b []byte) error {
c.store[ns] = b
return nil
}

func (c *ConfService) Add(registry *service.Registry) {
registry.Define(Namespace, struct {}{})
func (c *ConfService) Add(registry *service.Registry) {
registry.Define(Namespace, struct{}{})
registry.AddService(Namespace, "pull", c.Pull)
}

0 comments on commit 3eccbd1

Please sign in to comment.