-
Notifications
You must be signed in to change notification settings - Fork 508
/
server.go
57 lines (49 loc) · 1.79 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package remoteks
import (
google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/sirupsen/logrus"
"golang.org/x/net/context"
"github.com/theupdateframework/notary/trustmanager"
)
// GRPCStorage is an implementer of the GRPC storage server. It passes through
// the requested operations to an underlying trustmanager.Storage instance, translating
// between the Go and GRPC interfaces.
type GRPCStorage struct {
backend trustmanager.Storage
}
// NewGRPCStorage instantiates a new GRPC storage server using the provided
// backend.
func NewGRPCStorage(backend trustmanager.Storage) *GRPCStorage {
return &GRPCStorage{
backend: backend,
}
}
// Set writes the provided data under the given identifier.
func (s *GRPCStorage) Set(ctx context.Context, msg *SetMsg) (*google_protobuf.Empty, error) {
logrus.Debugf("storing: %s", msg.FileName)
err := s.backend.Set(msg.FileName, msg.Data)
if err != nil {
logrus.Errorf("failed to store: %s", err.Error())
}
return &google_protobuf.Empty{}, err
}
// Remove deletes the data associated with the provided identifier.
func (s *GRPCStorage) Remove(ctx context.Context, fn *FileNameMsg) (*google_protobuf.Empty, error) {
return &google_protobuf.Empty{}, s.backend.Remove(fn.FileName)
}
// Get returns the data associated with the provided identifier.
func (s *GRPCStorage) Get(ctx context.Context, fn *FileNameMsg) (*ByteMsg, error) {
data, err := s.backend.Get(fn.FileName)
if err != nil {
return &ByteMsg{}, err
}
return &ByteMsg{Data: data}, nil
}
// ListFiles returns all known identifiers in the storage backend.
func (s *GRPCStorage) ListFiles(ctx context.Context, _ *google_protobuf.Empty) (*StringListMsg, error) {
lst := s.backend.ListFiles()
logrus.Debugf("found %d keys", len(lst))
return &StringListMsg{
FileNames: lst,
}, nil
}