@@ -39,18 +39,11 @@ class AzuriteContainer(DockerContainer):
39
39
... api_version="2019-12-12"
40
40
... )
41
41
"""
42
-
43
- _AZURITE_ACCOUNT_NAME = os .environ .get ("AZURITE_ACCOUNT_NAME" , "devstoreaccount1" )
44
- _AZURITE_ACCOUNT_KEY = os .environ .get ("AZURITE_ACCOUNT_KEY" , "Eby8vdM02xNOcqFlqUwJPLlmEtlCDX"
45
- "J1OUzFT50uSRZ6IFsuFq2UVErCz4I6"
46
- "tq/K1SZFPTOtr/KBHBeksoGMGw==" )
47
-
48
- _BLOB_SERVICE_PORT = 10_000
49
- _QUEUE_SERVICE_PORT = 10_001
50
- _TABLE_SERVICE_PORT = 10_002
51
-
52
- def __init__ (self , image : str = "mcr.microsoft.com/azure-storage/azurite:latest" ,
53
- ports_to_expose : Optional [Iterable [int ]] = None , ** kwargs ) -> None :
42
+ def __init__ (self , image : str = "mcr.microsoft.com/azure-storage/azurite:latest" , * ,
43
+ ports_to_expose : Optional [Iterable [int ]] = None , blob_service_port : int = 10_000 ,
44
+ queue_service_port : int = 10_001 , table_service_port : int = 10_002 ,
45
+ account_name : Optional [str ] = None , account_key : Optional [str ] = None , ** kwargs ) \
46
+ -> None :
54
47
""" Constructs an AzuriteContainer.
55
48
56
49
Args:
@@ -59,41 +52,41 @@ def __init__(self, image: str = "mcr.microsoft.com/azure-storage/azurite:latest"
59
52
**kwargs: Keyword arguments passed to super class.
60
53
"""
61
54
super ().__init__ (image = image , ** kwargs )
62
-
63
- if ports_to_expose is None :
64
- ports_to_expose = [
65
- self ._BLOB_SERVICE_PORT ,
66
- self ._QUEUE_SERVICE_PORT ,
67
- self ._TABLE_SERVICE_PORT
68
- ]
69
-
70
- if len (ports_to_expose ) == 0 :
71
- raise ValueError ("Expected a list with port numbers to expose" )
55
+ self .account_name = account_name or os .environ .get (
56
+ "AZURITE_ACCOUNT_NAME" , "devstoreaccount1" )
57
+ self .account_key = account_key or os .environ .get (
58
+ "AZURITE_ACCOUNT_KEY" , "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/"
59
+ "K1SZFPTOtr/KBHBeksoGMGw==" )
60
+
61
+ self .blob_service_port = blob_service_port
62
+ self .queue_service_port = queue_service_port
63
+ self .table_service_port = table_service_port
64
+ if not ports_to_expose :
65
+ ports_to_expose = [blob_service_port , queue_service_port , table_service_port ]
72
66
73
67
self .with_exposed_ports (* ports_to_expose )
74
- self .with_env ("AZURITE_ACCOUNTS" ,
75
- f"{ self ._AZURITE_ACCOUNT_NAME } :{ self ._AZURITE_ACCOUNT_KEY } " )
68
+ self .with_env ("AZURITE_ACCOUNTS" , f"{ self .account_name } :{ self .account_key } " )
76
69
77
70
def get_connection_string (self ) -> str :
78
71
host_ip = self .get_container_host_ip ()
79
72
connection_string = f"DefaultEndpointsProtocol=http;" \
80
- f"AccountName={ self ._AZURITE_ACCOUNT_NAME } ;" \
81
- f"AccountKey={ self ._AZURITE_ACCOUNT_KEY } ;"
73
+ f"AccountName={ self .account_name } ;" \
74
+ f"AccountKey={ self .account_key } ;"
82
75
83
- if self ._BLOB_SERVICE_PORT in self .ports :
76
+ if self .blob_service_port in self .ports :
84
77
connection_string += f"BlobEndpoint=http://{ host_ip } :" \
85
- f"{ self .get_exposed_port (self ._BLOB_SERVICE_PORT )} " \
86
- f"/{ self ._AZURITE_ACCOUNT_NAME } ;"
78
+ f"{ self .get_exposed_port (self .blob_service_port )} " \
79
+ f"/{ self .account_name } ;"
87
80
88
- if self ._QUEUE_SERVICE_PORT in self .ports :
81
+ if self .queue_service_port in self .ports :
89
82
connection_string += f"QueueEndpoint=http://{ host_ip } :" \
90
- f"{ self .get_exposed_port (self ._QUEUE_SERVICE_PORT )} " \
91
- f"/{ self ._AZURITE_ACCOUNT_NAME } ;"
83
+ f"{ self .get_exposed_port (self .queue_service_port )} " \
84
+ f"/{ self .account_name } ;"
92
85
93
- if self ._TABLE_SERVICE_PORT in self .ports :
86
+ if self .table_service_port in self .ports :
94
87
connection_string += f"TableEndpoint=http://{ host_ip } :" \
95
- f"{ self .get_exposed_port (self ._TABLE_SERVICE_PORT )} " \
96
- f"/{ self ._AZURITE_ACCOUNT_NAME } ;"
88
+ f"{ self .get_exposed_port (self .table_service_port )} " \
89
+ f"/{ self .account_name } ;"
97
90
98
91
return connection_string
99
92
0 commit comments