cloud-foundry 0.1.9__tar.gz → 0.2.3__tar.gz

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.
Files changed (38) hide show
  1. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/PKG-INFO +1 -1
  2. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/__init__.py +3 -1
  3. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/api_waf.py +2 -2
  4. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/cdn.py +2 -1
  5. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/cdn_api_origin.py +2 -1
  6. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/cdn_site_origin.py +5 -2
  7. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/connection_store.py +2 -1
  8. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/document_repository.py +2 -3
  9. cloud_foundry-0.2.3/cloud_foundry/pulumi/idle_reaper.py +140 -0
  10. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/queue.py +34 -6
  11. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/rest_api.py +1 -1
  12. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/site_bucket.py +4 -2
  13. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/topic.py +29 -4
  14. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/websocket_api.py +2 -1
  15. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/python_archive_builder.py +1 -1
  16. cloud_foundry-0.2.3/cloud_foundry/utils/names.py +88 -0
  17. cloud_foundry-0.1.9/cloud_foundry/utils/names.py +0 -39
  18. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/.gitignore +0 -0
  19. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/LICENSE +0 -0
  20. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/README.md +0 -0
  21. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/archive_builder.py +0 -0
  22. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/mail_publisher.py +0 -0
  23. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/__init__.py +0 -0
  24. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/custom_domain.py +0 -0
  25. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/domain.py +0 -0
  26. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/function.py +0 -0
  27. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/publisher.py +0 -0
  28. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/python_function.py +0 -0
  29. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/ui_publisher.py +0 -0
  30. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/pulumi/websocket_function.py +0 -0
  31. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/services/authorization_api/security_lambda.py +0 -0
  32. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/services/mail_publisher.py +0 -0
  33. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/utils/aws_openapi_editor.py +0 -0
  34. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/utils/hash_comparator.py +0 -0
  35. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/utils/logger.py +0 -0
  36. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/utils/openapi_editor.py +0 -0
  37. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/cloud_foundry/utils/websocket_utils.py +0 -0
  38. {cloud_foundry-0.1.9 → cloud_foundry-0.2.3}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloud-foundry
3
- Version: 0.1.9
3
+ Version: 0.2.3
4
4
  Summary: cloud-foundry is a curated set of cloud components that can be used to assemble cloud-based applications.
5
5
  Project-URL: Documentation, https://github.com/DanRepik/cloud-foundry
6
6
  Project-URL: Source, https://github.com/DanRepik/cloud-foundry
@@ -21,7 +21,9 @@ from cloud_foundry.pulumi.domain import domain # noqa: F401
21
21
 
22
22
  from cloud_foundry.pulumi.queue import queue # noqa: F401
23
23
  from cloud_foundry.pulumi.topic import topic # noqa: F401
24
+ from cloud_foundry.pulumi.idle_reaper import attach_idle_reaper # noqa: F401
24
25
 
25
26
  from cloud_foundry.utils.names import resource_id # noqa: F401
27
+ from cloud_foundry.utils.names import project_slug # noqa: F401
26
28
 
27
- version = "0.1.9"
29
+ version = "0.2.3"
@@ -2,10 +2,10 @@
2
2
  import json
3
3
  from typing import Optional
4
4
 
5
- import pulumi
6
5
  from pulumi_aws import wafv2
7
6
 
8
7
  from cloud_foundry.utils.logger import logger
8
+ from cloud_foundry.utils.names import resource_id
9
9
 
10
10
  log = logger(__name__)
11
11
 
@@ -159,7 +159,7 @@ class GatewayRestApiWAF:
159
159
  # Create an IP set for trusted IPs and allow traffic from those ranges.
160
160
  ip_set = wafv2.IpSet(
161
161
  f"{name}-ip-set",
162
- name=f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}-ip-set",
162
+ name=resource_id(f"{name}-ip-set"),
163
163
  description="An IP Set for trusted IPs",
