@stacksjs/ts-cloud-core 0.1.1
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.
- package/LICENSE.md +21 -0
- package/README.md +321 -0
- package/package.json +31 -0
- package/src/advanced-features.test.ts +465 -0
- package/src/aws/cloudformation.ts +421 -0
- package/src/aws/cloudfront.ts +158 -0
- package/src/aws/credentials.test.ts +132 -0
- package/src/aws/credentials.ts +545 -0
- package/src/aws/index.ts +87 -0
- package/src/aws/s3.test.ts +188 -0
- package/src/aws/s3.ts +1088 -0
- package/src/aws/signature.test.ts +670 -0
- package/src/aws/signature.ts +1155 -0
- package/src/backup/disaster-recovery.test.ts +726 -0
- package/src/backup/disaster-recovery.ts +500 -0
- package/src/backup/index.ts +34 -0
- package/src/backup/manager.test.ts +498 -0
- package/src/backup/manager.ts +432 -0
- package/src/cicd/circleci.ts +430 -0
- package/src/cicd/github-actions.ts +424 -0
- package/src/cicd/gitlab-ci.ts +255 -0
- package/src/cicd/index.ts +8 -0
- package/src/cli/history.ts +396 -0
- package/src/cli/index.ts +10 -0
- package/src/cli/progress.ts +458 -0
- package/src/cli/repl.ts +454 -0
- package/src/cli/suggestions.ts +327 -0
- package/src/cli/table.test.ts +319 -0
- package/src/cli/table.ts +332 -0
- package/src/cloudformation/builder.test.ts +327 -0
- package/src/cloudformation/builder.ts +378 -0
- package/src/cloudformation/builders/api-gateway.ts +449 -0
- package/src/cloudformation/builders/cache.ts +334 -0
- package/src/cloudformation/builders/cdn.ts +278 -0
- package/src/cloudformation/builders/compute.ts +485 -0
- package/src/cloudformation/builders/database.ts +392 -0
- package/src/cloudformation/builders/functions.ts +343 -0
- package/src/cloudformation/builders/messaging.ts +140 -0
- package/src/cloudformation/builders/monitoring.ts +300 -0
- package/src/cloudformation/builders/network.ts +264 -0
- package/src/cloudformation/builders/queue.ts +147 -0
- package/src/cloudformation/builders/security.ts +399 -0
- package/src/cloudformation/builders/storage.ts +285 -0
- package/src/cloudformation/index.ts +30 -0
- package/src/cloudformation/types.ts +173 -0
- package/src/compliance/aws-config.ts +543 -0
- package/src/compliance/cloudtrail.ts +376 -0
- package/src/compliance/compliance.test.ts +423 -0
- package/src/compliance/guardduty.ts +446 -0
- package/src/compliance/index.ts +66 -0
- package/src/compliance/security-hub.ts +456 -0
- package/src/containers/build-optimization.ts +416 -0
- package/src/containers/containers.test.ts +508 -0
- package/src/containers/image-scanning.ts +360 -0
- package/src/containers/index.ts +9 -0
- package/src/containers/registry.ts +293 -0
- package/src/containers/service-mesh.ts +520 -0
- package/src/database/database.test.ts +762 -0
- package/src/database/index.ts +9 -0
- package/src/database/migrations.ts +444 -0
- package/src/database/performance.ts +528 -0
- package/src/database/replicas.ts +534 -0
- package/src/database/users.ts +494 -0
- package/src/dependency-graph.ts +143 -0
- package/src/deployment/ab-testing.ts +582 -0
- package/src/deployment/blue-green.ts +452 -0
- package/src/deployment/canary.ts +500 -0
- package/src/deployment/deployment.test.ts +526 -0
- package/src/deployment/index.ts +61 -0
- package/src/deployment/progressive.ts +62 -0
- package/src/dns/dns.test.ts +641 -0
- package/src/dns/dnssec.ts +315 -0
- package/src/dns/index.ts +8 -0
- package/src/dns/resolver.ts +496 -0
- package/src/dns/routing.ts +593 -0
- package/src/email/advanced/analytics.ts +445 -0
- package/src/email/advanced/index.ts +11 -0
- package/src/email/advanced/rules.ts +465 -0
- package/src/email/advanced/scheduling.ts +352 -0
- package/src/email/advanced/search.ts +412 -0
- package/src/email/advanced/shared-mailboxes.ts +404 -0
- package/src/email/advanced/templates.ts +455 -0
- package/src/email/advanced/threading.ts +281 -0
- package/src/email/analytics.ts +467 -0
- package/src/email/bounce-handling.ts +425 -0
- package/src/email/email.test.ts +431 -0
- package/src/email/handlers/__tests__/inbound.test.ts +38 -0
- package/src/email/handlers/__tests__/outbound.test.ts +37 -0
- package/src/email/handlers/converter.ts +227 -0
- package/src/email/handlers/feedback.ts +228 -0
- package/src/email/handlers/inbound.ts +169 -0
- package/src/email/handlers/outbound.ts +178 -0
- package/src/email/index.ts +15 -0
- package/src/email/reputation.ts +303 -0
- package/src/email/templates.ts +352 -0
- package/src/errors/index.test.ts +434 -0
- package/src/errors/index.ts +416 -0
- package/src/health-checks/index.ts +40 -0
- package/src/index.ts +360 -0
- package/src/intrinsic-functions.ts +118 -0
- package/src/lambda/concurrency.ts +330 -0
- package/src/lambda/destinations.ts +345 -0
- package/src/lambda/dlq.ts +425 -0
- package/src/lambda/index.ts +11 -0
- package/src/lambda/lambda.test.ts +840 -0
- package/src/lambda/layers.ts +263 -0
- package/src/lambda/versions.ts +376 -0
- package/src/lambda/vpc.ts +399 -0
- package/src/local/config.ts +114 -0
- package/src/local/index.ts +6 -0
- package/src/local/mock-aws.ts +351 -0
- package/src/modules/ai.ts +340 -0
- package/src/modules/api.ts +478 -0
- package/src/modules/auth.ts +805 -0
- package/src/modules/cache.ts +417 -0
- package/src/modules/cdn.ts +1062 -0
- package/src/modules/communication.ts +1094 -0
- package/src/modules/compute.ts +3348 -0
- package/src/modules/database.ts +554 -0
- package/src/modules/deployment.ts +1079 -0
- package/src/modules/dns.ts +337 -0
- package/src/modules/email.ts +1538 -0
- package/src/modules/filesystem.ts +515 -0
- package/src/modules/index.ts +32 -0
- package/src/modules/messaging.ts +486 -0
- package/src/modules/monitoring.ts +2086 -0
- package/src/modules/network.ts +664 -0
- package/src/modules/parameter-store.ts +325 -0
- package/src/modules/permissions.ts +1081 -0
- package/src/modules/phone.ts +494 -0
- package/src/modules/queue.ts +1260 -0
- package/src/modules/redirects.ts +464 -0
- package/src/modules/registry.ts +699 -0
- package/src/modules/search.ts +401 -0
- package/src/modules/secrets.ts +416 -0
- package/src/modules/security.ts +731 -0
- package/src/modules/sms.ts +389 -0
- package/src/modules/storage.ts +1120 -0
- package/src/modules/workflow.ts +680 -0
- package/src/multi-account/config.ts +521 -0
- package/src/multi-account/index.ts +7 -0
- package/src/multi-account/manager.ts +427 -0
- package/src/multi-region/cross-region.ts +410 -0
- package/src/multi-region/index.ts +8 -0
- package/src/multi-region/manager.ts +483 -0
- package/src/multi-region/regions.ts +435 -0
- package/src/network-security/index.ts +48 -0
- package/src/observability/index.ts +9 -0
- package/src/observability/logs.ts +522 -0
- package/src/observability/metrics.ts +460 -0
- package/src/observability/observability.test.ts +782 -0
- package/src/observability/synthetics.ts +568 -0
- package/src/observability/xray.ts +358 -0
- package/src/phone/advanced/analytics.ts +349 -0
- package/src/phone/advanced/callbacks.ts +428 -0
- package/src/phone/advanced/index.ts +8 -0
- package/src/phone/advanced/ivr-builder.ts +504 -0
- package/src/phone/advanced/recording.ts +310 -0
- package/src/phone/handlers/__tests__/incoming-call.test.ts +40 -0
- package/src/phone/handlers/incoming-call.ts +117 -0
- package/src/phone/handlers/missed-call.ts +116 -0
- package/src/phone/handlers/voicemail.ts +179 -0
- package/src/phone/index.ts +9 -0
- package/src/presets/api-backend.ts +134 -0
- package/src/presets/data-pipeline.ts +204 -0
- package/src/presets/extend.test.ts +295 -0
- package/src/presets/extend.ts +297 -0
- package/src/presets/fullstack-app.ts +144 -0
- package/src/presets/index.ts +27 -0
- package/src/presets/jamstack.ts +135 -0
- package/src/presets/microservices.ts +167 -0
- package/src/presets/ml-api.ts +208 -0
- package/src/presets/nodejs-server.ts +104 -0
- package/src/presets/nodejs-serverless.ts +114 -0
- package/src/presets/realtime-app.ts +184 -0
- package/src/presets/static-site.ts +64 -0
- package/src/presets/traditional-web-app.ts +339 -0
- package/src/presets/wordpress.ts +138 -0
- package/src/preview/github.test.ts +249 -0
- package/src/preview/github.ts +297 -0
- package/src/preview/index.ts +37 -0
- package/src/preview/manager.test.ts +440 -0
- package/src/preview/manager.ts +326 -0
- package/src/preview/notifications.test.ts +582 -0
- package/src/preview/notifications.ts +341 -0
- package/src/queue/batch-processing.ts +402 -0
- package/src/queue/dlq-monitoring.ts +402 -0
- package/src/queue/fifo.ts +342 -0
- package/src/queue/index.ts +9 -0
- package/src/queue/management.ts +428 -0
- package/src/queue/queue.test.ts +429 -0
- package/src/resource-mgmt/index.ts +39 -0
- package/src/resource-naming.ts +62 -0
- package/src/s3/index.ts +523 -0
- package/src/schema/cloud-config.schema.json +554 -0
- package/src/schema/index.ts +68 -0
- package/src/security/certificate-manager.ts +492 -0
- package/src/security/index.ts +9 -0
- package/src/security/scanning.ts +545 -0
- package/src/security/secrets-manager.ts +476 -0
- package/src/security/secrets-rotation.ts +456 -0
- package/src/security/security.test.ts +738 -0
- package/src/sms/advanced/ab-testing.ts +389 -0
- package/src/sms/advanced/analytics.ts +336 -0
- package/src/sms/advanced/campaigns.ts +523 -0
- package/src/sms/advanced/chatbot.ts +224 -0
- package/src/sms/advanced/index.ts +10 -0
- package/src/sms/advanced/link-tracking.ts +248 -0
- package/src/sms/advanced/mms.ts +308 -0
- package/src/sms/handlers/__tests__/send.test.ts +40 -0
- package/src/sms/handlers/delivery-status.ts +133 -0
- package/src/sms/handlers/receive.ts +162 -0
- package/src/sms/handlers/send.ts +174 -0
- package/src/sms/index.ts +9 -0
- package/src/stack-diff.ts +389 -0
- package/src/static-site/index.ts +85 -0
- package/src/template-builder.ts +110 -0
- package/src/template-validator.ts +574 -0
- package/src/utils/cache.ts +291 -0
- package/src/utils/diff.ts +269 -0
- package/src/utils/hash.ts +227 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/parallel.ts +294 -0
- package/src/validators/credentials.test.ts +274 -0
- package/src/validators/credentials.ts +233 -0
- package/src/validators/quotas.test.ts +434 -0
- package/src/validators/quotas.ts +217 -0
- package/test/ai.test.ts +327 -0
- package/test/api.test.ts +511 -0
- package/test/auth.test.ts +632 -0
- package/test/cache.test.ts +406 -0
- package/test/cdn.test.ts +247 -0
- package/test/compute.test.ts +861 -0
- package/test/database.test.ts +523 -0
- package/test/deployment.test.ts +499 -0
- package/test/dns.test.ts +270 -0
- package/test/email.test.ts +439 -0
- package/test/filesystem.test.ts +382 -0
- package/test/integration.test.ts +350 -0
- package/test/messaging.test.ts +514 -0
- package/test/monitoring.test.ts +634 -0
- package/test/network.test.ts +425 -0
- package/test/permissions.test.ts +488 -0
- package/test/queue.test.ts +484 -0
- package/test/registry.test.ts +306 -0
- package/test/security.test.ts +462 -0
- package/test/storage.test.ts +463 -0
- package/test/template-validator.test.ts +559 -0
- package/test/workflow.test.ts +592 -0
- package/tsconfig.json +16 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test'
|
|
2
|
+
import { Registry } from '../src/modules/registry'
|
|
3
|
+
import { TemplateBuilder } from '../src/template-builder'
|
|
4
|
+
|
|
5
|
+
describe('Registry Module', () => {
|
|
6
|
+
describe('createRepository', () => {
|
|
7
|
+
it('should create a basic ECR repository', () => {
|
|
8
|
+
const { repository, logicalId } = Registry.createRepository({
|
|
9
|
+
name: 'api',
|
|
10
|
+
slug: 'my-app',
|
|
11
|
+
environment: 'production',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
expect(repository.Type).toBe('AWS::ECR::Repository')
|
|
15
|
+
expect(repository.Properties?.RepositoryName).toBe('my-app-production-ecr-api')
|
|
16
|
+
expect(logicalId).toBe('MyAppProductionEcrApi')
|
|
17
|
+
expect(repository.Properties?.ImageScanningConfiguration?.ScanOnPush).toBe(true)
|
|
18
|
+
expect(repository.Properties?.ImageTagMutability).toBe('MUTABLE')
|
|
19
|
+
expect(repository.Properties?.EncryptionConfiguration?.EncryptionType).toBe('AES256')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('should create repository with immutable tags', () => {
|
|
23
|
+
const { repository } = Registry.createRepository({
|
|
24
|
+
name: 'api',
|
|
25
|
+
slug: 'my-app',
|
|
26
|
+
environment: 'production',
|
|
27
|
+
imageMutability: 'IMMUTABLE',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
expect(repository.Properties?.ImageTagMutability).toBe('IMMUTABLE')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('should create repository with KMS encryption', () => {
|
|
34
|
+
const { repository } = Registry.createRepository({
|
|
35
|
+
name: 'api',
|
|
36
|
+
slug: 'my-app',
|
|
37
|
+
environment: 'production',
|
|
38
|
+
encryption: 'KMS',
|
|
39
|
+
kmsKey: 'arn:aws:kms:us-east-1:123456789:key/12345',
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
expect(repository.Properties?.EncryptionConfiguration?.EncryptionType).toBe('KMS')
|
|
43
|
+
expect(repository.Properties?.EncryptionConfiguration?.KmsKey).toBe('arn:aws:kms:us-east-1:123456789:key/12345')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should create repository with scan on push disabled', () => {
|
|
47
|
+
const { repository } = Registry.createRepository({
|
|
48
|
+
name: 'api',
|
|
49
|
+
slug: 'my-app',
|
|
50
|
+
environment: 'production',
|
|
51
|
+
scanOnPush: false,
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
expect(repository.Properties?.ImageScanningConfiguration?.ScanOnPush).toBe(false)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('should create repository with lifecycle policy', () => {
|
|
58
|
+
const { repository } = Registry.createRepository({
|
|
59
|
+
name: 'api',
|
|
60
|
+
slug: 'my-app',
|
|
61
|
+
environment: 'production',
|
|
62
|
+
lifecyclePolicy: {
|
|
63
|
+
maxImageCount: 10,
|
|
64
|
+
untaggedImageExpireDays: 7,
|
|
65
|
+
},
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
expect(repository.Properties?.LifecyclePolicy).toBeDefined()
|
|
69
|
+
expect(repository.Properties?.LifecyclePolicy?.LifecyclePolicyText).toBeDefined()
|
|
70
|
+
|
|
71
|
+
const policy = JSON.parse(repository.Properties!.LifecyclePolicy!.LifecyclePolicyText!)
|
|
72
|
+
expect(policy.rules).toHaveLength(2)
|
|
73
|
+
expect(policy.rules[0].selection.tagStatus).toBe('untagged')
|
|
74
|
+
expect(policy.rules[0].selection.countNumber).toBe(7)
|
|
75
|
+
expect(policy.rules[1].selection.countNumber).toBe(10)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('should create repository with tags', () => {
|
|
79
|
+
const { repository } = Registry.createRepository({
|
|
80
|
+
name: 'api',
|
|
81
|
+
slug: 'my-app',
|
|
82
|
+
environment: 'production',
|
|
83
|
+
tags: {
|
|
84
|
+
Owner: 'Platform Team',
|
|
85
|
+
Project: 'MyApp',
|
|
86
|
+
},
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
expect(repository.Properties?.Tags).toHaveLength(2)
|
|
90
|
+
expect(repository.Properties?.Tags).toContainEqual({ Key: 'Owner', Value: 'Platform Team' })
|
|
91
|
+
expect(repository.Properties?.Tags).toContainEqual({ Key: 'Project', Value: 'MyApp' })
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('should create repository with production lifecycle preset', () => {
|
|
95
|
+
const { repository } = Registry.createRepository({
|
|
96
|
+
name: 'api',
|
|
97
|
+
slug: 'my-app',
|
|
98
|
+
environment: 'production',
|
|
99
|
+
lifecyclePolicy: Registry.LifecyclePolicies.production,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const policy = JSON.parse(repository.Properties!.LifecyclePolicy!.LifecyclePolicyText!)
|
|
103
|
+
expect(policy.rules).toHaveLength(2)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should create repository with development lifecycle preset', () => {
|
|
107
|
+
const { repository } = Registry.createRepository({
|
|
108
|
+
name: 'api',
|
|
109
|
+
slug: 'my-app',
|
|
110
|
+
environment: 'development',
|
|
111
|
+
lifecyclePolicy: Registry.LifecyclePolicies.development,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
const policy = JSON.parse(repository.Properties!.LifecyclePolicy!.LifecyclePolicyText!)
|
|
115
|
+
expect(policy.rules[0].selection.countNumber).toBe(3)
|
|
116
|
+
expect(policy.rules[1].selection.countNumber).toBe(5)
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
describe('LifecyclePolicies presets', () => {
|
|
121
|
+
it('should provide production preset', () => {
|
|
122
|
+
const preset = Registry.LifecyclePolicies.production
|
|
123
|
+
|
|
124
|
+
expect(preset.maxImageCount).toBe(10)
|
|
125
|
+
expect(preset.untaggedImageExpireDays).toBe(7)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('should provide development preset', () => {
|
|
129
|
+
const preset = Registry.LifecyclePolicies.development
|
|
130
|
+
|
|
131
|
+
expect(preset.maxImageCount).toBe(5)
|
|
132
|
+
expect(preset.untaggedImageExpireDays).toBe(3)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('should provide minimal preset', () => {
|
|
136
|
+
const preset = Registry.LifecyclePolicies.minimal
|
|
137
|
+
|
|
138
|
+
expect(preset.maxImageCount).toBe(3)
|
|
139
|
+
expect(preset.untaggedImageExpireDays).toBe(1)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('should provide archive preset', () => {
|
|
143
|
+
const preset = Registry.LifecyclePolicies.archive
|
|
144
|
+
|
|
145
|
+
expect(preset.maxImageCount).toBe(50)
|
|
146
|
+
expect(preset.untaggedImageExpireDays).toBe(30)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
describe('enableImmutableTags', () => {
|
|
151
|
+
it('should enable immutable tags on existing repository', () => {
|
|
152
|
+
const { repository } = Registry.createRepository({
|
|
153
|
+
name: 'api',
|
|
154
|
+
slug: 'my-app',
|
|
155
|
+
environment: 'production',
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
const updated = Registry.enableImmutableTags(repository)
|
|
159
|
+
|
|
160
|
+
expect(updated.Properties?.ImageTagMutability).toBe('IMMUTABLE')
|
|
161
|
+
})
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
describe('enableScanOnPush', () => {
|
|
165
|
+
it('should enable scan on push on existing repository', () => {
|
|
166
|
+
const { repository } = Registry.createRepository({
|
|
167
|
+
name: 'api',
|
|
168
|
+
slug: 'my-app',
|
|
169
|
+
environment: 'production',
|
|
170
|
+
scanOnPush: false,
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
const updated = Registry.enableScanOnPush(repository)
|
|
174
|
+
|
|
175
|
+
expect(updated.Properties?.ImageScanningConfiguration?.ScanOnPush).toBe(true)
|
|
176
|
+
})
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
describe('setLifecyclePolicy', () => {
|
|
180
|
+
it('should set lifecycle policy on existing repository', () => {
|
|
181
|
+
const { repository } = Registry.createRepository({
|
|
182
|
+
name: 'api',
|
|
183
|
+
slug: 'my-app',
|
|
184
|
+
environment: 'production',
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
const updated = Registry.setLifecyclePolicy(repository, {
|
|
188
|
+
maxImageCount: 20,
|
|
189
|
+
untaggedImageExpireDays: 14,
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
expect(updated.Properties?.LifecyclePolicy).toBeDefined()
|
|
193
|
+
const policy = JSON.parse(updated.Properties!.LifecyclePolicy!.LifecyclePolicyText!)
|
|
194
|
+
expect(policy.rules).toHaveLength(2)
|
|
195
|
+
expect(policy.rules[0].selection.countNumber).toBe(14)
|
|
196
|
+
expect(policy.rules[1].selection.countNumber).toBe(20)
|
|
197
|
+
})
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
describe('addCrossAccountAccess', () => {
|
|
201
|
+
it('should add cross-account access policy', () => {
|
|
202
|
+
const { repository } = Registry.createRepository({
|
|
203
|
+
name: 'api',
|
|
204
|
+
slug: 'my-app',
|
|
205
|
+
environment: 'production',
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
const updated = Registry.addCrossAccountAccess(repository, ['123456789012', '210987654321'])
|
|
209
|
+
|
|
210
|
+
expect(updated.Properties?.RepositoryPolicyText).toBeDefined()
|
|
211
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement).toHaveLength(1)
|
|
212
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement[0].Effect).toBe('Allow')
|
|
213
|
+
const principal = updated.Properties?.RepositoryPolicyText?.Statement[0].Principal as { AWS?: string | string[] }
|
|
214
|
+
expect(principal.AWS).toContain('arn:aws:iam::123456789012:root')
|
|
215
|
+
expect(principal.AWS).toContain('arn:aws:iam::210987654321:root')
|
|
216
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement[0].Action).toContain('ecr:GetDownloadUrlForLayer')
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
describe('addLambdaAccess', () => {
|
|
221
|
+
it('should add Lambda service access policy', () => {
|
|
222
|
+
const { repository } = Registry.createRepository({
|
|
223
|
+
name: 'api',
|
|
224
|
+
slug: 'my-app',
|
|
225
|
+
environment: 'production',
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const updated = Registry.addLambdaAccess(repository)
|
|
229
|
+
|
|
230
|
+
expect(updated.Properties?.RepositoryPolicyText).toBeDefined()
|
|
231
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement).toHaveLength(1)
|
|
232
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement[0].Effect).toBe('Allow')
|
|
233
|
+
const principal = updated.Properties?.RepositoryPolicyText?.Statement[0].Principal as { Service?: string | string[] }
|
|
234
|
+
expect(principal.Service).toBe('lambda.amazonaws.com')
|
|
235
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement[0].Action).toContain('ecr:GetDownloadUrlForLayer')
|
|
236
|
+
expect(updated.Properties?.RepositoryPolicyText?.Statement[0].Action).toContain('ecr:BatchGetImage')
|
|
237
|
+
})
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
describe('Integration with TemplateBuilder', () => {
|
|
241
|
+
it('should integrate with CloudFormation template', () => {
|
|
242
|
+
const template = new TemplateBuilder('Container Infrastructure')
|
|
243
|
+
|
|
244
|
+
const { repository, logicalId } = Registry.createRepository({
|
|
245
|
+
name: 'api',
|
|
246
|
+
slug: 'my-app',
|
|
247
|
+
environment: 'production',
|
|
248
|
+
imageMutability: 'IMMUTABLE',
|
|
249
|
+
lifecyclePolicy: Registry.LifecyclePolicies.production,
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
template.addResource(logicalId, repository)
|
|
253
|
+
|
|
254
|
+
const result = template.build()
|
|
255
|
+
|
|
256
|
+
expect(result.Resources[logicalId]).toBeDefined()
|
|
257
|
+
expect(result.Resources[logicalId].Type).toBe('AWS::ECR::Repository')
|
|
258
|
+
expect(result.AWSTemplateFormatVersion).toBe('2010-09-09')
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('should generate valid JSON template', () => {
|
|
262
|
+
const template = new TemplateBuilder('Test ECR')
|
|
263
|
+
|
|
264
|
+
const { repository, logicalId } = Registry.createRepository({
|
|
265
|
+
name: 'web',
|
|
266
|
+
slug: 'test',
|
|
267
|
+
environment: 'development',
|
|
268
|
+
encryption: 'KMS',
|
|
269
|
+
kmsKey: 'alias/ecr-key',
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
template.addResource(logicalId, repository)
|
|
273
|
+
|
|
274
|
+
const json = template.toJSON()
|
|
275
|
+
const parsed = JSON.parse(json)
|
|
276
|
+
|
|
277
|
+
expect(parsed.Resources[logicalId].Type).toBe('AWS::ECR::Repository')
|
|
278
|
+
expect(parsed.Resources[logicalId].Properties.EncryptionConfiguration.EncryptionType).toBe('KMS')
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
it('should create multiple repositories in same template', () => {
|
|
282
|
+
const template = new TemplateBuilder('Multi-Service Infrastructure')
|
|
283
|
+
|
|
284
|
+
const api = Registry.createRepository({
|
|
285
|
+
name: 'api',
|
|
286
|
+
slug: 'my-app',
|
|
287
|
+
environment: 'production',
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
const worker = Registry.createRepository({
|
|
291
|
+
name: 'worker',
|
|
292
|
+
slug: 'my-app',
|
|
293
|
+
environment: 'production',
|
|
294
|
+
})
|
|
295
|
+
|
|
296
|
+
template.addResource(api.logicalId, api.repository)
|
|
297
|
+
template.addResource(worker.logicalId, worker.repository)
|
|
298
|
+
|
|
299
|
+
const result = template.build()
|
|
300
|
+
|
|
301
|
+
expect(Object.keys(result.Resources)).toHaveLength(2)
|
|
302
|
+
expect(result.Resources[api.logicalId]).toBeDefined()
|
|
303
|
+
expect(result.Resources[worker.logicalId]).toBeDefined()
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
})
|