...
1 package promote
2
3 import (
4 "context"
5 "encoding/json"
6
7 "github.com/google/go-containerregistry/pkg/name"
8
9 "edge-infra.dev/pkg/edge/api/types"
10 )
11
12 const (
13 InsertAction = "INSERT"
14 PromotionTrue = "true"
15 PromotionsTopic = "promotions"
16 )
17
18 var Attributes = map[string]string{
19 "promotion": "true",
20 }
21
22 type promotionMessage struct {
23 Action string `json:"action"`
24 Digest string `json:"digest"`
25 Tag string `json:"tag"`
26 ProjectID string `json:"projectId"`
27 Registry string `json:"registry"`
28 Promotion string `json:"promotion"`
29 }
30
31
32 func (msg promotionMessage) Send(ctx context.Context, ps types.PubSubService) error {
33 data, err := msg.data()
34 if err != nil {
35 return err
36 }
37
38 return ps.Send(ctx, PromotionsTopic, data, Attributes)
39 }
40 func (msg promotionMessage) data() ([]byte, error) {
41 return json.Marshal(msg)
42 }
43
44 func newPromotionMessage(digest name.Digest, tag name.Tag, destinationRepo Repository) promotionMessage {
45 return promotionMessage{
46 Action: InsertAction,
47 Digest: digest.String(),
48 Tag: tag.String(),
49 ProjectID: destinationRepo.ProjectID,
50 Registry: destinationRepo.Name,
51 Promotion: PromotionTrue,
52 }
53 }
54
View as plain text