164
164
  scope="CLOUDFRONT", # Use 'REGIONAL' for regional WAF rules.
165
165
  addresses=firewall.allowed_cidr_blocks,
@@ -109,6 +109,7 @@ from cloud_foundry.pulumi.custom_domain import (
109
109
  )
110
110
  from cloud_foundry.pulumi.rest_api import RestAPI
111
111
  from cloud_foundry.utils.logger import logger
112
+ from cloud_foundry.utils.names import resource_id
112
113
 
113
114
  log = logger(__name__)
114
115
 
@@ -257,7 +258,7 @@ class CDN(pulumi.ComponentResource):
257
258
  origins, caches, target_origin_id = self.get_origins(name, args.origins)
258
259
  self.distribution = aws.cloudfront.Distribution(
259
260
  f"{name}-distro",
260
- comment=f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}",
261
+ comment=resource_id(name),
261
262
  enabled=True,
262
263
  is_ipv6_enabled=True,
263
264
  default_root_object=args.root_uri,
@@ -3,6 +3,7 @@ import pulumi_aws as aws
3
3
  from typing import Optional
4
4
  from pulumi import ResourceOptions
5
5
  from cloud_foundry.utils.logger import logger
6
+ from cloud_foundry.utils.names import resource_id
6
7
 
7
8
  log = logger(__name__)
8
9
 
@@ -87,7 +88,7 @@ class ApiOrigin(pulumi.ComponentResource):
87
88
  # Define a custom origin request policy
88
89
  aws.cloudfront.OriginRequestPolicy(
89
90
  f"{name}-request-policy",
90
- name=f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}-request-policy",
91
+ name=resource_id(f"{name}-request-policy"),
91
92
  cookies_config={
92
93
  "cookie_behavior": "none", # Do not forward cookies
93
94
  },
@@ -5,6 +5,7 @@ import pulumi_aws as aws
5
5
  from pulumi import ResourceOptions
6
6
 
7
7
  from cloud_foundry.pulumi.site_bucket import SiteBucket
8
+ from cloud_foundry.utils.names import resource_id
8
9
  from cloud_foundry.utils.logger import logger
9
10
 
10
11
  log = logger(__name__)
@@ -90,7 +91,9 @@ class SiteOrigin(pulumi.ComponentResource):
90
91
  self.bucket = bucket
91
92
  elif isinstance(bucket, SiteBucket):
92
93
  self.bucket = bucket.bucket
93
- elif hasattr(bucket, "bucket") and hasattr(bucket.bucket, "bucket_regional_domain_name"):
94
+ elif hasattr(bucket, "bucket") and hasattr(
95
+ bucket.bucket, "bucket_regional_domain_name"
96
+ ):
94
97
  self.bucket = bucket.bucket
95
98
  elif isinstance(bucket, str):
96
99
  self.bucket = aws.s3.BucketV2.get(bucket, bucket)
@@ -103,7 +106,7 @@ class SiteOrigin(pulumi.ComponentResource):
103
106
  # Create Origin Access Control
104
107
  origin_access_control = aws.cloudfront.OriginAccessControl(
105
108
  f"{name}-origin-access-control",
106
- name=f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}",
109
+ name=resource_id(name),
107
110
  origin_access_control_origin_type="s3",
108
111
  signing_behavior="always",
109
112
  signing_protocol="sigv4",
@@ -3,6 +3,7 @@
3
3
  import pulumi
4
4
  import pulumi_aws as aws
5
5
  from cloud_foundry.utils.logger import logger
6
+ from cloud_foundry.utils.names import resource_id
6
7
 
7
8
  log = logger(__name__)
8
9
 
