Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/maappy gets username #108

Merged
merged 19 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
(post 4.1.1 release)
### Added
### Changed
- listJobs no longer takes username as an argument, you can only list jobs for the current `MAAP_PGT` token user
- submitJob gets the username from the `MAAP_PGT` token and not username being submitted as an argument
### Deprecated
### Removed
### Fixed
Expand Down
17 changes: 6 additions & 11 deletions maap/maap.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def cancelJob(self, jobid):
job.id = jobid
return job.cancel_job()

def listJobs(self, username=None, *,
def listJobs(self, *,
algo_id=None,
end_time=None,
get_job_details=True,
Expand All @@ -274,7 +274,6 @@ def listJobs(self, username=None, *,
Returns a list of jobs for a given user that matches query params provided.

Args:
username (str, optional): Platform user. If no username is provided, the profile username will be used.
algo_id (str, optional): Algorithm type.
end_time (str, optional): Specifying this parameter will return all jobs that have completed from the provided end time to now. e.g. 2024-01-01 or 2024-01-01T00:00:00.000000Z.
get_job_details (bool, optional): Flag that determines whether to return a detailed job list or a compact list containing just the job ids and their associated job tags. Default is True.
Expand All @@ -290,18 +289,11 @@ def listJobs(self, username=None, *,
list: List of jobs for a given user that matches query params provided.

Raises:
ValueError: If username is not provided and cannot be obtained from the user's profile.
ValueError: If either algo_id or version is provided, but not both.
"""
if username is None and self.profile is not None and 'username' in self.profile.account_info().keys():
username = self.profile.account_info()['username']

if username is None:
raise ValueError("Unable to determine username from profile. Please provide a username.")

url = "/".join(
segment.strip("/")
for segment in (self.config.dps_job, username, endpoints.DPS_JOB_LIST)
for segment in (self.config.dps_job, endpoints.DPS_JOB_LIST)
)

params = {
Expand All @@ -316,7 +308,6 @@ def listJobs(self, username=None, *,
("start_time", start_time),
("status", status),
("tag", tag),
("username", username),
("version", version),
)
if v is not None
Expand Down Expand Up @@ -349,6 +340,10 @@ def listJobs(self, username=None, *,
return response

def submitJob(self, identifier, algo_id, version, queue, retrieve_attributes=False, **kwargs):
# Note that this is temporary and will be removed when we remove the API not requiring username to submit a job
# Also this now overrides passing someone else's username into submitJob since we don't want to allow that
if self.profile is not None and self.profile.account_info() is not None and 'username' in self.profile.account_info().keys():
kwargs['username'] = self.profile.account_info()['username']
response = self._DPS.submit_job(request_url=self.config.dps_job,
identifier=identifier, algo_id=algo_id, version=version, queue=queue, **kwargs)
job = DPSJob(self.config)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "maap-py"
version = "4.1.0a3"
version = "4.2.0"
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]>"]
Expand Down
Loading