33from typing import List , Optional , Dict
44from datetime import datetime
55from marshmallow import fields
6+ from enum import Enum
67
78
89# API endpoints
1213CONTAINER_REGISTRY_CREDENTIALS_ENDPOINT = '/container-registry-credentials'
1314
1415
16+ class EnvVarType (str , Enum ):
17+ PLAIN = "plain"
18+ SECRET = "secret"
19+
20+
21+ class VolumeMountType (str , Enum ):
22+ SCRATCH = "scratch"
23+ SECRET = "secret"
24+
25+
26+ class ContainerRegistryType (str , Enum ):
27+ GCR = "gcr"
28+ DOCKERHUB = "dockerhub"
29+ GITHUB = "ghcr"
30+ AWS_ECR = "aws-ecr"
31+ CUSTOM = "custom"
32+
33+
34+ class ContainerDeploymentStatus (str , Enum ):
35+ INITIALIZING = "initializing"
36+ HEALTHY = "healthy"
37+ DEGRADED = "degraded"
38+ UNHEALTHY = "unhealthy"
39+ PAUSED = "paused"
40+ QUOTA_REACHED = "quota_reached"
41+ IMAGE_PULLING = "image_pulling"
42+ VERSION_UPDATING = "version_updating"
43+
44+
1545@dataclass_json
1646@dataclass
1747class HealthcheckSettings :
@@ -33,21 +63,13 @@ class EntrypointOverridesSettings:
3363class EnvVar :
3464 name : str
3565 value_or_reference_to_secret : str
36- type : str # "plain" or "secret"
37-
38-
39- @dataclass_json
40- @dataclass
41- class AutoupdateSettings :
42- enabled : bool
43- mode : Optional [str ] = None # "latest" or "semantic"
44- tag_filter : Optional [str ] = None
66+ type : EnvVarType # "plain" or "secret"
4567
4668
4769@dataclass_json
4870@dataclass
4971class VolumeMount :
50- type : str # "scratch" or "secret"
72+ type : VolumeMountType # "scratch" or "secret"
5173 mount_path : str
5274
5375
@@ -60,7 +82,6 @@ class Container:
6082 healthcheck : Optional [HealthcheckSettings ] = None
6183 entrypoint_overrides : Optional [EntrypointOverridesSettings ] = None
6284 env : Optional [List [EnvVar ]] = None
63- autoupdate : Optional [AutoupdateSettings ] = None
6485 volume_mounts : Optional [List [VolumeMount ]] = None
6586
6687
@@ -262,17 +283,17 @@ def delete(self, deployment_name: str) -> None:
262283 self .client .delete (
263284 f"{ CONTAINER_DEPLOYMENTS_ENDPOINT } /{ deployment_name } " )
264285
265- def get_status (self , deployment_name : str ) -> Dict :
286+ def get_status (self , deployment_name : str ) -> ContainerDeploymentStatus :
266287 """Get deployment status
267288
268289 :param deployment_name: name of the deployment
269290 :type deployment_name: str
270291 :return: deployment status
271- :rtype: Dict
292+ :rtype: ContainerDeploymentStatus
272293 """
273294 response = self .client .get (
274295 f"{ CONTAINER_DEPLOYMENTS_ENDPOINT } /{ deployment_name } /status" )
275- return response .json ()
296+ return ContainerDeploymentStatus ( response .json ()[ "status" ] )
276297
277298 def restart (self , deployment_name : str ) -> None :
278299 """Restart a deployment
@@ -468,13 +489,13 @@ def get_registry_credentials(self) -> List[RegistryCredential]:
468489 response = self .client .get (CONTAINER_REGISTRY_CREDENTIALS_ENDPOINT )
469490 return [RegistryCredential .from_dict (credential ) for credential in response .json ()]
470491
471- def add_registry_credentials (self , name : str , registry_type : str , username : str , access_token : str ) -> RegistryCredential :
492+ def add_registry_credentials (self , name : str , registry_type : ContainerRegistryType , username : str , access_token : str ) -> RegistryCredential :
472493 """Add registry credentials
473494
474495 :param name: name of the credentials
475496 :type name: str
476- :param registry_type: type of registry (e.g. "dockerhub" )
477- :type registry_type: str
497+ :param registry_type: type of registry (e.g. ContainerRegistryType.DOCKERHUB )
498+ :type registry_type: ContainerRegistryType
478499 :param username: registry username
479500 :type username: str
480501 :param access_token: registry access token
@@ -484,7 +505,7 @@ def add_registry_credentials(self, name: str, registry_type: str, username: str,
484505 """
485506 data = {
486507 "name" : name ,
487- "registry_type" : registry_type ,
508+ "registry_type" : registry_type . value ,
488509 "username" : username ,
489510 "access_token" : access_token
490511 }
0 commit comments