gitea/manifests/bin/createadmin.sh
ange 0fd5175a1d
Some checks failed
/ deploy (push) Failing after 1m43s
fix: create user from secret instead of env
2024-12-22 06:15:20 +00:00

31 lines
867 B
Bash
Executable File

#!/bin/bash -e
function get_token() {
kubectl exec app-0 -- gitea admin user generate-access-token \
--username "$name" \
--token-name "${name^^}" \
--scopes "$scopes" \
| awk '{print $NF}'
}
name="$1"
scopes="$2"
email="$name@$BASE_URL"
secret="gitea-$name"
if ! kubectl get secret "$secret" > /dev/null 2>&1; then
kcreatesec "$secret" \
--from-literal=email="$email" \
--from-literal=username="$name" \
--from-literal=password="$(openssl rand -hex 32)"
SECRET="$secret" kapply common/createadmin.yaml
fi
if [ -n "$scopes" ]; then
kcreatesec "$secret" \
--from-literal=email="$email" \
--from-literal=username="$name" \
--from-literal=password="$(kgseckey "$secret" password)" \
--from-literal=token="$(kgseckey "$secret" token || get_token)"
fi