Skip to content

Commit 435f2e4

Browse files
committed
feat: introduce Platform class instead of JSON
1 parent 95f7f02 commit 435f2e4

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

docker/api/image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from .. import auth, errors, utils
55
from ..constants import DEFAULT_DATA_CHUNK_SIZE
6+
from ..types.image import Platform
67

78
log = logging.getLogger(__name__)
89

@@ -494,7 +495,7 @@ def push(self, repository, tag=None, stream=False, auth_config=None,
494495
raise errors.InvalidVersion(
495496
'platform was only introduced in API version 1.46'
496497
)
497-
params['platform'] = platform
498+
params['platform'] = Platform
498499

499500
response = self._post_json(
500501
u, None, headers=headers, stream=stream, params=params

docker/types/image.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from .base import DictType
2+
3+
4+
class Platform(DictType):
5+
def __init__(self, **kwargs):
6+
architecture = kwargs.get('architecture', kwargs.get('Architecture'))
7+
os = kwargs.get('os', kwargs.get('OS'))
8+
9+
if architecture is None and os is None:
10+
raise ValueError("At least one of 'architecture' or 'os' must be provided")
11+
12+
13+
super().__init__({
14+
'Architecture': architecture,
15+
'OS': os,
16+
'OSVersion': kwargs.get('os_version', kwargs.get('OSVersion')),
17+
'OSFeatures': kwargs.get('os_features', kwargs.get('OSFeatures')),
18+
'Variant': kwargs.get('variant', kwargs.get('Variant'))
19+
})
20+
21+
@property
22+
def architecture(self):
23+
return self['Architecture']
24+
25+
@property
26+
def os(self):
27+
return self['OS']
28+
29+
@architecture.setter
30+
def architecture(self, value):
31+
self['Architecture'] = value
32+
33+
@os.setter
34+
def os(self, value):
35+
self['OS'] = value

0 commit comments

Comments
 (0)