/
types.go
91 lines (76 loc) · 2.17 KB
/
types.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package configOperator
import (
"bytes"
"encoding/json"
"k8s.io/api/core/v1"
"github.com/pkg/errors"
)
// This is required because importing core/v1/Secret leads to a double import and redefinition
// of log_dir
type BindingSecret = v1.Secret
type Variant struct {
Name string `json:"name"`
Description string `json:"description"`
VariantID string `json:"variantID"`
Secret string `json:"secret"`
}
type AndroidVariant struct {
ProjectNumber string `json:"projectNumber"`
GoogleKey string `json:"googleKey"`
Variant
}
type IOSVariant struct {
Certificate []byte `json:"certificate"`
Passphrase string `json:"passphrase"`
Production bool `json:"production"`
Variant
}
type PushApplication struct {
ApplicationId string `json:"applicationId"`
}
func (this *AndroidVariant) getJson() ([]byte, error) {
config := map[string]string{
"senderId": this.ProjectNumber,
"variantId": this.VariantID,
"variantSecret": this.Secret,
}
buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
err := encoder.Encode(config)
return buffer.Bytes(), err
}
func (this *IOSVariant) getJson() ([]byte, error) {
config := map[string]string{
"variantId": this.VariantID,
"variantSecret": this.Secret,
}
buffer := &bytes.Buffer{}
encoder := json.NewEncoder(buffer)
encoder.SetEscapeHTML(false)
err := encoder.Encode(config)
return buffer.Bytes(), err
}
type UPSClientConfig struct {
Android *map[string]string `json:"android,omitempty"`
IOS *map[string]string `json:"ios,omitempty"`
}
type VariantServiceBindingMapping struct {
VariantId string
ServiceBindingId string
}
func GetClientConfigRepresentation(variantId, serviceBindingId string) (VariantServiceBindingMapping, error) {
config := VariantServiceBindingMapping{
VariantId: variantId,
ServiceBindingId: serviceBindingId,
}
return config, config.Validate()
}
func (configRepresentation *VariantServiceBindingMapping) Validate() error {
if configRepresentation.VariantId == "" {
return errors.New("missing variantId")
} else if configRepresentation.ServiceBindingId == "" {
return errors.New("missing serviceBindingId")
}
return nil
}