-
Notifications
You must be signed in to change notification settings - Fork 13
/
subscriptionbuilder.go
55 lines (47 loc) · 1.65 KB
/
subscriptionbuilder.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
package apic
// TODO - this file should be able to be removed once Unified Catalog support has been removed
import (
"fmt"
)
//SubscriptionBuilder -
type SubscriptionBuilder interface {
UpdateEnumProperty(key, newValue, dataType string) SubscriptionBuilder
SetStringPropertyValue(key, value string) SubscriptionBuilder
Process() error
}
type subscriptionBuilder struct {
err error
subscription Subscription
propertyValues map[string]interface{}
}
// NewSubscriptionBuilder - Creates a new subscription builder to update a subscriptions property and status
func NewSubscriptionBuilder(subscription Subscription) SubscriptionBuilder {
return &subscriptionBuilder{
subscription: subscription,
propertyValues: make(map[string]interface{}),
}
}
// Process - use the subscription property values and update the subscription on API Central
func (s *subscriptionBuilder) Process() error {
if s.err != nil {
return s.err
}
return s.subscription.UpdatePropertyValues(s.propertyValues)
}
// UpdateEnumProperty - updates the catalog item with the new value that should be in the enum
func (s *subscriptionBuilder) UpdateEnumProperty(key, newValue, dataType string) SubscriptionBuilder {
err := s.subscription.UpdateEnumProperty(key, newValue, dataType)
if err != nil {
s.err = err
}
return s
}
// SetStringPropertyValue - save the key/value pair to the map for the value in this subscription
func (s *subscriptionBuilder) SetStringPropertyValue(key, value string) SubscriptionBuilder {
if _, ok := s.propertyValues[key]; ok {
s.err = fmt.Errorf("key %v already had a value, not updated", key)
} else {
s.propertyValues[key] = value
}
return s
}