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

Add Session Handling #481

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

williamjsmith15
Copy link

Adds session handling for the BioBlend API library so that cookies can be used for an authentication layer external to Galaxy.

Fixes #480

Example of use in the docs/examples/session_handling/cookie_handler.py script. Note: this would need a Galaxy instance configured behind an authentication system.

To allow for the cookie from the reverse proxy to propogate through
the bioblend API requests - still need to do for all other requests
Good start through
Copy link
Member

@nsoranzo nsoranzo left a comment

Choose a reason for hiding this comment

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

Thanks for opening the PR! Can you also have a look at the linting errors (the test failures are about to be fixed in the main branch).

bioblend/galaxy/__init__.py Outdated Show resolved Hide resolved
bioblend/galaxy/objects/galaxy_instance.py Outdated Show resolved Hide resolved
bioblend/galaxy/objects/galaxy_instance.py Outdated Show resolved Hide resolved
bioblend/galaxyclient.py Outdated Show resolved Hide resolved
bioblend/galaxyclient.py Outdated Show resolved Hide resolved
bioblend/galaxy/__init__.py Outdated Show resolved Hide resolved
bioblend/galaxyclient.py Outdated Show resolved Hide resolved
docs/examples/session_handling/cookie_handler.py Outdated Show resolved Hide resolved
docs/examples/session_handling/cookie_handler.py Outdated Show resolved Hide resolved
bioblend/galaxy/objects/galaxy_instance.py Outdated Show resolved Hide resolved
@williamjsmith15 williamjsmith15 marked this pull request as draft September 28, 2023 00:30
Copy link
Member

@nsoranzo nsoranzo left a comment

Choose a reason for hiding this comment

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

Looking good! A few more suggestions for your example scripts.


with requests.Session() as session:
session.cookies = cookie_jar
session.verify = True
Copy link
Member

Choose a reason for hiding this comment

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

This is the default:

Suggested change
session.verify = True

Comment on lines +79 to +80
GALAXY_KEY = "user_api_key"
WORKFLOW_NAME = "workflow_name"
Copy link
Member

Choose a reason for hiding this comment

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

Move these 2 constants to the top with the other constants?

from bioblend.galaxy import GalaxyInstance


def get_inputs(server, api_key, workflow_name, session=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_inputs(server, api_key, workflow_name, session=None):
def get_inputs(gi, workflow_name):

Comment on lines +8 to +14
Usage:
get_inputs(
server = "galaxy.server.org",
api_key = "user_api_key",
workflow_name = "workflow_name",
)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Usage:
get_inputs(
server = "galaxy.server.org",
api_key = "user_api_key",
workflow_name = "workflow_name",
)

Comment on lines +16 to +18
server (string): Galaxy server address
api_key (string): User generated string from galaxy instance
to create: User > Preferences > Manage API Key > Create a new key
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
server (string): Galaxy server address
api_key (string): User generated string from galaxy instance
to create: User > Preferences > Manage API Key > Create a new key
gi: GalaxyInstance object

print(response)

print("Getting inputs for a workflow")
response = get_inputs(f"https://{API_HOSTNAME}", GALAXY_KEY, WORKFLOW_NAME, session=session)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
response = get_inputs(f"https://{API_HOSTNAME}", GALAXY_KEY, WORKFLOW_NAME, session=session)
response = get_inputs(gi, WORKFLOW_NAME)

Comment on lines +40 to +45
Usage:
get_workflows(
server = "galaxy.server.org",
api_key = "user_api_key",
)

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Usage:
get_workflows(
server = "galaxy.server.org",
api_key = "user_api_key",
)

return inputs


def get_workflows(server, api_key, session=None):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def get_workflows(server, api_key, session=None):
def get_workflows(gi):

Returns:
workflows (array of strings): Workflows available to be run on the galaxy instance provided
"""
gi = GalaxyInstance(url=server, key=api_key, session=session)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
gi = GalaxyInstance(url=server, key=api_key, session=session)

Comment on lines +47 to +49
server (string): Galaxy server address
api_key (string): User generated string from galaxy instance
to create: User > Preferences > Manage API Key > Create a new key
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
server (string): Galaxy server address
api_key (string): User generated string from galaxy instance
to create: User > Preferences > Manage API Key > Create a new key
gi: GalaxyInstance object

@nsoranzo
Copy link
Member

nsoranzo commented Oct 2, 2023

@williamjsmith15 I was thinking, what if we pass cookies: Optional[http.cookiejar.CookieJar] = None instead of session to the GalaxyInstance/GalaxyClient constructors?

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.

Allow Session Cookies in Requests
2 participants