-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathvalues.go
More file actions
119 lines (100 loc) · 2.72 KB
/
Copy pathvalues.go
File metadata and controls
119 lines (100 loc) · 2.72 KB
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
package common
import (
"errors"
"net"
"os"
"strings"
"time"
"github.com/gobwas/glob"
)
var NotFoundError error = errors.New("resource not found")
var NotImplementedError error = errors.New("resource method not implemented")
// <0=disabled, 0=auto, >0=fixed
type Spot float64
const (
SpotDisabled Spot = -1
SpotEnabled Spot = 0
)
type Status map[StatusCode]int
type StatusCode string
const (
StatusCodeActive StatusCode = "running"
StatusCodeSucceeded StatusCode = "succeeded"
StatusCodeFailed StatusCode = "failed"
StatusCodeTimeout StatusCode = "timeout"
)
type Size struct {
Storage int
Machine string
}
type Event struct {
Time time.Time
Code string
Description []string
}
// RemoteStorage contains the configuration for the cloud storage container
// used by the task.
type RemoteStorage struct {
// Container stores the id of the container to be used.
Container string
// Path stores the subdirectory inside the container.
Path string
// Config stores provider-specific configuration keys for accessing the pre-allocated
// storage container.
Config map[string]string
}
type Task struct {
Size Size
Environment Environment
Firewall Firewall
PermissionSet string
Spot Spot
Parallelism uint16
RemoteStorage *RemoteStorage
Addresses []net.IP
Status Status
Events []Event
}
// Firewall
type Firewall struct {
Ingress FirewallRule
Egress FirewallRule
}
// Firewall rule: not specified fields mean "allow any"; sepcified but empty mean "allow none";
// ports are both TCP and UDP; when ports is not specified, it will allow ingress to every port
// and every protocol, not only TCP&UDP
type FirewallRule struct {
Nets *[]net.IPNet
Ports *[]uint16
}
type Environment struct {
Image string
Script string
Variables Variables
Timeout time.Duration
Directory string
DirectoryOut string
ExcludeList []string
}
type Variables map[string]*string
// Enrich takes a map[string]*string of environment variables and, when a map value
// is <nil>, tries to get the value from the process environment variables. If
// the map key is a valid glob and the value is <nil>, all the matching environment
// variables will be set in the resulting map.
func (v Variables) Enrich() map[string]string {
result := make(map[string]string)
for name, value := range map[string]*string(v) {
if value == nil {
// FIXME: remove Replace and QuoteMeta to enable extended glob.
g := glob.MustCompile(strings.ReplaceAll(glob.QuoteMeta(name), `\*`, `*`))
for _, variable := range os.Environ() {
if key := strings.Split(variable, "=")[0]; g.Match(key) {
result[key] = os.Getenv(key)
}
}
} else {
result[name] = *value
}
}
return result
}