devzone 0.36.7 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ #!/usr/bin/env bash
2
+ # Argo CD Application manifest of devzone (#516), printed on stdout:
3
+ # application.sh <name> <kind> <destination namespace> <repo url> <revision> <path> [key=value ...]
4
+ # kind: workspace | service | project | root (label devzone.io/kind). Each key=value
5
+ # is a Helm parameter of the source. Automated sync with prune and selfHeal,
6
+ # the destination namespace created, the resources deleted with the
7
+ # Application (finalizer). The Application lives in devzone-argocd.
8
+ # bash 3.2 (macOS): used by the workstation and by the container.
9
+ set -euo pipefail
10
+
11
+ usage() {
12
+ echo "usage: application.sh <name> <kind> <destination namespace> <repo url> <revision> <path> [key=value ...]" >&2
13
+ exit 2
14
+ }
15
+
16
+ [ "$#" -ge 6 ] || usage
17
+ name="$1" kind="$2" namespace="$3" repo="$4" revision="$5" path="$6"
18
+ shift 6
19
+ case "$kind" in
20
+ workspace | service | project | root) ;;
21
+ *) echo "application.sh: unknown kind: $kind (workspace, service, project, root)" >&2; exit 2 ;;
22
+ esac
23
+ case "$name" in
24
+ '' | *[!a-z0-9-]* | -*) echo "application.sh: invalid name: ${name:-(none)} (lowercase letters, digits, dashes)" >&2; exit 2 ;;
25
+ esac
26
+ if [ -z "$namespace" ] || [ -z "$repo" ] || [ -z "$revision" ] || [ -z "$path" ]; then
27
+ usage
28
+ fi
29
+
30
+ cat <<EOF
31
+ apiVersion: argoproj.io/v1alpha1
32
+ kind: Application
33
+ metadata:
34
+ name: $name
35
+ namespace: devzone-argocd
36
+ labels:
37
+ app.kubernetes.io/managed-by: devzone
38
+ devzone.io/kind: $kind
39
+ finalizers:
40
+ - resources-finalizer.argocd.argoproj.io
41
+ spec:
42
+ project: default
43
+ source:
44
+ repoURL: $repo
45
+ targetRevision: $revision
46
+ path: $path
47
+ EOF
48
+ if [ "$#" -gt 0 ]; then
49
+ echo " helm:"
50
+ echo " parameters:"
51
+ for kv in "$@"; do
52
+ case "$kv" in
53
+ *=*) ;;
54
+ *) echo "application.sh: Helm parameter without value: $kv" >&2; exit 2 ;;
55
+ esac
56
+ printf ' - name: %s\n value: "%s"\n' "${kv%%=*}" "${kv#*=}"
57
+ done
58
+ fi
59
+ cat <<EOF
60
+ destination:
61
+ server: https://kubernetes.default.svc
62
+ namespace: $namespace
63
+ syncPolicy:
64
+ automated:
65
+ prune: true
66
+ selfHeal: true
67
+ syncOptions:
68
+ - CreateNamespace=true
69
+ EOF
@@ -0,0 +1,262 @@
1
+ #!/usr/bin/env bash
2
+ # Applications of the user's projects in the Argo CD of devzone (#516),
3
+ # declared in .argocd.conf (conf.sh) and reconciled:
4
+ # argocd_app add <repo url> [path] [--name N] [--revision R] [--namespace NS] [--token T] [--username U]
5
+ # argocd_app list
6
+ # argocd_app remove <N>
7
+ # apps_reconcile every [app N] of .argocd.conf applied, the others removed
8
+ # Sourced by the container (argocd.sh: kubectl --context devzone) and by the
9
+ # workstation (manage/scripts/argocd-services.sh), after conf.sh and
10
+ # gitops.sh. The includer defines argocd_kubectl, APPS_GENERATOR, APPS_CMD,
11
+ # ARGOCD_CONF and ARGOCD_CONF_DIR (the devzone folder: token-file paths are
12
+ # relative to it), and may define apps_gitlab_token (root token of the
13
+ # devzone GitLab, on stdout).
14
+ # Application app-<N> in devzone-argocd, resources in devzone-app-<N>. GitHub
15
+ # or any public repository: nothing else. A private one: --token (kept in
16
+ # workspace/.argocd/tokens/<N>, 600, out of Git) or token-file, and username
17
+ # (root by default), in a repository Secret, never in the Application. The
18
+ # GitLab of devzone: its gitlab.localhost URL is rewritten to the service of
19
+ # the cluster, the root token of the module is used unless a token is given,
20
+ # and the NetworkPolicy of devzone-gitlab lets the devzone namespaces in.
21
+ # bash 3.2 (macOS).
22
+
23
+ APPS_NS="devzone-argocd"
24
+ : "${APPS_CMD:=devzone argocd app}"
25
+ : "${APPS_GITLAB_NS:=devzone-gitlab}"
26
+
27
+ apps_usage() {
28
+ echo "usage: $APPS_CMD add <repo url> [path] [--name N] [--revision R] [--namespace NS] [--token T] [--username U] | list | remove <N>" >&2
29
+ return 2
30
+ }
31
+
32
+ apps_name_from_url() {
33
+ local n="$1"
34
+ n="${n%/}"
35
+ n="${n##*/}"
36
+ n="${n%.git}"
37
+ printf '%s' "$n" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9-' '-' | sed 's/^-*//; s/-*$//'
38
+ }
39
+
40
+ apps_name_valid() {
41
+ case "${1:-}" in
42
+ '' | *[!a-z0-9-]* | -*) return 1 ;;
43
+ esac
44
+ [ "${#1}" -le 40 ]
45
+ }
46
+
47
+ apps_is_devzone_gitlab() {
48
+ case "$1" in
49
+ http://gitlab.localhost:8929/* | http://gitlab.localhost/* | https://gitlab.localhost/* | https://gitlab.localhost:*/*) return 0 ;;
50
+ esac
51
+ return 1
52
+ }
53
+
54
+ # Address Argo CD reaches: the webservice of the GitLab namespace
55
+ apps_repo_internal() {
56
+ local url="$1" path
57
+ if apps_is_devzone_gitlab "$url"; then
58
+ path="${url#*://gitlab.localhost}"
59
+ case "$path" in :*) path="/${path#*/}" ;; esac
60
+ printf 'http://gitlab-webservice-default.%s.svc:8181%s' "$APPS_GITLAB_NS" "$path"
61
+ else
62
+ printf '%s' "$url"
63
+ fi
64
+ }
65
+
66
+ # Token of an app: its token-file (relative to the devzone folder), else the
67
+ # root token of the devzone GitLab for a devzone GitLab repository
68
+ apps_token_of() {
69
+ local file="$1" repo="$2"
70
+ if [ -n "$file" ]; then
71
+ case "$file" in /*) cat "$file" 2>/dev/null ;; *) cat "$ARGOCD_CONF_DIR/$file" 2>/dev/null ;; esac
72
+ return 0
73
+ fi
74
+ apps_is_devzone_gitlab "$repo" || return 0
75
+ if command -v apps_gitlab_token >/dev/null 2>&1; then
76
+ apps_gitlab_token
77
+ else
78
+ cat "$ARGOCD_CONF_DIR/workspace/.gitlab/root-token" 2>/dev/null
79
+ fi
80
+ }
81
+
82
+ apps_repo_secret() {
83
+ local name="$1" url="$2" username="$3" token="$4"
84
+ argocd_kubectl -n "$APPS_NS" apply -f - >/dev/null <<EOF
85
+ apiVersion: v1
86
+ kind: Secret
87
+ metadata:
88
+ name: repo-$name
89
+ namespace: $APPS_NS
90
+ labels:
91
+ argocd.argoproj.io/secret-type: repository
92
+ app.kubernetes.io/managed-by: devzone
93
+ type: Opaque
94
+ stringData:
95
+ type: git
96
+ url: $url
97
+ username: $username
98
+ password: $token
99
+ EOF
100
+ }
101
+
102
+ # Ingress of the GitLab namespace opened to the devzone namespaces (Argo CD
103
+ # repo-server among them): same rule as devzone postgres autoriser
104
+ apps_gitlab_allow_argocd() {
105
+ argocd_kubectl -n "$APPS_GITLAB_NS" patch networkpolicy devzone-meme-namespace --type merge \
106
+ -p '{"spec":{"ingress":[{"from":[{"podSelector":{},"namespaceSelector":{"matchLabels":{"app.kubernetes.io/managed-by":"devzone"}}}]}]}}' >/dev/null 2>&1 ||
107
+ echo "⚠ NetworkPolicy of $APPS_GITLAB_NS not opened to Argo CD: devzone postgres autoriser $APPS_NS, or the sync will fail" >&2
108
+ }
109
+
110
+ # One [app N] of .argocd.conf applied: Secret when a token exists, then the Application
111
+ apps_apply_one() {
112
+ local name="$1" repo path revision namespace username file token url
113
+ repo="$(conf_get "app $name" repo)"
114
+ if [ -z "$repo" ]; then
115
+ echo "⚠ [app $name] without repo in $ARGOCD_CONF: skipped" >&2
116
+ return 0
117
+ fi
118
+ path="$(conf_get "app $name" path)"; path="${path:-.}"
119
+ revision="$(conf_get "app $name" revision)"; revision="${revision:-HEAD}"
120
+ namespace="$(conf_get "app $name" namespace)"; namespace="${namespace:-devzone-app-$name}"
121
+ username="$(conf_get "app $name" username)"; username="${username:-root}"
122
+ file="$(conf_get "app $name" token-file)"
123
+ url="$(apps_repo_internal "$repo")"
124
+ token="$(apps_token_of "$file" "$repo")"
125
+ if apps_is_devzone_gitlab "$repo"; then
126
+ if [ -z "$token" ]; then
127
+ echo "✖ [app $name]: token of the devzone GitLab not found (workspace/.gitlab/root-token or token-file)" >&2
128
+ return 1
129
+ fi
130
+ apps_gitlab_allow_argocd
131
+ fi
132
+ if [ -n "$token" ]; then
133
+ apps_repo_secret "$name" "$url" "$username" "$token" || return 1
134
+ fi
135
+ gitops_apply_application "app-$name" project "$namespace" "$url" "$revision" "$path" || return 1
136
+ echo "✔ Application app-$name: $url ($path, $revision) → namespace $namespace${token:+; credentials in the Secret repo-$name}"
137
+ }
138
+
139
+ # An Application leaves the cluster with its resources, its repository
140
+ # Secret and the namespace devzone created for it (never one chosen by hand)
141
+ apps_purge() {
142
+ local name="$1" namespace
143
+ namespace="$(argocd_kubectl -n "$APPS_NS" get application.argoproj.io "app-$name" \
144
+ -o jsonpath='{.spec.destination.namespace}' 2>/dev/null)" || namespace=""
145
+ gitops_delete_application "app-$name" || return 1
146
+ argocd_kubectl -n "$APPS_NS" delete secret "repo-$name" --ignore-not-found >/dev/null 2>&1 || true
147
+ case "$namespace" in
148
+ devzone-app-*) argocd_kubectl delete namespace "$namespace" --ignore-not-found --wait=true >/dev/null 2>&1 || true ;;
149
+ esac
150
+ echo "✔ Application app-$name removed with its resources${namespace:+ (namespace $namespace)}"
151
+ }
152
+
153
+ # Every [app N] applied, the project Applications absent from the file removed
154
+ apps_reconcile() {
155
+ local name declared=" " app code=0
156
+ while IFS= read -r name; do
157
+ [ -n "$name" ] || continue
158
+ declared="$declared$name "
159
+ apps_apply_one "$name" || code=1
160
+ done <<<"$(conf_sections app)"
161
+ while IFS= read -r app; do
162
+ [ -n "$app" ] || continue
163
+ app="${app#*/}"
164
+ app="${app#app-}"
165
+ case "$declared" in *" $app "*) continue ;; esac
166
+ apps_purge "$app" || code=1
167
+ done <<<"$(argocd_kubectl -n "$APPS_NS" get applications.argoproj.io -l devzone.io/kind=project -o name 2>/dev/null || true)"
168
+ return "$code"
169
+ }
170
+
171
+ apps_add() {
172
+ local repo="" path="" name="" revision="" namespace="" token="" username=""
173
+ local arg expect="" pos=0 keys file
174
+ for arg in "$@"; do
175
+ if [ -n "$expect" ]; then
176
+ case "$expect" in
177
+ name) name="$arg" ;; revision) revision="$arg" ;; namespace) namespace="$arg" ;;
178
+ token) token="$arg" ;; username) username="$arg" ;;
179
+ esac
180
+ expect=""
181
+ continue
182
+ fi
183
+ case "$arg" in
184
+ --name) expect=name ;;
185
+ --revision) expect=revision ;;
186
+ --namespace) expect=namespace ;;
187
+ --token) expect=token ;;
188
+ --username) expect=username ;;
189
+ -*) echo "✖ $APPS_CMD add: unknown option: $arg" >&2; apps_usage; return 2 ;;
190
+ *)
191
+ pos=$((pos + 1))
192
+ case "$pos" in
193
+ 1) repo="$arg" ;;
194
+ 2) path="$arg" ;;
195
+ *) echo "✖ $APPS_CMD add: unexpected argument: $arg" >&2; apps_usage; return 2 ;;
196
+ esac
197
+ ;;
198
+ esac
199
+ done
200
+ if [ -n "$expect" ]; then
201
+ echo "✖ $APPS_CMD add: --$expect needs a value" >&2
202
+ return 2
203
+ fi
204
+ [ -n "$repo" ] || { apps_usage; return 2; }
205
+ case "$repo" in
206
+ https://* | http://* | ssh://* | git@*) ;;
207
+ *) echo "✖ $APPS_CMD add: repository URL expected (https://…): $repo" >&2; return 2 ;;
208
+ esac
209
+ [ -n "$name" ] || name="$(apps_name_from_url "$repo")"
210
+ if ! apps_name_valid "$name"; then
211
+ echo "✖ $APPS_CMD add: invalid name: ${name:-(empty)} (lowercase letters, digits, dashes, 40 at most: --name N)" >&2
212
+ return 2
213
+ fi
214
+ if apps_is_devzone_gitlab "$repo" && [ -z "$token" ] && [ -z "$(apps_token_of "" "$repo")" ]; then
215
+ echo "✖ $APPS_CMD add: token of the devzone GitLab not found (workspace/.gitlab/root-token): --token T" >&2
216
+ return 2
217
+ fi
218
+ keys="repo=$repo path=${path:-.} revision=${revision:-HEAD} namespace=${namespace:-devzone-app-$name}"
219
+ [ -z "$username" ] || keys="$keys username=$username"
220
+ if [ -n "$token" ]; then
221
+ # The token stays out of the file and out of Git: workspace/ is ignored
222
+ file="workspace/.argocd/tokens/$name"
223
+ mkdir -p "$ARGOCD_CONF_DIR/workspace/.argocd/tokens"
224
+ chmod 700 "$ARGOCD_CONF_DIR/workspace/.argocd" "$ARGOCD_CONF_DIR/workspace/.argocd/tokens"
225
+ (umask 077 && printf '%s' "$token" >"$ARGOCD_CONF_DIR/$file")
226
+ keys="$keys token-file=$file"
227
+ fi
228
+ # shellcheck disable=SC2086
229
+ conf_set "app $name" $keys
230
+ apps_apply_one "$name" || return 1
231
+ echo " declared in $ARGOCD_CONF; sync status: $APPS_CMD list"
232
+ }
233
+
234
+ apps_list() {
235
+ argocd_kubectl -n "$APPS_NS" get applications.argoproj.io -l devzone.io/kind=project \
236
+ -o custom-columns='APPLICATION:.metadata.name,REPOSITORY:.spec.source.repoURL,PATH:.spec.source.path,REVISION:.spec.source.targetRevision,NAMESPACE:.spec.destination.namespace,SYNC:.status.sync.status,HEALTH:.status.health.status'
237
+ }
238
+
239
+ apps_remove() {
240
+ local name="${1:-}"
241
+ if ! apps_name_valid "$name"; then
242
+ echo "✖ $APPS_CMD remove <name> ($APPS_CMD list)" >&2
243
+ return 2
244
+ fi
245
+ if ! argocd_kubectl -n "$APPS_NS" get application.argoproj.io "app-$name" >/dev/null 2>&1 &&
246
+ ! conf_sections app | grep -qx -- "$name"; then
247
+ echo "✖ $APPS_CMD remove: no Application app-$name ($APPS_CMD list)" >&2
248
+ return 1
249
+ fi
250
+ conf_remove "app $name"
251
+ rm -f "$ARGOCD_CONF_DIR/workspace/.argocd/tokens/$name"
252
+ apps_purge "$name"
253
+ }
254
+
255
+ argocd_app() {
256
+ case "${1:-}" in
257
+ add) apps_add "${@:2}" ;;
258
+ list) apps_list ;;
259
+ remove) apps_remove "${@:2}" ;;
260
+ *) apps_usage ;;
261
+ esac
262
+ }
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
  # Module argocd (#411) : Argo CD dans le cluster des services de devzone.
