From be26b67a0cf77a39662363d29eaebe1d9f6d7719 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 3 Feb 2020 14:16:30 +0100 Subject: [PATCH] list keys working as expected, datastructure not pretty --- go.sum | 1 + pkg/proto/v0/accounts.pb.go | 81 ++++++++++++++++++++++++------- pkg/proto/v0/accounts.pb.micro.go | 25 ++++++++-- pkg/proto/v0/accounts.proto | 6 +++ pkg/service/v0/service.go | 26 +++++++++- pkg/store/filesystem/store.go | 18 +++++-- 6 files changed, 132 insertions(+), 25 deletions(-) diff --git a/go.sum b/go.sum index 33cf295ca7..f8748c4b58 100644 --- a/go.sum +++ b/go.sum @@ -278,6 +278,7 @@ github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= diff --git a/pkg/proto/v0/accounts.pb.go b/pkg/proto/v0/accounts.pb.go index f30dd62521..36ddc5efe3 100644 --- a/pkg/proto/v0/accounts.pb.go +++ b/pkg/proto/v0/accounts.pb.go @@ -6,6 +6,7 @@ package proto import ( fmt "fmt" proto "github.com/golang/protobuf/proto" + _ "github.com/golang/protobuf/ptypes/empty" math "math" ) @@ -239,33 +240,77 @@ func (m *Query) GetKey() string { return "" } +type Records struct { + Records []*Record `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Records) Reset() { *m = Records{} } +func (m *Records) String() string { return proto.CompactTextString(m) } +func (*Records) ProtoMessage() {} +func (*Records) Descriptor() ([]byte, []int) { + return fileDescriptor_e3c84319968a576b, []int{5} +} + +func (m *Records) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Records.Unmarshal(m, b) +} +func (m *Records) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Records.Marshal(b, m, deterministic) +} +func (m *Records) XXX_Merge(src proto.Message) { + xxx_messageInfo_Records.Merge(m, src) +} +func (m *Records) XXX_Size() int { + return xxx_messageInfo_Records.Size(m) +} +func (m *Records) XXX_DiscardUnknown() { + xxx_messageInfo_Records.DiscardUnknown(m) +} + +var xxx_messageInfo_Records proto.InternalMessageInfo + +func (m *Records) GetRecords() []*Record { + if m != nil { + return m.Records + } + return nil +} + func init() { proto.RegisterType((*Record)(nil), "settings.Record") proto.RegisterType((*Payload)(nil), "settings.Payload") proto.RegisterType((*Account)(nil), "settings.Account") proto.RegisterType((*Phoenix)(nil), "settings.Phoenix") proto.RegisterType((*Query)(nil), "settings.Query") + proto.RegisterType((*Records)(nil), "settings.Records") } func init() { proto.RegisterFile("pkg/proto/v0/accounts.proto", fileDescriptor_e3c84319968a576b) } var fileDescriptor_e3c84319968a576b = []byte{ - // 264 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x51, 0xcd, 0x4e, 0x83, 0x40, - 0x10, 0x0e, 0x22, 0xc5, 0x4e, 0x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, 0x6e, 0x78, 0x8e, 0xc5, - 0x1a, 0xa6, 0xb9, 0x6b, 0x96, 0x93, 0xda, 0x57, 0x82, 0xf0, 0x1e, 0xfc, 0x9c, 0x34, 0xce, 0x8e, - 0x95, 0xed, 0x31, 0x6f, 0x06, 0x08, 0x26, 0xe0, 0xaf, 0x48, 0xe3, 0xf4, 0x48, 0x98, 0x3d, 0x43, - 0xe5, 0x32, 0xfc, 0x08, 0xcc, 0x2b, 0x7d, 0x8e, 0xcc, 0xe7, 0xe9, 0x37, 0x00, 0x00, 0xff, 0xff, - 0x82, 0xf2, 0xd3, 0x55, 0xcb, 0x01, 0x00, 0x00, + // 327 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0x41, 0x4f, 0xc2, 0x40, + 0x10, 0x85, 0x53, 0x0b, 0xac, 0x0c, 0x07, 0x60, 0x62, 0x0c, 0xc2, 0xc1, 0xa6, 0xa7, 0xaa, 0x49, + 0xab, 0x18, 0xcf, 0x46, 0x12, 0xc3, 0xc5, 0x44, 0x5d, 0x6e, 0xde, 0x6a, 0x19, 0x4a, 0x03, 0x74, + 0x9b, 0x76, 0x21, 0xf6, 0xa7, 0xf8, 0x6f, 0x0d, 0xbb, 0x5d, 0x51, 0xeb, 0xa9, 0xd3, 0xf7, 0xbe, + 0x99, 0x7d, 0x99, 0x81, 0x51, 0xb6, 0x8a, 0x83, 0x2c, 0x17, 0x52, 0x04, 0xbb, 0xeb, 0x20, 0x8c, + 0x22, 0xb1, 0x4d, 0x65, 0xe1, 0x2b, 0x05, 0x8f, 0x0b, 0x92, 0x32, 0x49, 0xe3, 0x62, 0x38, 0x8a, + 0x85, 0x88, 0xd7, 0xa4, 0xc9, 0xf7, 0xed, 0x22, 0xa0, 0x4d, 0x26, 0x4b, 0x8d, 0xb9, 0x53, 0x68, + 0x71, 0x8a, 0x44, 0x3e, 0xc7, 0x1e, 0xd8, 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xf8, 0xb0, 0xff, 0xb7, + 0xa3, 0x98, 0xb0, 0xb7, 0xa6, 0x86, 0x5a, 0xea, 0x73, 0xfb, 0x15, 0x00, 0x00, 0xff, 0xff, 0x06, + 0x2e, 0xab, 0xa7, 0x53, 0x02, 0x00, 0x00, } diff --git a/pkg/proto/v0/accounts.pb.micro.go b/pkg/proto/v0/accounts.pb.micro.go index 56a3c88a4f..56c4b739c9 100644 --- a/pkg/proto/v0/accounts.pb.micro.go +++ b/pkg/proto/v0/accounts.pb.micro.go @@ -5,13 +5,15 @@ package proto import ( fmt "fmt" - proto "github.com/golang/protobuf/proto" math "math" -) -import ( + proto "github.com/golang/protobuf/proto" + empty "github.com/golang/protobuf/ptypes/empty" + context "context" + client "github.com/micro/go-micro/client" + server "github.com/micro/go-micro/server" ) @@ -36,6 +38,7 @@ var _ server.Option type SettingsService interface { Set(ctx context.Context, in *Record, opts ...client.CallOption) (*Record, error) Get(ctx context.Context, in *Query, opts ...client.CallOption) (*Record, error) + List(ctx context.Context, in *empty.Empty, opts ...client.CallOption) (*Records, error) } type settingsService struct { @@ -76,17 +79,29 @@ func (c *settingsService) Get(ctx context.Context, in *Query, opts ...client.Cal return out, nil } +func (c *settingsService) List(ctx context.Context, in *empty.Empty, opts ...client.CallOption) (*Records, error) { + req := c.c.NewRequest(c.name, "SettingsService.List", in) + out := new(Records) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // Server API for SettingsService service type SettingsServiceHandler interface { Set(context.Context, *Record, *Record) error Get(context.Context, *Query, *Record) error + List(context.Context, *empty.Empty, *Records) error } func RegisterSettingsServiceHandler(s server.Server, hdlr SettingsServiceHandler, opts ...server.HandlerOption) error { type settingsService interface { Set(ctx context.Context, in *Record, out *Record) error Get(ctx context.Context, in *Query, out *Record) error + List(ctx context.Context, in *empty.Empty, out *Records) error } type SettingsService struct { settingsService @@ -106,3 +121,7 @@ func (h *settingsServiceHandler) Set(ctx context.Context, in *Record, out *Recor func (h *settingsServiceHandler) Get(ctx context.Context, in *Query, out *Record) error { return h.SettingsServiceHandler.Get(ctx, in, out) } + +func (h *settingsServiceHandler) List(ctx context.Context, in *empty.Empty, out *Records) error { + return h.SettingsServiceHandler.List(ctx, in, out) +} diff --git a/pkg/proto/v0/accounts.proto b/pkg/proto/v0/accounts.proto index 65960d4d35..b4185cef57 100644 --- a/pkg/proto/v0/accounts.proto +++ b/pkg/proto/v0/accounts.proto @@ -2,10 +2,12 @@ syntax = "proto3"; package settings; option go_package = "proto"; +import "google/protobuf/empty.proto"; service SettingsService { rpc Set(Record) returns (Record); rpc Get(Query) returns (Record); + rpc List(google.protobuf.Empty) returns(Records); } message Record { @@ -30,3 +32,7 @@ message Phoenix { message Query { string key = 1; } + +message Records { + repeated Record records = 1; +} \ No newline at end of file diff --git a/pkg/service/v0/service.go b/pkg/service/v0/service.go index 469778e4df..dcae8ed590 100644 --- a/pkg/service/v0/service.go +++ b/pkg/service/v0/service.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" + "github.com/golang/protobuf/ptypes/empty" mstore "github.com/micro/go-micro/v2/store" "github.com/owncloud/ocis-accounts/pkg/proto/v0" @@ -35,7 +36,10 @@ func (s Service) Set(c context.Context, req *proto.Record, res *proto.Record) er // Get implements the SettingsServiceHandler interface generated on accounts.pb.micro.go func (s Service) Get(c context.Context, req *proto.Query, res *proto.Record) error { - contents, _ := registry.Store.Read(req.Key) + contents, err := registry.Store.Read(req.Key) + if err != nil { + return err + } if len(contents) > 0 { r := &proto.Payload{} @@ -45,3 +49,23 @@ func (s Service) Get(c context.Context, req *proto.Query, res *proto.Record) err return nil } + +// List implements the SettingsServiceHandler interface generated on accounts.pb.micro.go +func (s Service) List(ctx context.Context, in *empty.Empty, res *proto.Records) error { + contents, err := registry.Store.List() + if err != nil { + return err + } + + records := &proto.Records{} + + for _, v := range contents { + records.Records = append(records.Records, &proto.Record{ + Key: v.Key, + }) + } + + res.Records = records.Records + + return nil +} diff --git a/pkg/store/filesystem/store.go b/pkg/store/filesystem/store.go index 4b14c259b3..06367c673d 100644 --- a/pkg/store/filesystem/store.go +++ b/pkg/store/filesystem/store.go @@ -44,14 +44,26 @@ func New() *Store { } // Init implements the store interface -// TODO it could prepare the destination path, for instance func (s Store) Init(...mstore.Option) error { return nil } -// List implements the store interface +// List returns all the identities in the mountPath folder func (s Store) List() ([]*mstore.Record, error) { - return nil, nil + records := []*mstore.Record{} + identities, err := ioutil.ReadDir(s.mountPath) + if err != nil { + s.Logger.Err(err).Msgf("error reading %v", s.mountPath) + } + + s.Logger.Info().Msg("listing identities") + for _, v := range identities { + records = append(records, &mstore.Record{ + Key: v.Name(), + }) + } + + return records, nil } // Read implements the store interface