package promote import ( "context" "encoding/json" "github.com/google/go-containerregistry/pkg/name" "edge-infra.dev/pkg/edge/api/types" ) const ( InsertAction = "INSERT" PromotionTrue = "true" PromotionsTopic = "promotions" ) var Attributes = map[string]string{ "promotion": "true", } type promotionMessage struct { Action string `json:"action"` Digest string `json:"digest"` Tag string `json:"tag"` ProjectID string `json:"projectId"` Registry string `json:"registry"` Promotion string `json:"promotion"` } // Sends the message to the promotions Pub/Sub topic func (msg promotionMessage) Send(ctx context.Context, ps types.PubSubService) error { data, err := msg.data() if err != nil { return err } return ps.Send(ctx, PromotionsTopic, data, Attributes) } func (msg promotionMessage) data() ([]byte, error) { return json.Marshal(msg) } func newPromotionMessage(digest name.Digest, tag name.Tag, destinationRepo Repository) promotionMessage { return promotionMessage{ Action: InsertAction, Digest: digest.String(), Tag: tag.String(), ProjectID: destinationRepo.ProjectID, Registry: destinationRepo.Name, Promotion: PromotionTrue, } }