forked from Dstack-TEE/dstack-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.sh
More file actions
84 lines (77 loc) · 2.09 KB
/
Copy pathfunctions.sh
File metadata and controls
84 lines (77 loc) · 2.09 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
#!/bin/bash
# Sanitizer helpers shared across scripts. Each function echoes the sanitized
# value on success; on failure it writes an error to stderr and returns non-zero.
sanitize_port() {
local candidate="$1"
if [[ "$candidate" =~ ^[0-9]+$ ]] && (( candidate >= 1 && candidate <= 65535 )); then
echo "$candidate"
else
echo "Error: Invalid PORT value: $candidate" >&2
return 1
fi
}
sanitize_domain() {
local candidate="$1"
if [ -z "$candidate" ]; then
echo ""
return 0
fi
if [[ "$candidate" =~ ^(\*\.)?[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$ ]]; then
echo "$candidate"
else
echo "Error: Invalid DOMAIN value: $candidate" >&2
return 1
fi
}
sanitize_target_endpoint() {
local candidate="$1"
if [ -z "$candidate" ]; then
echo ""
return 0
fi
if [[ "$candidate" =~ ^(grpc|https?)://[A-Za-z0-9._-]+(:[0-9]{1,5})?(/[A-Za-z0-9._~:/?&=%-]*)?$ ]]; then
echo "$candidate"
else
echo "Error: Invalid TARGET_ENDPOINT value: $candidate" >&2
return 1
fi
}
sanitize_client_max_body_size() {
local candidate="$1"
if [ -z "$candidate" ]; then
echo ""
return 0
fi
if [[ "$candidate" =~ ^[0-9]+[kKmMgG]?$ ]]; then
echo "$candidate"
else
echo "Warning: Ignoring invalid CLIENT_MAX_BODY_SIZE value: $candidate" >&2
echo ""
fi
}
sanitize_dns_label() {
local candidate="$1"
if [ -z "$candidate" ]; then
echo "Error: TXT_PREFIX cannot be empty" >&2
return 1
fi
if [[ "$candidate" =~ ^[A-Za-z0-9_-]+$ ]]; then
echo "$candidate"
else
echo "Error: Invalid TXT_PREFIX value: $candidate" >&2
return 1
fi
}
sanitize_proxy_timeout() {
local candidate="$1"
if [ -z "$candidate" ]; then
echo ""
return 0
fi
if [[ "$candidate" =~ ^[0-9]+[smh]?$ ]]; then
echo "$candidate"
else
echo "Warning: Ignoring invalid proxy timeout value: $candidate" >&2
echo ""
fi
}