This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
/
artifact.go
70 lines (58 loc) · 1.7 KB
/
artifact.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
58
59
60
61
62
63
64
65
66
67
68
69
70
package boltdbstate
import (
"context"
"github.com/hashicorp/go-memdb"
pb "github.com/hashicorp/waypoint/pkg/server/gen"
"github.com/hashicorp/waypoint/pkg/serverstate"
bolt "go.etcd.io/bbolt"
)
var artifactOp = &appOperation{
Struct: (*pb.PushedArtifact)(nil),
Bucket: []byte("artifact"),
}
func init() {
artifactOp.register()
}
// ArtifactPut inserts or updates a artifact record.
func (s *State) ArtifactPut(ctx context.Context, update bool, b *pb.PushedArtifact) error {
return artifactOp.Put(s, update, b)
}
// ArtifactGet gets a artifact by ref.
func (s *State) ArtifactGet(ctx context.Context, ref *pb.Ref_Operation) (*pb.PushedArtifact, error) {
result, err := artifactOp.Get(s, ref)
if err != nil {
return nil, err
}
return result.(*pb.PushedArtifact), nil
}
func (s *State) ArtifactList(
ctx context.Context,
ref *pb.Ref_Application,
opts ...serverstate.ListOperationOption,
) ([]*pb.PushedArtifact, error) {
raw, err := artifactOp.List(s, serverstate.BuildListOperationOptions(ref, opts...))
if err != nil {
return nil, err
}
result := make([]*pb.PushedArtifact, len(raw))
for i, v := range raw {
result[i] = v.(*pb.PushedArtifact)
}
return result, nil
}
// ArtifactLatest gets the latest artifact that was completed successfully.
func (s *State) ArtifactLatest(
ctx context.Context,
ref *pb.Ref_Application,
ws *pb.Ref_Workspace,
) (*pb.PushedArtifact, error) {
result, err := artifactOp.Latest(s, ref, ws)
if err != nil {
return nil, err
}
return result.(*pb.PushedArtifact), nil
}
// artifactDelete deletes the artifact from the DB
func (s *State) artifactDelete(dbTxn *bolt.Tx, memTxn *memdb.Txn, a *pb.PushedArtifact) error {
return artifactOp.delete(dbTxn, memTxn, a)
}