mirror of
https://github.com/clearml/clearml-agent
synced 2025-06-26 18:16:15 +00:00
Add environment variable for request method (#91)
* Add environment variable for default request method
This commit is contained in:
parent
5afb604e3d
commit
bf07b7f76d
@ -18,3 +18,12 @@ ENV_ENABLE_FILES_CONFIG_SECTION = EnvEntry('CLEARML_AGENT_ENABLE_FILES_CONFIG_SE
|
|||||||
ENV_INITIAL_CONNECT_RETRY_OVERRIDE = EnvEntry(
|
ENV_INITIAL_CONNECT_RETRY_OVERRIDE = EnvEntry(
|
||||||
'CLEARML_AGENT_INITIAL_CONNECT_RETRY_OVERRIDE', default=True, converter=safe_text_to_bool
|
'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")
|
@ -5,10 +5,16 @@ import six
|
|||||||
|
|
||||||
from .apimodel import ApiModel
|
from .apimodel import ApiModel
|
||||||
from .datamodel import DataModel
|
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):
|
class Request(ApiModel):
|
||||||
_method = 'get'
|
_method = ENV_API_DEFAULT_REQ_METHOD.get(default="get")
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
if kwargs:
|
if kwargs:
|
||||||
|
@ -15,7 +15,7 @@ from six.moves.urllib.parse import urlparse, urlunparse
|
|||||||
|
|
||||||
from .callresult import CallResult
|
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, \
|
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 .request import Request, BatchRequest
|
||||||
from .token_manager import TokenManager
|
from .token_manager import TokenManager
|
||||||
from ..config import load
|
from ..config import load
|
||||||
@ -615,6 +615,7 @@ class Session(TokenManager):
|
|||||||
try:
|
try:
|
||||||
data = {"expiration_sec": exp} if exp else {}
|
data = {"expiration_sec": exp} if exp else {}
|
||||||
res = self._send_request(
|
res = self._send_request(
|
||||||
|
method=ENV_API_DEFAULT_REQ_METHOD.get(default="get"),
|
||||||
service="auth",
|
service="auth",
|
||||||
action="login",
|
action="login",
|
||||||
auth=auth,
|
auth=auth,
|
||||||
|
Loading…
Reference in New Issue
Block a user