@@ -93,7 +94,7 @@ class ConnectionStore(pulumi.ComponentResource):
93
94
  """
94
95
  log.info("Creating connection store table: %s", self.name)
95
96
 
96
- table_name = f"{pulumi.get_project()}-{pulumi.get_stack()}-{self.name}"
97
+ table_name = resource_id(self.name)
97
98
 
98
99
  # Define base attributes
99
100
  attributes = [
@@ -3,6 +3,7 @@ from pulumi_aws import s3, lambda_, iam
3
3
  import json
4
4
 
5
5
  from cloud_foundry.utils.logger import logger
6
+ from cloud_foundry.utils.names import resource_id
6
7
 
7
8
  log = logger(__name__)
8
9
 
@@ -11,9 +12,7 @@ class DocumentRepository(pulumi.ComponentResource):
11
12
  def __init__(self, name, bucket_name: str = None, notifications=None, opts=None):
12
13
  super().__init__("cloud_foundry:s3:DocumentBucket", name, {}, opts)
13
14
 
14
- self.bucket_name = (
15
- bucket_name or f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}"
16
- )
15
+ self.bucket_name = bucket_name or resource_id(name)
17
16
 
18
17
  log.info(f"Creating S3 bucket: {self.bucket_name}")
19
18
 
@@ -0,0 +1,140 @@
1
+ """
2
+ Wiring for the shared idle-ESM-reaper Lambda (owned by
3
+ civarai-evidence/infra/shared-foundation). Queue owners call
4
+ `attach_idle_reaper` after subscribing their Lambda to their queue so the
5
+ reaper auto-disables the event source mapping once the queue is fully
6
+ drained -- avoiding empty-poll SQS request volume from a mapping nobody
7
+ remembered to turn off. It never re-enables anything; that stays each app's
8
+ own producer/ingestion script.
9
+
10
+ The reaper's function name and IAM role name are computed deterministically
11
+ via cloud_foundry's own naming convention (see
12
+ cloud_foundry.utils.names.resource_id) rather than read from
13
+ shared-foundation's stack outputs, so no cross-repo Pulumi state dependency
14
+ is introduced. Callers pass those names in explicitly (see
15
+ infra/shared-foundation/__main__.py for the exact formula).
16
+ """
17
+
18
+ import json
19
+ from typing import Optional
20
+
21
+ import pulumi_aws as aws
22
+ from pulumi import Output, ResourceOptions
23
+
24
+ from cloud_foundry.utils.names import account_id, region
25
+
26
+
27
+ def _aws_name(prefix: str, suffix: str, max_length: int) -> str:
28
+ """Build a physical AWS resource name, truncating `prefix` (never
29
+ `suffix`) so the result fits `max_length`. Resource-type-specific AWS
30
+ name limits (e.g. EventRule.name and EventTarget.target_id are both
31
+ capped at 64 chars) are easy to overflow once `prefix` incorporates a
32
+ project + stack + queue name, so every resource below sets its physical
33
+ name explicitly through this rather than relying on Pulumi's default
34
+ autonaming (logical name + random suffix), which has the same overflow
35
+ risk plus non-determinism.
36
+ """
37
+ name = f"{prefix}-{suffix}"
38
+ if len(name) <= max_length:
39
+ return name
40
+ return f"{prefix[: max_length - len(suffix) - 1]}-{suffix}"
41
+
42
+
43
+ def attach_idle_reaper(
44
+ queue,
45
+ event_source_mapping: aws.lambda_.EventSourceMapping,
46
+ *,
47
+ reaper_function_name: str,
48
+ reaper_role_name: str,
49
+ resource_prefix: str,
50
+ interval_minutes: int = 10,
51
+ opts: Optional[ResourceOptions] = None,
52
+ ) -> None:
53
+ """Schedule the shared idle-esm-reaper Lambda against one queue/mapping.
54
+
55
+ Args:
56
+ queue: The cloud_foundry Queue (or anything exposing `.arn`/`.url`)
57
+ whose event source mapping should be auto-disabled once idle.
58
+ event_source_mapping: The aws.lambda_.EventSourceMapping returned by
59
+ `queue.subscribe(...)`.
60
+ reaper_function_name: Deployed function name of the shared reaper
61
+ Lambda (see infra/shared-foundation).
62
+ reaper_role_name: Name of the reaper Lambda's execution role, used to
63
+ attach a scoped inline policy granting access to just this
64
+ queue/mapping.
65
+ resource_prefix: Unique prefix for this consumer's Pulumi resource
66
+ names, e.g. `resource_id("workflow")`.
67
+ interval_minutes: How often the reaper checks this queue.
68
+ opts: Pulumi ResourceOptions (e.g. `parent=`) applied to every
69
+ resource created here.
70
+ """
71
+ esm_arn = event_source_mapping.id.apply(
72
+ lambda uuid: f"arn:aws:lambda:{region()}:{account_id()}:event-source-mapping:{uuid}"
73
+ )
74
+
75
+ aws.iam.RolePolicy(
76
+ f"{resource_prefix}-idle-reaper-policy",
77
+ name=_aws_name(resource_prefix, "idle-reaper-policy", 128),
78
+ role=reaper_role_name,
79
+ policy=Output.all(queue.arn, esm_arn).apply(
80
+ lambda args: json.dumps(
81
+ {
82
+ "Version": "2012-10-17",
83
+ "Statement": [
84
+ {
85
+ "Effect": "Allow",
86
+ "Action": ["sqs:GetQueueAttributes"],
87
+ "Resource": args[0],
88
+ },
89
+ {
90
+ "Effect": "Allow",
91
+ "Action": [
92
+ "lambda:GetEventSourceMapping",
93
+ "lambda:UpdateEventSourceMapping",
94
+ ],
95
+ "Resource": args[1],
96
+ },
97
+ ],
98
+ }
99
+ )
100
+ ),
101
+ opts=opts,
102
+ )
103
+
104
+ rule = aws.cloudwatch.EventRule(
105
+ f"{resource_prefix}-idle-reaper-schedule",
106
+ name=_aws_name(resource_prefix, "idle-reaper-schedule", 64),
107
+ schedule_expression=f"rate({interval_minutes} minutes)",
108
+ opts=opts,
109
+ )
110
+
111
+ reaper_arn = (
112
+ f"arn:aws:lambda:{region()}:{account_id()}:function:{reaper_function_name}"
113
+ )
114
+
115
+ aws.cloudwatch.EventTarget(
116
+ f"{resource_prefix}-idle-reaper-target",
117
+ target_id=_aws_name(resource_prefix, "idle-reaper-target", 64),
118
+ rule=rule.name,
119
+ arn=reaper_arn,
120
+ input=Output.all(queue.url, event_source_mapping.id).apply(
121
+ lambda args: json.dumps(
122
+ {
123
+ "queue_url": args[0],
124
+ "queue_name": resource_prefix,
125
+ "event_source_mapping_uuid": args[1],
126
+ }
127
+ )
128
+ ),
129
+ opts=opts,
130
+ )
131
+
132
+ aws.lambda_.Permission(
133
+ f"{resource_prefix}-idle-reaper-invoke",
134
+ statement_id=_aws_name(resource_prefix, "idle-reaper-invoke", 100),
135
+ action="lambda:InvokeFunction",
136
+ function=reaper_function_name,
137
+ principal="events.amazonaws.com",
138
+ source_arn=rule.arn,
139
+ opts=opts,
140
+ )
@@ -39,9 +39,15 @@ class QueueArgs:
39
39
  self,
40
40
  visibility_timeout: Optional[int] = None,
41
41
  message_retention: Optional[int] = None,
42
+ receive_wait_time: Optional[int] = None,
43
+ tags: Optional[dict[str, str]] = None,
42
44
  ) -> None:
43
45
  self.visibility_timeout = visibility_timeout or 300 # 5 minutes
44
46
  self.message_retention = message_retention or 345600 # 4 days
47
+ # 0 (short polling) matches SQS's own default, so leaving this
48
+ # unset is a no-op for existing callers.
49
+ self.receive_wait_time = receive_wait_time or 0
50
+ self.tags = tags or {}
45
51
 
46
52
 
47
53
  class Queue(ComponentResource):
@@ -83,10 +89,12 @@ class Queue(ComponentResource):
83
89
  self.name = name
84
90
  """Create SQS queue with DLQ."""
85
91
  # Dead letter queue
92
+ dlq_name = f"{resource_id(self.name)}-dlq"
86
93
  self.dlq = aws.sqs.Queue(
87
94
  f"{name}-dlq",
88
- name=f"{resource_id(self.name)}-dlq",
95
+ name=dlq_name,
89
96
  message_retention_seconds=1209600, # 14 days
97
+ tags={"Name": dlq_name, **args.tags},
90
98
  opts=ResourceOptions(
91
99
  parent=self,
92
100
  ignore_changes=["region", "tagsAll"],
@@ -94,11 +102,13 @@ class Queue(ComponentResource):
94
102
  )
95
103
 
96
104
  # Main queue
105
+ queue_name = resource_id(self.name)
97
106
  self.queue = aws.sqs.Queue(
98
107
  name,
99
- name=resource_id(self.name),
108
+ name=queue_name,
100
109
  visibility_timeout_seconds=args.visibility_timeout,
101
110
  message_retention_seconds=args.message_retention,
111
+ receive_wait_time_seconds=args.receive_wait_time,
102
112
  redrive_policy=self.dlq.arn.apply(
103
113
  lambda arn: json.dumps(
104
114
  {
@@ -107,6 +117,7 @@ class Queue(ComponentResource):
107
117
  }
108
118
  )
109
119
  ),
120
+ tags={"Name": queue_name, **args.tags},
110
121
  opts=ResourceOptions(
111
122
  parent=self,
112
123
  ignore_changes=["region", "tagsAll"],
@@ -135,7 +146,7 @@ class Queue(ComponentResource):
135
146
  function: str | Function | aws.lambda_.Function,
136
147
  batch_size: Optional[int] = 10,
137
148
  maximum_concurrency: Optional[int] = None,
138
- ) -> None:
149
+ ) -> aws.lambda_.EventSourceMapping:
139
150
  """Add SQS queue as Lambda event source.
