feat: gitea create oauth2 application
parent
e4c418b45b
commit
8712b6d442
|
@ -26,6 +26,7 @@ class Gitea:
|
||||||
self.create_repository()
|
self.create_repository()
|
||||||
self.install_sso()
|
self.install_sso()
|
||||||
self.add_deploy_key()
|
self.add_deploy_key()
|
||||||
|
self.new_oauth2_app()
|
||||||
|
|
||||||
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")
|
||||||
|
@ -121,6 +122,33 @@ class Gitea:
|
||||||
|
|
||||||
self.install_sso_parser.set_defaults(func=run)
|
self.install_sso_parser.set_defaults(func=run)
|
||||||
|
|
||||||
|
def new_oauth2_app(self):
|
||||||
|
def run(args, c: Session):
|
||||||
|
gitea = gitea_from_args(args, c=c)
|
||||||
|
# checks if user exists
|
||||||
|
gitea.login()
|
||||||
|
creds = gitea.add_oauth_application(
|
||||||
|
name=args.app_name,
|
||||||
|
redirect_urls=[args.redirect_uri],
|
||||||
|
)
|
||||||
|
print(f"client_id: {creds[0]}client_secret: \n{creds[1]}")
|
||||||
|
|
||||||
|
self.install_oauth2_app = self.subparser.add_parser(
|
||||||
|
name="new_oauth2_app",
|
||||||
|
description="Create new oauth2 app on Gitea",
|
||||||
|
help="Create new oauth2 app on Gitea",
|
||||||
|
)
|
||||||
|
self.__add_credentials_parser(self.install_oauth2_app)
|
||||||
|
self.install_oauth2_app.add_argument(
|
||||||
|
"app_name", type=str, help="(Human readable)Name of the OAuth app"
|
||||||
|
)
|
||||||
|
self.install_oauth2_app.add_argument(
|
||||||
|
"redirect_uri",
|
||||||
|
type=str,
|
||||||
|
help="Redirect URI of the app",
|
||||||
|
)
|
||||||
|
self.install_oauth2_app.set_defaults(func=run)
|
||||||
|
|
||||||
def add_deploy_key(self):
|
def add_deploy_key(self):
|
||||||
def run(args, c: Session):
|
def run(args, c: Session):
|
||||||
gitea = gitea_from_args(args, c=c)
|
gitea = gitea_from_args(args, c=c)
|
||||||
|
|
|
@ -297,6 +297,15 @@ class Gitea:
|
||||||
resp = self.c.post(url, json=payload)
|
resp = self.c.post(url, json=payload)
|
||||||
assert resp.status_code == 201
|
assert resp.status_code == 201
|
||||||
|
|
||||||
|
def add_oauth_application(self, name: str, redirect_urls: [str]):
|
||||||
|
url = self.get_api_uri(f"/api/v1/user/applicaitons/oauth2")
|
||||||
|
payload = {"name": name, "redirect_urls": redirect_urls}
|
||||||
|
resp = self.c.post(url, json=payload)
|
||||||
|
print(f"new oauth status code: {resp.status_code}")
|
||||||
|
assert resp.status_code == 201
|
||||||
|
data = resp.json()
|
||||||
|
return (data["client_id"], data["client_secret"])
|
||||||
|
|
||||||
|
|
||||||
class ParseSSOLogin(HTMLParser):
|
class ParseSSOLogin(HTMLParser):
|
||||||
url: str = None
|
url: str = None
|
||||||
|
|
|
@ -13,13 +13,15 @@ then
|
||||||
MAILDEV_URL="http://smtp:1080"
|
MAILDEV_URL="http://smtp:1080"
|
||||||
GITEA_URL="http://gitea:3000"
|
GITEA_URL="http://gitea:3000"
|
||||||
GITEA_SSH_URL="ssh://git@gitea:22"
|
GITEA_SSH_URL="ssh://git@gitea:22"
|
||||||
|
WOODPECKER_URL="http://woodpecker:8000"
|
||||||
else
|
else
|
||||||
MAILDEV_URL="http://localhost:1080"
|
MAILDEV_URL="http://localhost:1080"
|
||||||
GITEA_URL="http://localhost:3000"
|
GITEA_URL="http://localhost:3000"
|
||||||
GITEA_SSH_URL="ssh://git@localhost:22"
|
GITEA_SSH_URL="ssh://git@localhost:22"
|
||||||
|
WOODPECKER_URL="http://localhost:8000"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
readonly DASHBOARD_URL="http://localhost:8000"
|
readonly DASHBOARD_URL="http://localhost:7000"
|
||||||
|
|
||||||
|
|
||||||
readonly DASHBOARD_OIDC_DISCOVERY_URL="$DASHBOARD_URL/o/.well-known/openid-configuration/"
|
readonly DASHBOARD_OIDC_DISCOVERY_URL="$DASHBOARD_URL/o/.well-known/openid-configuration/"
|
||||||
|
@ -36,6 +38,10 @@ 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="$(realpath tests/fleet-deploy-key.pub)"
|
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY="$(realpath tests/fleet-deploy-key.pub)"
|
||||||
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE="$(realpath tests/fleet-deploy-key)"
|
readonly GITEA_HOSTEA_FLEET_DEPLOY_KEY_PRIVATE="$(realpath tests/fleet-deploy-key)"
|
||||||
|
readonly GITEA_WOODPECKER_OAUTH_NAME="woodpecker"
|
||||||
|
|
||||||
|
readonly WOODPECKER_REDIRECT_URL="$WOODPECKER_URL/authorize"
|
||||||
|
|
||||||
|
|
||||||
readonly GITEA_HOSTEA_USERNAME=hostea
|
readonly GITEA_HOSTEA_USERNAME=hostea
|
||||||
readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword
|
readonly GITEA_HOSTEA_PASSWORD=supercomplicatedpassword
|
||||||
|
@ -89,6 +95,13 @@ 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 \
|
||||||
|
gitea new_oauth2_app \
|
||||||
|
$GITEA_ROOT_USERNAME $GITEA_ROOT_PASSOWRD \
|
||||||
|
$GITEA_ROOT_EMAIL \
|
||||||
|
$GITEA_URL \
|
||||||
|
$GITEA_WOODPECKER_OAUTH_NAME \
|
||||||
|
$WOODPECKER_REDIRECT_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 \
|
||||||
|
|
Loading…
Reference in New Issue