ab-bff-service 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,209 @@
1
+ Metadata-Version: 2.4
2
+ Name: ab-bff-service
3
+ Version: 0.2.0
4
+ Summary: Auth Broker BFF Service.
5
+ Author-email: Matthew Coulter <53892067+mattcoulter7@users.noreply.github.com>
6
+ License-File: LICENSE
7
+ Requires-Python: <4,>=3.12
8
+ Requires-Dist: ab-alembic-auto-migrate<1,>=0.2.0
9
+ Requires-Dist: ab-client-auth-client>=0.1.0
10
+ Requires-Dist: ab-client-token-validator>=0.1.0
11
+ Requires-Dist: ab-client-user>=0.1.0
12
+ Requires-Dist: ab-database[postgres-async,postgres-sync,sqlite-async]<1,>=0.2.2
13
+ Requires-Dist: ab-identity-context[fastapi]>=0.1.1
14
+ Requires-Dist: ab-logging>=0.1.2
15
+ Requires-Dist: fastapi<0.116,>=0.115.14
16
+ Requires-Dist: pydantic[email]<3,>=2.11.7
17
+ Requires-Dist: uvicorn<0.36,>=0.35.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ <div align="center">
21
+
22
+ # Auth Broker BFF
23
+
24
+ The template repository for creating python packages, shared across auth-broker.
25
+
26
+ ![Python](https://img.shields.io/badge/Python-3.12-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
27
+ ![UV](https://img.shields.io/badge/UV-Fast-6E40C9?style=for-the-badge)
28
+ ![Hatchling](https://img.shields.io/badge/Hatchling-PEP517-6E40C9?style=for-the-badge)
29
+ ![Ruff](https://img.shields.io/badge/Ruff-Lint-000000?style=for-the-badge)
30
+ ![Pre-commit](https://img.shields.io/badge/Pre--commit-Hooks-000000?style=for-the-badge)
31
+ ![Pytest](https://img.shields.io/badge/Pytest-Unit%2BAsync-08979C?style=for-the-badge)
32
+ ![Coverage](https://img.shields.io/badge/Cov-Reports-08979C?style=for-the-badge)
33
+ ![GitHub Actions](https://img.shields.io/badge/Actions-CI%2FCD-F7B500?style=for-the-badge&logo=github-actions)
34
+ ![PyPI](https://img.shields.io/badge/PyPI-Publish-6E40C9?style=for-the-badge)
35
+ ![Docker](https://img.shields.io/badge/Docker-Builds-2496ED?style=for-the-badge&logo=docker)
36
+ ![Compose](https://img.shields.io/badge/Compose-Local-2496ED?style=for-the-badge&logo=docker)
37
+ ![Makefile](https://img.shields.io/badge/Makefile-Scripts-F7B500?style=for-the-badge)
38
+
39
+ 🦜🕸️
40
+
41
+ [![CI](https://github.com/auth-broker/service-template/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/auth-broker/service-template/actions/workflows/ci.yaml)
42
+
43
+ </div>
44
+
45
+ ______________________________________________________________________
46
+
47
+ ## Table of Contents
48
+
49
+ <!-- toc -->
50
+
51
+ - [Introduction](#introduction)
52
+ - [Quick Start](#quick-start)
53
+ - [Installation](#installation)
54
+ - [Usage](#usage)
55
+ - [Formatting and linting](#formatting-and-linting)
56
+ - [CICD](#cicd)
57
+
58
+ <!-- tocstop -->
59
+
60
+ ______________________________________________________________________
61
+
62
+ ## Introduction
63
+
64
+ This template repository aims to create a reusable package template which
65
+ streamlines the creation and publishing of isolated python packages in auth-broker.
66
+ This is aligned with the engineering vision @ auth-broker for better modularisation and
67
+ reusability of code.
68
+
69
+ ______________________________________________________________________
70
+
71
+ ## Quick Start
72
+
73
+ Since this is just a package, and not a service, there is no real "run" action.
74
+ But you can run the tests immediately.
75
+
76
+ Here are a list of available commands via make.
77
+
78
+ ### Bare Metal (i.e. your machine)
79
+
80
+ 1. `make install` - install the required dependencies.
81
+ 1. `make test` - runs the tests.
82
+
83
+ ### Docker
84
+
85
+ 1. `make build-docker` - build the docker image.
86
+ 1. `make run-docker` - run the docker compose services.
87
+ 1. `make test-docker` - run the tests in docker.
88
+ 1. `make clean-docker` - remove all docker containers etc.
89
+
90
+ ______________________________________________________________________
91
+
92
+ ## Installation
93
+
94
+ ### For Dev work on the repo
95
+
96
+ Install `uv`, (_if you haven't already_)
97
+ https://docs.astral.sh/uv/getting-started/installation/#installation-methods
98
+
99
+ ```shell
100
+ brew install uv
101
+ ```
102
+
103
+ Initialise pre-commit (validates ruff on commit.)
104
+
105
+ ```shell
106
+ uv run pre-commit install
107
+ ```
108
+
109
+ Install dependencies (including dev dependencies)
110
+
111
+ ```shell
112
+ uv sync
113
+ ```
114
+
115
+ If you are adding a new dev dependency, please run:
116
+
117
+ ```shell
118
+ uv add --dev {your-new-package}
119
+ ```
120
+
121
+ ### Namespaces
122
+
123
+ Packages all share the same namespace `ab_core`. To import this package into
124
+ your project:
125
+
126
+ ```python
127
+ from ab_core.template import placeholder_func
128
+ ```
129
+
130
+ We encourage you to make your package available to all of ab via this
131
+ `ab_core` namespace. The goal is to streamline development, POCs and overall
132
+ collaboration.
133
+
134
+ ______________________________________________________________________
135
+
136
+ ## Usage
137
+
138
+ ### Adding the dependency to your project
139
+
140
+ The library is available on PyPI. You can install it using the following
141
+ command:
142
+
143
+ **Using pip**:
144
+
145
+ ```shell
146
+ pip install service-bff
147
+ ```
148
+
149
+ **Using UV**
150
+
151
+ Note: there is currently no nice way like poetry, hence we still needd to
152
+ provide the full url. https://github.com/astral-sh/uv/issues/10140
153
+
154
+ Add the dependency
155
+
156
+ ```shell
157
+ uv add service-bff
158
+ ```
159
+
160
+ **Using poetry**:
161
+
162
+ Then run the following command to install the package:
163
+
164
+ ```shell
165
+ poetry add service-bff
166
+ ```
167
+
168
+ ### How tos
169
+
170
+ **Example Usage**
171
+
172
+ ```python
173
+ # Please update this based on your package!
174
+
175
+ from ab_core.template import placeholder_func
176
+
177
+
178
+ if __name__ == "__main__":
179
+ print("This is a placeholder: ", placeholdder_func())
180
+ ```
181
+
182
+ ______________________________________________________________________
183
+
184
+ ## Formatting and linting
185
+
186
+ We use Ruff as the formatter and linter. The pre-commit has hooks which runs
187
+ checking and applies linting automatically. The CI validates the linting,
188
+ ensuring main is always looking clean.
189
+
190
+ You can manually use these commands too:
191
+
192
+ 1. `make lint` - check for linting issues.
193
+ 1. `make format` - fix linting issues.
194
+
195
+ ______________________________________________________________________
196
+
197
+ ## CICD
198
+
199
+ ### Publishing to PyPI
200
+
201
+ We publish to PyPI using Github releases. Steps are as follows:
202
+
203
+ 1. Manually update the version in `pyproject.toml` file using a PR and merge to
204
+ main. Use `uv version --bump {patch/minor/major}` to update the version.
205
+ 1. Create a new release in Github with the tag name as the version number. This
206
+ will trigger the `publish` workflow. In the Release window, type in the
207
+ version number and it will prompt to create a new tag.
208
+ 1. Verify the release in
209
+ [PyPI](https://pypi.org/project/service-bff/)
@@ -0,0 +1,8 @@
1
+ ab_service/bff/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ab_service/bff/main.py,sha256=PduGR-AxBbdgedkI2r-VS55QLp7CDZmuy11ft1wpYuA,1858
3
+ ab_service/bff/routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ ab_service/bff/routes/identity_context.py,sha256=2WNGG35EgbY6ohB-V-zj15Q16wgYu9LrS-JU6pKs9Yk,704
5
+ ab_bff_service-0.2.0.dist-info/METADATA,sha256=HpDzCf8SKwyousTuPsl2NPa8annuMcgBE-ofSqtgPWg,6079
6
+ ab_bff_service-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ ab_bff_service-0.2.0.dist-info/licenses/LICENSE,sha256=REBFOD_HdKi9ZZ38nP3A_NjpLFaijF1A6_PDiMglbLk,1072
8
+ ab_bff_service-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Matthew Coulter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
File without changes
ab_service/bff/main.py ADDED
@@ -0,0 +1,55 @@
1
+ """Main application for the User Service."""
2
+
3
+ from contextlib import asynccontextmanager
4
+ from typing import Annotated
5
+
6
+ from ab_client_auth_client.client import Client as AuthClient
7
+ from ab_client_token_validator.client import Client as TokenValidatorClient
8
+ from ab_client_user.client import Client as UserClient
9
+ from ab_core.alembic_auto_migrate.service import AlembicAutoMigrate
10
+ from ab_core.database.databases import Database
11
+ from ab_core.dependency import Depends, inject
12
+ from ab_core.dependency.loaders.environment_object import ObjectLoaderEnvironment
13
+ from ab_core.logging.config import LoggingConfig
14
+ from fastapi import FastAPI
15
+
16
+ from ab_service.bff.routes.identity_context import router as identity_context_router
17
+
18
+
19
+ @inject
20
+ @asynccontextmanager
21
+ async def lifespan(
22
+ _app: FastAPI,
23
+ _db: Annotated[
24
+ Database,
25
+ Depends(Database, persist=True),
26
+ ], # cold start load db into cache
27
+ logging_config: Annotated[
28
+ LoggingConfig,
29
+ Depends(LoggingConfig, persist=True),
30
+ ],
31
+ alembic_auto_migrate: Annotated[
32
+ AlembicAutoMigrate,
33
+ Depends(AlembicAutoMigrate, persist=True),
34
+ ],
35
+ _auth_client: Annotated[
36
+ AuthClient,
37
+ Depends(ObjectLoaderEnvironment[AuthClient](env_prefix="AUTH_SERVICE"), persist=True),
38
+ ],
39
+ _token_validator_client: Annotated[
40
+ TokenValidatorClient,
41
+ Depends(ObjectLoaderEnvironment[TokenValidatorClient](env_prefix="TOKEN_VALIDATOR_SERVICE"), persist=True),
42
+ ],
43
+ _user_client: Annotated[
44
+ UserClient,
45
+ Depends(ObjectLoaderEnvironment[UserClient](env_prefix="USER_SERVICE"), persist=True),
46
+ ],
47
+ ):
48
+ """Lifespan context manager to handle startup and shutdown events."""
49
+ logging_config.apply()
50
+ alembic_auto_migrate.run()
51
+ yield
52
+
53
+
54
+ app = FastAPI(lifespan=lifespan)
55
+ app.include_router(identity_context_router)
File without changes
@@ -0,0 +1,20 @@
1
+ """User-related API routes."""
2
+
3
+ from typing import Annotated
4
+
5
+ from ab_core.database.session_context import db_session_async
6
+ from ab_core.identity_context.dependency import IdentityContext, get_identity_context
7
+ from fastapi import APIRouter
8
+ from fastapi import Depends as FDepends
9
+ from sqlalchemy.ext.asyncio import AsyncSession
10
+
11
+ router = APIRouter(prefix="/identity-context", tags=["Identity Context"])
12
+
13
+
14
+ @router.get("", response_model=IdentityContext)
15
+ async def me(
16
+ _db_session: Annotated[AsyncSession, FDepends(db_session_async)],
17
+ identity_context: Annotated[IdentityContext, FDepends(get_identity_context)],
18
+ ):
19
+ """Return the current user's identity context."""
20
+ return identity_context