This repository has been archived by the owner on Nov 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
/
subscription.go
58 lines (52 loc) · 1.65 KB
/
subscription.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
///////////////////////////////////////////////////////////////////////
// Copyright (c) 2017 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
///////////////////////////////////////////////////////////////////////
package entities
import (
"github.com/go-openapi/swag"
"github.com/vmware/dispatch/pkg/api/v1"
"github.com/vmware/dispatch/pkg/entity-store"
"github.com/vmware/dispatch/pkg/utils"
)
// NO TESTS
// Subscription struct represents a single subscription of subscriber to publisher
type Subscription struct {
entitystore.BaseEntity
EventType string `json:"eventType"`
Function string `json:"function"`
Secrets []string `json:"secrets,omitempty"`
}
// ToModel converts subscription to swagger model
func (s *Subscription) ToModel() *v1.Subscription {
var tags []*v1.Tag
for k, v := range s.Tags {
tags = append(tags, &v1.Tag{Key: k, Value: v})
}
m := v1.Subscription{
Name: swag.String(s.Name),
Kind: utils.SubscriptionKind,
EventType: swag.String(s.EventType),
Function: &s.Function,
Status: v1.Status(s.Status),
Secrets: s.Secrets,
CreatedTime: s.CreatedTime.Unix(),
ModifiedTime: s.ModifiedTime.Unix(),
Tags: tags,
}
return &m
}
// FromModel builds subscription based on swagger model
func (s *Subscription) FromModel(m *v1.Subscription, orgID string) {
tags := make(map[string]string)
for _, t := range m.Tags {
tags[t.Key] = t.Value
}
s.BaseEntity.OrganizationID = orgID
s.BaseEntity.Name = *m.Name
s.BaseEntity.Status = entitystore.Status(m.Status)
s.BaseEntity.Tags = tags
s.EventType = *m.EventType
s.Function = *m.Function
s.Secrets = m.Secrets
}