-
Notifications
You must be signed in to change notification settings - Fork 170
/
spec.go
112 lines (94 loc) · 2.47 KB
/
spec.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
package scaffold
import (
"fmt"
"strings"
)
type InfraSpec struct {
Parameters []Parameter
Services []ServiceSpec
// Databases to create
DbPostgres *DatabasePostgres
DbCosmosMongo *DatabaseCosmosMongo
}
type Parameter struct {
Name string
Value any
Type string
Secret bool
}
type DatabasePostgres struct {
DatabaseUser string
DatabaseName string
}
type DatabaseCosmosMongo struct {
DatabaseName string
}
type ServiceSpec struct {
Name string
Port int
// Front-end properties.
Frontend *Frontend
// Back-end properties
Backend *Backend
// Connection to a database
DbPostgres *DatabaseReference
DbCosmosMongo *DatabaseReference
DbRedis *DatabaseReference
}
type Frontend struct {
Backends []ServiceReference
}
type Backend struct {
Frontends []ServiceReference
}
type ServiceReference struct {
Name string
}
type DatabaseReference struct {
DatabaseName string
}
func containerAppExistsParameter(serviceName string) Parameter {
return Parameter{
Name: BicepName(serviceName) + "Exists",
Value: fmt.Sprintf("${SERVICE_%s_RESOURCE_EXISTS=false}",
strings.ReplaceAll(strings.ToUpper(serviceName), "-", "_")),
Type: "bool",
}
}
type serviceDef struct {
Settings []serviceDefSettings `json:"settings"`
}
type serviceDefSettings struct {
Name string `json:"name"`
Value string `json:"value"`
Secret bool `json:"secret,omitempty"`
SecretRef string `json:"secretRef,omitempty"`
CommentName string `json:"_comment_name,omitempty"`
CommentValue string `json:"_comment_value,omitempty"`
}
func serviceDefPlaceholder(serviceName string) Parameter {
return Parameter{
Name: BicepName(serviceName) + "Definition",
Value: serviceDef{
Settings: []serviceDefSettings{
{
Name: "",
Value: "${VAR}",
CommentName: "The name of the environment variable when running in Azure. If empty, ignored.",
//nolint:lll
CommentValue: "The value to provide. This can be a fixed literal, or an expression like ${VAR} to use the value of 'VAR' from the current environment.",
},
{
Name: "",
Value: "${VAR_S}",
Secret: true,
CommentName: "The name of the environment variable when running in Azure. If empty, ignored.",
//nolint:lll
CommentValue: "The value to provide. This can be a fixed literal, or an expression like ${VAR_S} to use the value of 'VAR_S' from the current environment.",
},
},
},
Type: "object",
Secret: true,
}
}