mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-19 07:18:27 +01:00
Allow config option for HTTP method for uploads (Artifactory) (#4553)
* allow for a config option for http method * add tests * fix tests with method * Update dvc/tree/http.py Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
co-authored by
Ruslan Kuprieiev
parent
54a48e3256
commit
7fa90e425d
@@ -119,6 +119,7 @@ HTTP_COMMON = {
|
||||
"password": str,
|
||||
"ask_password": Bool,
|
||||
"ssl_verify": Bool,
|
||||
"method": str,
|
||||
}
|
||||
WEBDAV_COMMON = {
|
||||
"user": str,
|
||||
|
||||
+2
-1
@@ -54,6 +54,7 @@ class HTTPTree(BaseTree): # pylint:disable=abstract-method
|
||||
self.ask_password = config.get("ask_password", False)
|
||||
self.headers = {}
|
||||
self.ssl_verify = config.get("ssl_verify", True)
|
||||
self.method = config.get("method", "POST")
|
||||
|
||||
def _auth_method(self, path_info=None):
|
||||
from requests.auth import HTTPBasicAuth, HTTPDigestAuth
|
||||
@@ -194,7 +195,7 @@ class HTTPTree(BaseTree): # pylint:disable=abstract-method
|
||||
break
|
||||
yield chunk
|
||||
|
||||
response = self.request("POST", to_info.url, data=chunks())
|
||||
response = self.request(self.method, to_info.url, data=chunks())
|
||||
if response.status_code not in (200, 201):
|
||||
raise HTTPError(response.status_code, response.reason)
|
||||
|
||||
|
||||
@@ -103,3 +103,25 @@ def test_ssl_verify_disable(dvc):
|
||||
tree = HTTPTree(dvc, config)
|
||||
|
||||
assert tree._session.verify is False
|
||||
|
||||
|
||||
def test_http_method(dvc):
|
||||
from requests.auth import HTTPBasicAuth
|
||||
|
||||
user = "username"
|
||||
password = "password"
|
||||
auth = HTTPBasicAuth(user, password)
|
||||
config = {
|
||||
"url": "http://example.com/",
|
||||
"path_info": "file.html",
|
||||
"auth": "basic",
|
||||
"user": user,
|
||||
"password": password,
|
||||
"method": "PUT",
|
||||
}
|
||||
|
||||
tree = HTTPTree(dvc, config)
|
||||
|
||||
assert tree._auth_method() == auth
|
||||
assert tree.method == "PUT"
|
||||
assert isinstance(tree._auth_method(), HTTPBasicAuth)
|
||||
|
||||
Reference in New Issue
Block a user