forked from PADAS/gundi-integration-action-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from movebank_client import MovebankClient | ||
|
||
from app.actions.configurations import AuthenticateConfig | ||
from app.services.errors import ConfigurationNotFound | ||
from app.services.utils import find_config_for_action | ||
|
||
|
||
def get_auth_config(integration): | ||
# Look for the login credentials, needed for any action | ||
auth_config = find_config_for_action( | ||
configurations=integration.configurations, | ||
action_id="auth" | ||
) | ||
if not auth_config: | ||
raise ConfigurationNotFound( | ||
f"Authentication settings for integration {str(integration.id)} " | ||
f"are missing. Please fix the integration setup in the portal." | ||
) | ||
return AuthenticateConfig.parse_obj(auth_config.data) |
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,27 @@ | ||
from datetime import datetime, timezone | ||
from pydantic import Field | ||
|
||
from app.actions import AuthActionConfiguration, PullActionConfiguration | ||
|
||
|
||
class AuthenticateConfig(AuthActionConfiguration): | ||
username: str | ||
password: str | ||
|
||
|
||
class FetchIndividualEventsConfig(PullActionConfiguration): | ||
start_time: datetime | ||
study_id: int | ||
individual_id: int | ||
|
||
|
||
class FetchStudyIndividualsConfig(PullActionConfiguration): | ||
study_id: str = Field( | ||
title='Movebank Study IDs', | ||
description='ID of the desired Movebank Study.', | ||
) | ||
start_time: datetime = Field( | ||
title='Start Datetime', | ||
description='Datetime events are going to be fetched from.', | ||
default=datetime.now(tz=timezone.utc) | ||
) |
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,38 @@ | ||
import datetime | ||
import httpx | ||
import logging | ||
import stamina | ||
|
||
import app.services.gundi as gundi_tools | ||
import app.settings.integration as settings | ||
import app.actions.client as client | ||
|
||
from app.actions.configurations import AuthenticateConfig, FetchStudyIndividualsConfig, FetchIndividualEventsConfig | ||
from app.services.activity_logger import activity_logger | ||
from app.services.state import IntegrationStateManager | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
state_manager = IntegrationStateManager() | ||
|
||
|
||
async def action_auth(integration, action_config: AuthenticateConfig): | ||
logger.info( | ||
f"Executing auth action with integration {integration} and action_config {action_config}..." | ||
) | ||
mb_client = client.MovebankClient( | ||
base_url=integration.base_url, | ||
username=action_config.username, | ||
password=action_config.password | ||
) | ||
|
||
token = await mb_client.get_token() | ||
|
||
if token: | ||
logger.info(f"Auth successful for integration '{integration.name}'. Token: '{token['api-token']}'") | ||
return True | ||
else: | ||
logger.error(f"Auth unsuccessful for integration {integration}.") | ||
return False |
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 +1 @@ | ||
movebank-client~=1.0.0 | ||
movebank-client~=1.1.0 |
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