-
Notifications
You must be signed in to change notification settings - Fork 12
/
push.go
47 lines (36 loc) · 1.03 KB
/
push.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
package app
import (
"github.com/opcr-io/policy/oci"
"github.com/opcr-io/policy/parser"
"github.com/opcr-io/policy/pkg/errors"
)
func (c *PolicyApp) Push(userRef string) error {
defer c.Cancel()
ref, err := parser.CalculatePolicyRef(userRef, c.Configuration.DefaultDomain)
if err != nil {
return errors.PushFailed.WithError(err)
}
ociClient, err := oci.NewOCI(c.Context, c.Logger, c.getHosts, c.Configuration.PoliciesRoot())
if err != nil {
return errors.PushFailed.WithError(err)
}
refs, err := ociClient.ListReferences()
if err != nil {
return errors.PushFailed.WithError(err)
}
refDescriptor, ok := refs[ref]
if !ok {
return errors.NotFound.WithMessage("policy [%s] not in the local store", ref)
}
c.UI.Normal().
WithStringValue("digest", refDescriptor.Digest.String()).
Msgf("Resolved ref [%s].", ref)
digest, err := ociClient.Push(ref)
if err != nil {
return errors.PushFailed.WithError(err)
}
c.UI.Normal().
WithStringValue("digest", digest.String()).
Msgf("Pushed ref [%s].", ref)
return nil
}