-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove the need to track maap.cfg file (#93) * Remove the need to track maap.cfg * Fix merge issues * Allow overriding of MAAP_API_HOST * Split config url construction into functions * Add test for config reader * Add script to perform functional test of maap-py * Construct api root url from provided maap host * Apply suggestions from code review Co-authored-by: Chuck Daniels <[email protected]> * Apply suggestions from code review to update url handling Co-authored-by: Chuck Daniels <[email protected]> * Remove unused code and memoize get config function * Update request utils to drop class and use methods * Use new request utils and pass maap config object * Update imports and url handling * Simplify boolean self-signed for request utils * Remove usage of os.path.join for constructing urls * Fix variable name in exception message * Remove incorrect import * Update functional tests --------- Co-authored-by: Chuck Daniels <[email protected]> * added pagination to listJobs endpoint * change request * Issues/95: Add CICD pipeline (#101) * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Setup CICD * Fetch full repo in checkout for sonar analysis * tweak pr template wording * /version 4.0.1a0 * /version 4.1.0a1 * added more query params (#98) * added more query params * added get_job_details flag * cleanup * Update maap/maap.py Co-authored-by: Chuck Daniels <[email protected]> * Update maap/maap.py Co-authored-by: Chuck Daniels <[email protected]> * Update maap/maap.py Co-authored-by: Chuck Daniels <[email protected]> * added docstring | updated param handling * review updates * review updates * renamed file --------- Co-authored-by: Chuck Daniels <[email protected]> * /version 4.1.0a2 * secret management (#104) * wip * cleanup * updated get_secret endpoint to return value * added tests for secrets management * updated error handling | added logging * review comments * /version 4.1.0a3 * /version 4.2.0a0 * added changelog entry * /version 4.1.0rc1 --------- Co-authored-by: Sujen Shah <[email protected]> Co-authored-by: Chuck Daniels <[email protected]> Co-authored-by: Frank Greguska <[email protected]> Co-authored-by: frankinspace <[email protected]> Co-authored-by: marjo-luc <[email protected]>
- Loading branch information
1 parent
d3ffa47
commit 0fdf235
Showing
7 changed files
with
283 additions
and
6 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 |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import requests | ||
import logging | ||
import json | ||
from maap.utils import endpoints | ||
from maap.utils import requests_utils | ||
from maap.utils import endpoints | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class Secrets: | ||
""" | ||
Functions used for member secrets API interfacing | ||
""" | ||
def __init__(self, member_endpoint, api_header): | ||
self._api_header = api_header | ||
self._members_endpoint = f"{member_endpoint}/{endpoints.MEMBERS_SECRETS}" | ||
|
||
|
||
def get_secrets(self): | ||
""" | ||
Returns a list of secrets for a given user. | ||
Returns: | ||
list: Returns a list of dicts containing secret names e.g. [{'secret_name': 'secret1'}, {'secret_name': 'secret2'}]. | ||
""" | ||
try: | ||
response = requests.get( | ||
url = self._members_endpoint, | ||
headers=self._api_header | ||
) | ||
logger.debug(f"Response from get_secrets request: {response.text}") | ||
return json.loads(response.text) | ||
except Exception as e: | ||
raise(f"Error retrieving secrets: {e}") | ||
|
||
|
||
def get_secret(self, secret_name): | ||
""" | ||
Returns secret value for provided secret name. | ||
Args: | ||
secret_name (str, required): Secret name. | ||
Returns: | ||
string: Secret value. | ||
Raises: | ||
ValueError: If secret name is not provided. | ||
""" | ||
if secret_name is None: | ||
raise ValueError("Secret name parameter cannot be None.") | ||
|
||
try: | ||
response = requests.get( | ||
url = f"{self._members_endpoint}/{secret_name}", | ||
headers=self._api_header | ||
) | ||
|
||
# Return secret value directly for user ease-of-use | ||
if response.ok: | ||
response = response.json() | ||
return response["secret_value"] | ||
|
||
logger.debug(f"Response from get_secret request: {response.text}") | ||
return json.loads(response.text) | ||
except Exception as e: | ||
raise(f"Error retrieving secret: {e}") | ||
|
||
|
||
def add_secret(self, secret_name=None, secret_value=None): | ||
""" | ||
Adds a secret. Secret name must be provided. Secret value may be null. | ||
Args: | ||
secret_name (str, required): Secret name. | ||
secret_value (str, optional): Secret value. | ||
Returns: | ||
dict: Containing name and value of secret that was just added. | ||
Raises: | ||
ValueError: If secret name or secret value is not provided. | ||
""" | ||
if secret_name is None or secret_value is None: | ||
raise ValueError("Failed to add secret. Secret name and secret value must not be 'None'.") | ||
|
||
try: | ||
response = requests.post( | ||
url = self._members_endpoint, | ||
headers=self._api_header, | ||
data=json.dumps({"secret_name": secret_name, "secret_value": secret_value}) | ||
) | ||
|
||
logger.debug(f"Response from add_secret: {response.text}") | ||
return json.loads(response.text) | ||
except Exception as e: | ||
raise(f"Error adding secret: {e}") | ||
|
||
|
||
def delete_secret(self, secret_name=None): | ||
""" | ||
Deletes a secret. | ||
Args: | ||
secret_name (str, required): Secret name. | ||
Returns: | ||
dict: Containing response code and message indicating whether or not deletion was successful. | ||
Raises: | ||
ValueError: If secret name is not provided. | ||
""" | ||
if secret_name is None: | ||
raise ValueError("Failed to delete secret. Please provide secret name.") | ||
|
||
try: | ||
response = requests.delete( | ||
url = f"{self._members_endpoint}/{secret_name}", | ||
headers=self._api_header | ||
) | ||
|
||
logger.debug(f"Response from delete_secret: {response.text}") | ||
return json.loads(response.text) | ||
except Exception as e: | ||
raise(f"Error deleting secret: {e}") | ||
|
||
|
||
|
||
|
||
|
||
|
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
DPS_JOB_DISMISS = "cancel" | ||
DPS_JOB_LIST = "list" | ||
CMR_ALGORITHM_DATA = "data" | ||
|
||
MEMBERS_SECRETS = "secrets" |
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,21 @@ | ||
# Valid job statuses (loosely based on OGC job status types) | ||
JOB_STATUSES = {'Accepted', 'Running', 'Succeeded', 'Failed', 'Dismissed', 'Deduped', 'Offline'} | ||
|
||
def validate_job_status(status): | ||
''' | ||
Validates job status | ||
Args: | ||
status (str): Job status. Accepted values are: 'Accepted', 'Running', 'Succeeded', 'Failed, 'Dismissed', 'Deduped', and 'Offline'. | ||
Returns: | ||
status (str): Returns unmodified job status if job status is valid. | ||
Raises: | ||
ValueError: If invalid job status is provided. | ||
''' | ||
if status not in JOB_STATUSES: | ||
valid_statuses = ", ".join(str(status) for status in JOB_STATUSES) | ||
raise ValueError("Invalid job status: '{}'. Job status must be one of the following: {}".format(status, valid_statuses)) | ||
|
||
return status |
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,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "maap-py" | ||
version = "4.0.1" | ||
version = "4.1.0rc1" | ||
description = "Python client API for interacting with the NASA MAAP API" | ||
repository = "https://github.com/MAAP-Project/maap-py" | ||
authors = ["Jet Propulsion Laboratory <[email protected]>"] | ||
|
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