-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from haochenpan/action-provider-code-merge
Action provider code merge
- Loading branch information
Showing
11 changed files
with
379 additions
and
31 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ TODOs | |
- action provider basic tests | ||
|
||
- add docs along the way | ||
- octopus icon |
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,83 @@ | ||
{ | ||
"title": "Diaspora Event Fabric Messaging Schema", | ||
"type": "object", | ||
"properties": { | ||
"action": { | ||
"description": "The action to perform: 'produce' for publishing events, 'consume' for retrieving recent events.", | ||
"type": "string", | ||
"enum": [ | ||
"produce", | ||
"consume" | ||
] | ||
}, | ||
"topic": { | ||
"description": "The topic to publish or retrieve the events.", | ||
"type": "string" | ||
}, | ||
"msgs": { | ||
"type": "array", | ||
"description": "List of events, each formatted as a JSON string. Required for 'produce' action.", | ||
"items": { | ||
"type": "object" | ||
} | ||
}, | ||
"keys": { | ||
"oneOf": [ | ||
{ | ||
"type": "string", | ||
"description": "Optional single event key for 'produce' action." | ||
}, | ||
{ | ||
"type": "array", | ||
"description": "Optional list of event keys for 'produce' action.", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
] | ||
}, | ||
"ts": { | ||
"description": "Timestamp in milliseconds since the beginning of the epoch to start retrieving messages from. Required for 'consume' action.", | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"servers": { | ||
"description": "Optional list of diaspora servers separated by commas (dev use only).", | ||
"type": "string" | ||
} | ||
}, | ||
"additionalProperties": false, | ||
"required": [ | ||
"action", | ||
"topic" | ||
], | ||
"dependencies": { | ||
"action": { | ||
"oneOf": [ | ||
{ | ||
"properties": { | ||
"action": { | ||
"const": "produce" | ||
}, | ||
"msgs": { | ||
"minItems": 1 | ||
} | ||
}, | ||
"required": [ | ||
"msgs" | ||
] | ||
}, | ||
{ | ||
"properties": { | ||
"action": { | ||
"const": "consume" | ||
}, | ||
"ts": { | ||
"type": "integer" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
} |
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,60 @@ | ||
"""Diaspora Action Provider utilities. | ||
This module contains utility functions and classes for handling AWS MSK tokens, | ||
Kafka operations, and building action statuses. | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import datetime | ||
import json | ||
import os | ||
from typing import Any | ||
|
||
from globus_action_provider_tools import ActionRequest | ||
from globus_action_provider_tools import ActionStatus | ||
from globus_action_provider_tools import ActionStatusValue | ||
from globus_action_provider_tools import AuthState | ||
|
||
|
||
def load_schema() -> dict[str, Any]: | ||
"""Load Event Schema.""" | ||
with open( | ||
os.path.join( | ||
os.path.dirname(os.path.abspath(__file__)), | ||
'schema.json', | ||
), | ||
) as f: | ||
schema = json.load(f) | ||
return schema | ||
|
||
|
||
def build_action_status( | ||
auth: AuthState, | ||
status_value: ActionStatusValue | None = None, | ||
request: ActionRequest | None = None, | ||
result: dict[str, Any] | None = None, | ||
) -> ActionStatus: | ||
"""Build an ActionStatus object depending on whetherrequest is None.""" | ||
if request is None: | ||
return ActionStatus( | ||
status=ActionStatusValue.SUCCEEDED, | ||
creator_id=auth.effective_identity, | ||
start_time=str(datetime.datetime.now().isoformat()), | ||
completion_time=str(datetime.datetime.now().isoformat()), | ||
release_after='P30D', | ||
display_status=ActionStatusValue.SUCCEEDED, | ||
details={'result': None}, | ||
) | ||
else: | ||
return ActionStatus( | ||
status=status_value, | ||
creator_id=auth.effective_identity, | ||
monitor_by=request.monitor_by, | ||
manage_by=request.manage_by, | ||
start_time=str(datetime.datetime.now().isoformat()), | ||
completion_time=str(datetime.datetime.now().isoformat()), | ||
release_after=request.release_after or 'P30D', | ||
display_status=status_value, | ||
details=result, | ||
) |
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,3 @@ | ||
"""Testing code for Diaspora Service.""" | ||
|
||
from __future__ import annotations |
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,22 @@ | ||
"""Fixtures for Diaspora Service.""" | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from action_provider.main import create_app | ||
from testing.globus import get_access_token | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def client(): | ||
"""Create the Flask service.""" | ||
app = create_app() | ||
with app.test_client() as client: | ||
yield client | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def access_token(): | ||
"""Retrieve the access token.""" | ||
return get_access_token() |
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,32 @@ | ||
"""Globus related testing code for Diaspora Service.""" | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
|
||
from globus_sdk import ConfidentialAppAuthClient | ||
|
||
from common.utils import EnvironmentChecker | ||
|
||
|
||
def get_access_token() -> str: | ||
"""Get an access token to SERVER_CLIENT_ID.""" | ||
EnvironmentChecker.check_env_variables( | ||
'SERVER_CLIENT_ID', | ||
'SERVER_SECRET', | ||
'CLIENT_SCOPE', | ||
) | ||
|
||
client_id = os.getenv('SERVER_CLIENT_ID') | ||
client_secret = os.getenv('SERVER_SECRET') | ||
requested_scopes = os.getenv('CLIENT_SCOPE') | ||
|
||
ca = ConfidentialAppAuthClient( | ||
client_id=client_id, | ||
client_secret=client_secret, | ||
) | ||
token_response = ca.oauth2_client_credentials_tokens( | ||
requested_scopes=requested_scopes, | ||
) | ||
access_token = token_response.by_resource_server[client_id]['access_token'] | ||
return access_token |
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,3 +1,3 @@ | ||
"""Testing code for Diaspora Service.""" | ||
"""Tests for Diaspora Service.""" | ||
|
||
from __future__ import annotations |
Oops, something went wrong.