feat: add deploy key client implementation
parent
0dac5121fd
commit
a4a34194f3
|
@ -0,0 +1,20 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -Exeuo pipefail
|
||||||
|
|
||||||
|
source integration/lib.sh
|
||||||
|
|
||||||
|
|
||||||
|
main() {
|
||||||
|
docker_compose_down || true
|
||||||
|
docker_compose_up
|
||||||
|
setup_env
|
||||||
|
wait_for_env
|
||||||
|
gitea_root
|
||||||
|
support_repo_init
|
||||||
|
fleet_repo_init
|
||||||
|
teardown_env
|
||||||
|
docker_compose_down
|
||||||
|
}
|
||||||
|
|
||||||
|
main
|
|
@ -25,6 +25,7 @@ class Gitea:
|
||||||
self.login()
|
self.login()
|
||||||
self.create_repository()
|
self.create_repository()
|
||||||
self.install_sso()
|
self.install_sso()
|
||||||
|
self.add_deploy_key()
|
||||||
|
|
||||||
def __add_credentials_parser(self, parser):
|
def __add_credentials_parser(self, parser):
|
||||||
group = parser.add_argument_group("credentials", "User credentials")
|
group = parser.add_argument_group("credentials", "User credentials")
|
||||||
|
@ -120,6 +121,28 @@ class Gitea:
|
||||||
|
|
||||||
self.install_sso_parser.set_defaults(func=run)
|
self.install_sso_parser.set_defaults(func=run)
|
||||||
|
|
||||||
|
def add_deploy_key(self):
|
||||||
|
def run(args, c: Session):
|
||||||
|
gitea = gitea_from_args(args, c=c)
|
||||||
|
gitea.login()
|
||||||
|
gitea.add_deploy_key(repo=args.repo_name, key=args.key_file)
|
||||||
|
|
||||||
|
self.add_deploy_key_parser = self.subparser.add_parser(
|
||||||
|
name="add_deploy_key",
|
||||||
|
description="Create repository on Gitea",
|
||||||
|
help="Add deploy key to a repository on Gitea",
|
||||||
|
)
|
||||||
|
self.__add_credentials_parser(self.add_deploy_key_parser)
|
||||||
|
self.add_deploy_key_parser.add_argument(
|
||||||
|
"repo_name",
|
||||||
|
type=str,
|
||||||
|
help="Name of the repository to which key should be added",
|
||||||
|
)
|
||||||
|
self.add_deploy_key_parser.add_argument(
|
||||||
|
"key_file", type=str, help="Path of the deploy key. Public key."
|
||||||
|
)
|
||||||
|
self.add_deploy_key_parser.set_defaults(func=run)
|
||||||
|
|
||||||
|
|
||||||
def dash_from_args(args, c: Session):
|
def dash_from_args(args, c: Session):
|
||||||
from .hostea import Hostea
|
from .hostea import Hostea
|
||||||
|
|
|
@ -70,8 +70,8 @@ class Gitea:
|
||||||
Install Gitea, first form that a user sees when a new instance is
|
Install Gitea, first form that a user sees when a new instance is
|
||||||
deployed
|
deployed
|
||||||
"""
|
"""
|
||||||
cwd = os.environ.get("PWD")
|
# cwd = os.environ.get("PWD")
|
||||||
user = os.environ.get("USER")
|
# user = os.environ.get("USER")
|
||||||
payload = {
|
payload = {
|
||||||
"db_type": "sqlite3",
|
"db_type": "sqlite3",
|
||||||
"db_host": "localhost:3306",
|
"db_host": "localhost:3306",
|
||||||
|
@ -81,16 +81,16 @@ class Gitea:
|
||||||
"ssl_mode": "disable",
|
"ssl_mode": "disable",
|
||||||
"db_schema": "",
|
"db_schema": "",
|
||||||
"charset": "utf8",
|
"charset": "utf8",
|
||||||
"db_path": f"{cwd}/tmp/gitea/db/gitea.db",
|
"db_path": "/data/gitea/gitea.db",
|
||||||
"app_name": "Gitea:+Git+with+a+cup+of+tea",
|
"app_name": "Gitea:+Git+with+a+cup+of+tea",
|
||||||
"repo_root_path": f"{cwd}/tmp/gitea/repos/",
|
"repo_root_path": "/data/git/repositories",
|
||||||
"lfs_root_path": f"{cwd}/tmp/gitea/lfs/",
|
"lfs_root_path": "/data/git/lfs",
|
||||||
"run_user": user,
|
"run_user": "git",
|
||||||
"domain": "localhost",
|
"domain": "localhost",
|
||||||
"ssh_port": "2222",
|
"ssh_port": "2221",
|
||||||
"http_port": "3000",
|
"http_port": "3000",
|
||||||
"app_url": self.get_uri(""),
|
"app_url": "http://localhost:3000/",
|
||||||
"log_root_path": f"{cwd}/tmp/gitea/log/",
|
"log_root_path": "/data/gitea/log",
|
||||||
"smtp_host": "",
|
"smtp_host": "",
|
||||||
"smtp_from": "",
|
"smtp_from": "",
|
||||||
"smtp_user": "",
|
"smtp_user": "",
|
||||||
|
@ -285,6 +285,18 @@ class Gitea:
|
||||||
|
|
||||||
resp = self.c.post(self.get_uri("/admin/auths/new"), data=payload)
|
resp = self.c.post(self.get_uri("/admin/auths/new"), data=payload)
|
||||||
|
|
||||||
|
def add_deploy_key(self, repo: str, key: str):
|
||||||
|
url = self.get_api_uri(f"/api/v1/repos/{self.username}/{repo}/keys")
|
||||||
|
with open(key, "r", encoding="utf-8") as f:
|
||||||
|
key = f.read()
|
||||||
|
payload = {
|
||||||
|
"key": key,
|
||||||
|
"read_only": False,
|
||||||
|
"title": f"{self.username}/{repo} Dashboard test key",
|
||||||
|
}
|
||||||
|
resp = self.c.post(url, json=payload)
|
||||||
|
assert resp.status_code == 201
|
||||||
|
|
||||||
|
|
||||||
class ParseSSOLogin(HTMLParser):
|
class ParseSSOLogin(HTMLParser):
|
||||||
url: str = None
|
url: str = None
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
readonly GITEA_PID_FILE=./tmp/gitea.pid
|
readonly SERVER_PID_FILE=./tmp/server.pid
|
||||||
readonly SERVER_PID_FILE=./tmp/gitea.pid
|
|
||||||
|
|
||||||
readonly DASHBOARD_URL="http://localhost:8000"
|
readonly DASHBOARD_URL="http://localhost:8000"
|
||||||
readonly GITEA_URL="http://localhost:3000"
|
readonly GITEA_URL="http://localhost:3000"
|
||||||
|
@ -17,11 +16,13 @@ readonly GITEA_ROOT_EMAIL="$GITEA_ROOT_USERNAME@example.org"
|
||||||
readonly GITEA_ROOT_PASSOWRD=supercomplicatedpassword
|
readonly GITEA_ROOT_PASSOWRD=supercomplicatedpassword
|
||||||
readonly GITEA_HOSTEA_SSO_NAME=hostea-sso
|
readonly GITEA_HOSTEA_SSO_NAME=hostea-sso
|
||||||
readonly GITEA_OIDC_CALLBACK="$GITEA_URL/user/oauth2/$GITEA_HOSTEA_SSO_NAME/callback"
|
readonly GITEA_OIDC_CALLBACK="$GITEA_URL/user/oauth2/$GITEA_HOSTEA_SSO_NAME/callback"
|
||||||
|
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY="tests/fleet-deploy-key.pub"
|
||||||
|
|
||||||
readonly GITEA_HOSTEA_USERNAME=hostea
|
readonly GITEA_HOSTEA_USERNAME=hostea
|
||||||
readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword
|
readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword
|
||||||
readonly GITEA_HOSTEA_EMAIL="$GITEA_HOSTEA_USERNAME@example.org"
|
readonly GITEA_HOSTEA_EMAIL="$GITEA_HOSTEA_USERNAME@example.org"
|
||||||
readonly GITEA_HOSTEA_SUPPORT_REPO="support"
|
readonly GITEA_HOSTEA_SUPPORT_REPO="support"
|
||||||
|
readonly GITEA_HOSTEA_FLEET_REPO="fleet"
|
||||||
|
|
||||||
readonly HOSTEA_CUSTOMER_USERNAME=batman
|
readonly HOSTEA_CUSTOMER_USERNAME=batman
|
||||||
readonly HOSTEA_CUSTOMER_PASSWORD=supercomplicatedpassword
|
readonly HOSTEA_CUSTOMER_PASSWORD=supercomplicatedpassword
|
||||||
|
@ -38,7 +39,6 @@ OIDC_CLIENT_ID=""
|
||||||
OIDC_CLIENT_SECRET=""
|
OIDC_CLIENT_SECRET=""
|
||||||
|
|
||||||
wait_for_env() {
|
wait_for_env() {
|
||||||
curl $DASHBOARD_URL || true
|
|
||||||
python -m integration \
|
python -m integration \
|
||||||
check_env $GITEA_URL $DASHBOARD_URL $MAILDEV_URL
|
check_env $GITEA_URL $DASHBOARD_URL $MAILDEV_URL
|
||||||
}
|
}
|
||||||
|
@ -76,14 +76,14 @@ gitea_root(){
|
||||||
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
||||||
$GITEA_ROOT_EMAIL \
|
$GITEA_ROOT_EMAIL \
|
||||||
$GITEA_URL
|
$GITEA_URL
|
||||||
python -m integration \
|
# python -m integration \
|
||||||
gitea install_sso \
|
# gitea install_sso \
|
||||||
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
# $GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
||||||
$GITEA_ROOT_EMAIL \
|
# $GITEA_ROOT_EMAIL \
|
||||||
$GITEA_URL \
|
# $GITEA_URL \
|
||||||
$GITEA_HOSTEA_SSO_NAME \
|
# $GITEA_HOSTEA_SSO_NAME \
|
||||||
$OIDC_CLIENT_ID $OIDC_CLIENT_SECRET \
|
# $OIDC_CLIENT_ID $OIDC_CLIENT_SECRET \
|
||||||
$DASHBOARD_OIDC_DISCOVERY_URL
|
# $DASHBOARD_OIDC_DISCOVERY_URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,6 +107,34 @@ support_repo_init() {
|
||||||
$GITEA_HOSTEA_SUPPORT_REPO
|
$GITEA_HOSTEA_SUPPORT_REPO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# register user "Hostea" on Gitea and create support repository
|
||||||
|
fleet_repo_init() {
|
||||||
|
python -m integration \
|
||||||
|
gitea register \
|
||||||
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
||||||
|
$GITEA_HOSTEA_EMAIL \
|
||||||
|
$GITEA_URL || true
|
||||||
|
python -m integration \
|
||||||
|
gitea login \
|
||||||
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
||||||
|
$GITEA_HOSTEA_EMAIL \
|
||||||
|
$GITEA_URL
|
||||||
|
python -m integration \
|
||||||
|
gitea create_repo \
|
||||||
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
||||||
|
$GITEA_HOSTEA_EMAIL \
|
||||||
|
$GITEA_URL \
|
||||||
|
$GITEA_HOSTEA_FLEET_REPO
|
||||||
|
|
||||||
|
python -m integration \
|
||||||
|
gitea add_deploy_key \
|
||||||
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_PASSWORD \
|
||||||
|
$GITEA_HOSTEA_EMAIL \
|
||||||
|
$GITEA_URL \
|
||||||
|
$GITEA_HOSTEA_FLEET_REPO \
|
||||||
|
$GITEA_HOSTEA_FLEET_DEPLOY_KEY
|
||||||
|
}
|
||||||
|
|
||||||
# Create user on Hostea to simulate a Hostea customer
|
# Create user on Hostea to simulate a Hostea customer
|
||||||
hostea_customer_simulation() {
|
hostea_customer_simulation() {
|
||||||
python -m integration \
|
python -m integration \
|
||||||
|
@ -128,39 +156,22 @@ hostea_customer_simulation() {
|
||||||
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_SUPPORT_REPO
|
$GITEA_HOSTEA_USERNAME $GITEA_HOSTEA_SUPPORT_REPO
|
||||||
}
|
}
|
||||||
|
|
||||||
gitea(){
|
|
||||||
readonly BIN=tmp/gitea/bin/gitea
|
|
||||||
readonly SOURCE="https://github.com/go-gitea/gitea/releases/download/v1.16.5/gitea-1.16.5-linux-amd64"
|
|
||||||
readonly CONFIG_FILE=gitea/app.ini
|
|
||||||
|
|
||||||
mkdir -p tmp/gitea/bin || true
|
|
||||||
|
|
||||||
for dir in repos db lfs log
|
|
||||||
do
|
|
||||||
rm -rf tmp/gitea/$dir || true
|
|
||||||
mkdir -p tmp/gitea/$dir || true
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ! -e $BIN ];
|
|
||||||
then
|
|
||||||
wget --quiet --output-document=$BIN $SOURCE
|
|
||||||
chmod +x $BIN
|
|
||||||
fi
|
|
||||||
|
|
||||||
nohup $BIN --config $CONFIG_FILE web > /dev/null 2>&1 &
|
|
||||||
GITEA_PID=$!
|
|
||||||
echo $GITEA_PID > $GITEA_PID_FILE
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_env() {
|
setup_env() {
|
||||||
mkdir tmp/ || true
|
mkdir tmp/ || true
|
||||||
nohup python manage.py runserver > /dev/null 2>&1 &
|
nohup python manage.py runserver > /dev/null 2>&1 &
|
||||||
SERVER_PID=$!
|
SERVER_PID=$!
|
||||||
echo $SERVER_PID > $SERVER_PID_FILE
|
echo $SERVER_PID > $SERVER_PID_FILE
|
||||||
gitea
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown_env() {
|
teardown_env() {
|
||||||
kill $(cat $GITEA_PID_FILE)
|
|
||||||
kill $(cat $SERVER_PID_FILE)
|
kill $(cat $SERVER_PID_FILE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docker_compose_up() {
|
||||||
|
docker-compose -f docker-compose-dev-deps.yml up -d
|
||||||
|
}
|
||||||
|
|
||||||
|
docker_compose_down() {
|
||||||
|
docker-compose -f docker-compose-dev-deps.yml down
|
||||||
|
docker-compose -f docker-compose-dev-deps.yml down --remove-orphans
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue