Skip to content

Commit

Permalink
Merge pull request #112 from sirosen/release/0.14.0
Browse files Browse the repository at this point in the history
Release of version 0.14.0
  • Loading branch information
sirosen authored Oct 19, 2023
2 parents 0bf58a9 + ba129a0 commit a5ff31a
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 41 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
groups:
github-actions:
patterns:
- "*"
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout the repo"
uses: "actions/checkout@v3"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1

- name: "Identify the week number"
run: |
Expand All @@ -24,7 +24,7 @@ jobs:
- name: "Setup Python"
id: "setup-python"
uses: "actions/setup-python@v4"
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1
with:
python-version: "3.12"
cache: "pip"
Expand All @@ -36,7 +36,7 @@ jobs:
- name: "Restore the cache"
id: "restore-cache"
uses: "actions/cache@v3"
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2
with:
path: |
.tox/
Expand Down Expand Up @@ -64,7 +64,7 @@ jobs:
wheel-filename: "${{ steps.build-wheel.outputs.wheel-filename }}"
steps:
- name: "Checkout the repo"
uses: "actions/checkout@v3"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1

- name: "Identify the week number"
run: |
Expand All @@ -73,7 +73,7 @@ jobs:
- name: "Setup Python"
id: "setup-python"
uses: "actions/setup-python@v4"
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1
with:
python-version: "3.11"
cache: "pip"
Expand All @@ -90,7 +90,7 @@ jobs:
echo "wheel-filename=$(ls -1 globus_action_provider_tools-*.whl | head -n 1)" >> $GITHUB_OUTPUT
- name: "Upload the artifact"
uses: "actions/upload-artifact@v3"
uses: "actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32" # v3.1.3
with:
name: "globus_action_provider_tools-${{ github.sha }}.whl"
path: "${{ steps.build-wheel.outputs.wheel-filename }}"
Expand Down Expand Up @@ -144,7 +144,7 @@ jobs:

steps:
- name: "Checkout the repo"
uses: "actions/checkout@v3"
uses: "actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11" # v4.1.1

- name: "Identify the week number"
shell: "bash"
Expand All @@ -154,7 +154,7 @@ jobs:
- name: "Setup Python"
id: "setup-python"
uses: "actions/setup-python@v4"
uses: "actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236" # v4.7.1
with:
python-version: "${{ matrix.python-version }}"
cache: "pip"
Expand All @@ -166,7 +166,7 @@ jobs:
- name: "Restore cache"
id: "restore-cache"
uses: "actions/cache@v3"
uses: "actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84" # v3.3.2
with:
path: |
.tox/
Expand All @@ -190,7 +190,7 @@ jobs:
${{ env.venv-path }}/pip install tox
- name: "Download the artifact"
uses: "actions/download-artifact@v3"
uses: "actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a" # v3.0.2
with:
name: "globus_action_provider_tools-${{ github.sha }}.whl"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 1

- name: Set target python version
uses: actions/setup-python@v4
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: "3.11"

Expand Down
12 changes: 9 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# pre-commit.ci routinely submits PRs to update hook versions.
ci:
autoupdate_schedule: "monthly"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -17,7 +18,7 @@ repos:

# Enforce Python 3.8+ idioms.
- repo: https://github.com/asottile/pyupgrade
rev: v3.14.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -31,3 +32,8 @@ repos:
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/sirosen/slyp
rev: 0.1.1
hooks:
- id: slyp
17 changes: 17 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ Unreleased changes are documented in files in the `changelog.d`_ directory.

.. scriv-insert-here
.. _changelog-0.14.0:

0.14.0 — 2023-10-19
===================

Features
--------

- Added a CloudWatchEMFLogger ``RequestLifecycleHook`` class.
When attached to an ``ActionProviderBlueprint``, it will emit request count, latency,
and response category (2xxs, 4xxs, 5xxs) count metrics through CloudWatch EMF. Metrics
are emitted both for the aggregate AP dimension set and the individual route dimension
set.

- Classes may be provided at Blueprint instantiation time to register before, after,
and/or teardown functionality wrapping route invocation.

.. _changelog-0.13.0rc2:

