@@ -41,7 +41,7 @@ class CosmosDBEmulatorContainer(DockerContainer):
41
41
.. doctest::
42
42
>>> from testcontainers.cosmosdb import CosmosDBEmulatorContainer
43
43
>>> with CosmosDBEmulatorContainer() as cosmosdb:
44
- ... db = cosmosdb.sync_client ().create_database_if_not_exists("test")
44
+ ... db = cosmosdb.insecure_sync_client ().create_database_if_not_exists("test")
45
45
46
46
.. doctest::
47
47
>>> from testcontainers.cosmosdb import CosmosDBEmulatorContainer
@@ -84,39 +84,51 @@ def __init__(
84
84
), "A MongoDB version is required to use the MongoDB Endpoint"
85
85
self .mongodb_version = mongodb_version
86
86
87
- def start (self ) -> Self :
88
- self ._configure ()
89
- super ().start ()
90
- self ._wait_until_ready ()
91
- return self
92
-
93
87
@property
94
88
def url (self ) -> str :
95
89
"""
96
- Returns the url to interact with the emulator
90
+ The url to the CosmosDB server
97
91
"""
98
92
return f"https://{ self .host } :{ self .get_exposed_port (EMULATOR_PORT )} "
99
93
100
94
@property
101
95
def host (self ) -> str :
102
96
return self .get_container_host_ip ()
103
97
98
+ @property
99
+ def certificate_pem (self ) -> bytes :
100
+ """
101
+ PEM-encoded certificate of the CosmosDB server
102
+ """
103
+ return self ._cert_pem_bytes
104
+
104
105
def ports (self , endpoint : Endpoints ) -> Iterable [int ]:
106
+ """
107
+ Returns the set of exposed ports for a given endpoint.
108
+ If bind_ports is True, the returned ports will be the NAT-ed ports reachable from the host.
109
+ """
105
110
assert endpoint in self .endpoints , f"Endpoint { endpoint } is not exposed"
106
111
return {self .get_exposed_port (p ) for p in endpoint_ports [endpoint ]}
107
112
108
- def async_client (self ) -> AsyncCosmosClient :
113
+ def insecure_async_client (self ) -> AsyncCosmosClient :
109
114
"""
110
- Returns an asynchronous CosmosClient instance to interact with the CosmosDB server
115
+ Returns an asynchronous CosmosClient instance
111
116
"""
112
117
return AsyncCosmosClient (url = self .url , credential = self .key , connection_verify = False )
113
118
114
- def sync_client (self ) -> SyncCosmosClient :
119
+ def insecure_sync_client (self ) -> SyncCosmosClient :
115
120
"""
116
- Returns a synchronous CosmosClient instance to interact with the CosmosDB server
121
+ Returns a synchronous CosmosClient instance
117
122
"""
118
123
return SyncCosmosClient (url = self .url , credential = self .key , connection_verify = False )
119
124
125
+ def start (self ) -> Self :
126
+ self ._configure ()
127
+ super ().start ()
128
+ self ._wait_until_ready ()
129
+ self ._cert_pem_bytes = self ._download_cert ()
130
+ return self
131
+
120
132
def _configure (self ) -> None :
121
133
self .with_bind_ports (EMULATOR_PORT , EMULATOR_PORT )
122
134
@@ -162,6 +174,10 @@ def _wait_for_logs(self, *args, **kwargs) -> Self:
162
174
163
175
@wait_container_is_ready (ServiceRequestError )
164
176
def _wait_for_query_success (self , query : Callable [[SyncCosmosClient ], None ]) -> Self :
165
- with self .sync_client () as c :
177
+ with self .insecure_sync_client () as c :
166
178
query (c )
167
179
return self
180
+
181
+ def _download_cert (self ) -> bytes :
182
+ with urlopen (f"{ self .url } /_explorer/emulator.pem" , context = ssl ._create_unverified_context ()) as response :
183
+ return response .read ()
0 commit comments