Skip to content

Commit

Permalink
root: generate python client (#9107)
Browse files Browse the repository at this point in the history
* generate api client

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

# Conflicts:
#	authentik/lib/expression/evaluator.py
#	poetry.lock

* don't attempt to pr upgrade api client

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

# Conflicts:
#	poetry.lock
#	pyproject.toml

* use new generator

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* t

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* use upstream generator since that one is v2 already 🤦

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

* add missing help to makefile

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
  • Loading branch information
BeryJu authored Apr 4, 2024
1 parent 261eebe commit bb1f18d
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 1,713 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/api-py-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: authentik-api-py-publish
on:
push:
branches: [main]
paths:
- "schema.yml"
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- id: generate_token
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.GH_APP_ID }}
private_key: ${{ secrets.GH_APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.generate_token.outputs.token }}
- uses: actions/setup-python@v4
with:
python-version-file: "pyproject.toml"
cache: "poetry"
- name: Generate API Client
run: make gen-client-py
- name: Publish package
working-directory: gen-py-api/
run: |
poetry build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: gen-py-api/dist/
# We can't easily upgrade the API client being used due to poetry being poetry
# so we'll have to rely on dependabot
# - name: Upgrade /
# run: |
# export VERSION=$(cd gen-py-api && poetry version -s)
# poetry add "authentik_client=$VERSION" --allow-prereleases --lock
# - uses: peter-evans/create-pull-request@v6
# id: cpr
# with:
# token: ${{ steps.generate_token.outputs.token }}
# branch: update-root-api-client
# commit-message: "root: bump API Client version"
# title: "root: bump API Client version"
# body: "root: bump API Client version"
# delete-branch: true
# signoff: true
# # ID from https://api.github.com/users/authentik-automation[bot]
# author: authentik-automation[bot] <135050075+authentik-automation[bot]@users.noreply.github.com>
# - uses: peter-evans/enable-pull-request-automerge@v3
# with:
# token: ${{ steps.generate_token.outputs.token }}
# pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
# merge-method: squash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: authentik-web-api-publish
name: authentik-api-ts-publish
on:
push:
branches: [main]
Expand Down
20 changes: 19 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ PY_SOURCES = authentik tests scripts lifecycle .github
DOCKER_IMAGE ?= "authentik:test"

GEN_API_TS = "gen-ts-api"
GEN_API_PY = "gen-py-api"
GEN_API_GO = "gen-go-api"

pg_user := $(shell python -m authentik.lib.config postgresql.user 2>/dev/null)
Expand Down Expand Up @@ -137,7 +138,10 @@ gen-clean-ts: ## Remove generated API client for Typescript
gen-clean-go: ## Remove generated API client for Go
rm -rf ./${GEN_API_GO}/

gen-clean: gen-clean-ts gen-clean-go ## Remove generated API clients
gen-clean-py: ## Remove generated API client for Python
rm -rf ./${GEN_API_PY}/

gen-clean: gen-clean-ts gen-clean-go gen-clean-py ## Remove generated API clients

gen-client-ts: gen-clean-ts ## Build and install the authentik API for Typescript into the authentik UI Application
docker run \
Expand All @@ -155,6 +159,20 @@ gen-client-ts: gen-clean-ts ## Build and install the authentik API for Typescri
cd ./${GEN_API_TS} && npm i
\cp -rf ./${GEN_API_TS}/* web/node_modules/@goauthentik/api

gen-client-py: gen-clean-py ## Build and install the authentik API for Python
docker run \
--rm -v ${PWD}:/local \
--user ${UID}:${GID} \
docker.io/openapitools/openapi-generator-cli:v7.4.0 generate \
-i /local/schema.yml \
-g python \
-o /local/${GEN_API_PY} \
-c /local/scripts/api-py-config.yaml \
--additional-properties=packageVersion=${NPM_VERSION} \
--git-repo-id authentik \
--git-user-id goauthentik
pip install ./${GEN_API_PY}

gen-client-go: gen-clean-go ## Build and install the authentik API for Golang
mkdir -p ./${GEN_API_GO} ./${GEN_API_GO}/templates
wget https://raw.githubusercontent.com/goauthentik/client-go/main/config.yaml -O ./${GEN_API_GO}/config.yaml
Expand Down
2 changes: 1 addition & 1 deletion authentik/core/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class UserGroupSerializer(ModelSerializer):
"""Simplified Group Serializer for user's groups"""

attributes = JSONDictField(required=False)
parent_name = CharField(source="parent.name", read_only=True)
parent_name = CharField(source="parent.name", read_only=True, allow_null=True)

class Meta:
model = Group
Expand Down
1 change: 1 addition & 0 deletions authentik/root/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
"UserTypeEnum": "authentik.core.models.UserTypes",
},
"ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False,
"ENUM_GENERATE_CHOICE_DESCRIPTION": False,
"POSTPROCESSING_HOOKS": [
"authentik.api.schema.postprocess_schema_responses",
"drf_spectacular.hooks.postprocess_schema_enums",
Expand Down
Loading

0 comments on commit bb1f18d

Please sign in to comment.