This commit is contained in:
parent
0a86bed0ce
commit
0fd5175a1d
@ -2,32 +2,29 @@
|
|||||||
|
|
||||||
function get_token() {
|
function get_token() {
|
||||||
kubectl exec app-0 -- gitea admin user generate-access-token \
|
kubectl exec app-0 -- gitea admin user generate-access-token \
|
||||||
--username "$NAME" \
|
--username "$name" \
|
||||||
--token-name "${NAME^^}" \
|
--token-name "${name^^}" \
|
||||||
--scopes "$scopes" \
|
--scopes "$scopes" \
|
||||||
| awk '{print $NF}'
|
| awk '{print $NF}'
|
||||||
}
|
}
|
||||||
|
|
||||||
export NAME="$1"
|
name="$1"
|
||||||
scopes="$2"
|
scopes="$2"
|
||||||
export EMAIL="$NAME@$BASE_URL"
|
email="$name@$BASE_URL"
|
||||||
export SECRET="gitea-$NAME"
|
secret="gitea-$name"
|
||||||
|
|
||||||
if ! kubectl get secret "$SECRET" > /dev/null 2>&1; then
|
if ! kubectl get secret "$secret" > /dev/null 2>&1; then
|
||||||
p="$(openssl rand -hex 32)"
|
kcreatesec "$secret" \
|
||||||
kapply common/createadmin.yaml
|
--from-literal=email="$email" \
|
||||||
else
|
--from-literal=username="$name" \
|
||||||
p="$(kgseckey "$SECRET" password)"
|
--from-literal=password="$(openssl rand -hex 32)"
|
||||||
|
SECRET="$secret" kapply common/createadmin.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
opts=()
|
|
||||||
if [ -n "$scopes" ]; then
|
if [ -n "$scopes" ]; then
|
||||||
token="$(kgseckey "$SECRET" token || get_token)"
|
kcreatesec "$secret" \
|
||||||
opts+=(--from-literal=token="$token")
|
--from-literal=email="$email" \
|
||||||
|
--from-literal=username="$name" \
|
||||||
|
--from-literal=password="$(kgseckey "$secret" password)" \
|
||||||
|
--from-literal=token="$(kgseckey "$secret" token || get_token)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kcreatesec "$SECRET" \
|
|
||||||
--from-literal=email="$NAME@$BASE_URL" \
|
|
||||||
--from-literal=username="$NAME" \
|
|
||||||
--from-literal=password="$p" \
|
|
||||||
"${opts[@]}"
|
|
||||||
|
@ -10,17 +10,20 @@ spec:
|
|||||||
containers:
|
containers:
|
||||||
- name: createuser
|
- name: createuser
|
||||||
image: "$IMAGEAPP"
|
image: "$IMAGEAPP"
|
||||||
|
envFrom:
|
||||||
|
- secretRef:
|
||||||
|
name: "$SECRET"
|
||||||
command:
|
command:
|
||||||
- bash
|
- bash
|
||||||
- -c
|
- -c
|
||||||
- |
|
- |
|
||||||
gitea admin user change-password --must-change-password=false \
|
gitea admin user change-password --must-change-password=false
|
||||||
--username "$NAME" \
|
--username "$username"
|
||||||
--password "$PASS" 2> /dev/null \
|
--password "$password"
|
||||||
|| gitea admin user create --admin --must-change-password=false \
|
|| gitea admin user create --admin --must-change-password=false
|
||||||
--email "$EMAIL" \
|
--email "$email"
|
||||||
--username "$NAME" \
|
--username "$username"
|
||||||
--password "$PASS"
|
--password "$password"
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: config
|
- name: config
|
||||||
mountPath: /etc/gitea/app.ini
|
mountPath: /etc/gitea/app.ini
|
||||||
|
Loading…
Reference in New Issue
Block a user