3
3
  # argocd.sh installer | desinstaller | etat | relais-lancer | relais-arreter
4
+ # argocd.sh app add <repo url> [path] [--name N] [--revision R] | app list | app remove <N>
4
5
  # Namespace devzone-argocd isolé, relais 127.0.0.1:8443 dans le conteneur.
5
6
  # Mot de passe admin dans workspace/.argocd/admin.env (600), repris dans
6
7
  # .password ; jamais affiché.
@@ -195,14 +196,58 @@ relais() {
195
196
  fi
196
197
  }
197
198
 
199
+ # Applications of the projects (#516): shared with the workstation (apps.sh),
200
+ # here with the limited devzone context (aggregate roles of the chart)
201
+ # shellcheck disable=SC2034 # read by apps.sh
202
+ APPS_CMD="devzone argocd app"
203
+ # shellcheck disable=SC2034 # read by apps.sh
204
+ APPS_GENERATOR="$ICI/application.sh"
205
+ # shellcheck disable=SC2034 # read by apps.sh: GitLab namespace of this instance
206
+ APPS_GITLAB_NS="devzone-gitlab${INSTANCE_SUFFIX}"
207
+ # shellcheck disable=SC2034 # read by apps.sh
208
+ APPS_GITLAB_TOKEN_FILE="$RACINE/workspace/.gitlab/root-token"
209
+ # shellcheck disable=SC2034 # read by gitops.sh
210
+ GITOPS_CMD="devzone argocd init"
211
+ # shellcheck disable=SC2034 # read by conf.sh and apps.sh: .argocd.conf of the instance
212
+ ARGOCD_CONF_DIR="$RACINE"
213
+ # shellcheck disable=SC2034
214
+ ARGOCD_CONF="${DEVZONE_ARGOCD_CONF:-$RACINE/.argocd.conf}"
215
+ # shellcheck source=SCRIPTDIR/conf.sh
216
+ # shellcheck disable=SC1091
217
+ . "$ICI/conf.sh"
218
+ # shellcheck source=SCRIPTDIR/gitops.sh
219
+ # shellcheck disable=SC1091
220
+ . "$ICI/gitops.sh"
221
+ # shellcheck source=SCRIPTDIR/apps.sh
222
+ # shellcheck disable=SC1091
223
+ . "$ICI/apps.sh"
224
+ argocd_kubectl() { kubectl --context devzone "$@"; }
225
+
198
226
  case "${1:-}" in
