@quadnix/octo 0.0.30 → 0.2.0
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 +661 -0
- package/README.md +117 -8
- package/dist/app.type.d.ts +277 -19
- package/dist/app.type.js +80 -9
- package/dist/app.type.js.map +1 -1
- package/dist/decorators/action.decorator.d.ts +10 -6
- package/dist/decorators/action.decorator.js +19 -6
- package/dist/decorators/action.decorator.js.map +1 -1
- package/dist/decorators/anchor.decorator.d.ts +12 -5
- package/dist/decorators/anchor.decorator.js +12 -5
- package/dist/decorators/anchor.decorator.js.map +1 -1
- package/dist/decorators/enable-hook.decorator.d.ts +1 -1
- package/dist/decorators/enable-hook.decorator.js +1 -1
- package/dist/decorators/factory.decorator.d.ts +18 -34
- package/dist/decorators/factory.decorator.js +18 -34
- package/dist/decorators/factory.decorator.js.map +1 -1
- package/dist/decorators/model.decorator.d.ts +4 -6
- package/dist/decorators/model.decorator.js +2 -7
- package/dist/decorators/model.decorator.js.map +1 -1
- package/dist/decorators/module.decorator.d.ts +16 -10
- package/dist/decorators/module.decorator.js +16 -10
- package/dist/decorators/module.decorator.js.map +1 -1
- package/dist/decorators/on-event.decorator.d.ts +7 -2
- package/dist/decorators/on-event.decorator.js +5 -0
- package/dist/decorators/on-event.decorator.js.map +1 -1
- package/dist/decorators/resource.decorator.d.ts +50 -1
- package/dist/decorators/resource.decorator.js +38 -1
- package/dist/decorators/resource.decorator.js.map +1 -1
- package/dist/decorators/validate.decorator.d.ts +15 -1
- package/dist/decorators/validate.decorator.js +15 -1
- package/dist/decorators/validate.decorator.js.map +1 -1
- package/dist/errors/container.error.d.ts +18 -0
- package/dist/errors/container.error.js +18 -0
- package/dist/errors/container.error.js.map +1 -1
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/module.error.d.ts +6 -0
- package/dist/errors/module.error.js +6 -0
- package/dist/errors/module.error.js.map +1 -1
- package/dist/errors/node.error.d.ts +56 -0
- package/dist/errors/node.error.js +56 -0
- package/dist/errors/node.error.js.map +1 -1
- package/dist/errors/schema.error.d.ts +14 -1
- package/dist/errors/schema.error.js +11 -1
- package/dist/errors/schema.error.js.map +1 -1
- package/dist/errors/terraform.error.d.ts +20 -0
- package/dist/errors/terraform.error.js +24 -0
- package/dist/errors/terraform.error.js.map +1 -0
- package/dist/errors/transaction.error.d.ts +93 -2
- package/dist/errors/transaction.error.js +83 -0
- package/dist/errors/transaction.error.js.map +1 -1
- package/dist/events/action.event.d.ts +8 -4
- package/dist/events/action.event.js +2 -4
- package/dist/events/action.event.js.map +1 -1
- package/dist/events/command.event.d.ts +43 -0
- package/dist/events/command.event.js +33 -0
- package/dist/events/command.event.js.map +1 -0
- package/dist/events/event.model.d.ts +26 -8
- package/dist/events/event.model.js +15 -7
- package/dist/events/event.model.js.map +1 -1
- package/dist/events/hook/commit.hook.event.d.ts +1 -7
- package/dist/events/hook/commit.hook.event.js +0 -6
- package/dist/events/hook/commit.hook.event.js.map +1 -1
- package/dist/events/hook/hook.event.d.ts +1 -3
- package/dist/events/hook/hook.event.js +0 -2
- package/dist/events/hook/hook.event.js.map +1 -1
- package/dist/events/hook/model.hook.event.d.ts +1 -7
- package/dist/events/hook/model.hook.event.js +0 -6
- package/dist/events/hook/model.hook.event.js.map +1 -1
- package/dist/events/hook/resource.hook.event.d.ts +1 -7
- package/dist/events/hook/resource.hook.event.js +0 -6
- package/dist/events/hook/resource.hook.event.js.map +1 -1
- package/dist/events/index.d.ts +5 -0
- package/dist/events/index.js +5 -0
- package/dist/events/index.js.map +1 -1
- package/dist/events/mode-result.event.d.ts +57 -0
- package/dist/events/mode-result.event.js +24 -0
- package/dist/events/mode-result.event.js.map +1 -0
- package/dist/events/mode.event.d.ts +61 -0
- package/dist/events/mode.event.js +32 -0
- package/dist/events/mode.event.js.map +1 -0
- package/dist/events/module.event.d.ts +7 -5
- package/dist/events/module.event.js +3 -4
- package/dist/events/module.event.js.map +1 -1
- package/dist/events/registration.event.d.ts +19 -15
- package/dist/events/registration.event.js +18 -14
- package/dist/events/registration.event.js.map +1 -1
- package/dist/events/serialization.event.d.ts +16 -13
- package/dist/events/serialization.event.js +15 -12
- package/dist/events/serialization.event.js.map +1 -1
- package/dist/events/state.event.d.ts +102 -0
- package/dist/events/state.event.js +69 -0
- package/dist/events/state.event.js.map +1 -0
- package/dist/events/terraform.event.d.ts +78 -0
- package/dist/events/terraform.event.js +55 -0
- package/dist/events/terraform.event.js.map +1 -0
- package/dist/events/transaction.event.d.ts +3 -40
- package/dist/events/transaction.event.js +1 -29
- package/dist/events/transaction.event.js.map +1 -1
- package/dist/functions/container/container.d.ts +54 -13
- package/dist/functions/container/container.js +64 -19
- package/dist/functions/container/container.js.map +1 -1
- package/dist/functions/container/test-container.d.ts +43 -29
- package/dist/functions/container/test-container.js +71 -43
- package/dist/functions/container/test-container.js.map +1 -1
- package/dist/functions/dependency/dependency.d.ts +84 -23
- package/dist/functions/dependency/dependency.js +84 -14
- package/dist/functions/dependency/dependency.js.map +1 -1
- package/dist/functions/diff/aggregate-resource-actions.d.ts +19 -0
- package/dist/functions/diff/aggregate-resource-actions.js +41 -0
- package/dist/functions/diff/aggregate-resource-actions.js.map +1 -0
- package/dist/functions/diff/diff-metadata.d.ts +21 -3
- package/dist/functions/diff/diff-metadata.js +18 -0
- package/dist/functions/diff/diff-metadata.js.map +1 -1
- package/dist/functions/diff/diff.d.ts +68 -7
- package/dist/functions/diff/diff.js +44 -3
- package/dist/functions/diff/diff.js.map +1 -1
- package/dist/functions/hook/commit.hook.d.ts +16 -1
- package/dist/functions/hook/commit.hook.js +21 -6
- package/dist/functions/hook/commit.hook.js.map +1 -1
- package/dist/functions/hook/model-action.hook.d.ts +16 -1
- package/dist/functions/hook/model-action.hook.js +21 -6
- package/dist/functions/hook/model-action.hook.js.map +1 -1
- package/dist/functions/hook/resource-action.hook.d.ts +16 -1
- package/dist/functions/hook/resource-action.hook.js +21 -6
- package/dist/functions/hook/resource-action.hook.js.map +1 -1
- package/dist/functions/node/node-action.abstract.d.ts +23 -2
- package/dist/functions/node/node-action.abstract.js +22 -8
- package/dist/functions/node/node-action.abstract.js.map +1 -1
- package/dist/functions/node/node.abstract.d.ts +56 -5
- package/dist/functions/node/node.abstract.js +106 -22
- package/dist/functions/node/node.abstract.js.map +1 -1
- package/dist/functions/node/node.interface.d.ts +3 -1
- package/dist/functions/schema/schema.d.ts +7 -0
- package/dist/functions/schema/schema.js +10 -1
- package/dist/functions/schema/schema.js.map +1 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.js +9 -4
- package/dist/index.js.map +1 -1
- package/dist/index.type.d.ts +5 -0
- package/dist/index.type.js +2 -0
- package/dist/index.type.js.map +1 -0
- package/dist/main.d.ts +245 -14
- package/dist/main.js +377 -72
- package/dist/main.js.map +1 -1
- package/dist/models/account/account.model.d.ts +43 -7
- package/dist/models/account/account.model.js +56 -8
- package/dist/models/account/account.model.js.map +1 -1
- package/dist/models/account/account.schema.d.ts +13 -1
- package/dist/models/account/account.schema.js +12 -0
- package/dist/models/account/account.schema.js.map +1 -1
- package/dist/models/app/app.model.d.ts +13 -8
- package/dist/models/app/app.model.js +17 -32
- package/dist/models/app/app.model.js.map +1 -1
- package/dist/models/app/app.schema.d.ts +6 -0
- package/dist/models/app/app.schema.js +6 -0
- package/dist/models/app/app.schema.js.map +1 -1
- package/dist/models/deployment/deployment.model.d.ts +13 -1
- package/dist/models/deployment/deployment.model.js +16 -4
- package/dist/models/deployment/deployment.model.js.map +1 -1
- package/dist/models/deployment/deployment.schema.d.ts +6 -0
- package/dist/models/deployment/deployment.schema.js +6 -0
- package/dist/models/deployment/deployment.schema.js.map +1 -1
- package/dist/models/environment/environment.model.d.ts +15 -3
- package/dist/models/environment/environment.model.js +22 -10
- package/dist/models/environment/environment.model.js.map +1 -1
- package/dist/models/environment/environment.schema.d.ts +2 -0
- package/dist/models/environment/environment.schema.js +2 -0
- package/dist/models/environment/environment.schema.js.map +1 -1
- package/dist/models/execution/execution.model.d.ts +21 -3
- package/dist/models/execution/execution.model.js +47 -29
- package/dist/models/execution/execution.model.js.map +1 -1
- package/dist/models/execution/execution.schema.d.ts +11 -0
- package/dist/models/execution/execution.schema.js +11 -0
- package/dist/models/execution/execution.schema.js.map +1 -1
- package/dist/models/filesystem/filesystem.model.d.ts +27 -1
- package/dist/models/filesystem/filesystem.model.js +30 -4
- package/dist/models/filesystem/filesystem.model.js.map +1 -1
- package/dist/models/filesystem/filesystem.schema.d.ts +5 -0
- package/dist/models/filesystem/filesystem.schema.js +5 -0
- package/dist/models/filesystem/filesystem.schema.js.map +1 -1
- package/dist/models/image/image.model.d.ts +19 -5
- package/dist/models/image/image.model.js +25 -11
- package/dist/models/image/image.model.js.map +1 -1
- package/dist/models/image/image.schema.d.ts +8 -0
- package/dist/models/image/image.schema.js +8 -0
- package/dist/models/image/image.schema.js.map +1 -1
- package/dist/models/model-action.interface.d.ts +17 -4
- package/dist/models/model.abstract.d.ts +96 -1
- package/dist/models/model.abstract.js +107 -8
- package/dist/models/model.abstract.js.map +1 -1
- package/dist/models/model.interface.d.ts +3 -0
- package/dist/models/pipeline/pipeline.model.d.ts +14 -2
- package/dist/models/pipeline/pipeline.model.js +19 -7
- package/dist/models/pipeline/pipeline.model.js.map +1 -1
- package/dist/models/pipeline/pipeline.schema.d.ts +8 -0
- package/dist/models/pipeline/pipeline.schema.js +8 -0
- package/dist/models/pipeline/pipeline.schema.js.map +1 -1
- package/dist/models/region/region.model.d.ts +16 -1
- package/dist/models/region/region.model.js +19 -4
- package/dist/models/region/region.model.js.map +1 -1
- package/dist/models/region/region.schema.d.ts +6 -0
- package/dist/models/region/region.schema.js +6 -0
- package/dist/models/region/region.schema.js.map +1 -1
- package/dist/models/server/server.model.d.ts +15 -3
- package/dist/models/server/server.model.js +18 -6
- package/dist/models/server/server.model.js.map +1 -1
- package/dist/models/server/server.schema.d.ts +3 -1
- package/dist/models/server/server.schema.js +3 -1
- package/dist/models/server/server.schema.js.map +1 -1
- package/dist/models/service/service.model.d.ts +37 -6
- package/dist/models/service/service.model.js +65 -11
- package/dist/models/service/service.model.js.map +1 -1
- package/dist/models/service/service.schema.d.ts +48 -1
- package/dist/models/service/service.schema.js +56 -1
- package/dist/models/service/service.schema.js.map +1 -1
- package/dist/models/subnet/subnet.model.d.ts +27 -3
- package/dist/models/subnet/subnet.model.js +40 -16
- package/dist/models/subnet/subnet.model.js.map +1 -1
- package/dist/models/subnet/subnet.schema.d.ts +9 -0
- package/dist/models/subnet/subnet.schema.js +9 -0
- package/dist/models/subnet/subnet.schema.js.map +1 -1
- package/dist/modes/apply-transaction.d.ts +23 -0
- package/dist/modes/apply-transaction.js +25 -0
- package/dist/modes/apply-transaction.js.map +1 -0
- package/dist/modes/commit.mode.d.ts +54 -0
- package/dist/modes/commit.mode.js +235 -0
- package/dist/modes/commit.mode.js.map +1 -0
- package/dist/modes/generate.mode.d.ts +30 -0
- package/dist/modes/generate.mode.js +50 -0
- package/dist/modes/generate.mode.js.map +1 -0
- package/dist/modes/run-action.mode.d.ts +30 -0
- package/dist/modes/run-action.mode.js +140 -0
- package/dist/modes/run-action.mode.js.map +1 -0
- package/dist/modes/validate.mode.d.ts +186 -0
- package/dist/modes/validate.mode.js +558 -0
- package/dist/modes/validate.mode.js.map +1 -0
- package/dist/modules/module.abstract.d.ts +51 -0
- package/dist/modules/module.abstract.js +36 -0
- package/dist/modules/module.abstract.js.map +1 -1
- package/dist/modules/module.container.d.ts +43 -1
- package/dist/modules/module.container.js +77 -5
- package/dist/modules/module.container.js.map +1 -1
- package/dist/modules/test-module.container.d.ts +139 -25
- package/dist/modules/test-module.container.js +383 -199
- package/dist/modules/test-module.container.js.map +1 -1
- package/dist/overlays/anchor.abstract.d.ts +32 -1
- package/dist/overlays/anchor.abstract.js +42 -11
- package/dist/overlays/anchor.abstract.js.map +1 -1
- package/dist/overlays/anchor.schema.d.ts +21 -0
- package/dist/overlays/anchor.schema.js +21 -0
- package/dist/overlays/anchor.schema.js.map +1 -1
- package/dist/overlays/overlay-data.repository.d.ts +18 -0
- package/dist/overlays/overlay-data.repository.js +18 -0
- package/dist/overlays/overlay-data.repository.js.map +1 -1
- package/dist/overlays/overlay.abstract.d.ts +56 -1
- package/dist/overlays/overlay.abstract.js +79 -20
- package/dist/overlays/overlay.abstract.js.map +1 -1
- package/dist/overlays/overlay.schema.d.ts +20 -0
- package/dist/overlays/overlay.schema.js +20 -0
- package/dist/overlays/overlay.schema.js.map +1 -1
- package/dist/resources/resource-action.interface.d.ts +29 -3
- package/dist/resources/resource-data.repository.d.ts +63 -1
- package/dist/resources/resource-data.repository.js +94 -4
- package/dist/resources/resource-data.repository.js.map +1 -1
- package/dist/resources/resource.abstract.d.ts +163 -6
- package/dist/resources/resource.abstract.js +223 -59
- package/dist/resources/resource.abstract.js.map +1 -1
- package/dist/resources/resource.interface.d.ts +0 -2
- package/dist/resources/resource.schema.d.ts +39 -1
- package/dist/resources/resource.schema.js +38 -0
- package/dist/resources/resource.schema.js.map +1 -1
- package/dist/resources/terraform-resource.abstract.d.ts +44 -0
- package/dist/resources/terraform-resource.abstract.js +45 -0
- package/dist/resources/terraform-resource.abstract.js.map +1 -0
- package/dist/services/event/event.service.d.ts +32 -5
- package/dist/services/event/event.service.js +58 -16
- package/dist/services/event/event.service.js.map +1 -1
- package/dist/services/input/input.service.d.ts +82 -5
- package/dist/services/input/input.service.js +143 -12
- package/dist/services/input/input.service.js.map +1 -1
- package/dist/services/schema-translation/schema-translation.service.d.ts +9 -0
- package/dist/services/schema-translation/schema-translation.service.js +9 -0
- package/dist/services/schema-translation/schema-translation.service.js.map +1 -1
- package/dist/services/serialization/model/model-serialization.service.d.ts +25 -3
- package/dist/services/serialization/model/model-serialization.service.js +113 -62
- package/dist/services/serialization/model/model-serialization.service.js.map +1 -1
- package/dist/services/serialization/resource/resource-serialization.service.d.ts +36 -6
- package/dist/services/serialization/resource/resource-serialization.service.js +77 -28
- package/dist/services/serialization/resource/resource-serialization.service.js.map +1 -1
- package/dist/services/state-management/local.state-provider.d.ts +67 -4
- package/dist/services/state-management/local.state-provider.js +168 -41
- package/dist/services/state-management/local.state-provider.js.map +1 -1
- package/dist/services/state-management/remote.state-provider.d.ts +216 -0
- package/dist/services/state-management/remote.state-provider.js +645 -0
- package/dist/services/state-management/remote.state-provider.js.map +1 -0
- package/dist/services/state-management/state-management.service.d.ts +195 -17
- package/dist/services/state-management/state-management.service.js +259 -10
- package/dist/services/state-management/state-management.service.js.map +1 -1
- package/dist/services/state-management/state-provider.interface.d.ts +98 -3
- package/dist/services/state-management/state-provider.interface.js +14 -1
- package/dist/services/state-management/state-provider.interface.js.map +1 -1
- package/dist/services/state-management/terraform-state.service.d.ts +99 -0
- package/dist/services/state-management/terraform-state.service.js +197 -0
- package/dist/services/state-management/terraform-state.service.js.map +1 -0
- package/dist/services/state-management/test.state-provider.d.ts +42 -4
- package/dist/services/state-management/test.state-provider.js +77 -25
- package/dist/services/state-management/test.state-provider.js.map +1 -1
- package/dist/services/terraform/terraform.service.d.ts +480 -0
- package/dist/services/terraform/terraform.service.js +1082 -0
- package/dist/services/terraform/terraform.service.js.map +1 -0
- package/dist/services/terraform/terraform.type.d.ts +387 -0
- package/dist/services/terraform/terraform.type.js +579 -0
- package/dist/services/terraform/terraform.type.js.map +1 -0
- package/dist/services/transaction/transaction.service.d.ts +110 -10
- package/dist/services/transaction/transaction.service.js +570 -251
- package/dist/services/transaction/transaction.service.js.map +1 -1
- package/dist/services/validation/validation.service.d.ts +15 -3
- package/dist/services/validation/validation.service.js +12 -0
- package/dist/services/validation/validation.service.js.map +1 -1
- package/dist/utilities/array/array.utility.d.ts +3 -0
- package/dist/utilities/array/array.utility.js +3 -0
- package/dist/utilities/array/array.utility.js.map +1 -1
- package/dist/{functions → utilities}/diff/diff.utility.d.ts +19 -3
- package/dist/{functions → utilities}/diff/diff.utility.js +57 -41
- package/dist/utilities/diff/diff.utility.js.map +1 -0
- package/dist/utilities/file/file.utility.d.ts +16 -2
- package/dist/utilities/file/file.utility.js +23 -61
- package/dist/utilities/file/file.utility.js.map +1 -1
- package/dist/utilities/hcl/hcl.utility.d.ts +128 -0
- package/dist/utilities/hcl/hcl.utility.js +402 -0
- package/dist/utilities/hcl/hcl.utility.js.map +1 -0
- package/dist/utilities/http/http.utility.d.ts +57 -0
- package/dist/utilities/http/http.utility.js +98 -0
- package/dist/utilities/http/http.utility.js.map +1 -0
- package/dist/utilities/node/node.utility.d.ts +3 -0
- package/dist/utilities/node/node.utility.js +3 -0
- package/dist/utilities/node/node.utility.js.map +1 -1
- package/dist/utilities/object/object.utility.d.ts +12 -0
- package/dist/utilities/object/object.utility.js +12 -0
- package/dist/utilities/object/object.utility.js.map +1 -1
- package/dist/utilities/project/project.utility.d.ts +28 -0
- package/dist/utilities/project/project.utility.js +35 -0
- package/dist/utilities/project/project.utility.js.map +1 -0
- package/dist/utilities/string/string.utility.d.ts +41 -0
- package/dist/utilities/string/string.utility.js +65 -0
- package/dist/utilities/string/string.utility.js.map +1 -0
- package/dist/utilities/terraform/terraform.utility.d.ts +276 -0
- package/dist/utilities/terraform/terraform.utility.js +623 -0
- package/dist/utilities/terraform/terraform.utility.js.map +1 -0
- package/dist/utilities/test-helpers/test-classes.d.ts +36 -30
- package/dist/utilities/test-helpers/test-classes.js +38 -39
- package/dist/utilities/test-helpers/test-classes.js.map +1 -1
- package/dist/utilities/test-helpers/test-models.d.ts +8 -1
- package/dist/utilities/test-helpers/test-models.js +37 -12
- package/dist/utilities/test-helpers/test-models.js.map +1 -1
- package/dist/utilities/test-helpers/test-modes.d.ts +315 -0
- package/dist/utilities/test-helpers/test-modes.js +486 -0
- package/dist/utilities/test-helpers/test-modes.js.map +1 -0
- package/dist/utilities/test-helpers/test-modules.d.ts +47 -0
- package/dist/utilities/test-helpers/test-modules.js +85 -0
- package/dist/utilities/test-helpers/test-modules.js.map +1 -0
- package/dist/utilities/test-helpers/test-overlays.d.ts +20 -2
- package/dist/utilities/test-helpers/test-overlays.js +56 -6
- package/dist/utilities/test-helpers/test-overlays.js.map +1 -1
- package/dist/utilities/test-helpers/test-resources.d.ts +23 -3
- package/dist/utilities/test-helpers/test-resources.js +83 -23
- package/dist/utilities/test-helpers/test-resources.js.map +1 -1
- package/dist/utilities/validation/validation.utility.d.ts +24 -0
- package/dist/utilities/validation/validation.utility.js +24 -0
- package/dist/utilities/validation/validation.utility.js.map +1 -1
- package/package.json +12 -6
- package/dist/functions/diff/diff.utility.js.map +0 -1
- package/dist/services/capture/capture.service.d.ts +0 -19
- package/dist/services/capture/capture.service.js +0 -43
- package/dist/services/capture/capture.service.js.map +0 -1
- package/dist/services/state-management/local-encryption.state-provider.d.ts +0 -20
- package/dist/services/state-management/local-encryption.state-provider.js +0 -90
- package/dist/services/state-management/local-encryption.state-provider.js.map +0 -1
- package/dist/utilities/cidr/cidr.utility.d.ts +0 -10
- package/dist/utilities/cidr/cidr.utility.js +0 -51
- package/dist/utilities/cidr/cidr.utility.js.map +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { createReadStream, createWriteStream } from 'node:fs';
|
|
2
|
+
import { stat } from 'node:fs/promises';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { pipeline } from 'node:stream/promises';
|
|
5
|
+
import { TransactionError } from '../../errors/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* The one place octo speaks HTTP.
|
|
8
|
+
*
|
|
9
|
+
* A response is handed back whatever its status, so the caller decides what a refusal means instead
|
|
10
|
+
* of catching one. Only a request that never reached a server throws.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export class HttpUtility {
|
|
15
|
+
/**
|
|
16
|
+
* Downloads `url` into `filePath`, streaming it so its size is not bounded by memory. False when the
|
|
17
|
+
* server refused it or the download was cut short, which can leave part of the file behind.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
* @throws {@link TransactionError} When the host could not be reached at all.
|
|
21
|
+
*/
|
|
22
|
+
static async downloadToFile(url, filePath) {
|
|
23
|
+
const response = await this.send(url);
|
|
24
|
+
if (!response.ok || !response.body) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await pipeline(Readable.fromWeb(response.body), createWriteStream(filePath));
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* What a refused request said went wrong, as one line. A service that answers a list - a failed
|
|
37
|
+
* validation usually does - is read as a sentence, and a body that is not JSON as its status.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
static async readErrorMessage(response) {
|
|
42
|
+
let body;
|
|
43
|
+
try {
|
|
44
|
+
body = (await response.json());
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
return `${response.status} ${response.statusText}`;
|
|
48
|
+
}
|
|
49
|
+
const message = Array.isArray(body.message) ? body.message.join(', ') : body.message;
|
|
50
|
+
return message || `${response.status} ${response.statusText}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A body may be a stream, which is sent as it is read rather than held in memory. A stream's length
|
|
54
|
+
* is unknown to fetch, so a server that needs one is given `Content-Length` in `headers`.
|
|
55
|
+
*
|
|
56
|
+
* @internal
|
|
57
|
+
* @throws {@link TransactionError} When the host could not be reached at all, which is a different
|
|
58
|
+
* thing from being refused by it and is the caller's to report differently.
|
|
59
|
+
*/
|
|
60
|
+
static async send(url, { body, headers = {}, method = 'GET' } = {}) {
|
|
61
|
+
try {
|
|
62
|
+
// `duplex` is what lets the body be a stream; Node's fetch refuses one without it.
|
|
63
|
+
return await fetch(url, { body, duplex: 'half', headers, method });
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
throw new TransactionError(`Cannot reach "${new URL(url).origin}"!`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* {@link HttpUtility.send} with a JSON body, which is every request octo makes that carries one
|
|
71
|
+
* other than an upload.
|
|
72
|
+
*
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
static async sendJson(url, { body, headers = {}, method = 'GET' } = {}) {
|
|
76
|
+
return this.send(url, {
|
|
77
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
78
|
+
headers: { ...headers, 'Content-Type': 'application/json' },
|
|
79
|
+
method,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* PUTs the file at `filePath` to `url`, streaming it so its size is not bounded by memory, with its
|
|
84
|
+
* `Content-Length`, which a presigned URL is usually signed with.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
* @throws {@link TransactionError} When the host could not be reached at all.
|
|
88
|
+
*/
|
|
89
|
+
static async uploadFile(url, filePath, headers = {}) {
|
|
90
|
+
const { size } = await stat(filePath);
|
|
91
|
+
return this.send(url, {
|
|
92
|
+
body: Readable.toWeb(createReadStream(filePath)),
|
|
93
|
+
headers: { ...headers, 'Content-Length': String(size) },
|
|
94
|
+
method: 'PUT',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=http.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.utility.js","sourceRoot":"","sources":["../../../src/utilities/http/http.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;;;;;;GAOG;AACH,MAAM,OAAO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,"file":"node.utility.js","sourceRoot":"","sources":["../../../src/utilities/node/node.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB,MAAM,CAAC,yBAAyB,CAAC,SAA4B;QAC3D,MAAM,eAAe,GAAsB,EAAE,CAAC;QAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,KAAK,GAAG,CAAC,CAAC;YAEd,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC;YAChD,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;gBACtC,IAAI,UAAU,CAAC,mBAAmB,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC/F,MAAM,cAAc,GAAG,UAAU,CAAC,EAAqB,CAAC;oBACxD,MAAM,WAAW,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,cAAc,CAAC,UAAU,CAAC,CAAC;oBACjG,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;wBACvB,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;oBAC3C,CAAC;gBACH,CAAC;YACH,CAAC;YAED,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"node.utility.js","sourceRoot":"","sources":["../../../src/utilities/node/node.utility.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAE1D;;GAEG;AACH,MAAM,OAAO,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,yBAAyB,CAAC,SAA4B;QAC3D,MAAM,eAAe,GAAsB,EAAE,CAAC;QAE9C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,KAAK,GAAG,CAAC,CAAC;YAEd,MAAM,YAAY,GAAG,QAAQ,CAAC,eAAe,EAAE,CAAC;YAChD,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;gBACtC,IAAI,UAAU,CAAC,mBAAmB,CAAC,YAAY,EAAE,UAAU,CAAC,GAAG,EAAE,YAAY,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;oBAC/F,MAAM,cAAc,GAAG,UAAU,CAAC,EAAqB,CAAC;oBACxD,MAAM,WAAW,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,cAAc,CAAC,UAAU,CAAC,CAAC;oBACjG,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;wBACvB,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,CAAC;oBAC3C,CAAC;gBACH,CAAC;YACH,CAAC;YAED,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -2,8 +2,20 @@
|
|
|
2
2
|
* @internal
|
|
3
3
|
*/
|
|
4
4
|
export declare class ObjectUtility {
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
5
8
|
static deepFreeze<T extends object>(object: T): void;
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
6
12
|
static deepMergeInPlace(target: object, source: object): void;
|
|
13
|
+
/**
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
7
16
|
static isPlainObject(value: unknown): value is object;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
8
20
|
static onEveryNestedKey(object: object, callback: (parent: object, key: string, value: unknown) => void): void;
|
|
9
21
|
}
|
|
@@ -4,12 +4,18 @@ import { ANode } from '../../functions/node/node.abstract.js';
|
|
|
4
4
|
*/
|
|
5
5
|
export class ObjectUtility {
|
|
6
6
|
// Source: https://stackoverflow.com/a/58496119/1834562
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
static deepFreeze(object) {
|
|
8
11
|
Object.freeze(object);
|
|
9
12
|
Object.values(object)
|
|
10
13
|
.filter((x) => !Object.isFrozen(x))
|
|
11
14
|
.forEach(ObjectUtility.deepFreeze);
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
13
19
|
static deepMergeInPlace(target, source) {
|
|
14
20
|
for (const key of Object.keys(source)) {
|
|
15
21
|
const sourceValue = source[key];
|
|
@@ -25,9 +31,15 @@ export class ObjectUtility {
|
|
|
25
31
|
}
|
|
26
32
|
}
|
|
27
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
28
37
|
static isPlainObject(value) {
|
|
29
38
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
31
43
|
static onEveryNestedKey(object, callback) {
|
|
32
44
|
const keys = object instanceof ANode ? Object.keys(object.synth()) : Object.keys(object);
|
|
33
45
|
for (const key of keys) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.utility.js","sourceRoot":"","sources":["../../../src/utilities/object/object.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uCAAuC,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,uDAAuD;IACvD,MAAM,CAAC,UAAU,CAAmB,MAAS;QAC3C,MAAM,CAAC,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AE,QAA+D;QACrG,MAAM,IAAI,GAAG,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACzF,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;gBACtD,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;gBAE1B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBAChD,aAAa,CAAC,gBAAgB,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;gBAClD,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;gBAC/B,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The octo project root, for code that cannot rely on the current working directory being it.
|
|
3
|
+
*
|
|
4
|
+
* An external resource's action is the case this exists for. Octo runs it in two different places:
|
|
5
|
+
* `octo commit` runs the delete action from the project root, but terraform runs the add and update
|
|
6
|
+
* actions from a terragrunt cache directory, so a path a module resolved against the project root
|
|
7
|
+
* resolves against nothing by the time the action reads it. Octo already supplies the root to every
|
|
8
|
+
* terragrunt command as `TF_VAR_OCTO_PROJECT_ROOT`, which terraform passes down to `local-exec`;
|
|
9
|
+
* this reads it back, and falls back to the working directory for the run that has no terraform in
|
|
10
|
+
* the middle.
|
|
11
|
+
*
|
|
12
|
+
* Store a project-relative path in a resource's `properties` and resolve it here. An absolute one
|
|
13
|
+
* would put the developer's directory layout into octo state, and into the properties hash that
|
|
14
|
+
* generated terraform commits as an external resource's trigger.
|
|
15
|
+
*
|
|
16
|
+
* @group Utilities
|
|
17
|
+
*/
|
|
18
|
+
export declare class ProjectUtility {
|
|
19
|
+
/**
|
|
20
|
+
* The absolute path of the octo project root.
|
|
21
|
+
*/
|
|
22
|
+
static getProjectRoot(): string;
|
|
23
|
+
/**
|
|
24
|
+
* Resolves a project-relative path against {@link ProjectUtility.getProjectRoot}. An absolute path
|
|
25
|
+
* is returned as given.
|
|
26
|
+
*/
|
|
27
|
+
static resolveFromProjectRoot(filePath: string): string;
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { isAbsolute, resolve } from 'node:path';
|
|
2
|
+
import { PROJECT_ROOT_VARIABLE_NAME } from '../../services/terraform/terraform.type.js';
|
|
3
|
+
/**
|
|
4
|
+
* The octo project root, for code that cannot rely on the current working directory being it.
|
|
5
|
+
*
|
|
6
|
+
* An external resource's action is the case this exists for. Octo runs it in two different places:
|
|
7
|
+
* `octo commit` runs the delete action from the project root, but terraform runs the add and update
|
|
8
|
+
* actions from a terragrunt cache directory, so a path a module resolved against the project root
|
|
9
|
+
* resolves against nothing by the time the action reads it. Octo already supplies the root to every
|
|
10
|
+
* terragrunt command as `TF_VAR_OCTO_PROJECT_ROOT`, which terraform passes down to `local-exec`;
|
|
11
|
+
* this reads it back, and falls back to the working directory for the run that has no terraform in
|
|
12
|
+
* the middle.
|
|
13
|
+
*
|
|
14
|
+
* Store a project-relative path in a resource's `properties` and resolve it here. An absolute one
|
|
15
|
+
* would put the developer's directory layout into octo state, and into the properties hash that
|
|
16
|
+
* generated terraform commits as an external resource's trigger.
|
|
17
|
+
*
|
|
18
|
+
* @group Utilities
|
|
19
|
+
*/
|
|
20
|
+
export class ProjectUtility {
|
|
21
|
+
/**
|
|
22
|
+
* The absolute path of the octo project root.
|
|
23
|
+
*/
|
|
24
|
+
static getProjectRoot() {
|
|
25
|
+
return process.env[`TF_VAR_${PROJECT_ROOT_VARIABLE_NAME}`] || process.cwd();
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolves a project-relative path against {@link ProjectUtility.getProjectRoot}. An absolute path
|
|
29
|
+
* is returned as given.
|
|
30
|
+
*/
|
|
31
|
+
static resolveFromProjectRoot(filePath) {
|
|
32
|
+
return isAbsolute(filePath) ? filePath : resolve(this.getProjectRoot(), filePath);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=project.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project.utility.js","sourceRoot":"","sources":["../../../src/utilities/project/project.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAExF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,cAAc;IACzB;;OAEG;IACH,MAAM,CAAC,cAAc;QACnB,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,0BAA0B,EAAE,CAAC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9E,CAAC;IAED;;;OAGG;IACH,MAAM,CAAC,sBAAsB,CAAC,QAAgB;QAC5C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,QAAQ,CAAC,CAAC;IACpF,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* String helpers for module and resource authors: hashing values into stable ids, fitting names into
|
|
3
|
+
* a provider's length limit, and making names safe for terraform.
|
|
4
|
+
*
|
|
5
|
+
* @group Utilities/String
|
|
6
|
+
*/
|
|
7
|
+
export declare class StringUtility {
|
|
8
|
+
/**
|
|
9
|
+
* Shortens a name to at most `maxLength` characters, replacing what is cut with a digest of the whole
|
|
10
|
+
* name. Two names that differ anywhere still differ after shortening, and the same name always
|
|
11
|
+
* shortens the same way. A name already within the limit is returned as it is.
|
|
12
|
+
*
|
|
13
|
+
* Use it where a provider limits a name that is built by joining others, e.g. a distribution name and
|
|
14
|
+
* an origin id, so that cutting the tail alone could make two names collide.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* StringUtility.boundedName('my-distribution-with-a-very-long-origin-id', 20);
|
|
19
|
+
* // The first 11 characters, a dash and 8 hex characters: 20 in all.
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
static boundedName(name: string, maxLength: number): string;
|
|
23
|
+
/**
|
|
24
|
+
* Produces a 16-character hex hash of any value, with object keys sorted recursively, so the hash
|
|
25
|
+
* does not change when key insertion order does. Hash several parts as an array,
|
|
26
|
+
* `deterministicHash([bucketName, accessPrefix])`, which keeps `['ab', 'c']` and `['a', 'bc']` apart.
|
|
27
|
+
* Take a prefix of it where a shorter id is enough.
|
|
28
|
+
*/
|
|
29
|
+
static deterministicHash(value: unknown): string;
|
|
30
|
+
/**
|
|
31
|
+
* Replaces every character that is not a letter, digit, or underscore with an underscore.
|
|
32
|
+
* Suitable for names that travel through environment variables (e.g. terraform variables,
|
|
33
|
+
* which terragrunt passes as `TF_VAR_<name>`), where dashes are not allowed.
|
|
34
|
+
*/
|
|
35
|
+
static sanitizeForEnvironmentVariable(value: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Replaces every character that is not a letter, digit, underscore, or dash with an underscore.
|
|
38
|
+
* Suitable for terraform identifiers (resource names, output names), which allow dashes.
|
|
39
|
+
*/
|
|
40
|
+
static sanitizeForIdentifier(value: string): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* String helpers for module and resource authors: hashing values into stable ids, fitting names into
|
|
4
|
+
* a provider's length limit, and making names safe for terraform.
|
|
5
|
+
*
|
|
6
|
+
* @group Utilities/String
|
|
7
|
+
*/
|
|
8
|
+
export class StringUtility {
|
|
9
|
+
/**
|
|
10
|
+
* Shortens a name to at most `maxLength` characters, replacing what is cut with a digest of the whole
|
|
11
|
+
* name. Two names that differ anywhere still differ after shortening, and the same name always
|
|
12
|
+
* shortens the same way. A name already within the limit is returned as it is.
|
|
13
|
+
*
|
|
14
|
+
* Use it where a provider limits a name that is built by joining others, e.g. a distribution name and
|
|
15
|
+
* an origin id, so that cutting the tail alone could make two names collide.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* StringUtility.boundedName('my-distribution-with-a-very-long-origin-id', 20);
|
|
20
|
+
* // The first 11 characters, a dash and 8 hex characters: 20 in all.
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
static boundedName(name, maxLength) {
|
|
24
|
+
if (name.length <= maxLength) {
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
const digest = StringUtility.deterministicHash(name).substring(0, 8);
|
|
28
|
+
return `${name.substring(0, maxLength - digest.length - 1)}-${digest}`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Produces a 16-character hex hash of any value, with object keys sorted recursively, so the hash
|
|
32
|
+
* does not change when key insertion order does. Hash several parts as an array,
|
|
33
|
+
* `deterministicHash([bucketName, accessPrefix])`, which keeps `['ab', 'c']` and `['a', 'bc']` apart.
|
|
34
|
+
* Take a prefix of it where a shorter id is enough.
|
|
35
|
+
*/
|
|
36
|
+
static deterministicHash(value) {
|
|
37
|
+
const stableStringify = (v) => {
|
|
38
|
+
if (v === null || typeof v !== 'object') {
|
|
39
|
+
return JSON.stringify(v);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(v)) {
|
|
42
|
+
return `[${v.map(stableStringify).join(',')}]`;
|
|
43
|
+
}
|
|
44
|
+
const keys = Object.keys(v).sort();
|
|
45
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(v[k])}`).join(',')}}`;
|
|
46
|
+
};
|
|
47
|
+
return createHash('sha256').update(stableStringify(value)).digest('hex').substring(0, 16);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Replaces every character that is not a letter, digit, or underscore with an underscore.
|
|
51
|
+
* Suitable for names that travel through environment variables (e.g. terraform variables,
|
|
52
|
+
* which terragrunt passes as `TF_VAR_<name>`), where dashes are not allowed.
|
|
53
|
+
*/
|
|
54
|
+
static sanitizeForEnvironmentVariable(value) {
|
|
55
|
+
return value.replace(/[^a-zA-Z0-9_]/g, '_');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Replaces every character that is not a letter, digit, underscore, or dash with an underscore.
|
|
59
|
+
* Suitable for terraform identifiers (resource names, output names), which allow dashes.
|
|
60
|
+
*/
|
|
61
|
+
static sanitizeForIdentifier(value) {
|
|
62
|
+
return value.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=string.utility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string.utility.js","sourceRoot":"","sources":["../../../src/utilities/string/string.utility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACxB;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,WAAW,CAAC,IAAY,EAAE,SAAiB;QAChD,IAAI,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,MAAM,GAAG,aAAa,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;IACzE,CAAC;IAED;;;;;OAKG;IACH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js';
|
|
2
|
+
import type { TerraformPlan } from '../../modes/validate.mode.js';
|
|
3
|
+
interface TerraformRawResult {
|
|
4
|
+
readonly args: string[];
|
|
5
|
+
readonly exitCode: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The result of planning every module folder under a terragrunt directory.
|
|
9
|
+
*
|
|
10
|
+
* A folder appears in exactly one of the two maps: in `plans` when terraform produced a plan, or in
|
|
11
|
+
* `errors` with the reason it could not. Both are keyed by the folder name, i.e. the octo `moduleId`.
|
|
12
|
+
* `errors` is what lets `validate` say why a folder could not be inspected.
|
|
13
|
+
*/
|
|
14
|
+
interface TerraformPlanResult {
|
|
15
|
+
errors: Map<string, string>;
|
|
16
|
+
plans: Map<string, TerraformPlan>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Octo's single interface to the terraform and terragrunt binaries.
|
|
20
|
+
*
|
|
21
|
+
* {@link Octo.generate} writes module folders; this runs them, and turns their output back into the
|
|
22
|
+
* shapes the other modes expect - `plan(dir, { json: true })` feeds {@link Octo.validate}, and
|
|
23
|
+
* `output(dir, { json: true })` feeds {@link Octo.commit}. Routing every invocation through one class
|
|
24
|
+
* is what keeps flags, timeouts, and event emission consistent.
|
|
25
|
+
*
|
|
26
|
+
* Resolve it from the {@link Container} so that a run's terraform events reach the same listeners as
|
|
27
|
+
* everything else.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* const terraform = await Container.getInstance().get(TerraformUtility);
|
|
32
|
+
* const { errors, plans } = await terraform.plan('./infrastructure', { json: true });
|
|
33
|
+
* const report = await octo.validate(app, { errors, plans });
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @group Utilities/Terraform
|
|
37
|
+
*/
|
|
38
|
+
export declare class TerraformUtility {
|
|
39
|
+
/**
|
|
40
|
+
* The id of the last process any instance started, so ids never repeat within one octo process.
|
|
41
|
+
*/
|
|
42
|
+
private static lastProcessId;
|
|
43
|
+
private onceArgs;
|
|
44
|
+
private readonly options;
|
|
45
|
+
/**
|
|
46
|
+
* The timeout the caller asked for, or undefined when they asked for none. A command that changes
|
|
47
|
+
* infrastructure is bounded only by this, never by the default.
|
|
48
|
+
*/
|
|
49
|
+
private readonly requestedTimeoutInMs;
|
|
50
|
+
/**
|
|
51
|
+
* @param options Overrides for the binaries invoked, the per-command timeout, and the state
|
|
52
|
+
* check-in interval. `terragruntBinary` defaults to `terragrunt`.
|
|
53
|
+
*
|
|
54
|
+
* `timeoutInMs` defaults to 60 minutes for the commands that only read - `plan`, `output`, `show`.
|
|
55
|
+
* `apply` and `destroy` run unbounded unless it is given: a timeout there turns a slow apply into
|
|
56
|
+
* one killed part way through a mutation, and how long a stack legitimately takes is a fact about
|
|
57
|
+
* that stack rather than something a default can know. What bounds them instead is the caller -
|
|
58
|
+
* a CI job's own timeout, or a person at a terminal.
|
|
59
|
+
*
|
|
60
|
+
* `stateCheckInIntervalInMs` is how often terraform state is checked into the state provider while
|
|
61
|
+
* a command runs, 10 seconds by default. Terraform rewrites it as each resource completes.
|
|
62
|
+
*/
|
|
63
|
+
constructor(options?: {
|
|
64
|
+
stateCheckInIntervalInMs?: number;
|
|
65
|
+
terraformBinary?: string;
|
|
66
|
+
terragruntBinary?: string;
|
|
67
|
+
timeoutInMs?: number;
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* Runs `terragrunt run --all -- apply` over every generated module folder.
|
|
71
|
+
*
|
|
72
|
+
* **This changes real infrastructure**, and runs with `-auto-approve`. Use
|
|
73
|
+
* {@link TerraformUtility.findPlannedDestroys} beforehand if a destroy needs confirming.
|
|
74
|
+
*
|
|
75
|
+
* @param terragruntDir The directory octo generated the module folders into.
|
|
76
|
+
*/
|
|
77
|
+
apply(terragruntDir: string): Promise<TerraformRawResult>;
|
|
78
|
+
/**
|
|
79
|
+
* Runs `terragrunt run --all -- destroy` over every generated module folder.
|
|
80
|
+
*
|
|
81
|
+
* **This tears down real infrastructure**, and runs with `-auto-approve`.
|
|
82
|
+
*/
|
|
83
|
+
destroy(terragruntDir: string): Promise<TerraformRawResult>;
|
|
84
|
+
/**
|
|
85
|
+
* Every address a set of plans will destroy, across all folders. A recreate (`create` + `delete`)
|
|
86
|
+
* counts, since the old object is still destroyed.
|
|
87
|
+
*
|
|
88
|
+
* Lets a caller refuse to apply until the destroys have been shown, which {@link apply} cannot do on
|
|
89
|
+
* its own because it runs with `-auto-approve`.
|
|
90
|
+
*/
|
|
91
|
+
findPlannedDestroys(plans: Map<string, TerraformPlan>): {
|
|
92
|
+
address: string;
|
|
93
|
+
moduleId: string;
|
|
94
|
+
tfActions: string[];
|
|
95
|
+
}[];
|
|
96
|
+
/**
|
|
97
|
+
* Returns the immediate sub-directories of `terragruntDir` that look like generated module
|
|
98
|
+
* folders (they contain a `terragrunt.hcl`). Each folder name is the octo `moduleId`.
|
|
99
|
+
*/
|
|
100
|
+
listModuleFolders(terragruntDir: string): Promise<string[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Reads the outputs of every generated module folder.
|
|
103
|
+
*
|
|
104
|
+
* @param terragruntDir The directory octo generated the module folders into.
|
|
105
|
+
* @param options Pass `{ json: true }` to get the outputs parsed and keyed by `moduleId`, which is
|
|
106
|
+
* the shape {@link Octo.commit} takes. Without it, terragrunt's output goes out only as events.
|
|
107
|
+
*/
|
|
108
|
+
output(terragruntDir: string, options: {
|
|
109
|
+
json: true;
|
|
110
|
+
}): Promise<Map<string, TerraformOutputs>>;
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
output(terragruntDir: string, options?: {
|
|
115
|
+
json?: false;
|
|
116
|
+
}): Promise<TerraformRawResult>;
|
|
117
|
+
/**
|
|
118
|
+
* Plans every generated module folder.
|
|
119
|
+
*
|
|
120
|
+
* @param terragruntDir The directory octo generated the module folders into.
|
|
121
|
+
* @param options Pass `{ json: true }` to get the plans parsed and keyed by `moduleId`, which is
|
|
122
|
+
* the shape {@link Octo.validate} takes - along with the `errors` of any folder that could not be
|
|
123
|
+
* planned. Without it, terragrunt's output goes out only as events.
|
|
124
|
+
*/
|
|
125
|
+
plan(terragruntDir: string, options: {
|
|
126
|
+
json: true;
|
|
127
|
+
}): Promise<TerraformPlanResult>;
|
|
128
|
+
/**
|
|
129
|
+
* @internal
|
|
130
|
+
*/
|
|
131
|
+
plan(terragruntDir: string, options?: {
|
|
132
|
+
json?: false;
|
|
133
|
+
}): Promise<TerraformRawResult>;
|
|
134
|
+
/**
|
|
135
|
+
* To append extra CLI arguments to the *next* command only. Returns `this`, so it chains.
|
|
136
|
+
*/
|
|
137
|
+
setArgsOnce(args: string[]): this;
|
|
138
|
+
/**
|
|
139
|
+
* Runs `terragrunt run --all -- validate` over every generated module folder, checking the generated
|
|
140
|
+
* HCL is well-formed. Unrelated to {@link Octo.validate}, which compares plans against intent.
|
|
141
|
+
*/
|
|
142
|
+
validate(terragruntDir: string): Promise<TerraformRawResult>;
|
|
143
|
+
/**
|
|
144
|
+
* Runs `file` with `args`, handing each chunk it writes to `onChunk` as it arrives. Keeps its whole
|
|
145
|
+
* stdout only when `keepStdout` asks for it, and the last {@link STDERR_TAIL_LENGTH} characters of its
|
|
146
|
+
* stderr, so a process writing for an hour holds no more memory than one writing for a second.
|
|
147
|
+
*/
|
|
148
|
+
protected spawnAsync(file: string, args: string[], options: {
|
|
149
|
+
cwd?: string;
|
|
150
|
+
env: NodeJS.ProcessEnv;
|
|
151
|
+
keepStdout: boolean;
|
|
152
|
+
timeout?: number;
|
|
153
|
+
}, onChunk: (text: string, stream: 'stderr' | 'stdout') => void): Promise<{
|
|
154
|
+
stderr: string;
|
|
155
|
+
stdout: string;
|
|
156
|
+
}>;
|
|
157
|
+
/**
|
|
158
|
+
* The environment a terragrunt command runs with, carrying the terraform binary override.
|
|
159
|
+
*/
|
|
160
|
+
private buildEnv;
|
|
161
|
+
/**
|
|
162
|
+
* Takes the arguments set by {@link TerraformUtility.setArgsOnce}, clearing them.
|
|
163
|
+
*/
|
|
164
|
+
private consumeArgs;
|
|
165
|
+
/**
|
|
166
|
+
* Renders why one folder could not be planned.
|
|
167
|
+
*
|
|
168
|
+
* Terragrunt writes its diagnostics to stderr, which carries the `Error:` block, so that comes
|
|
169
|
+
* first. The wrapped {@link TerraformCommandError} message is the fallback for failures that
|
|
170
|
+
* produce no stderr, such as a malformed `show -json` payload failing at `JSON.parse`.
|
|
171
|
+
*/
|
|
172
|
+
private describePlanFailure;
|
|
173
|
+
/**
|
|
174
|
+
* Publishes the same started/finished pair {@link runAll} does, around a body that drives
|
|
175
|
+
* terragrunt folder by folder instead.
|
|
176
|
+
*
|
|
177
|
+
* The JSON-mode `plan` and `output` take that per-folder path, and it is the slowest step of a
|
|
178
|
+
* `validate` - a full plan runs for tens of seconds - so the log must not fall silent through it.
|
|
179
|
+
*/
|
|
180
|
+
private emitAround;
|
|
181
|
+
/**
|
|
182
|
+
* The `terragrunt run --all` invocation itself, wrapped in its started/finished pair.
|
|
183
|
+
*/
|
|
184
|
+
private invokeRunAll;
|
|
185
|
+
/**
|
|
186
|
+
* Moves the terraform state of every move the last generate recorded out of its old module folder
|
|
187
|
+
* into its new one, with `terraform state mv`, and copies the moved resources' outputs along, since
|
|
188
|
+
* folders depending on the new one read them there. An address the old folder's state does not hold,
|
|
189
|
+
* or the new one's already holds, is skipped, which is what a move already made leaves behind.
|
|
190
|
+
* Records in `originalStates` what each state file held before its first move, `undefined` where none
|
|
191
|
+
* existed.
|
|
192
|
+
*/
|
|
193
|
+
private moveStates;
|
|
194
|
+
/**
|
|
195
|
+
* Runs `terragrunt output -json` in one module folder.
|
|
196
|
+
*
|
|
197
|
+
* A folder whose output fails is reported as `undefined`, not thrown — one bad module folder must not
|
|
198
|
+
* abort every other folder's result.
|
|
199
|
+
*/
|
|
200
|
+
private readOutputs;
|
|
201
|
+
/**
|
|
202
|
+
* Runs `terragrunt plan -out=<planFile>` followed by `terragrunt show -json <planFile>` in one module folder.
|
|
203
|
+
*
|
|
204
|
+
* The plan file is written to an absolute temp path, never inside a terragrunt
|
|
205
|
+
* cache — terragrunt picks a different cache sub-directory per invocation, so a relative plan file
|
|
206
|
+
* written by one command cannot be found by the next.
|
|
207
|
+
*
|
|
208
|
+
* A folder whose plan/show/parse fails is reported as an `error`, not thrown — one bad module folder must not
|
|
209
|
+
* abort every other folder's result. The failure is carried so `validate` can report it verbatim.
|
|
210
|
+
*/
|
|
211
|
+
private readPlan;
|
|
212
|
+
/**
|
|
213
|
+
* The directory with every symbolic link on its path resolved, or the directory as given when it does
|
|
214
|
+
* not exist. Terragrunt drops `dependency` blocks when its working directory is reached through a
|
|
215
|
+
* symbolic link, as macOS's temporary directory is.
|
|
216
|
+
*/
|
|
217
|
+
private resolveRealPath;
|
|
218
|
+
/**
|
|
219
|
+
* Writes back what each state file held before {@link TerraformUtility.moveStates}, deleting one that
|
|
220
|
+
* did not exist.
|
|
221
|
+
*/
|
|
222
|
+
private restoreStates;
|
|
223
|
+
/**
|
|
224
|
+
* Runs one terragrunt command in a single module folder (`cwd` = that folder).
|
|
225
|
+
*/
|
|
226
|
+
private run;
|
|
227
|
+
/**
|
|
228
|
+
* Runs `terragrunt run --all -- <command>` across every module folder under `terragruntDir`, with
|
|
229
|
+
* the terraform state of every folder checked out around it.
|
|
230
|
+
*/
|
|
231
|
+
private runAll;
|
|
232
|
+
/**
|
|
233
|
+
* Runs `binary` with `args` in `dir`. Its stdout is returned only when it is asked for JSON, which is
|
|
234
|
+
* the output octo reads; every other process's output goes out only as events.
|
|
235
|
+
*/
|
|
236
|
+
private runIn;
|
|
237
|
+
/**
|
|
238
|
+
* Runs one process. Every terraform and terragrunt process octo starts goes through here, and goes out
|
|
239
|
+
* as events: a {@link TerraformProcessStartedEvent}, a {@link TerraformProcessOutputEvent} for each
|
|
240
|
+
* chunk it writes, and a {@link TerraformProcessExitedEvent}, all named after `command`.
|
|
241
|
+
*
|
|
242
|
+
* @throws {@link TerraformCommandError} When the process cannot start or exits non-zero.
|
|
243
|
+
*/
|
|
244
|
+
private runProcess;
|
|
245
|
+
/**
|
|
246
|
+
* Wraps whatever a failed spawn threw into a {@link TerraformCommandError}.
|
|
247
|
+
*/
|
|
248
|
+
private toTerraformCommandError;
|
|
249
|
+
/**
|
|
250
|
+
* Checks every module folder's terraform state out of Octo's state provider, moves the state of every
|
|
251
|
+
* resource generate moved between folders, runs `body`, and checks the state back in.
|
|
252
|
+
*
|
|
253
|
+
* Only a command that changes infrastructure (`keepMoves`) checks the moves in. Any other runs on them
|
|
254
|
+
* and puts back what the state files held before, so a move nobody applied never reaches the provider.
|
|
255
|
+
*
|
|
256
|
+
* The check-in runs on the way out of a failure as much as a success, because what terraform has
|
|
257
|
+
* already built is real whether or not the command that built it returned cleanly. A timer checks
|
|
258
|
+
* in through the command as well, bounding what a killed runner loses.
|
|
259
|
+
*
|
|
260
|
+
* A failed command keeps its own error when the check-in after it fails too; the check-in's error
|
|
261
|
+
* is printed on stderr. The folder's state is ahead of the provider's then, and the next run keeps
|
|
262
|
+
* it and checks it in.
|
|
263
|
+
*/
|
|
264
|
+
private withTerraformState;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
export declare class TerraformUtilityFactory {
|
|
270
|
+
private static instance;
|
|
271
|
+
/**
|
|
272
|
+
* @internal
|
|
273
|
+
*/
|
|
274
|
+
static create(options?: ConstructorParameters<typeof TerraformUtility>[0], forceNew?: boolean): Promise<TerraformUtility>;
|
|
275
|
+
}
|
|
276
|
+
export {};
|