mirror of
https://github.com/clearml/clearml
synced 2025-03-03 18:52:12 +00:00
Add environment variable for default request method (#521)
This commit is contained in:
parent
13645661d8
commit
8f1e2b0aae
@ -17,3 +17,12 @@ ENV_CLEARML_NO_DEFAULT_SERVER = EnvEntry("CLEARML_NO_DEFAULT_SERVER", "TRAINS_NO
|
|||||||
ENV_DISABLE_VAULT_SUPPORT = EnvEntry('CLEARML_DISABLE_VAULT_SUPPORT', type=bool)
|
ENV_DISABLE_VAULT_SUPPORT = EnvEntry('CLEARML_DISABLE_VAULT_SUPPORT', type=bool)
|
||||||
ENV_ENABLE_ENV_CONFIG_SECTION = EnvEntry('CLEARML_ENABLE_ENV_CONFIG_SECTION', type=bool)
|
ENV_ENABLE_ENV_CONFIG_SECTION = EnvEntry('CLEARML_ENABLE_ENV_CONFIG_SECTION', type=bool)
|
||||||
ENV_ENABLE_FILES_CONFIG_SECTION = EnvEntry('CLEARML_ENABLE_FILES_CONFIG_SECTION', type=bool)
|
ENV_ENABLE_FILES_CONFIG_SECTION = EnvEntry('CLEARML_ENABLE_FILES_CONFIG_SECTION', type=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")
|
||||||
|
@ -1,15 +1,22 @@
|
|||||||
import abc
|
import abc
|
||||||
|
|
||||||
import jsonschema
|
import jsonschema
|
||||||
|
import os
|
||||||
import six
|
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.exists() and 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):
|
||||||
allow_extra_fields = kwargs.pop("_allow_extra_fields_", False)
|
allow_extra_fields = kwargs.pop("_allow_extra_fields_", False)
|
||||||
if not allow_extra_fields and kwargs:
|
if not allow_extra_fields and kwargs:
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import json as json_lib
|
import json as json_lib
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import types
|
import types
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
@ -24,6 +25,7 @@ from .defs import (
|
|||||||
ENV_DISABLE_VAULT_SUPPORT,
|
ENV_DISABLE_VAULT_SUPPORT,
|
||||||
ENV_ENABLE_ENV_CONFIG_SECTION,
|
ENV_ENABLE_ENV_CONFIG_SECTION,
|
||||||
ENV_ENABLE_FILES_CONFIG_SECTION,
|
ENV_ENABLE_FILES_CONFIG_SECTION,
|
||||||
|
ENV_API_DEFAULT_REQ_METHOD,
|
||||||
)
|
)
|
||||||
from .request import Request, BatchRequest # noqa: F401
|
from .request import Request, BatchRequest # noqa: F401
|
||||||
from .token_manager import TokenManager
|
from .token_manager import TokenManager
|
||||||
@ -709,6 +711,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