mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 16:41:35 -04:00
working prototype
This commit is contained in:
@@ -201,7 +201,7 @@ func (m *Phoenix) GetTheme() string {
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -232,9 +232,9 @@ func (m *Query) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_Query proto.InternalMessageInfo
|
||||
|
||||
func (m *Query) GetId() string {
|
||||
func (m *Query) GetKey() string {
|
||||
if m != nil {
|
||||
return m.Id
|
||||
return m.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -250,22 +250,22 @@ func init() {
|
||||
func init() { proto.RegisterFile("pkg/proto/v0/accounts.proto", fileDescriptor_e3c84319968a576b) }
|
||||
|
||||
var fileDescriptor_e3c84319968a576b = []byte{
|
||||
// 271 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x51, 0x4f, 0x4f, 0x83, 0x30,
|
||||
0x14, 0x0f, 0x20, 0xc3, 0xbd, 0x25, 0x6e, 0xbe, 0x98, 0xb8, 0xe8, 0x41, 0xc2, 0x09, 0x63, 0x02,
|
||||
0x66, 0x7e, 0x00, 0xe3, 0x2e, 0x3b, 0xaa, 0xe5, 0xe6, 0x0d, 0xe1, 0x6d, 0x34, 0x53, 0x4a, 0x4a,
|
||||
0xb7, 0xc8, 0xb7, 0x37, 0x6b, 0x8b, 0x73, 0xe1, 0xd4, 0xd7, 0xdf, 0xbf, 0xf7, 0x4b, 0x0b, 0xb7,
|
||||
0xcd, 0x76, 0x93, 0x36, 0x52, 0x28, 0x91, 0xee, 0x1f, 0xd3, 0xbc, 0x28, 0xc4, 0xae, 0x56, 0x6d,
|
||||
0xa2, 0x11, 0x3c, 0x6f, 0x49, 0x29, 0x5e, 0x6f, 0xda, 0x68, 0x05, 0x23, 0x46, 0x85, 0x90, 0x25,
|
||||
0xce, 0xc0, 0xdb, 0x52, 0x37, 0x77, 0x42, 0x27, 0x1e, 0xb3, 0xc3, 0x88, 0x0f, 0x10, 0x34, 0x79,
|
||||
0xf7, 0x25, 0xf2, 0x72, 0xee, 0x86, 0x4e, 0x3c, 0x59, 0x5c, 0x26, 0xbd, 0x2f, 0x79, 0x33, 0x04,
|
||||
0xeb, 0x15, 0x51, 0x01, 0x81, 0xc5, 0xb4, 0xaf, 0x12, 0x54, 0xf3, 0x1f, 0x9d, 0x76, 0xea, 0x33,
|
||||
0x04, 0xeb, 0x15, 0x07, 0xb1, 0x2d, 0x37, 0x5c, 0xf2, 0x62, 0x08, 0xd6, 0x2b, 0xa2, 0x67, 0x08,
|
||||
0x2c, 0x86, 0x08, 0x67, 0x75, 0xfe, 0x4d, 0xb6, 0xaf, 0x9e, 0x31, 0x84, 0x49, 0x99, 0x2b, 0x7a,
|
||||
0x5d, 0x2f, 0xb9, 0x54, 0x95, 0xce, 0x1b, 0xb3, 0xff, 0x50, 0x74, 0x07, 0x81, 0x6d, 0x80, 0x57,
|
||||
0xe0, 0xab, 0x8a, 0xfe, 0x12, 0xcc, 0x25, 0xba, 0x06, 0xff, 0x7d, 0x47, 0xb2, 0xc3, 0x0b, 0x70,
|
||||
0x79, 0x69, 0x39, 0x97, 0x97, 0x8b, 0x35, 0x4c, 0x33, 0xdb, 0x2b, 0x23, 0xb9, 0xe7, 0x05, 0xe1,
|
||||
0x3d, 0x78, 0x19, 0x29, 0x9c, 0x1d, 0x0b, 0x9b, 0xa7, 0xbc, 0x19, 0x20, 0x18, 0x83, 0xb7, 0x22,
|
||||
0x85, 0xd3, 0x23, 0xa1, 0xb7, 0x0c, 0x95, 0xcb, 0xe0, 0xc3, 0xd7, 0x7f, 0xf4, 0x39, 0xd2, 0xc7,
|
||||
0xd3, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x66, 0x19, 0xd7, 0xce, 0xc9, 0x01, 0x00, 0x00,
|
||||
// 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, 0x0f, 0xad, 0x13, 0x0f, 0x55, 0x0f, 0x12, 0x4e, 0x18, 0x13, 0x30,
|
||||
0xf5, 0x01, 0x8c, 0xbd, 0xf4, 0xa8, 0x2e, 0x37, 0x6f, 0xeb, 0x32, 0x2d, 0xa4, 0xca, 0x92, 0x65,
|
||||
0xdb, 0xc8, 0xdb, 0x9b, 0xee, 0x2e, 0xd6, 0x86, 0x13, 0xc3, 0xf7, 0x37, 0x5f, 0x66, 0xe1, 0xb6,
|
||||
0xd9, 0x6e, 0xb2, 0x46, 0x49, 0x2d, 0xb3, 0xfd, 0x63, 0xc6, 0x85, 0x90, 0xbb, 0x5a, 0xb7, 0xa9,
|
||||
0x41, 0xf0, 0xa2, 0x25, 0xad, 0xab, 0x7a, 0xd3, 0xc6, 0x2b, 0x18, 0x31, 0x12, 0x52, 0x15, 0x38,
|
||||
0x03, 0x7f, 0x4b, 0xdd, 0xdc, 0x8b, 0xbc, 0x64, 0xcc, 0x0e, 0x23, 0x3e, 0x40, 0xd8, 0xf0, 0xee,
|
||||
0x4b, 0xf2, 0x62, 0x7e, 0x16, 0x79, 0xc9, 0x64, 0x71, 0x99, 0xf6, 0xbe, 0xf4, 0xcd, 0x12, 0xac,
|
||||
0x57, 0xc4, 0x02, 0x42, 0x87, 0x19, 0x5f, 0x29, 0xa9, 0xae, 0x7e, 0x4c, 0xda, 0xa9, 0xcf, 0x12,
|
||||
0xac, 0x57, 0x1c, 0xc4, 0xae, 0xdc, 0x70, 0xc9, 0x8b, 0x25, 0x58, 0xaf, 0x88, 0x9f, 0x21, 0x74,
|
||||
0x18, 0x22, 0x9c, 0xd7, 0xfc, 0x9b, 0x5c, 0x5f, 0x33, 0x63, 0x04, 0x93, 0x82, 0x6b, 0x7a, 0x5d,
|
||||
0x2f, 0x2b, 0xa5, 0x4b, 0x93, 0x37, 0x66, 0xff, 0xa1, 0xf8, 0x0e, 0x42, 0xd7, 0x00, 0xaf, 0x20,
|
||||
0xd0, 0x25, 0xfd, 0x25, 0xd8, 0x9f, 0xf8, 0x1a, 0x82, 0xf7, 0x1d, 0xa9, 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,
|
||||
}
|
||||
|
||||
@@ -28,5 +28,5 @@ message Phoenix {
|
||||
}
|
||||
|
||||
message Query {
|
||||
string id = 1;
|
||||
string key = 1;
|
||||
}
|
||||
|
||||
@@ -36,10 +36,15 @@ 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 {
|
||||
res.Payload = &proto.Payload{
|
||||
Phoenix: &proto.Phoenix{
|
||||
Theme: "light",
|
||||
},
|
||||
st := store.New()
|
||||
contents, err := st.Read(req.Key)
|
||||
if err != nil {
|
||||
// TODO deal with this
|
||||
}
|
||||
|
||||
r := &proto.Payload{}
|
||||
json.Unmarshal(contents[0].Value, r)
|
||||
|
||||
res.Payload = r
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -5,39 +5,47 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
mstore "github.com/micro/go-micro/v2/store"
|
||||
olog "github.com/owncloud/ocis-pkg/log"
|
||||
)
|
||||
|
||||
// Logger is a global logger
|
||||
var Logger olog.Logger
|
||||
// StoreName is the default name for the store container
|
||||
var StoreName string = "ocis-store"
|
||||
|
||||
// Store interacts with the filesystem to manage account information
|
||||
type Store struct {
|
||||
logger olog.Logger
|
||||
mountPath string
|
||||
logger olog.Logger
|
||||
}
|
||||
|
||||
// New returns a new file system store manager
|
||||
// TODO add mountPath as a flag. Accept a *config argument
|
||||
func New() Store {
|
||||
store := Store{
|
||||
s := Store{
|
||||
logger: olog.NewLogger(),
|
||||
}
|
||||
|
||||
// default to the current working directory if not configured
|
||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||
if err != nil {
|
||||
store.logger.Err(err).Msg("initializing the accounts store")
|
||||
s.logger.Err(err).Msg("initializing accounts store")
|
||||
}
|
||||
store.mountPath = dir
|
||||
|
||||
return store
|
||||
dest := filepath.Join(dir, StoreName)
|
||||
if _, err := os.Stat(dest); err != nil {
|
||||
s.logger.Info().Msgf("creating container on %v", dest)
|
||||
os.Mkdir(dest, 0700)
|
||||
}
|
||||
|
||||
s.mountPath = dest
|
||||
return s
|
||||
}
|
||||
|
||||
// Init implements the store interface
|
||||
// TODO it could prepare the destination path, for instance
|
||||
func (s *Store) Init(...mstore.Options) {}
|
||||
|
||||
// List implements the store interface
|
||||
@@ -46,8 +54,20 @@ func (s *Store) List() ([]*mstore.Record, error) {
|
||||
}
|
||||
|
||||
// Read implements the store interface
|
||||
// this implementation only reads by id.
|
||||
func (s *Store) Read(key string, opts ...mstore.ReadOption) ([]*mstore.Record, error) {
|
||||
return nil, nil
|
||||
contents, err := ioutil.ReadFile(path.Join(s.mountPath, key))
|
||||
if err != nil {
|
||||
s.logger.Err(err).Msgf("error reading contents of key %v: file not found", key)
|
||||
return []*mstore.Record{}, err
|
||||
}
|
||||
|
||||
return []*mstore.Record{
|
||||
&mstore.Record{
|
||||
Key: key,
|
||||
Value: contents,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Write implements the store interface
|
||||
@@ -76,3 +96,8 @@ func (s *Store) Delete(key string) error {
|
||||
func (s *Store) String() string {
|
||||
return "store"
|
||||
}
|
||||
|
||||
// creates the default container for the ocis-store if it doesn't exist
|
||||
func init() {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user