BuzzerboyAWSLightsail 0.329.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,113 @@
1
+
2
+ class LightSailPostDeploy:
3
+
4
+
5
+ #Get container service url from container service
6
+ #update the dns record for each domain to that container service url
7
+
8
+ def __init__(self, domains = [], container_service_name, region, profile="default"):
9
+ self.domains = domains
10
+ self.container_service_name = container_service_name
11
+ self.region = region
12
+ self.profile = profile
13
+ self.container_service_url = self.get_container_service_url()
14
+
15
+ def get_container_service_url(self):
16
+ return LightsailPostDeploy.get_lightsail_domain_from_aws(
17
+ self.container_service_name, self.region, self.profile
18
+ )
19
+
20
+
21
+ @static_method
22
+ def static_execute(domain, container_service_name, region='ca-central-1', profile='default'):
23
+ lightSailDeploy = LightsailPostDeploy(domains=[domain],
24
+ container_service_name=container_service_name, region=region, profile=profile)
25
+ lightSailDeploy.execute()
26
+
27
+ def execute(self):
28
+ for domain in self.domains:
29
+ self.update_dns_record(domain, self.container_service_url)
30
+
31
+ @staticmethod
32
+ def attach_cert_to_container(container_service_name, region, profile="default"):
33
+ """
34
+ Static method to attach SSL certificate to Lightsail container service.
35
+
36
+ :param container_service_name: Name of the container service
37
+ :type container_service_name: str
38
+ :param region: AWS region where the service is deployed
39
+ :type region: str
40
+ :param profile: AWS profile to use (default: "default")
41
+ :type profile: str
42
+ """
43
+ # Implementation for attaching SSL certificate goes here
44
+ import LightSailDomainAttachWrapper
45
+ lightsailWrapper = LightSailDomainAttachWrapper(container_service_name, region, profile)
46
+
47
+
48
+ def update_dns_record(domain, container_service_url):
49
+ print (f"Updating DNS record for {domain} to point to {container_service_url}")
50
+ pass
51
+
52
+ @staticmethod
53
+ def get_lightsail_domain_from_aws(container_service_name, region, profile="default"):
54
+ """
55
+ Static method to retrieve Lightsail container service domain from AWS.
56
+
57
+ This is a utility method that can be called independently to get the actual
58
+ domain name from AWS Lightsail for a given container service.
59
+
60
+ :param container_service_name: Name of the container service
61
+ :type container_service_name: str
62
+ :param region: AWS region where the service is deployed
63
+ :type region: str
64
+ :param profile: AWS profile to use (default: "default")
65
+ :type profile: str
66
+ :returns: The public domain URL ending with amazonlightsail.com
67
+ :rtype: str
68
+
69
+ Example:
70
+ >>> domain = BBAWSLightsailMiniV1a.get_lightsail_domain_from_aws(
71
+ ... "my-app", "us-east-1", "my-profile"
72
+ ... )
73
+ >>> print(domain) # my-app.us-east-1.cs.amazonlightsail.com
74
+ """
75
+ import boto3
76
+ from botocore.exceptions import ClientError
77
+
78
+ try:
79
+ # Create a session with the specified profile
80
+ session = boto3.Session(profile_name=profile)
81
+ lightsail_client = session.client('lightsail', region_name=region)
82
+
83
+ # Get container services
84
+ response = lightsail_client.get_container_services()
85
+
86
+ # Find our container service by name
87
+ for service in response.get('containerServices', []):
88
+ if service.get('containerServiceName') == container_service_name:
89
+ # Get the public domain endpoints
90
+ public_domain_names = service.get('publicDomainNames', {})
91
+
92
+ # Look for the domain that ends with amazonlightsail.com
93
+ for domain_list in public_domain_names.values():
94
+ for domain in domain_list:
95
+ if domain.endswith('amazonlightsail.com'):
96
+ return domain
97
+
98
+ # Fallback: use the URL from container service properties
99
+ url = service.get('url', '')
100
+ if url and 'amazonlightsail.com' in url:
101
+ # Extract domain from URL (remove https://)
102
+ return url.replace('https://', '').replace('http://', '')
103
+
104
+ # If not found, fall back to constructed domain
105
+ print(f"Warning: Could not find actual domain for {container_service_name}")
106
+ return f"{container_service_name}.{region}.cs.amazonlightsail.com"
107
+
108
+ except ClientError as e:
109
+ print(f"Error retrieving Lightsail domain: {e}")
110
+ return f"{container_service_name}.{region}.cs.amazonlightsail.com"
111
+ except Exception as e:
112
+ print(f"Unexpected error: {e}")
113
+ return f"{container_service_name}.{region}.cs.amazonlightsail.com"
File without changes