Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
docker-py
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
docker-py
Commits
bd73225e
Unverified
Kaydet (Commit)
bd73225e
authored
Tem 08, 2016
tarafından
Ben Firshman
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Set custom user agent on client
Signed-off-by:
Ben Firshman
<
ben@firshman.co.uk
>
üst
e15ba740
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
1 deletion
+37
-1
client.py
docker/client.py
+3
-1
constants.py
docker/constants.py
+3
-0
api.md
docs/api.md
+1
-0
api_test.py
tests/unit/api_test.py
+30
-0
No files found.
docker/client.py
Dosyayı görüntüle @
bd73225e
...
...
@@ -50,7 +50,8 @@ class Client(
api
.
VolumeApiMixin
,
api
.
NetworkApiMixin
):
def
__init__
(
self
,
base_url
=
None
,
version
=
None
,
timeout
=
constants
.
DEFAULT_TIMEOUT_SECONDS
,
tls
=
False
):
timeout
=
constants
.
DEFAULT_TIMEOUT_SECONDS
,
tls
=
False
,
user_agent
=
constants
.
DEFAULT_USER_AGENT
):
super
(
Client
,
self
)
.
__init__
()
if
tls
and
not
base_url
:
...
...
@@ -60,6 +61,7 @@ class Client(
self
.
base_url
=
base_url
self
.
timeout
=
timeout
self
.
headers
[
'User-Agent'
]
=
user_agent
self
.
_auth_configs
=
auth
.
load_config
()
...
...
docker/constants.py
Dosyayı görüntüle @
bd73225e
import
sys
from
.version
import
version
DEFAULT_DOCKER_API_VERSION
=
'1.22'
DEFAULT_TIMEOUT_SECONDS
=
60
...
...
@@ -12,3 +13,5 @@ INSECURE_REGISTRY_DEPRECATION_WARNING = \
'is deprecated and non-functional. Please remove it.'
IS_WINDOWS_PLATFORM
=
(
sys
.
platform
==
'win32'
)
DEFAULT_USER_AGENT
=
"docker-py/{0}"
.
format
(
version
)
docs/api.md
Dosyayı görüntüle @
bd73225e
...
...
@@ -16,6 +16,7 @@ is hosted.
to use the API version provided by the server.
*
timeout (int): The HTTP request timeout, in seconds.
*
tls (bool or
[
TLSConfig
](
tls.md#TLSConfig
)
): Equivalent CLI options:
`docker --tls ...`
*
user_agent (str): Set a custom user agent for requests to the server.
****
...
...
tests/unit/api_test.py
Dosyayı görüntüle @
bd73225e
...
...
@@ -420,3 +420,33 @@ class StreamTest(base.Cleanup, base.BaseTestCase):
self
.
assertEqual
(
list
(
stream
),
[
str
(
i
)
.
encode
()
for
i
in
range
(
50
)])
class
UserAgentTest
(
base
.
BaseTestCase
):
def
setUp
(
self
):
self
.
patcher
=
mock
.
patch
.
object
(
docker
.
Client
,
'send'
,
return_value
=
fake_resp
(
"GET"
,
"
%
s/version"
%
fake_api
.
prefix
)
)
self
.
mock_send
=
self
.
patcher
.
start
()
def
tearDown
(
self
):
self
.
patcher
.
stop
()
def
test_default_user_agent
(
self
):
client
=
docker
.
Client
()
client
.
version
()
self
.
assertEqual
(
self
.
mock_send
.
call_count
,
1
)
headers
=
self
.
mock_send
.
call_args
[
0
][
0
]
.
headers
expected
=
'docker-py/
%
s'
%
docker
.
__version__
self
.
assertEqual
(
headers
[
'User-Agent'
],
expected
)
def
test_custom_user_agent
(
self
):
client
=
docker
.
Client
(
user_agent
=
'foo/bar'
)
client
.
version
()
self
.
assertEqual
(
self
.
mock_send
.
call_count
,
1
)
headers
=
self
.
mock_send
.
call_args
[
0
][
0
]
.
headers
self
.
assertEqual
(
headers
[
'User-Agent'
],
'foo/bar'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment