Skip to content

Commit

Permalink
add flag to force_api_key, defaults to False
Browse files Browse the repository at this point in the history
when api_key is forced the connection to stash will persist past cookie expiration this is useful for long running connections to stash that need to last longer than normal

this may cause issues if stash is expecting a cookie from a plugin, especially with hooks, note in the stash manual

"It is possible for hooks to trigger each other or themselves if they perform mutations. For safety, hooks will not be triggered if they have already been triggered in the context of the operation. Stash uses cookies to track this context, so it's important for plugins to send cookies when performing operations."
  • Loading branch information
stg-annon committed Jan 4, 2025
1 parent 6901523 commit db94262
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions stashapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StashInterface(GQLWrapper):
port = ""
url = ""

def __init__(self, conn:dict={}, fragments:list[str]=[], verify_ssl:bool=True):
def __init__(self, conn:dict={}, fragments:list[str]=[], verify_ssl:bool=True, force_api_key=False):
super().__init__()
self.s.verify = verify_ssl

Expand Down Expand Up @@ -58,7 +58,8 @@ def __init__(self, conn:dict={}, fragments:list[str]=[], verify_ssl:bool=True):
self.log.debug(f'Using stash ({self.version}) endpoint at {self.url}')

# grab API key to persist connection past session cookie duration
if api_key := self.call_GQL("query getApiKey{ configuration { general { apiKey } } }")["configuration"]["general"]["apiKey"]:
api_key = self.call_GQL("query getApiKey{ configuration { general { apiKey } } }")["configuration"]["general"]["apiKey"]
if force_api_key and api_key:
self.log.debug("Persisting Connection to Stash with ApiKey...")
self.s.headers.update({"ApiKey":api_key})
self.s.cookies.clear()
Expand Down

0 comments on commit db94262

Please sign in to comment.