diff --git a/clearml_agent/backend_api/session/defs.py b/clearml_agent/backend_api/session/defs.py index d49f920..9f66d7f 100644 --- a/clearml_agent/backend_api/session/defs.py +++ b/clearml_agent/backend_api/session/defs.py @@ -18,3 +18,12 @@ ENV_ENABLE_FILES_CONFIG_SECTION = EnvEntry('CLEARML_AGENT_ENABLE_FILES_CONFIG_SE ENV_INITIAL_CONNECT_RETRY_OVERRIDE = EnvEntry( 'CLEARML_AGENT_INITIAL_CONNECT_RETRY_OVERRIDE', default=True, converter=safe_text_to_bool ) + +""" +Experimental option to set the request method for all API requests and auth login. +This could be useful when GET requests with payloads are blocked by a server as +POST requests can be used instead. + +However this has not been vigorously tested and may have unintended consequences. +""" +ENV_API_DEFAULT_REQ_METHOD = EnvEntry("CLEARML_API_DEFAULT_REQ_METHOD") \ No newline at end of file diff --git a/clearml_agent/backend_api/session/request.py b/clearml_agent/backend_api/session/request.py index 7640b5a..028d9e4 100644 --- a/clearml_agent/backend_api/session/request.py +++ b/clearml_agent/backend_api/session/request.py @@ -5,10 +5,16 @@ import six from .apimodel import ApiModel from .datamodel import DataModel +from .defs import ENV_API_DEFAULT_REQ_METHOD +if ENV_API_DEFAULT_REQ_METHOD.get().upper() not in ("GET", "POST"): + raise ValueError( + "CLEARML_API_DEFAULT_REQ_METHOD environment variable must be 'get' or 'post' (any case is allowed)." + ) + class Request(ApiModel): - _method = 'get' + _method = ENV_API_DEFAULT_REQ_METHOD.get(default="get") def __init__(self, **kwargs): if kwargs: diff --git a/clearml_agent/backend_api/session/session.py b/clearml_agent/backend_api/session/session.py index b36f980..4a245f6 100644 --- a/clearml_agent/backend_api/session/session.py +++ b/clearml_agent/backend_api/session/session.py @@ -15,7 +15,7 @@ from six.moves.urllib.parse import urlparse, urlunparse from .callresult import CallResult from .defs import ENV_VERBOSE, ENV_HOST, ENV_ACCESS_KEY, ENV_SECRET_KEY, ENV_WEB_HOST, ENV_FILES_HOST, ENV_AUTH_TOKEN, \ - ENV_NO_DEFAULT_SERVER, ENV_DISABLE_VAULT_SUPPORT, ENV_INITIAL_CONNECT_RETRY_OVERRIDE + ENV_NO_DEFAULT_SERVER, ENV_DISABLE_VAULT_SUPPORT, ENV_INITIAL_CONNECT_RETRY_OVERRIDE, ENV_API_DEFAULT_REQ_METHOD from .request import Request, BatchRequest from .token_manager import TokenManager from ..config import load @@ -615,6 +615,7 @@ class Session(TokenManager): try: data = {"expiration_sec": exp} if exp else {} res = self._send_request( + method=ENV_API_DEFAULT_REQ_METHOD.get(default="get"), service="auth", action="login", auth=auth,