0.13.0rc2 — 2023-10-06
Expand Down
27 changes: 27 additions & 0 deletions globus_action_provider_tools/flask/apt_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
globus_auth_client_name: t.Optional[str] = None,
additional_scopes: t.Iterable[str] = (),
action_repository: t.Optional[AbstractActionRepository] = None,
request_lifecycle_hooks: t.Optional[t.List[t.Any]] = None,
**kwarg,
):
"""Create a new ActionProviderBlueprint. All arguments not listed here are the
Expand All @@ -71,6 +72,11 @@ def __init__(
``globus_auth_scope`` value of the input provider description. Only
needed if more than one scope has been allocated for the Action
Provider's Globus Auth client_id.
:param request_lifecycle_hooks: A list of classes defining a before_request,
after_request, and/or teardown_request method. If any of these functions exist
they will be registered with the blueprint. RequestLifecycleHook classes are
registered and therefore executed in the order they are provided.
"""

super().__init__(*args, **kwarg)
Expand All @@ -86,6 +92,15 @@ def __init__(
self.register_error_handler(Exception, blueprint_error_handler)
self.record_once(self._create_token_checker)

if request_lifecycle_hooks:
for hooks in request_lifecycle_hooks:
if hasattr(hooks, "before_request"):
self.before_request(hooks.before_request)
if hasattr(hooks, "after_request"):
self.after_request(hooks.after_request)
if hasattr(hooks, "teardown_request"):
self.teardown_request(hooks.teardown_request)

self.add_url_rule(
"/",
"action_introspect",
Expand Down Expand Up @@ -152,6 +167,7 @@ def _action_introspect(self):
"""
Runs as an Action Provider's introspection endpoint.
"""
self._register_route_type("introspect")
if not g.auth_state.check_authorization(
self.provider_description.visible_to,
allow_public=True,
Expand All @@ -166,6 +182,7 @@ def _action_introspect(self):
return jsonify(self.provider_description), 200

def _action_enumerate(self):
self._register_route_type("enumerate")
if not g.auth_state.check_authorization(
self.provider_description.runnable_by,
allow_public=True,
Expand Down Expand Up @@ -206,6 +223,7 @@ def action_enumerate(self, func: ActionEnumerationCallback):
return func

def _action_run(self):
self._register_route_type("run")
if not g.auth_state.check_authorization(
self.provider_description.runnable_by,
allow_all_authenticated_users=True,
Expand Down Expand Up @@ -257,6 +275,7 @@ def action_run(self, func: ActionRunCallback):
return func

def _action_resume(self, action_id: str):
self._register_route_type("resume")
# Attempt to lookup the Action based on its action_id if there was an
# Action Repo defined. If an action is found, verify access to it.
action = None
Expand Down Expand Up @@ -307,6 +326,7 @@ def action_status(self, func: ActionStatusCallback):
return func

def _action_status(self, action_id: str):
self._register_route_type("status")
"""
Attempts to load an action_status via its action_id using an
action_loader. If an action is successfully loaded, view access by the
Expand Down Expand Up @@ -351,6 +371,7 @@ def action_cancel(self, func: ActionCancelCallback):
return func

def _action_cancel(self, action_id: str):
self._register_route_type("cancel")
"""
Executes a user-defined function for cancelling an Action.
"""
Expand Down Expand Up @@ -405,6 +426,7 @@ def action_release(self, func: ActionReleaseCallback):
return func

def _action_release(self, action_id: str):
self._register_route_type("release")
"""
Decorates a function to be run as an Action Provider's release endpoint.
"""
Expand Down Expand Up @@ -446,6 +468,7 @@ def action_log(self, func: ActionLogCallback):
return func

def _action_log(self, action_id: str):
self._register_route_type("log")
# Attempt to use a user-defined function to lookup the Action based
# on its action_id. If an action is found, authorize access to it
action = None
Expand All @@ -456,6 +479,10 @@ def _action_log(self, action_id: str):
status = self.action_log_callback(action_id, g.auth_state)
return jsonify(status), 200

def _register_route_type(self, route_type: str):
if not hasattr(g, "route_type"):
g.route_type = route_type

def _load_action_by_id(
self, repo: AbstractActionRepository, action_id: str
) -> ActionStatus:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .cloudwatch_metrics import CloudWatchMetricEMFLogger

__all__ = [
"CloudWatchMetricEMFLogger",
]
Loading

0 comments on commit a5ff31a

Please sign in to comment.