-
Notifications
You must be signed in to change notification settings - Fork 54
/
app.go
127 lines (109 loc) · 3.45 KB
/
app.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package payloads
import (
"fmt"
"net/url"
"code.cloudfoundry.org/korifi/api/config"
"code.cloudfoundry.org/korifi/api/repositories"
)
// DefaultLifecycleConfig is overwritten by main.go
var DefaultLifecycleConfig = config.DefaultLifecycleConfig{
Type: "buildpack",
Stack: "cflinuxfs3",
StagingMemoryMB: 1024,
StagingDiskMB: 1024,
}
type AppCreate struct {
Name string `json:"name" validate:"required"`
EnvironmentVariables map[string]string `json:"environment_variables"`
Relationships AppRelationships `json:"relationships" validate:"required"`
Lifecycle *Lifecycle `json:"lifecycle"`
Metadata Metadata `json:"metadata"`
}
type AppRelationships struct {
Space Relationship `json:"space" validate:"required"`
}
func (p AppCreate) ToAppCreateMessage() repositories.CreateAppMessage {
lifecycleBlock := repositories.Lifecycle{
Type: DefaultLifecycleConfig.Type,
Data: repositories.LifecycleData{
Stack: DefaultLifecycleConfig.Stack,
},
}
if p.Lifecycle != nil {
lifecycleBlock.Data.Stack = p.Lifecycle.Data.Stack
lifecycleBlock.Data.Buildpacks = p.Lifecycle.Data.Buildpacks
}
return repositories.CreateAppMessage{
Name: p.Name,
SpaceGUID: p.Relationships.Space.Data.GUID,
Metadata: repositories.Metadata(p.Metadata),
State: repositories.StoppedState,
Lifecycle: lifecycleBlock,
EnvironmentVariables: p.EnvironmentVariables,
}
}
type AppSetCurrentDroplet struct {
Relationship `json:",inline" validate:"required"`
}
type AppList struct {
Names string
GUIDs string
SpaceGuids string
}
func (a *AppList) ToMessage() repositories.ListAppsMessage {
return repositories.ListAppsMessage{
Names: ParseArrayParam(a.Names),
Guids: ParseArrayParam(a.GUIDs),
SpaceGuids: ParseArrayParam(a.SpaceGuids),
}
}
func (a *AppList) SupportedKeys() []string {
return []string{"names", "guids", "space_guids", "order_by"}
}
func (a *AppList) DecodeFromURLValues(values url.Values) error {
a.Names = values.Get("names")
a.GUIDs = values.Get("guids")
a.SpaceGuids = values.Get("space_guids")
return nil
}
type AppPatchEnvVars struct {
Var map[string]interface{} `json:"var" validate:"required,dive,keys,startsnotwith=VCAP_,startsnotwith=VMC_,ne=PORT,endkeys"`
}
func (a *AppPatchEnvVars) ToMessage(appGUID, spaceGUID string) repositories.PatchAppEnvVarsMessage {
message := repositories.PatchAppEnvVarsMessage{
AppGUID: appGUID,
SpaceGUID: spaceGUID,
EnvironmentVariables: map[string]*string{},
}
for k, v := range a.Var {
switch v := v.(type) {
case nil:
message.EnvironmentVariables[k] = nil
case bool:
stringVar := fmt.Sprintf("%t", v)
message.EnvironmentVariables[k] = &stringVar
case float32:
stringVar := fmt.Sprintf("%f", v)
message.EnvironmentVariables[k] = &stringVar
case int:
stringVar := fmt.Sprintf("%d", v)
message.EnvironmentVariables[k] = &stringVar
case string:
message.EnvironmentVariables[k] = &v
}
}
return message
}
type AppPatch struct {
Metadata MetadataPatch `json:"metadata"`
}
func (a *AppPatch) ToMessage(appGUID, spaceGUID string) repositories.PatchAppMetadataMessage {
return repositories.PatchAppMetadataMessage{
AppGUID: appGUID,
SpaceGUID: spaceGUID,
MetadataPatch: repositories.MetadataPatch{
Annotations: a.Metadata.Annotations,
Labels: a.Metadata.Labels,
},
}
}