Skip to content

Commit f47c416

Browse files
committed
Revert "Refactor CloudProxy initialization and configuration loading"
This reverts commit dc099bf.
1 parent dc099bf commit f47c416

File tree

4 files changed

+201
-292
lines changed

4 files changed

+201
-292
lines changed

cloudproxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from cloudproxy.providers import manager
22

3-
# Removed: manager.init_schedule()
3+
manager.init_schedule()

cloudproxy/__main__.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
#!/usr/bin/env python
2-
import sys
3-
from loguru import logger
4-
from cloudproxy.providers import manager
5-
from cloudproxy.main import start as start_api
6-
# Importing settings ensures environment variables are loaded for standalone mode
7-
from cloudproxy.providers import settings
2+
from cloudproxy.main import start
83

94
if __name__ == "__main__":
10-
logger.info("Starting CloudProxy in standalone mode...")
11-
12-
# Configuration is loaded from environment variables via settings.py import
13-
14-
logger.info("Initializing background scheduler...")
15-
# Explicitly start the scheduler for standalone mode
16-
try:
17-
manager.init_schedule()
18-
logger.info("Scheduler initialized successfully.")
19-
except Exception as e:
20-
logger.exception("Failed to initialize scheduler.")
21-
sys.exit(1) # Exit if scheduler fails
22-
23-
logger.info("Starting API server...")
24-
# Start the FastAPI/Uvicorn server
25-
try:
26-
start_api() # This function calls uvicorn.run
27-
except Exception as e:
28-
logger.exception("Failed to start API server.")
29-
sys.exit(1) # Exit if API server fails
5+
start()

cloudproxy/providers/aws/functions.py

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,19 @@ def reset_clients():
2222
ec2 = None
2323
ec2_client = None
2424

25-
def get_clients(instance_config=None, ec2_resource=None, ec2_client_obj=None):
25+
def get_clients(instance_config=None):
2626
"""
2727
Initialize and return AWS clients based on the provided configuration.
28-
Accepts optional pre-configured clients.
2928
3029
Args:
3130
instance_config: The specific instance configuration
32-
ec2_resource: Optional pre-configured EC2 resource
33-
ec2_client_obj: Optional pre-configured EC2 client
3431
3532
Returns:
3633
tuple: (ec2_resource, ec2_client)
3734
"""
3835
# Use global variables to allow mocking in tests
3936
global ec2, ec2_client
4037

41-
# If specific clients are passed in, use them
42-
if ec2_resource is not None and ec2_client_obj is not None:
43-
return ec2_resource, ec2_client_obj
44-
4538
# If clients are already set (likely by a test), return them
4639
if ec2 is not None and ec2_client is not None:
4740
return ec2, ec2_client
@@ -105,20 +98,18 @@ def get_tags(instance_config=None):
10598
return tags, tag_specification
10699

107100

108-
def create_proxy(instance_config=None, ec2_resource=None, ec2_client_obj=None):
101+
def create_proxy(instance_config=None):
109102
"""
110103
Create an AWS proxy instance.
111104
112105
Args:
113106
instance_config: The specific instance configuration
114-
ec2_resource: Optional pre-configured EC2 resource
115-
ec2_client_obj: Optional pre-configured EC2 client
116107
"""
117108
if instance_config is None:
118109
instance_config = config["providers"]["aws"]["instances"]["default"]
119110

120111
# Get clients and tags
121-
ec2, ec2_client = get_clients(instance_config, ec2_resource, ec2_client_obj)
112+
ec2, ec2_client = get_clients(instance_config)
122113
tags, tag_specification = get_tags(instance_config)
123114

124115
# Find default VPC
@@ -216,21 +207,19 @@ def create_proxy(instance_config=None, ec2_resource=None, ec2_client_obj=None):
216207
return instance
217208

218209

