Releases: lsst-sqre/safir
4.1.0
New features
- Add
read_*
methods forConfigMap
andResourceQuota
to the mock Kubernetes API for testing. - Add
patch_namespaced_pod_status
to the mock Kubernetes API for testing. Application code is unlikely to call this, but it's useful for test suites. - The mock
list_namespaced_pod
Kubernetes API now supports watches (but be aware that all changes must be made through the API).
Bug fixes
- Fix concurrency locking when watching namespace events in the Kubernetes testing mock. The previous logic degenerated into busy-waiting rather than correctly waiting on a condition variable.
- Watches for namespace events using the mock Kubernetes API now start with the next event, not the first stored event, if
resource_version
is not set, aligning behavior with the Kubernetes API.
What's Changed
- DM-38795: Add read for ConfigMap and ResourceQuota to mock by @rra in #162
- DM-38795: Fix concurrency for event watches by @rra in #163
- DM-38795: Add watch support for list_namespaced_pod by @rra in #164
- DM-38795: Set release date for 4.1.0 by @rra in #165
Full Changelog: 4.0.0...4.1.0
4.0.0
Backwards-incompatible changes
- Safir now requires a minimum Python version of 3.11.
safir.pydantic.validate_exactly_one_of
is now a Pydantic root validator instead of an individual field validator, which simplifies how it should be called.- Custom Kubernetes objects are no longer copied before being stored in the Kubernetes mock by
create_namespaced_custom_object
, and no longer automatically get ametadata.uid
value. This brings handling of custom objects in line with the behavior of other mockedcreate_*
andreplace_*
APIs. - All objects stored in the Kubernetes mock will be modified to set
api_version
,kind
, and (where appropriate)namespace
. If any of those values are set in the object, they are checked for correctness and rejected withAssertionError
if they don't match the API call and its parameters. - The mocked
create_*
Kubernetes APIs now use the namebody
for the parameter containing the API object, instead of using some other name specific to the kind of object. This fixes compatibility with the Python Kubernetes API that this class is mocking.
New features
- The new
safir.redis.PydanticRedisStorage
class enables you to store Pydantic model objects in Redis.
Asafir.redis.EncryptedPydanticRedisStorage
class also encrypts data in Redis.
To use thesafir.redis
module, install Safir with theredis
extra (i.e.,pip install safir[redis]
). - Add
safir.fastapi.ClientRequestError
base class for exceptions and the corresponding exception handlersafir.fastapi.client_request_error_handler
. These may be used together to raise structured exceptions and automatically transform them into structured HTTP errors with the correct HTTP status code and an error body compatible withsafir.models.ErrorModel
and FastAPI's own internally-generated errors. - Add
safir.slack.webhook.SlackWebException
, which is a child class ofsafir.slack.webhook.SlackException
that knows how to capture and report details from an underlying HTTPX exception. - Add a
safir.testing.kubernetes.strip_none
helper function that makes it easier to compare Kubernetes objects against expected test data. - Add a
get_namespace_objects_for_test
method to the Kubernetes mock to retrieve all objects (of any kind) in a namespace. - Add a mock for the
list_nodes
Kubernetes API, which returns data set by a call to the newset_nodes_for_test
method. - Add optional rudimentary namespace tracking to the Kubernetes mock. Namespaces can be created, deleted (which deletes all objects in the namespace), read, and listed. Explicit namespace creation remains optional; if an object is created in a namespace and that namespace does not exist, one will be implicitly created by the mock.
- Add support for namespaced events (the older core API, not the new events API) to the Kubernetes mock. Newly-created pods with the default initial status post an event by default; otherwise, events must be created by calling the mocked
create_namespaced_event
API. Thelist_namespaced_event
API supports watches with timeouts. - Add rudimentary support for
NetworkPolicy
,ResourceQuota
, andService
objects to the Kubernetes mock. - Add a
safir.github
module for writing GitHub integrations with GidgetHub and Pydantic modeling.safir.github.GitHubAppClientFactory
helps create authenticated clients for GitHub Apps and app installations.safir.github.models
contains Pydantic models for GitHub v3 REST API resources.safir.github.webhooks
contains Pydantic models for GitHub webhook payloads.
Bug fixes
- Stop adding the
X-Auth-Request-User
header to the OpenAPI schema for routes that useauth_dependency
orauth_logger_dependency
.
Other changes
- The
safir.testing.kubernetes.MockKubernetesApi
mock now has rudimentary API documentation for the Kubernetes APIs that it supports. - The documentation for running commands with
tox
has been updated for the new command-line syntax in tox v4.
Pull requests
- DM-38466: Suppress pkg_resources warnings by @rra in #145
- DM-38466: Require Python 3.11 and use it for type annotations by @rra in #144
- [neophile] Update dependencies by @sqrbot in #147
- DM-38466: Update Python versions in periodic CI by @rra in #149
- DM-38466: Document using non-default PostgreSQL schemas by @rra in #150
- DM-38491: Add PydanticRedisStorage and EncryptedPydanticRedisStorage by @jonathansick in #146
- DM-38533: Exclude X-Auth-Request-User from the schema by @rra in #148
- DM-38533: Merge Kubernetes API mock with lab controller work by @rra in #152
- DM-38660: Change validate_exactly_one_of to a root validator by @rra in #153
- DM-38660: Add SlackWebException for HTTPX errors by @rra in #154
- DM-38660: Add support for generating structured errors by @rra in #155
- DM-38660: Don't include body twice in SlackWebException by @rra in #156
- DM-38414: Remove stray colon in DeserializeError by @rra in #157
- DM-38414: Add missing all to safir.kubernetes by @rra in #159
- DM-38414: Use new tox v4 syntax by @rra in #160
- DM-38490: Support for building GitHub Apps by @jonathansick in #151
- DM-38773: Prepare 4.0.0 release by @jonathansick in #161
Full Changelog: 3.8.0...4.0.0
3.8.0
New features
- Add
safir.slack.webhook.SlackWebhookClient
and accompanying models to post a structured message to Slack via an incoming webhook. Add asafir.slack.blockkit.SlackException
base class that can be used to create exceptions with supplemental metadata that can be sent to Slack as a formatted alert. - Add a FastAPI route class (
safir.slack.webhook.SlackRouteErrorHandler
) that reports all uncaught exceptions to Slack using an incoming webhook. - Add
safir.datetime.format_datetime_for_logging
to convert adatetime
object into an easily human-readable representation. - Add
safir.testing.slack.mock_slack_webhook
and an associated mock class to mock a Slack webhook for testing. - Add
microseconds=True
parameter tosafir.datetime.current_datetime
to get adatetime
object with microseconds filled in. By default,current_datetime
suppresses the microseconds since databases often cannot store them, but there are some timestamp uses, such as error reporting, that benefit from microseconds and are never stored in databases.
What's Changed
Full Changelog: 3.7.0...3.8.0
3.7.0
New features
- Add a
safir.testing.uvicorn.spawn_uvicorn
helper function to spawn an ASGI app under an external Uvicorn process. Normally, ASGI apps should be tested by passing the app directly to anhttpx.AsyncClient
, but in some cases (such as Selenium testing) the app needs to listen to regular HTTP requests. safir.database.initialize_database
now creates a non-default schema if the underlying SQLAlchemy model declares one.
Bug fixes
- After
safir.logging.configure_uvicorn_logging
was called, exception tracebacks were no longer expanded. Add the missing processor to the logging stack. - In
safir.logging.configure_uvicorn_logging
, send the access log to standard output instead of combining it with all other messages on standard error.
What's Changed
- [neophile] Update dependencies by @sqrbot in #139
- Add support for initialization of non-default schema by @fritzm in #140
- DM-38170: Fix Uvicorn logging, add Uvicorn testing function by @rra in #141
- DM-38170: Finalize changes for 3.7.0 by @rra in #142
New Contributors
Full Changelog: 3.6.0...3.7.0
3.6.0
New features
- Add a
safir.models.ErrorLocation
enum holding valid values for the first element of theloc
array insafir.models.ErrorModel
. Due to limitations in Python typing,loc
is not type-checked against this enum, but it may be useful to applications constructing FastAPI-compatible error messages. - Add
safir.datetime.current_datetime
to get a normalizeddatetime
object representing the current date and time. - Add
safir.datetime.isodatetime
andsafir.datetime.parse_isodatetime
to convert to and from the most useful form of ISO 8601 dates, used by both Kubernetes and the IVOA UWS standard. Also addsafir.pydantic.normalize_isodatetime
to accept only that same format as input to a Pydantic model with adatetime
field.
What's Changed
- [neophile] Update dependencies by @sqrbot in #133
- DM-37589: Add ErrorLocation enum to models by @rra in #132
- DM-37589: Add datetime utility functions by @rra in #134
- DM-37589: Fix example for normalize_isodatetime by @rra in #135
- [neophile] Update dependencies by @sqrbot in #136
- DM-37760: Change the change log format by @rra in #137
- DM-37760: Prepare for 3.6.0 release by @rra in #138
Full Changelog: 3.5.0...3.6.0
3.5.0
This release adds safir.pydantic.CamelCaseModel
to further automate support for camel-case attributes in Pydantic models. It also adds the helper class safir.gcs.SignedURLService
to generate signed URLs for Google Cloud Storage objects, and the module safir.testing.gcs
to provide a mock of the Google Cloud Storage API for testing.
What's Changed
- DM-37192: Enable more mypy checks by @rra in #125
- [neophile] Update dependencies by @sqrbot in #126
- Generate API docs for safir.asyncio by @jonathansick in #127
- DM-37291: Add CamelCaseModel helper class by @rra in #128
- [neophile] Update dependencies by @sqrbot in #129
- [neophile] Update dependencies by @sqrbot in #130
- DM-37516: Add Google Cloud Storage utilities and testing support by @rra in #131
Full Changelog: 3.4.0...3.5.0
3.4.0
The 3.4.0 release adds new functions safir.pydantic.normalize_datetime
, safir.pydantic.to_camel_case
, and safir.pydantic.validate_exactly_one_of
, which are helpful for some common Pydantic validation and configuration use cases. It also adds new enums for Profile
and LogLevel
that can be passed to safir.logging.configure_logging
and safir.logging.configure_uvicorn_logging
, allowing better validation of Safir-related application configuration. Finally, it fixes a bug in the Kubernetes mock API, where an intended spec constraint was not applied due to an ordering problem.
What's Changed
- Install graphviz for periodic doc build by @jonathansick in #119
- [neophile] Update dependencies by @sqrbot in #120
- DM-37046: Add Profile and LogLevel enums by @rra in #121
- DM-37051: Drop now-unnecessary types from docs by @rra in #122
- [neophile] Update dependencies by @sqrbot in #123
- DM-37051: Add some Pydantic helper functions from Gafaelfawr by @rra in #124
Full Changelog: 3.3.0...3.4.0
3.3.0
The 3.3.0 release adds a new function, safir.logging.configure_uvicorn_logging
, that routes Uvicorn logs through structlog and adds the context expected by Google's Cloud Logging. The safir.metadata.get_metadata
function now also supports packages that use only pyproject.toml
.
What's Changed
- [neophile] Update dependencies by @sqrbot in #107
- DM-30063: Update logging documentation by @rra in #108
- Avoid Sphinx 5.1.0 by @rra in #109
- [neophile] Update dependencies by @sqrbot in #110
- [neophile] Update dependencies by @sqrbot in #111
- DM-28121: Handle the new pyproject.toml package metadata by @rra in #112
- Bump arq from 0.23a1 to 0.23 by @dependabot in #113
- [neophile] Update dependencies by @sqrbot in #114
- DM-36156: Drop use of sqlalchemy _IsolationLevel type by @jonathansick in #116
- DM-36156: Refresh Safir packaging and adopt new Rubin user guide theme by @jonathansick in #117
- DM-35879: Support sending Uvicorn logs through structlog by @rra in #118
Full Changelog: 3.2.0...3.3.0
3.2.0
The 3.2.0 release adds new support for arq, the Redis-based asyncio distributed queue package. The safir.arq
module provides an arq client and metadata/result data classes with a mock implementation for testing. The FastAPI dependency, safir.dependencies.arq.arq_dependency
, provides a convenient way to use the arq client from HTTP handlers.
What's Changed
- Bump pre-commit/action from 2.0.3 to 3.0.0 by @dependabot in #103
- [neophile] Update dependencies by @sqrbot in #105
- Bump actions/setup-python from 3 to 4 by @dependabot in #106
- DM-34473: Add arq FastAPI dependency by @jonathansick in #98
Full Changelog: 3.1.0...3.2.0