-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reformat, package, validate request body
- Loading branch information
Showing
47 changed files
with
1,974 additions
and
1,794 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python Debugger: Starlette", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"module": "uvicorn", | ||
"args": [ | ||
"app:app", | ||
"--port", | ||
"5000", | ||
"--reload" | ||
] | ||
} | ||
] | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug: Backend", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"module": "uvicorn", | ||
"args": ["app:app", "--port", "5000", "--reload"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
{ | ||
"css.customData": [".vscode/tailwind.json"], | ||
"editor.formatOnSave": true, | ||
"[python]": { | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "charliermarsh.ruff", | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "explicit" | ||
} | ||
}, | ||
"python.testing.unittestArgs": [ | ||
"-v", | ||
"-s", | ||
".", | ||
"-p", | ||
"*test.py" | ||
], | ||
"python.testing.pytestEnabled": false, | ||
"python.testing.unittestEnabled": true | ||
"python.testing.unittestEnabled": true, | ||
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "*_test.py"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,6 @@ | ||
FROM node:lts-alpine AS builder | ||
COPY . /app | ||
WORKDIR /app | ||
RUN npm audit && npm i && npm run build | ||
|
||
FROM alpine:3 | ||
COPY --from=builder /app/dist /app/dist | ||
RUN apk add --no-cache python3 py3-pip py3-pyldap py3-pytoml \ | ||
&& pip3 install --break-system-packages python-multipart starlette uvicorn | ||
COPY app.py ldap_api.py ldap_helpers.py schema.py settings.py /app/ | ||
RUN apk add --no-cache py3-pip py3-pyldap | ||
RUN pip3 install --break-system-packages ldap-ui | ||
|
||
WORKDIR /app | ||
EXPOSE 5000 | ||
CMD ["/usr/bin/uvicorn", "--host", "0.0.0.0", "--port", "5000", "app:app"] | ||
CMD ["ldap-ui", "--host", "0.0.0.0", "--port", "5000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,50 @@ | ||
.PHONY: debug run clean tidy image push manifest | ||
|
||
TAG = latest-$(subst aarch64,arm64,$(shell uname -m)) | ||
SITE = backend/ldap_ui/statics | ||
|
||
debug: app.py settings.py .env .venv3 dist | ||
.venv3/bin/python3 .venv3/bin/uvicorn --reload --port 5000 app:app | ||
|
||
run: app.py settings.py .env .venv3 dist | ||
.venv3/bin/uvicorn --host 0.0.0.0 --port 5000 app:app | ||
debug: .env .venv3 $(SITE) | ||
.venv3/bin/uvicorn --reload --port 5000 ldap_ui.app:app | ||
|
||
.env: env.example | ||
cp $< $@ | ||
|
||
.venv3: requirements.txt | ||
.venv3: pyproject.toml | ||
[ -d $@ ] || python3 -m venv --system-site-packages $@ | ||
.venv3/bin/pip3 install -U pip wheel | ||
.venv3/bin/pip3 install -r $< | ||
.venv3/bin/pip3 install -U build pip httpx twine | ||
.venv3/bin/pip3 install --editable . | ||
touch $@ | ||
|
||
dist: node_modules | ||
dist: .venv3 $(SITE) | ||
.venv3/bin/python3 -m build --wheel | ||
|
||
pypi: clean dist | ||
.venv3/bin/twine upload dist/* | ||
|
||
$(SITE): node_modules | ||
npm audit | ||
npm run build | ||
|
||
node_modules: package.json | ||
npm install | ||
npm audit | ||
touch $@ | ||
|
||
clean: | ||
rm -rf dist __pycache__ | ||
rm -rf build dist $(SITE) __pycache__ | ||
|
||
tidy: clean | ||
rm -rf .venv3 node_modules | ||
|
||
image: clean | ||
docker build -t dnknth/ldap-ui:$(TAG) . | ||
image: | ||
docker build --no-cache -t dnknth/ldap-ui:$(TAG) . | ||
|
||
push: image | ||
docker push dnknth/ldap-ui:$(TAG) | ||
|
||
manifest: push | ||
manifest: | ||
docker manifest create \ | ||
dnknth/ldap-ui \ | ||
--amend dnknth/ldap-ui:latest-x86_64 \ | ||
--amend dnknth/ldap-ui:latest-arm64 | ||
docker manifest push --purge dnknth/ldap-ui | ||
docker compose pull |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.9.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import logging | ||
|
||
import click | ||
import uvicorn | ||
from uvicorn.config import LOG_LEVELS | ||
from uvicorn.logging import ColourizedFormatter | ||
from uvicorn.main import LEVEL_CHOICES | ||
|
||
import ldap_ui | ||
|
||
from . import settings | ||
|
||
|
||
def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> None: | ||
if value: | ||
click.echo(ldap_ui.__version__) | ||
ctx.exit() | ||
|
||
|
||
@click.command() | ||
@click.option( | ||
"-b", | ||
"--base-dn", | ||
type=str, | ||
default=settings.BASE_DN, | ||
help="LDAP base DN (required). [default: BASE_DN environment variable]", | ||
) | ||
@click.option( | ||
"-h", | ||
"--host", | ||
type=str, | ||
default="127.0.0.1", | ||
help="Bind socket to this host.", | ||
show_default=True, | ||
) | ||
@click.option( | ||
"-p", | ||
"--port", | ||
type=int, | ||
default=5000, | ||
help="Bind socket to this port. If 0, an available port will be picked.", | ||
show_default=True, | ||
) | ||
@click.option( | ||
"-u", | ||
"--ldap-url", | ||
type=str, | ||
help="LDAP directory connection URL. [default: LDAP_URL environment variable or 'ldap:///']", | ||
) | ||
@click.option( | ||
"-l", | ||
"--log-level", | ||
type=LEVEL_CHOICES, | ||
default="info", | ||
help="Log level. [default: info]", | ||
show_default=True, | ||
) | ||
@click.option( | ||
"--version", | ||
is_flag=True, | ||
callback=print_version, | ||
expose_value=False, | ||
is_eager=True, | ||
help="Display the current version and exit.", | ||
) | ||
def main(base_dn, host, port, ldap_url, log_level): | ||
logging.basicConfig(level=LOG_LEVELS[log_level]) | ||
rootHandler = logging.getLogger().handlers[0] | ||
rootHandler.setFormatter(ColourizedFormatter(fmt="%(levelprefix)s %(message)s")) | ||
|
||
if base_dn is not None: | ||
settings.BASE_DN = base_dn | ||
|
||
if ldap_url is not None: | ||
settings.LDAP_URL = ldap_url | ||
|
||
uvicorn.run( | ||
"ldap_ui.app:app", | ||
host=host, | ||
port=port, | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.