140
151
 
141
152
  Args:
@@ -146,6 +157,9 @@ class Queue(ComponentResource):
146
157
  1-10000 for FIFO queues.
147
158
  maximum_concurrency: Maximum number of concurrent Lambda function
148
159
  invocations. Defaults to None (no limit). Valid values: 2-1000.
160
+
161
+ Returns:
162
+ aws.lambda_.EventSourceMapping: The created event source mapping.
149
163
  """
150
164
  # Extract function name based on type
151
165
  if isinstance(function, Function):
@@ -182,7 +196,7 @@ class Queue(ComponentResource):
182
196
  )
183
197
  )
184
198
 
185
- aws.lambda_.EventSourceMapping(
199
+ return aws.lambda_.EventSourceMapping(
186
200
  f"{resource_id(self.name)}-source",
187
201
  **mapping_args,
188
202
  )
@@ -192,6 +206,8 @@ def queue(
192
206
  name: str,
193
207
  visibility_timeout: Optional[int] = None,
194
208
  message_retention: Optional[int] = None,
209
+ receive_wait_time: Optional[int] = None,
210
+ tags: Optional[dict[str, str]] = None,
195
211
  opts: ResourceOptions = None,
196
212
  ) -> Queue:
197
213
  """Factory function to create a Queue component.
