-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.go
More file actions
105 lines (84 loc) · 2.63 KB
/
defaults.go
File metadata and controls
105 lines (84 loc) · 2.63 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
// Copyright (C) 2017-2019 Vanessa Sochat.
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
// License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package client
import (
"os"
"strings"
)
// getenv will return an environment variable, or return a default
func getenv(key string, fallback string) string {
value := os.Getenv(key)
if len(value) == 0 {
return fallback
}
return value
}
// getBoolEnv returns a boolean environment variable
func getBoolEnv(key string, fallback bool) bool {
value := os.Getenv(key)
// If the value isn't set, return False
if len(value) == 0 {
return fallback
}
// Ensure lowercase
value = strings.ToLower(value)
// Strings that are valid to indicate a setting of "True"
list := [5]string{"yes", "true", "t", "1", "y"}
for _, yes := range list {
if value == yes {
return true
}
}
return false
}
// getStringDefault returns the default for a string, or empty string
// if you need to add a new default from the environment, define it here
// and add it to client.go under ScifRecipe and NewScifRecipe (the init)
func getStringDefault(key string) string {
defaults := map[string]string{
"BASE": "/scif",
"DATA": "/scif/data",
"APPS": "/scif/apps",
"SHELL": "/bin/bash",
"ENTRYPOINT": "/bin/bash",
"ENTRYFOLDER": "",
}
if value, ok := defaults[key]; ok {
return value
}
return ""
}
// getBoolDefault returns the default for a bool, or false
func getBoolDefault(key string) bool {
defaults := map[string]bool{
"ALLOW_APPEND_PATHS": true,
}
if value, ok := defaults[key]; ok {
return value
}
return false
}
// An array of paths to append
// return all environment variables in a particular namespace, such as for
// SCIF apps based on starting with SCIF_APPS.
func getenvNamespace(prefix string) []string {
var namespace []string
for _, env := range os.Environ() {
// pair[0] is the key, pair[1] is value
pair := strings.Split(env, "=")
// If the key starts with prefix, add to namespace list
if strings.HasPrefix(pair[0], prefix) {
namespace = append(namespace, pair[1])
}
}
return namespace
}