219-
def delete_proxy(instance_id, instance_config=None, ec2_resource=None, ec2_client_obj=None):
210+
def delete_proxy(instance_id, instance_config=None):
220211
"""
221212
Delete an AWS proxy instance.
222213
223214
Args:
224215
instance_id: ID of the instance to delete
225216
instance_config: The specific instance configuration
226-
ec2_resource: Optional pre-configured EC2 resource
227-
ec2_client_obj: Optional pre-configured EC2 client
228217
"""
229218
if instance_config is None:
230219
instance_config = config["providers"]["aws"]["instances"]["default"]
231220

232221
# Get clients
233-
ec2, ec2_client = get_clients(instance_config, ec2_resource, ec2_client_obj)
222+
ec2, ec2_client = get_clients(instance_config)
234223

235224
ids = [instance_id]
236225
deleted = ec2.instances.filter(InstanceIds=ids).terminate()
@@ -251,42 +240,38 @@ def delete_proxy(instance_id, instance_config=None, ec2_resource=None, ec2_clien
251240
return deleted
252241

253242

254-
def stop_proxy(instance_id, instance_config=None, ec2_resource=None, ec2_client_obj=None):
243+
def stop_proxy(instance_id, instance_config=None):
255244
"""
256245
Stop an AWS proxy instance.
257246
258247
Args:
259248
instance_id: ID of the instance to stop
260249
instance_config: The specific instance configuration
261-
ec2_resource: Optional pre-configured EC2 resource
262-
ec2_client_obj: Optional pre-configured EC2 client
263250
"""
264251
if instance_config is None:
265252
instance_config = config["providers"]["aws"]["instances"]["default"]
266253

267254
# Get clients
268-
ec2, ec2_client = get_clients(instance_config, ec2_resource, ec2_client_obj)
255+
ec2, ec2_client = get_clients(instance_config)
269256

270257
ids = [instance_id]
271258
stopped = ec2.instances.filter(InstanceIds=ids).stop()
272259
return stopped
273260

274261

275-
def start_proxy(instance_id, instance_config=None, ec2_resource=None, ec2_client_obj=None):
262+
def start_proxy(instance_id, instance_config=None):
276263
"""
277264
Start an AWS proxy instance.
278265
279266
Args:
280267
instance_id: ID of the instance to start
281268
instance_config: The specific instance configuration
282-
ec2_resource: Optional pre-configured EC2 resource
283-
ec2_client_obj: Optional pre-configured EC2 client
284269
"""
285270
if instance_config is None:
286271
instance_config = config["providers"]["aws"]["instances"]["default"]
287272

288273
# Get clients
289-
ec2, ec2_client = get_clients(instance_config, ec2_resource, ec2_client_obj)
274+
ec2, ec2_client = get_clients(instance_config)
290275

291276
ids = [instance_id]
292277
try:
@@ -299,24 +284,21 @@ def start_proxy(instance_id, instance_config=None, ec2_resource=None, ec2_client
299284
return started
300285

301286

302-
def list_instances(instance_config=None, ec2_resource=None, ec2_client_obj=None):
287+
def list_instances(instance_config=None):
303288
"""
304-
List all AWS proxy instances.
289+
List AWS proxy instances.
305290
306291
Args:
307292
instance_config: The specific instance configuration
308-
ec2_resource: Optional pre-configured EC2 resource
309-
ec2_client_obj: Optional pre-configured EC2 client
310293
311294
Returns:
312-
list: List of instance objects
295+
list: List of AWS instances
313296
"""
314297
if instance_config is None:
315298
instance_config = config["providers"]["aws"]["instances"]["default"]
316299

317-
# Get clients and tags
318-
ec2, ec2_client = get_clients(instance_config, ec2_resource, ec2_client_obj)
319-
tags, _ = get_tags(instance_config)
300+
# Get clients
301+
ec2, ec2_client = get_clients(instance_config)
320302

321303
# Get instance ID for this configuration
322304
instance_id = next(

0 commit comments

Comments
 (0)