-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathlocal.go
More file actions
65 lines (56 loc) · 1.6 KB
/
local.go
File metadata and controls
65 lines (56 loc) · 1.6 KB
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
58
59
60
61
62
63
64
65
package registry
import (
"github.com/google/uuid"
"os"
"path/filepath"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/timestamppb"
"github.com/feast-dev/feast/go/protos/feast/core"
)
// A FileRegistryStore is a file-based implementation of the RegistryStore interface.
type FileRegistryStore struct {
filePath string
}
// NewFileRegistryStore creates a FileRegistryStore with the given configuration and infers
// the file path from the repo path and registry path.
func NewFileRegistryStore(config *RegistryConfig, repoPath string) *FileRegistryStore {
lr := FileRegistryStore{}
registryPath := config.Path
if filepath.IsAbs(registryPath) {
lr.filePath = registryPath
} else {
lr.filePath = filepath.Join(repoPath, registryPath)
}
return &lr
}
// GetRegistryProto reads and parses the registry proto from the file path.
func (r *FileRegistryStore) GetRegistryProto() (*core.Registry, error) {
registry := &core.Registry{}
in, err := os.ReadFile(r.filePath)
if err != nil {
return nil, err
}
if err := proto.Unmarshal(in, registry); err != nil {
return nil, err
}
return registry, nil
}
func (r *FileRegistryStore) UpdateRegistryProto(rp *core.Registry) error {
return r.writeRegistry(rp)
}
func (r *FileRegistryStore) Teardown() error {
return os.Remove(r.filePath)
}
func (r *FileRegistryStore) writeRegistry(rp *core.Registry) error {
rp.VersionId = uuid.New().String()
rp.LastUpdated = timestamppb.Now()
bytes, err := proto.Marshal(rp)
if err != nil {
return err
}
err = os.WriteFile(r.filePath, bytes, 0644)
if err != nil {
return err
}
return nil
}