@@ -201,6 +217,13 @@ def queue(
201
217
  Defaults to None (300 seconds).
202
218
  message_retention (Optional[int]): Message retention period in
203
219
  seconds. Defaults to None (345600 seconds).
220
+ receive_wait_time (Optional[int]): Long-polling wait time in
221
+ seconds for ReceiveMessage calls. Defaults to None (0, i.e.
222
+ short polling -- SQS's own default).
223
+ tags (Optional[dict[str, str]]): Extra tags applied to both the
224
+ main queue and its DLQ, alongside the "Name" tag each already
225
+ gets set to its own resource_id()-generated name. A "Name" key
226
+ here overrides that default.
204
227
  opts (ResourceOptions, optional): Pulumi resource options.
205
228
  Defaults to None.
206
229
  Returns:
@@ -209,13 +232,18 @@ def queue(
209
232
  >>> my_queue = queue(
210
233
  ... name="my-message-queue",
211
234
  ... visibility_timeout=300,
212
- ... message_retention=345600
235
+ ... message_retention=345600,
236
+ ... receive_wait_time=20,
237
+ ... tags={"Environment": "prod"},
213
238
  ... )
214
239
  """
215
240
  return Queue(
216
241
  name,
217
242
  QueueArgs(
218
- visibility_timeout=visibility_timeout, message_retention=message_retention
243
+ visibility_timeout=visibility_timeout,
244
+ message_retention=message_retention,
245
+ receive_wait_time=receive_wait_time,
246
+ tags=tags,
219
247
  ),
220
248
  opts,
221
249
  )
@@ -349,7 +349,7 @@ class RestAPI(pulumi.ComponentResource):
349
349
  log.info("Setting up logging for API stage")
350
350
  log_group = aws.cloudwatch.LogGroup(
351
351
  f"{self.name}-log",
352
- name=f"/aws/api/{pulumi.get_project()}/{pulumi.get_stack()}/{self.name}", # noqa
352
+ name=f"/aws/api/{resource_id(self.name, separator='/')}",
353
353
  retention_in_days=3,
354
354
  opts=pulumi.ResourceOptions(parent=self, retain_on_delete=False),
355
355
  )
@@ -2,11 +2,13 @@ import pulumi
2
2
  import pulumi_aws as aws
3
3
  from pulumi import ResourceOptions
4
4
  from cloud_foundry.pulumi.ui_publisher import UIPublisher, UIPublisherArgs
5
+ from cloud_foundry.utils.names import resource_id
5
6
 
6
7
 
7
8
  def default_bucket_name(name: str) -> str:
8
- """Preserve the historical default S3 bucket naming scheme."""
9
- return f"{pulumi.get_project()}-{pulumi.get_stack()}-{name}"
9
+ """Default S3 bucket name, via resource_id() (project/stack prefixed,
10
+ honoring an opted-in project_slug)."""
11
+ return resource_id(name)
10
12
 
11
13
 
12
14
  def is_production_stack(stack_name: str | None = None) -> bool:
@@ -12,10 +12,14 @@ class TopicArgs:
12
12
  """Arguments for Topic component."""
13
13
 
14
14
  def __init__(
15
- self, display_name: Optional[str], subscriptions: Optional[list[dict]] = None
15
+ self,
16
+ display_name: Optional[str],
17
+ subscriptions: Optional[list[dict]] = None,
18
+ tags: Optional[dict[str, str]] = None,
16
19
  ):
17
20
  self.display_name = display_name
18
21
  self.subscriptions = subscriptions
22
+ self.tags = tags or {}
19
23
 
20
24
 
21
25
  class Topic(ComponentResource):
@@ -44,10 +48,12 @@ class Topic(ComponentResource):
44
48
  super().__init__("cloud_foundry:topic:Topic", name, {}, opts)
45
49
 
46
50
  self.name = name
51
+ topic_name = resource_id(name)
47
52
  self.topic = aws.sns.Topic(
48
53
  name,
49
- name=resource_id(name),
54
+ name=topic_name,
50
55
  display_name=args.display_name or name,
56
+ tags={"Name": topic_name, **args.tags},
51
57
  opts=ResourceOptions(parent=self),
52
58
  )
53
59
 
@@ -69,6 +75,17 @@ class Topic(ComponentResource):
69
75
  """Get the ARN of the SNS topic."""
70
76
  return self.topic.arn
71
77
 
78
+ @property
79
+ def topic_name(self) -> Output[str]:
80
+ """Get the deployed AWS name of the SNS topic.
81
+
82
+ Named `topic_name` rather than `name` because `self.name` already
83
+ holds the logical component name (a plain str, used internally for
84
+ default display_name and subscription resource naming) -- reusing
85
+ `name` for this would shadow that with an Output[str] and break it.
86
+ """
87
+ return self.topic.name
88
+
72
89
  def subscribe(self, queue: Queue, opts: ResourceOptions = None) -> None:
73
90
  """Subscribe an SQS queue to this SNS topic.
74
91
  Args:
@@ -121,6 +138,7 @@ def topic(
121
138
  name: str,
122
139
  display_name: Optional[str] = None,
123
140
  subscriptions: Optional[list[dict]] = None,
141
+ tags: Optional[dict[str, str]] = None,
124
142
  opts: ResourceOptions = None,
125
143
  ) -> Topic:
126
144
  """Factory function to create a Topic component.
@@ -131,6 +149,10 @@ def topic(
131
149
  subscriptions (Optional[list[dict]]): List of subscription configs.
132
150
  Each config should be a dict with a 'queue' key for SQS queues.
133
151
  Defaults to None.
152
+ tags (Optional[dict[str, str]]): Extra tags applied to the topic,
153
+ alongside the "Name" tag it already gets set to its own
154
+ resource_id()-generated name. A "Name" key here overrides
155
+ that default.
134
156
  opts (ResourceOptions, optional): Pulumi resource options.
135
157
  Defaults to None.
136
158
  Returns:
@@ -139,9 +161,12 @@ def topic(
139
161
  >>> my_topic = topic(
140
162
  ... name="my-topic",
141
163
  ... display_name="My Topic",
142
- ... subscriptions=[{"queue": my_queue}]
164
+ ... subscriptions=[{"queue": my_queue}],
165
+ ... tags={"Environment": "prod"},
143
166
  ... )
144
167
  """
145
168
  return Topic(
146
- name, TopicArgs(display_name=display_name, subscriptions=subscriptions), opts
169
+ name,
170
+ TopicArgs(display_name=display_name, subscriptions=subscriptions, tags=tags),
171
+ opts,
147
172
  )
@@ -11,6 +11,7 @@ from cloud_foundry.pulumi.custom_domain import (
11
11
  domain_from_subdomain,
12
12
  )
13
13
  from cloud_foundry.utils.logger import logger
14
+ from cloud_foundry.utils.names import resource_id
14
15
 
15
16
  log = logger(__name__)
16
17
 
@@ -213,7 +214,7 @@ class WebSocketAPI(pulumi.ComponentResource):
213
214
  # Create the WebSocket API
214
215
  api = aws.apigatewayv2.Api(
215
216
  f"{self.name}-api",
216
- name=f"{pulumi.get_project()}-{pulumi.get_stack()}-{self.name}",
217
+ name=resource_id(self.name),
217
218
  protocol_type="WEBSOCKET",
218
219
  route_selection_expression="$request.body.action",
219
220
  opts=pulumi.ResourceOptions(parent=self),
@@ -50,7 +50,7 @@ class PythonArchiveBuilder(ArchiveBuilder):
50
50
  """
51
51
  self.name = name
52
52
  self._sources = sources
53
- self._requirements = requirements
53
+ self._requirements = requirements or []
54
54
  self._working_dir = working_dir
55
55
  self._target_architecture = self._normalize_architecture(target_architecture)
56
56
 
@@ -0,0 +1,88 @@
1
+ import os
2
+
3
+ import pulumi
4
+ import pulumi_aws as aws
5
+
6
+
7
+ _account_id = None
8
+
9
+
10
+ def account_id() -> str:
11
+ global _account_id
12
+ if not _account_id:
13
+ _account_id = aws.get_caller_identity().account_id
14
+
15
+ return _account_id
16
+
17
+
18
+ _region = None
19
+
20
+
21
+ def region() -> str:
22
+ global _region
23
+ if not _region:
24
+ _region = aws.get_region().name
25
+ return _region
26
+
27
+
28
+ def project_slug() -> str:
29
+ """
30
+ Resolve the short name to use as the "project" component of generated
31
+ AWS resource names.
32
+
33
+ AWS resource names are frequently length-limited (SNS topics, IAM
34
+ roles, Lambda functions, DynamoDB tables, ...), so a Pulumi project
35
+ with a long `name:` in Pulumi.yaml can push `resource_id()`-generated
36
+ names past those limits, forcing names to be overridden by hand at
37
+ each call site.
38
+
39
+ Projects can opt into a shorter alias two ways, checked in this
40
+ order:
41
+
42
+ 1. The `CLOUD_FOUNDRY_PROJECT_SLUG` environment variable, e.g.:
43
+
44
+ export CLOUD_FOUNDRY_PROJECT_SLUG=cep
45
+
46
+ Useful for CI or a local shell override without touching checked-in
47
+ stack config.
48
+
49
+ 2. The `project_slug` Pulumi config value, e.g.:
50
+
51
+ pulumi config set civarai-evidence:project_slug cep
52
+
53
+ If neither is set, falls back to the full Pulumi project name
54
+ (`pulumi.get_project()`) — existing behavior is unchanged unless a
55
+ project explicitly opts in.
56
+
57
+ Returns:
58
+ str: The configured project slug, or the full Pulumi project name
59
+ if no slug has been configured.
60
+ """
61
+ env_slug = (os.environ.get("CLOUD_FOUNDRY_PROJECT_SLUG") or "").strip()
62
+ if env_slug:
63
+ return env_slug
64
+
65
+ config_slug = (pulumi.Config().get("project_slug") or "").strip()
66
+ return config_slug or pulumi.get_project()
67
+
68
+
69
+ def resource_id(name: str = None, separator: str = "-") -> str:
70
+ """
71
+ Generate a standardized resource ID by combining the project slug, stack
72
+ name, and resource name.
73
+
74
+ The project component is `project_slug()` rather than the raw Pulumi
75
+ project name, so a project can configure a short alias (e.g. "cep"),
76
+ via the `CLOUD_FOUNDRY_PROJECT_SLUG` environment variable or the
77
+ `project_slug` Pulumi config value, to keep generated AWS names under
78
+ service length limits.
79
+
80
+ Args:
81
+ name (str): The base name of the resource.
82
+
83
+ Returns:
84
+ str: A standardized resource ID in the format "project-stack-resource".
85
+ """
86
+ project = project_slug()
87
+ stack = pulumi.get_stack()
88
+ return f"{project}{separator}{stack}{separator + name if name else ''}"
@@ -1,39 +0,0 @@
1
- import pulumi
2
- import pulumi_aws as aws
3
-
4
-
5
- _account_id = None
6
-
7
-
8
- def account_id() -> str:
9
- global _account_id
10
- if not _account_id:
11
- _account_id = aws.get_caller_identity().account_id
12
-
13
- return _account_id
14
-
15
-
16
- _region = None
17
-
18
-
19
- def region() -> str:
20
- global _region
21
- if not _region:
22
- _region = aws.get_region().name
23
- return _region
24
-
25
-
26
- def resource_id(name: str = None, separator: str = "-") -> str:
27
- """
28
- Generate a standardized resource ID by combining the project name, stack name,
29
- and resource name.
30
-
31
- Args:
32
- name (str): The base name of the resource.
33
-
34
- Returns:
35
- str: A standardized resource ID in the format "project-stack-resource".
36
- """
37
- project = pulumi.get_project()
38
- stack = pulumi.get_stack()
39
- return f"{project}{separator}{stack}{separator + name if name else ''}"
File without changes
File without changes
File without changes