199
227
  installer) installer ;;
200
228
  desinstaller) desinstaller ;;
201
229
  etat) etat ;;
202
230
  relais-lancer) relais ;;
203
231
  relais-arreter) relais_arreter argocd ;;
232
+ init)
233
+ # GitOps repository of the user (#516): created or designated, then
234
+ # the root Application when the module is installed
235
+ gitops_init "${@:2}" || exit $?
236
+ if installe; then gitops_root; fi
237
+ ;;
238
+ apply)
239
+ installe || refuse "module off: devzone enable argocd"
240
+ gitops_init && gitops_root && apps_reconcile
241
+ ;;
242
+ app)
243
+ if [ "${DEVZONE_WORKSPACE:-}" = kubernetes ]; then
244
+ refuse "in the workspace pod, on the workstation: devzone workspace argocd app ${*:2}"
245
+ fi
246
+ installe || refuse "module off: devzone enable argocd"
247
+ argocd_app "${@:2}"
248
+ ;;
204
249
  *)
205
- echo "devzone argocd : installer | desinstaller | etat" >&2
250
+ echo "devzone argocd : installer | desinstaller | etat | init [--repo <url>|--none] | apply | app add|list|remove" >&2
206
251
  exit 1
207
252
  ;;
208
253
  esac
@@ -0,0 +1,141 @@
1
+ #!/usr/bin/env bash
2
+ # Configuration file of the Argo CD of devzone (#516): .argocd.conf at the
3
+ # root of the devzone folder, the same shape as .repowarden.conf:
4
+ # [argocd]
5
+ # repo = https://github.com/<login>/devzone-argocd.git # none: direct apply
6
+ # [app demo]
7
+ # repo = https://github.com/argoproj/argocd-example-apps
8
+ # path = guestbook
9
+ # revision = HEAD
10
+ # namespace = devzone-app-demo
11
+ # username = root # private repositories
12
+ # token-file = workspace/.gitlab/root-token
13
+ # The file is the declaration, versioned with the devzone folder: devzone
14
+ # writes it (argocd init, app add, app remove) and applies it (workspace
15
+ # start, argocd apply). Tokens never go in it, only paths to them. The
16
+ # includer defines ARGOCD_CONF (the path of the file).
17
+ # conf_get <section> <key> value, empty when absent
18
+ # conf_sections <prefix> names of the sections "[<prefix> <name>]"
19
+ # conf_set <section> key=value... section replaced (or added at the end)
20
+ # conf_remove <section>
21
+ # bash 3.2 (macOS): no associative array, one pass per call.
22
+
23
+ conf_trim() {
24
+ local s="$1"
25
+ s="${s#"${s%%[![:space:]]*}"}"
26
+ s="${s%"${s##*[![:space:]]}"}"
27
+ printf '%s' "$s"
28
+ }
29
+
30
+ # Section name of a "[...]" line, trimmed
31
+ conf_section_of() {
32
+ local s="$1"
33
+ s="${s#\[}"
34
+ s="${s%\]}"
35
+ conf_trim "$s"
36
+ }
37
+
38
+ # Lines of the file as "section<TAB>key<TAB>value"; comments and blanks dropped
39
+ conf_entries() {
40
+ local line section="" key value
41
+ [ -f "$ARGOCD_CONF" ] || return 0
42
+ while IFS= read -r line || [ -n "$line" ]; do
43
+ line="$(conf_trim "$line")"
44
+ case "$line" in
45
+ '' | '#'*) continue ;;
46
+ '['*']') section="$(conf_section_of "$line")"; continue ;;
47
+ esac
48
+ case "$line" in *=*) ;; *) continue ;; esac
49
+ key="$(conf_trim "${line%%=*}")"
50
+ value="${line#*=}"
51
+ value="${value%%#*}"
52
+ value="$(conf_trim "$value")"
53
+ printf '%s\t%s\t%s\n' "$section" "$key" "$value"
54
+ done <"$ARGOCD_CONF"
55
+ }
56
+
57
+ conf_get() {
58
+ local s k v
59
+ while IFS="$(printf '\t')" read -r s k v; do
60
+ if [ "$s" = "$1" ] && [ "$k" = "$2" ]; then
61
+ printf '%s' "$v"
62
+ return 0
63
+ fi
64
+ done <<<"$(conf_entries)"
65
+ return 0
66
+ }
67
+
68
+ conf_sections() {
69
+ local line t n
70
+ [ -f "$ARGOCD_CONF" ] || return 0
71
+ while IFS= read -r line || [ -n "$line" ]; do
72
+ t="$(conf_trim "$line")"
73
+ case "$t" in
74
+ '['*']')
75
+ n="$(conf_section_of "$t")"
76
+ case "$n" in
77
+ "$1 "*)
78
+ n="$(conf_trim "${n#"$1"}")"
79
+ [ -z "$n" ] || printf '%s\n' "$n"
80
+ ;;
81
+ esac
82
+ ;;
83
+ esac
84
+ done <"$ARGOCD_CONF"
85
+ }
86
+
87
+ # The file without the section $1 (its header and its keys)
88
+ conf_without() {
89
+ local line t skip=0
90
+ [ -f "$ARGOCD_CONF" ] || return 0
91
+ while IFS= read -r line || [ -n "$line" ]; do
92
+ t="$(conf_trim "$line")"
93
+ case "$t" in
94
+ '['*']')
95
+ if [ "$(conf_section_of "$t")" = "$1" ]; then skip=1; continue; fi
96
+ skip=0
97
+ ;;
98
+ esac
99
+ [ "$skip" = 1 ] && continue
100
+ printf '%s\n' "$line"
101
+ done <"$ARGOCD_CONF"
102
+ }
103
+
104
+ conf_header() {
105
+ cat <<'EOF'
106
+ # Argo CD of devzone (#516): what devzone declares in its GitOps repository.
107
+ # Written by devzone (argocd init, app add, app remove), applied by
108
+ # devzone workspace argocd apply and by workspace start. Tokens never go
109
+ # here, only paths to them (token-file).
110
+ EOF
111
+ }
112
+
113
+ # Section $1 replaced by the key=value pairs that follow (added at the end
114
+ # when absent); blank lines squeezed
115
+ conf_set() {
116
+ local section="$1" tmp kv
117
+ shift
118
+ tmp="$(mktemp)"
119
+ if [ -f "$ARGOCD_CONF" ]; then
120
+ conf_without "$section" >"$tmp"
121
+ else
122
+ conf_header >"$tmp"
123
+ fi
124
+ {
125
+ echo
126
+ echo "[$section]"
127
+ for kv in "$@"; do
128
+ printf ' %s = %s\n' "${kv%%=*}" "${kv#*=}"
129
+ done
130
+ } >>"$tmp"
131
+ cat -s "$tmp" >"$ARGOCD_CONF"
132
+ rm -f "$tmp"
133
+ }
134
+
135
+ conf_remove() {
136
+ local tmp
137
+ [ -f "$ARGOCD_CONF" ] || return 0
138
+ tmp="$(mktemp)"
139
+ conf_without "$1" | cat -s >"$tmp"
140
+ mv "$tmp" "$ARGOCD_CONF"
141
+ }