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

Implement login endpoint #46 #47

Merged
merged 5 commits into from
Jan 14, 2025
Merged

Conversation

patrick-austin
Copy link

@patrick-austin patrick-austin commented Nov 28, 2024

Should be independent of other changes

  • Add login endpoint to UserResource
  • Add login function to IcatClient

Closes #46

*/
@POST
@Path("/session")
public String login(@QueryParam("facilityName") String facilityName, @FormParam("json") String jsonString) throws BadRequestException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this endpoint is not simple/user-friendly enough for a DLS user, mainly for 2 reasons.

  1. They should not have to specify that the facilityName is "DLS"
  2. We should not pass on the horrible task of creating the ICAT json string required for the credentials.

Ideally a DLS user just wants to submit their username and password and get a session ID back.
So probably what we need is 2 mandatory parameters for username and password, and the facility name as an optional parameter that if not provided is either picked up from a new property (facility.default?) or just assumed to be the first facility in the facility.list property. The plugin could also be an optional parameter that if not specified is picked up from a new property (login.plugin.default?)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to simplify this along those lines. In the first instance was trying to keep things consistent with how ICAT server accepts login requests (the JSON string) and how all the other download-api endpoints require the facilityName as a PathParam, QueryParam or FormParam.

Have replaced the json string with username, password, plugin. facility_name and plugin are optional. The latter just uses a new default value in the properties. The former will default to the only facility set in cases where there is only one facility set. I assumed this would be the case for Diamond (i.e. that API is only running for them and not multiple facilities) but if not I can relax this to just always use the first if facility_name is null. Note that this removed explicit null checks that existed before, but didn't notice any unexpected behaviour. It will also allow other endpoints created as part of this feature to benefit from not needing to specify the Facility.

@patrick-austin
Copy link
Author

Implemented explicit defaultFacilityName for cases where multiple Facilities specified in config.

Local and CI test failures were being caused by (I suspect) Downloads generated from the new tests from #43 and/or #44 not being cleared up after the tests finished, which then caused tests from #45 to fail as these other Downloads were being processed instead. Added similar clean up in a finally to these locations, as well as moving an existing deletion in testDownloadAPI to a finally block to try and preempt any further bad data interfering with later tests.

testDownload.setTransport("http");
downloadRepository.save(testDownload);
downloadId = testDownload.getId();
System.out.println("userstatus:" + downloadId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo/copy paste? (It prints "userstatus:" but then adds the download ID)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string is intentional (UserResourceTest + testSetDownloadStatus -> "userstatus") but it's a debug statement left in from when I was trying to work out which Downloads were being generated by one test and then triggering failures in another - will remove it.

@patrick-austin patrick-austin merged commit ae9fd7e into 36_queuing Jan 14, 2025
1 check passed
@patrick-austin patrick-austin deleted the 46_login_endpoint branch January 14, 2025 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants