@stackonward/cli 0.0.1 → 1.0.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/dist/index.js +4588 -205
- package/dist/index.js.map +1 -1
- package/dist/resources/apple/.claude/docs/architecture-template.md +54 -0
- package/dist/resources/apple/.claude/docs/architecture.md +52 -0
- package/dist/resources/apple/.claude/docs/index.md +13 -0
- package/dist/resources/apple/.claude/docs/security-lifecycle.md +57 -0
- package/dist/resources/apple/.claude/docs/stack.md +93 -0
- package/dist/resources/apple/.claude/docs/verification.md +63 -0
- package/dist/resources/apple/AGENTS.md +397 -0
- package/dist/resources/apple/CLAUDE.md +397 -0
- package/dist/resources/apple/Gemfile +2 -0
- package/dist/resources/apple/Gemfile.lock +365 -0
- package/dist/resources/apple/_gitignore +14 -0
- package/dist/resources/apple/fastlane/Fastfile +123 -0
- package/dist/resources/components/nuxt/site-source/app/app.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/assets/css/site-shell.css +1035 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/brand/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/assets/icons/common/.gitkeep +0 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationHeader.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationShell.vue +56 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ApplicationSidebar.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/BackToTop.vue +42 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentArticlePage.vue +40 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ContentListPage.vue +30 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/CookieConsent.vue +18 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingFooter.vue +52 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingHeader.vue +106 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/MarketingShell.vue +35 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/SiteBrand.vue +10 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/StaticPage.vue +21 -0
- package/dist/resources/components/nuxt/site-source/app/components/site/ToastViewport.vue +25 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseButton.vue +86 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseGradientBorder.vue +59 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseModal.vue +131 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BasePopover.vue +150 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/BaseText.vue +138 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutStatus.vue +112 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/CheckoutSummary.vue +172 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/GoogleSignInButton.vue +113 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/InfiniteScroll.vue +123 -0
- package/dist/resources/components/nuxt/site-source/app/components/ui/YoutubeEmbed.vue +126 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useAnalytics.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useCheckout.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useConsent.ts +31 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useGoogleIdentity.ts +163 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useNavigation.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSeo.ts +33 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useSiteShell.ts +58 -0
- package/dist/resources/components/nuxt/site-source/app/composables/useToasts.ts +48 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/app.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/layouts/default.vue +5 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/analytics.client.ts +121 -0
- package/dist/resources/components/nuxt/site-source/app/plugins/google-identity.client.ts +24 -0
- package/dist/resources/components/nuxt/site-source/app/theme/accordion.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/breadcrumb.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/button.ts +92 -0
- package/dist/resources/components/nuxt/site-source/app/theme/carousel.ts +11 -0
- package/dist/resources/components/nuxt/site-source/app/theme/checkbox.ts +12 -0
- package/dist/resources/components/nuxt/site-source/app/theme/index.ts +30 -0
- package/dist/resources/components/nuxt/site-source/app/theme/input.ts +47 -0
- package/dist/resources/components/nuxt/site-source/app/theme/modal.ts +9 -0
- package/dist/resources/components/nuxt/site-source/app/theme/pagination.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/theme/select.ts +23 -0
- package/dist/resources/components/nuxt/site-source/app/theme/stepper.ts +10 -0
- package/dist/resources/components/nuxt/site-source/app/theme/toast.ts +8 -0
- package/dist/resources/components/nuxt/site-source/app/theme/tooltip.ts +6 -0
- package/dist/resources/components/nuxt/site-source/app/types/site-shell.ts +85 -0
- package/dist/resources/components/react/ui/Button.tsx +73 -0
- package/dist/resources/components/react/ui/Input.tsx +44 -0
- package/dist/resources/components/registry.json +355 -0
- package/dist/resources/components/vue/feedback/Toast.vue +120 -0
- package/dist/resources/components/vue/feedback/useToast.ts +70 -0
- package/dist/resources/components/vue/media/FileUpload.vue +229 -0
- package/dist/resources/components/vue/media/VideoPlayer.vue +157 -0
- package/dist/resources/components/vue/ui/AppImage.vue +147 -0
- package/dist/resources/components/vue/ui/BottomSheet.vue +217 -0
- package/dist/resources/components/vue/ui/Button.vue +154 -0
- package/dist/resources/components/vue/ui/Card.vue +111 -0
- package/dist/resources/components/vue/ui/Input.vue +113 -0
- package/dist/resources/components/vue/ui/Modal.vue +193 -0
- package/dist/resources/components/vue/ui/ScrollArea.vue +163 -0
- package/dist/resources/components/vue/ui/Tooltip.vue +115 -0
- package/dist/resources/registry.json +158 -0
- package/dist/resources/snippets/node/cache.ts +116 -0
- package/dist/resources/snippets/node/date.ts +126 -0
- package/dist/resources/snippets/node/logger.ts +104 -0
- package/dist/resources/snippets/node/validation.ts +132 -0
- package/dist/resources/snippets/react/useDebounce.ts +90 -0
- package/dist/resources/snippets/registry.json +65 -0
- package/dist/resources/snippets/vue/useAsync.ts +96 -0
- package/dist/resources/snippets/vue/usePagination.ts +102 -0
- package/dist/resources/templates/base/.claude/docs/architecture-template.md +459 -0
- package/dist/resources/templates/base/.claude/docs/architecture.md +137 -0
- package/dist/resources/templates/base/.claude/docs/index.md +42 -0
- package/dist/resources/templates/base/.claude/docs/security-lifecycle.md +129 -0
- package/dist/resources/templates/base/.claude/docs/verification.md +121 -0
- package/dist/resources/templates/base/AGENTS.md +415 -0
- package/dist/resources/templates/base/CLAUDE.md +415 -0
- package/dist/resources/templates/go-backend/.claude/docs/api-design.md +486 -0
- package/dist/resources/templates/go-backend/.claude/docs/architecture-template.md +449 -0
- package/dist/resources/templates/go-backend/.claude/docs/check-list.md +155 -0
- package/dist/resources/templates/go-backend/.claude/docs/database.md +369 -0
- package/dist/resources/templates/go-backend/.claude/docs/e2e-standards.md +161 -0
- package/dist/resources/templates/go-backend/.claude/docs/error-handling.md +558 -0
- package/dist/resources/templates/go-backend/.claude/docs/event-runtime-boundary.md +124 -0
- package/dist/resources/templates/go-backend/.claude/docs/identifier-contract.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/index.md +22 -0
- package/dist/resources/templates/go-backend/.claude/docs/logging.md +314 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-onboarding-sop.md +917 -0
- package/dist/resources/templates/go-backend/.claude/docs/mediagen-provider-quick-reference.md +195 -0
- package/dist/resources/templates/go-backend/.claude/docs/module-standards.md +309 -0
- package/dist/resources/templates/go-backend/.claude/docs/openapi-contract.md +141 -0
- package/dist/resources/templates/go-backend/.claude/docs/payment-gateway-onboarding.md +283 -0
- package/dist/resources/templates/go-backend/.claude/docs/platform-boundary.md +191 -0
- package/dist/resources/templates/go-backend/.claude/docs/quality-gates.md +112 -0
- package/dist/resources/templates/go-backend/.dockerignore +6 -0
- package/dist/resources/templates/go-backend/.env.example +13 -0
- package/dist/resources/templates/go-backend/.gitattributes +2 -0
- package/dist/resources/templates/go-backend/AGENTS.md +1139 -0
- package/dist/resources/templates/go-backend/CLAUDE.md +1139 -0
- package/dist/resources/templates/go-backend/Dockerfile +14 -0
- package/dist/resources/templates/go-backend/Makefile +71 -0
- package/dist/resources/templates/go-backend/README.md +66 -0
- package/dist/resources/templates/go-backend/_gitignore +10 -0
- package/dist/resources/templates/go-backend/api/openapi/README.md +29 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/artifact-manifest.json +19 -0
- package/dist/resources/templates/go-backend/api/openapi/dist/conformance-matrix.json +276 -0
- package/dist/resources/templates/go-backend/api/openapi/document.go +30 -0
- package/dist/resources/templates/go-backend/api/openapi/package.json +28 -0
- package/dist/resources/templates/go-backend/api/openapi/pnpm-lock.yaml +3052 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly-source.yaml +18 -0
- package/dist/resources/templates/go-backend/api/openapi/redocly.yaml +8 -0
- package/dist/resources/templates/go-backend/api/openapi/sdk-generators.json +16 -0
- package/dist/resources/templates/go-backend/api/openapi/service-registry.json +39 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/product-api/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/conformance/runtime.arazzo.yaml +65 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/internal.openapi.json +327 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/dist/runtime-contract.json +56 -0
- package/dist/resources/templates/go-backend/api/openapi/services/worker/openapi.yaml +222 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/breaking.mjs +416 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/build.mjs +103 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/conformance_coverage.mjs +111 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_compiler.mjs +62 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/contract_policy.mjs +208 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/delegated_contract.mjs +302 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/deterministic_archive.mjs +69 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_example_privacy.mjs +93 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_projection.mjs +498 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/documentation_quality.mjs +346 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/git_artifact_history.mjs +188 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/manifest.mjs +170 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/overlay.mjs +98 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/project.mjs +549 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/route_contract.mjs +156 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/runtime_conformance.mjs +193 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/scalar_asset_localization.mjs +164 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/sdk_generator.mjs +229 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/semantic_version.mjs +64 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/service_contract_inputs.mjs +16 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/breaking.test.mjs +365 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/build.test.mjs +42 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/conformance_coverage.test.mjs +88 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/contract_policy.test.mjs +257 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/delegated_contract.test.mjs +205 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_example_privacy.test.mjs +51 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_projection.test.mjs +368 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/documentation_quality.test.mjs +151 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/git_artifact_history.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/head_policy.test.mjs +8 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/overlay.test.mjs +44 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/projection.test.mjs +270 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/redocly_documentation_rules.test.mjs +146 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/release_manifest.test.mjs +76 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/route_contract.test.mjs +119 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/runtime_conformance.test.mjs +75 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/scalar_asset_localization.test.mjs +50 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/sdk_generator.test.mjs +31 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/semantic_version.test.mjs +60 -0
- package/dist/resources/templates/go-backend/api/openapi/tooling/test/service_contract_inputs.test.mjs +27 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/resources.go +125 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime.go +102 -0
- package/dist/resources/templates/go-backend/cmd/internal/runtime/runtime_test.go +70 -0
- package/dist/resources/templates/go-backend/cmd/product-api/lifecycle_test.go +58 -0
- package/dist/resources/templates/go-backend/cmd/product-api/main.go +32 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire.go +13 -0
- package/dist/resources/templates/go-backend/cmd/product-api/wire_gen.go +94 -0
- package/dist/resources/templates/go-backend/cmd/worker/main.go +47 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire.go +14 -0
- package/dist/resources/templates/go-backend/cmd/worker/wire_gen.go +111 -0
- package/dist/resources/templates/go-backend/configs/config.yaml +37 -0
- package/dist/resources/templates/go-backend/deployments/compose.yaml +71 -0
- package/dist/resources/templates/go-backend/docs/openapi-provenance.json +489 -0
- package/dist/resources/templates/go-backend/docs/runtime-provenance.json +175 -0
- package/dist/resources/templates/go-backend/docs/source-provenance.json +3568 -0
- package/dist/resources/templates/go-backend/docs/standards-provenance.json +1624 -0
- package/dist/resources/templates/go-backend/go.mod +256 -0
- package/dist/resources/templates/go-backend/go.sum +805 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical.go +370 -0
- package/dist/resources/templates/go-backend/internal/common/canonicaljson/canonical_test.go +223 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/contracts.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/checkoutbff/platform_client_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/contentaccess/contentaccess.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/contracts/contact.go +85 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/identity.go +20 -0
- package/dist/resources/templates/go-backend/internal/common/ctxutil/product.go +53 -0
- package/dist/resources/templates/go-backend/internal/common/enumdomain/payment.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/dto_admin.go +9 -0
- package/dist/resources/templates/go-backend/internal/common/enums/enum.go +1247 -0
- package/dist/resources/templates/go-backend/internal/common/enums/handler_admin.go +66 -0
- package/dist/resources/templates/go-backend/internal/common/enums/module.go +46 -0
- package/dist/resources/templates/go-backend/internal/common/enums/provider.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_audit.go +274 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_command_replay.go +12 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_config.go +27 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_locale.go +37 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_ops.go +14 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_outbox.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/enums/register_rule_expression.go +63 -0
- package/dist/resources/templates/go-backend/internal/common/enums/registry.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/httporigin/origin_test.go +38 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/iamcredential/plaintext_test.go +29 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope.go +212 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_binding.go +26 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter.go +173 -0
- package/dist/resources/templates/go-backend/internal/common/iamscope/scope_filter_test.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/authorization_details.go +10 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies.go +660 -0
- package/dist/resources/templates/go-backend/internal/common/internalapi/route_permission_policies_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/audience_token_source.go +166 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bootstrap_token_exchanger.go +183 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/bound_service_token_signer.go +52 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger.go +189 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/delegated_access_token_exchanger_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/product_scoped_service_token_signer.go +92 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/provider.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/request_signer.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver.go +69 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/resolver_test.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope.go +95 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/route_scope_test.go +78 -0
- package/dist/resources/templates/go-backend/internal/common/internalservice/service_identity_test.go +387 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/jsonschema/compiler_test.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/jwksapi/handler_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale.go +145 -0
- package/dist/resources/templates/go-backend/internal/common/locale/locale_test.go +75 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref.go +54 -0
- package/dist/resources/templates/go-backend/internal/common/mediaref/mediaref_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_auth.go +320 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/apikey_throttle.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/auth_test.go +50 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/client_context.go +86 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/cors.go +68 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/event_context.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/gateway_identity.go +279 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/helpers.go +159 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_route_permission.go +171 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth.go +151 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_delegated_token_auth_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_identity.go +138 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/iam_service_token_auth.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent.go +273 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/idempotent_test.go +83 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/internal_route_permission_test.go +186 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/logging.go +191 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/metrics.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/middleware_test.go +1516 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context.go +160 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/principal_context_test.go +355 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/product_context.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/recovery.go +40 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/referral_attribution.go +178 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/requestid.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission.go +790 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/resource_permission_test.go +440 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/service_credential_auth.go +67 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/tenant.go +148 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/throttle.go +310 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/middleware/trusted_client_ip_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/money/currency.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/money/errors.go +23 -0
- package/dist/resources/templates/go-backend/internal/common/money/format.go +123 -0
- package/dist/resources/templates/go-backend/internal/common/money/format_test.go +204 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway.go +144 -0
- package/dist/resources/templates/go-backend/internal/common/money/gateway_test.go +165 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/money/rounding_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/principal/context.go +56 -0
- package/dist/resources/templates/go-backend/internal/common/principal/principal.go +49 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/productcode/code_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema.go +577 -0
- package/dist/resources/templates/go-backend/internal/common/providerconfig/schema_test.go +47 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request.go +246 -0
- package/dist/resources/templates/go-backend/internal/common/requestprivacy/request_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/common/response/pagination.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/response/response.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/response/response_test.go +463 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast.go +141 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/ast_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical.go +184 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/canonical_test.go +319 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder.go +555 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/decoder_test.go +260 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/errors.go +55 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator.go +96 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/evaluator_test.go +220 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/fuzz_test.go +116 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/limits.go +331 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema.go +412 -0
- package/dist/resources/templates/go-backend/internal/common/ruleexpression/schema_test.go +164 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input.go +627 -0
- package/dist/resources/templates/go-backend/internal/common/runtimeinput/runtime_input_test.go +245 -0
- package/dist/resources/templates/go-backend/internal/common/semver/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver.go +125 -0
- package/dist/resources/templates/go-backend/internal/common/semver/semver_test.go +205 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience.go +48 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/audience_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier.go +33 -0
- package/dist/resources/templates/go-backend/internal/common/serviceidentity/resource_identifier_test.go +32 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator.go +99 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/generator_test.go +396 -0
- package/dist/resources/templates/go-backend/internal/common/tradeno/prefix.go +247 -0
- package/dist/resources/templates/go-backend/internal/common/types/asset_url.go +11 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing.go +89 -0
- package/dist/resources/templates/go-backend/internal/common/types/billing_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/common/types/country.go +74 -0
- package/dist/resources/templates/go-backend/internal/common/types/country_test.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/currency.go +60 -0
- package/dist/resources/templates/go-backend/internal/common/types/identifiers.go +41 -0
- package/dist/resources/templates/go-backend/internal/common/types/operator.go +28 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/types/subscription_entitlement_test.go +35 -0
- package/dist/resources/templates/go-backend/internal/common/types/tier.go +72 -0
- package/dist/resources/templates/go-backend/internal/common/types/types.go +411 -0
- package/dist/resources/templates/go-backend/internal/common/types/types_test.go +295 -0
- package/dist/resources/templates/go-backend/internal/common/utils/constants.go +100 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto.go +158 -0
- package/dist/resources/templates/go-backend/internal/common/utils/crypto_test.go +345 -0
- package/dist/resources/templates/go-backend/internal/common/utils/duration.go +25 -0
- package/dist/resources/templates/go-backend/internal/common/utils/helpers.go +18 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json.go +62 -0
- package/dist/resources/templates/go-backend/internal/common/utils/json_test.go +76 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination.go +51 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pagination_test.go +45 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer.go +107 -0
- package/dist/resources/templates/go-backend/internal/common/utils/pointer_test.go +15 -0
- package/dist/resources/templates/go-backend/internal/common/utils/slice.go +24 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake.go +110 -0
- package/dist/resources/templates/go-backend/internal/common/utils/snowflake_test.go +316 -0
- package/dist/resources/templates/go-backend/internal/common/utils/string.go +16 -0
- package/dist/resources/templates/go-backend/internal/common/utils/timefmt.go +42 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator.go +136 -0
- package/dist/resources/templates/go-backend/internal/common/validator/validator_test.go +240 -0
- package/dist/resources/templates/go-backend/internal/common/youtubeapi/client.go +224 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/document_test.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator.go +78 -0
- package/dist/resources/templates/go-backend/internal/core/apicontract/route_validator_test.go +108 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.js +2385 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/assets/scalar-api-reference.metadata.json +10 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route.go +107 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/route_test.go +200 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar.go +117 -0
- package/dist/resources/templates/go-backend/internal/core/apidocs/scalar_test.go +99 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy.go +91 -0
- package/dist/resources/templates/go-backend/internal/core/audit/access_log_policy_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/audit/actor_resolver.go +36 -0
- package/dist/resources/templates/go-backend/internal/core/audit/constants.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context.go +119 -0
- package/dist/resources/templates/go-backend/internal/core/audit/context_test.go +310 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto.go +468 -0
- package/dist/resources/templates/go-backend/internal/core/audit/dto_admin.go +172 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum.go +460 -0
- package/dist/resources/templates/go-backend/internal/core/audit/enum_test.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/audit/errors.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/handler.go +568 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener.go +319 -0
- package/dist/resources/templates/go-backend/internal/core/audit/listener_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware.go +669 -0
- package/dist/resources/templates/go-backend/internal/core/audit/middleware_test.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/audit/model.go +306 -0
- package/dist/resources/templates/go-backend/internal/core/audit/partition_job.go +316 -0
- package/dist/resources/templates/go-backend/internal/core/audit/ports.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/audit/provider.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository.go +1007 -0
- package/dist/resources/templates/go-backend/internal/core/audit/repository_test.go +934 -0
- package/dist/resources/templates/go-backend/internal/core/audit/router.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service.go +770 -0
- package/dist/resources/templates/go-backend/internal/core/audit/service_test.go +331 -0
- package/dist/resources/templates/go-backend/internal/core/audit/vo_admin.go +475 -0
- package/dist/resources/templates/go-backend/internal/core/cache/config.go +30 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key.go +41 -0
- package/dist/resources/templates/go-backend/internal/core/cache/key_test.go +62 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1.go +153 -0
- package/dist/resources/templates/go-backend/internal/core/cache/l1_test.go +212 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager.go +278 -0
- package/dist/resources/templates/go-backend/internal/core/cache/manager_provider.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/cache/metrics.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/cache/namespace_test.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options.go +39 -0
- package/dist/resources/templates/go-backend/internal/core/cache/options_test.go +96 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis.go +311 -0
- package/dist/resources/templates/go-backend/internal/core/cache/redis_test.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer.go +31 -0
- package/dist/resources/templates/go-backend/internal/core/cache/serializer_test.go +139 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/cache/singleflight_test.go +211 -0
- package/dist/resources/templates/go-backend/internal/core/cache/warming.go +86 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock.go +66 -0
- package/dist/resources/templates/go-backend/internal/core/clock/clock_test.go +26 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock.go +283 -0
- package/dist/resources/templates/go-backend/internal/core/clock/runtime_clock_test.go +98 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/errors.go +6 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model.go +90 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/model_test.go +79 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/namespace.go +7 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/persistence_test.go +185 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/provider.go +9 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/repository.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service.go +853 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_persistence_test.go +432 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/service_test.go +891 -0
- package/dist/resources/templates/go-backend/internal/core/commandreplay/types.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/config/config.go +2069 -0
- package/dist/resources/templates/go-backend/internal/core/config/config_test.go +1122 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/contract_test.go +388 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/docs.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/config/contract/verify.go +424 -0
- package/dist/resources/templates/go-backend/internal/core/config/enum.go +46 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata.go +717 -0
- package/dist/resources/templates/go-backend/internal/core/config/metadata_test.go +228 -0
- package/dist/resources/templates/go-backend/internal/core/config/product_admin_config_test.go +210 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm.go +111 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/aes_gcm_test.go +364 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/encryptor.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor.go +134 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/envelope_encryptor_test.go +118 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/pem_test.go +44 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider.go +130 -0
- package/dist/resources/templates/go-backend/internal/core/crypto/provider_test.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/database/base_model.go +24 -0
- package/dist/resources/templates/go-backend/internal/core/database/clickhouse.go +121 -0
- package/dist/resources/templates/go-backend/internal/core/database/database.go +112 -0
- package/dist/resources/templates/go-backend/internal/core/database/database_logger_test.go +95 -0
- package/dist/resources/templates/go-backend/internal/core/database/errors.go +25 -0
- package/dist/resources/templates/go-backend/internal/core/database/metrics_plugin.go +105 -0
- package/dist/resources/templates/go-backend/internal/core/database/pool_collector.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/database/read_replica.go +520 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/database/transaction_test.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock.go +353 -0
- package/dist/resources/templates/go-backend/internal/core/distlock/lock_test.go +106 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler.go +189 -0
- package/dist/resources/templates/go-backend/internal/core/errors/handler_test.go +515 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus.go +667 -0
- package/dist/resources/templates/go-backend/internal/core/eventbus/eventbus_test.go +792 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/noop.go +22 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/provider.go +20 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/publisher.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/redis.go +109 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing.go +104 -0
- package/dist/resources/templates/go-backend/internal/core/eventstream/routing_test.go +71 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/model.go +19 -0
- package/dist/resources/templates/go-backend/internal/core/geoip/service.go +88 -0
- package/dist/resources/templates/go-backend/internal/core/health/health.go +333 -0
- package/dist/resources/templates/go-backend/internal/core/health/health_test.go +27 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client.go +772 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/client_test.go +287 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download.go +578 -0
- package/dist/resources/templates/go-backend/internal/core/httpclient/download_test.go +374 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/jwk.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring.go +144 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/keyring_test.go +128 -0
- package/dist/resources/templates/go-backend/internal/core/jwtkeyring/registry.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/logger/logger_test.go +194 -0
- package/dist/resources/templates/go-backend/internal/core/observability/metrics.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry.go +445 -0
- package/dist/resources/templates/go-backend/internal/core/observability/sentry_privacy_test.go +175 -0
- package/dist/resources/templates/go-backend/internal/core/observability/tracing.go +187 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model.go +314 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/model_test.go +77 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/persistence.go +51 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/provider.go +23 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay.go +1138 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_postgres_test.go +257 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/relay_test.go +690 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler.go +164 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/rescheduler_test.go +209 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer.go +249 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_postgres_test.go +170 -0
- package/dist/resources/templates/go-backend/internal/core/outbox/writer_test.go +123 -0
- package/dist/resources/templates/go-backend/internal/core/provider.go +198 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/queue/metrics_middleware_test.go +12 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue.go +288 -0
- package/dist/resources/templates/go-backend/internal/core/queue/queue_test.go +159 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead.go +514 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/bulkhead_test.go +984 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker.go +358 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/circuitbreaker_test.go +788 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry.go +318 -0
- package/dist/resources/templates/go-backend/internal/core/resilience/retry_test.go +735 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/recorder.go +305 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context.go +124 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/run_context_test.go +85 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler.go +1589 -0
- package/dist/resources/templates/go-backend/internal/core/schedule/scheduler_control_test.go +808 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider.go +398 -0
- package/dist/resources/templates/go-backend/internal/core/storage/oss_provider_test.go +89 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path.go +110 -0
- package/dist/resources/templates/go-backend/internal/core/storage/path_test.go +301 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider.go +489 -0
- package/dist/resources/templates/go-backend/internal/core/storage/s3_provider_test.go +60 -0
- package/dist/resources/templates/go-backend/internal/core/storage/storage.go +268 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation.go +225 -0
- package/dist/resources/templates/go-backend/internal/core/storage/validation_test.go +495 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/logger.go +38 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider.go +126 -0
- package/dist/resources/templates/go-backend/internal/core/temporal/provider_test.go +67 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client.go +282 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/client_test.go +81 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/config.go +58 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/handler.go +53 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/hub.go +269 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/message.go +273 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/notifier.go +92 -0
- package/dist/resources/templates/go-backend/internal/core/websocket/provider.go +33 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action.go +77 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/action_test.go +238 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/condition.go +107 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/decision.go +256 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/enum.go +643 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/errors.go +102 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/principal_record.go +21 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/product_context.go +486 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource.go +215 -0
- package/dist/resources/templates/go-backend/internal/integrations/onex/iam/resource_test.go +242 -0
- package/dist/resources/templates/go-backend/internal/products/README.md +5 -0
- package/dist/resources/templates/go-backend/internal/sharedevents/README.md +5 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.down.sql +13 -0
- package/dist/resources/templates/go-backend/migrations/000001_infrastructure.up.sql +886 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error.go +327 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_code.go +65 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_test.go +41 -0
- package/dist/resources/templates/go-backend/pkg/apierror/error_type.go +14 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response.go +216 -0
- package/dist/resources/templates/go-backend/pkg/apierror/http_response_test.go +216 -0
- package/dist/resources/templates/go-backend/scripts/check-openapi-clean-deletion.sh +54 -0
- package/dist/resources/templates/go-backend/scripts/test-migrations.sh +32 -0
- package/dist/resources/templates/go-backend/tests/infrastructure.sql +69 -0
- package/dist/resources/templates/mcp-server/.claude/docs/stack.md +338 -0
- package/dist/resources/templates/mcp-server/.editorconfig +13 -0
- package/dist/resources/templates/mcp-server/.env.example +8 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/bug_report.yml +104 -0
- package/dist/resources/templates/mcp-server/.github/ISSUE_TEMPLATE/feature_request.yml +54 -0
- package/dist/resources/templates/mcp-server/.github/PULL_REQUEST_TEMPLATE.md +36 -0
- package/dist/resources/templates/mcp-server/.github/workflows/ci.yml +78 -0
- package/dist/resources/templates/mcp-server/.husky/commit-msg +1 -0
- package/dist/resources/templates/mcp-server/.husky/pre-commit +1 -0
- package/dist/resources/templates/mcp-server/.lintstagedrc.json +4 -0
- package/dist/resources/templates/mcp-server/.nvmrc +1 -0
- package/dist/resources/templates/mcp-server/.prettierrc +8 -0
- package/dist/resources/templates/mcp-server/CONTRIBUTING.md +184 -0
- package/dist/resources/templates/mcp-server/Dockerfile +23 -0
- package/dist/resources/templates/mcp-server/LICENSE +21 -0
- package/dist/resources/templates/mcp-server/README.md +123 -0
- package/dist/resources/templates/mcp-server/_gitignore +26 -0
- package/dist/resources/templates/mcp-server/commitlint.config.js +24 -0
- package/dist/resources/templates/mcp-server/eslint.config.js +30 -0
- package/dist/resources/templates/mcp-server/package.json +72 -0
- package/dist/resources/templates/mcp-server/src/index.ts +27 -0
- package/dist/resources/templates/mcp-server/src/resources.ts +33 -0
- package/dist/resources/templates/mcp-server/src/services/.gitkeep +0 -0
- package/dist/resources/templates/mcp-server/src/tools.ts +43 -0
- package/dist/resources/templates/mcp-server/src/types/index.ts +19 -0
- package/dist/resources/templates/mcp-server/src/utils/index.ts +31 -0
- package/dist/resources/templates/mcp-server/tsconfig.json +22 -0
- package/dist/resources/templates/mcp-server/tsup.config.ts +14 -0
- package/dist/resources/templates/mcp-server/vitest.config.ts +15 -0
- package/dist/resources/templates/nuxt/.claude/docs/stack.md +666 -0
- package/dist/resources/templates/nuxt/.editorconfig +15 -0
- package/dist/resources/templates/nuxt/.env.example +22 -0
- package/dist/resources/templates/nuxt/.github/workflows/ci.yml +34 -0
- package/dist/resources/templates/nuxt/.husky/commit-msg +1 -0
- package/dist/resources/templates/nuxt/.husky/pre-commit +1 -0
- package/dist/resources/templates/nuxt/.nvmrc +1 -0
- package/dist/resources/templates/nuxt/.prettierignore +9 -0
- package/dist/resources/templates/nuxt/.prettierrc +1 -0
- package/dist/resources/templates/nuxt/README.md +23 -0
- package/dist/resources/templates/nuxt/_gitignore +7 -0
- package/dist/resources/templates/nuxt/app/app.config.ts +105 -0
- package/dist/resources/templates/nuxt/app/i18n/locales/en.json +5 -0
- package/dist/resources/templates/nuxt/app/pages/app/index.vue +224 -0
- package/dist/resources/templates/nuxt/app/pages/authors/[slug].vue +37 -0
- package/dist/resources/templates/nuxt/app/pages/blog/[slug].vue +55 -0
- package/dist/resources/templates/nuxt/app/pages/blog/category/[category].vue +38 -0
- package/dist/resources/templates/nuxt/app/pages/blog/index.vue +46 -0
- package/dist/resources/templates/nuxt/app/pages/index.vue +626 -0
- package/dist/resources/templates/nuxt/app/pages/legal/privacy.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/legal/terms.vue +21 -0
- package/dist/resources/templates/nuxt/app/pages/ui/index.vue +397 -0
- package/dist/resources/templates/nuxt/commitlint.config.mjs +1 -0
- package/dist/resources/templates/nuxt/eslint.config.mjs +4 -0
- package/dist/resources/templates/nuxt/lint-staged.config.mjs +8 -0
- package/dist/resources/templates/nuxt/nuxt.config.ts +71 -0
- package/dist/resources/templates/nuxt/package.json +67 -0
- package/dist/resources/templates/nuxt/public/apple-touch-icon.png +0 -0
- package/dist/resources/templates/nuxt/public/favicon.ico +0 -0
- package/dist/resources/templates/nuxt/public/favicon.svg +5 -0
- package/dist/resources/templates/nuxt/public/icon-16x16.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-192x192.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-32x32.png +0 -0
- package/dist/resources/templates/nuxt/public/icon-512x512.png +0 -0
- package/dist/resources/templates/nuxt/public/logo.svg +6 -0
- package/dist/resources/templates/nuxt/public/media/hero-product-gallery.png +0 -0
- package/dist/resources/templates/nuxt/server/api/content/sitemap-urls.get.ts +12 -0
- package/dist/resources/templates/nuxt/server/api/preview.get.ts +9 -0
- package/dist/resources/templates/nuxt/stylelint.config.mjs +3 -0
- package/dist/resources/templates/nuxt/test/e2e/rendering.test.ts +13 -0
- package/dist/resources/templates/nuxt/tsconfig.json +3 -0
- package/dist/resources/templates/nuxt/vitest.config.ts +8 -0
- package/package.json +8 -5
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
package crypto
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
"github.com/stretchr/testify/assert"
|
|
8
|
+
"github.com/stretchr/testify/require"
|
|
9
|
+
"go.uber.org/zap"
|
|
10
|
+
|
|
11
|
+
"{{module}}/internal/core/config"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// validKey 是合法的 64 字符 hex 字符串(32 字节 AES-256 密钥)
|
|
15
|
+
const validKey = "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
|
|
16
|
+
|
|
17
|
+
// --------------------------------------------------------
|
|
18
|
+
// NewAesGcmEncryptor
|
|
19
|
+
// --------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
func TestNewAesGcmEncryptor(t *testing.T) {
|
|
22
|
+
tests := []struct {
|
|
23
|
+
name string
|
|
24
|
+
key string
|
|
25
|
+
wantErr bool
|
|
26
|
+
errMsg string
|
|
27
|
+
}{
|
|
28
|
+
{
|
|
29
|
+
name: "合法 64 字符 hex 密钥",
|
|
30
|
+
key: validKey,
|
|
31
|
+
wantErr: false,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "空密钥",
|
|
35
|
+
key: "",
|
|
36
|
+
wantErr: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "密钥太短(32 字符 = 16 字节)",
|
|
40
|
+
key: "0102030405060708090a0b0c0d0e0f10",
|
|
41
|
+
wantErr: true,
|
|
42
|
+
errMsg: "32 bytes",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "密钥太长(96 字符 = 48 字节)",
|
|
46
|
+
key: "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f200102030405060708090a0b0c0d0e0f10",
|
|
47
|
+
wantErr: true,
|
|
48
|
+
errMsg: "32 bytes",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "非法 hex 字符",
|
|
52
|
+
key: "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
|
|
53
|
+
wantErr: true,
|
|
54
|
+
errMsg: "invalid encryption key format",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "奇数长度 hex(无法 decode)",
|
|
58
|
+
key: "abc",
|
|
59
|
+
wantErr: true,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for _, tc := range tests {
|
|
64
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
65
|
+
enc, err := NewAesGcmEncryptor(tc.key)
|
|
66
|
+
if tc.wantErr {
|
|
67
|
+
require.Error(t, err)
|
|
68
|
+
if tc.errMsg != "" {
|
|
69
|
+
assert.Contains(t, err.Error(), tc.errMsg)
|
|
70
|
+
}
|
|
71
|
+
assert.Nil(t, enc)
|
|
72
|
+
} else {
|
|
73
|
+
require.NoError(t, err)
|
|
74
|
+
assert.NotNil(t, enc)
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --------------------------------------------------------
|
|
81
|
+
// Encrypt + Decrypt 往返
|
|
82
|
+
// --------------------------------------------------------
|
|
83
|
+
|
|
84
|
+
func TestAesGcmEncryptor_RoundTrip(t *testing.T) {
|
|
85
|
+
enc, err := NewAesGcmEncryptor(validKey)
|
|
86
|
+
require.NoError(t, err)
|
|
87
|
+
|
|
88
|
+
tests := []struct {
|
|
89
|
+
name string
|
|
90
|
+
plaintext string
|
|
91
|
+
}{
|
|
92
|
+
{
|
|
93
|
+
name: "普通 ASCII 字符串",
|
|
94
|
+
plaintext: "hello, world",
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "空字符串",
|
|
98
|
+
plaintext: "",
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
name: "Unicode / 多字节字符串",
|
|
102
|
+
plaintext: "你好,世界 🌍 こんにちは مرحبا",
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "包含特殊字符",
|
|
106
|
+
plaintext: "!@#$%^&*()_+-=[]{}|;':\",./<>?",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "超长字符串(10 KB+)",
|
|
110
|
+
plaintext: strings.Repeat("abcdefghij", 1024), // 10240 字节
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: "换行与制表符",
|
|
114
|
+
plaintext: "line1\nline2\ttabbed",
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "JSON 格式字符串",
|
|
118
|
+
plaintext: `{"user_id":42,"token":"secret-token-value","scope":["read","write"]}`,
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for _, tc := range tests {
|
|
123
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
124
|
+
ciphertext, err := enc.Encrypt(tc.plaintext)
|
|
125
|
+
require.NoError(t, err)
|
|
126
|
+
assert.NotEmpty(t, ciphertext)
|
|
127
|
+
|
|
128
|
+
decrypted, err := enc.Decrypt(ciphertext)
|
|
129
|
+
require.NoError(t, err)
|
|
130
|
+
assert.Equal(t, tc.plaintext, decrypted)
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// --------------------------------------------------------
|
|
136
|
+
// 不同明文产生不同密文
|
|
137
|
+
// --------------------------------------------------------
|
|
138
|
+
|
|
139
|
+
func TestAesGcmEncryptor_DifferentPlaintextsProduceDifferentCiphertexts(t *testing.T) {
|
|
140
|
+
enc, err := NewAesGcmEncryptor(validKey)
|
|
141
|
+
require.NoError(t, err)
|
|
142
|
+
|
|
143
|
+
plaintexts := []string{
|
|
144
|
+
"message one",
|
|
145
|
+
"message two",
|
|
146
|
+
"message three",
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
ciphertexts := make([]string, len(plaintexts))
|
|
150
|
+
for i, pt := range plaintexts {
|
|
151
|
+
ct, err := enc.Encrypt(pt)
|
|
152
|
+
require.NoError(t, err)
|
|
153
|
+
ciphertexts[i] = ct
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// 所有密文互不相同
|
|
157
|
+
for i := 0; i < len(ciphertexts); i++ {
|
|
158
|
+
for j := i + 1; j < len(ciphertexts); j++ {
|
|
159
|
+
assert.NotEqual(t, ciphertexts[i], ciphertexts[j],
|
|
160
|
+
"plaintext[%d] 和 plaintext[%d] 不同,密文也应不同", i, j)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// --------------------------------------------------------
|
|
166
|
+
// 相同明文两次加密产生不同密文(随机 nonce)
|
|
167
|
+
// --------------------------------------------------------
|
|
168
|
+
|
|
169
|
+
func TestAesGcmEncryptor_SamePlaintextProducesDifferentCiphertexts(t *testing.T) {
|
|
170
|
+
enc, err := NewAesGcmEncryptor(validKey)
|
|
171
|
+
require.NoError(t, err)
|
|
172
|
+
|
|
173
|
+
plaintext := "same input"
|
|
174
|
+
const iterations = 5
|
|
175
|
+
|
|
176
|
+
ciphertexts := make([]string, iterations)
|
|
177
|
+
for i := range ciphertexts {
|
|
178
|
+
ct, err := enc.Encrypt(plaintext)
|
|
179
|
+
require.NoError(t, err)
|
|
180
|
+
ciphertexts[i] = ct
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// 每次加密结果互不相同(随机 nonce 保证)
|
|
184
|
+
seen := make(map[string]bool)
|
|
185
|
+
for _, ct := range ciphertexts {
|
|
186
|
+
assert.False(t, seen[ct], "发现重复密文,随机 nonce 失效: %s", ct)
|
|
187
|
+
seen[ct] = true
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// --------------------------------------------------------
|
|
192
|
+
// Decrypt 异常场景
|
|
193
|
+
// --------------------------------------------------------
|
|
194
|
+
|
|
195
|
+
func TestAesGcmEncryptor_DecryptFailures(t *testing.T) {
|
|
196
|
+
enc, err := NewAesGcmEncryptor(validKey)
|
|
197
|
+
require.NoError(t, err)
|
|
198
|
+
|
|
199
|
+
tests := []struct {
|
|
200
|
+
name string
|
|
201
|
+
ciphertext string
|
|
202
|
+
}{
|
|
203
|
+
{
|
|
204
|
+
name: "非法 base64 字符串",
|
|
205
|
+
ciphertext: "!!!not-base64!!!",
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
name: "base64 但数据太短(短于 nonce)",
|
|
209
|
+
ciphertext: "dG9vc2hvcnQ=", // "tooshort" in base64,< 12 字节 nonce
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: "正确格式但 auth tag 被篡改",
|
|
213
|
+
ciphertext: func() string {
|
|
214
|
+
ct, _ := enc.Encrypt("original plaintext")
|
|
215
|
+
// 将最后一个字符替换掉,破坏 auth tag
|
|
216
|
+
if ct[len(ct)-1] == 'A' {
|
|
217
|
+
return ct[:len(ct)-1] + "B"
|
|
218
|
+
}
|
|
219
|
+
return ct[:len(ct)-1] + "A"
|
|
220
|
+
}(),
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "空字符串",
|
|
224
|
+
ciphertext: "",
|
|
225
|
+
},
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
for _, tc := range tests {
|
|
229
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
230
|
+
result, err := enc.Decrypt(tc.ciphertext)
|
|
231
|
+
require.Error(t, err)
|
|
232
|
+
assert.Empty(t, result)
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// --------------------------------------------------------
|
|
238
|
+
// 密文被整体篡改(nonce 区域修改)
|
|
239
|
+
// --------------------------------------------------------
|
|
240
|
+
|
|
241
|
+
func TestAesGcmEncryptor_TamperedNonce(t *testing.T) {
|
|
242
|
+
enc, err := NewAesGcmEncryptor(validKey)
|
|
243
|
+
require.NoError(t, err)
|
|
244
|
+
|
|
245
|
+
plaintext := "tamper test"
|
|
246
|
+
ciphertext, err := enc.Encrypt(plaintext)
|
|
247
|
+
require.NoError(t, err)
|
|
248
|
+
|
|
249
|
+
// 将 base64 字符串首字节改掉,破坏 nonce 区域
|
|
250
|
+
tampered := []byte(ciphertext)
|
|
251
|
+
if tampered[0] == 'A' {
|
|
252
|
+
tampered[0] = 'B'
|
|
253
|
+
} else {
|
|
254
|
+
tampered[0] = 'A'
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
_, err = enc.Decrypt(string(tampered))
|
|
258
|
+
assert.Error(t, err)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// --------------------------------------------------------
|
|
262
|
+
// 不同密钥无法互解
|
|
263
|
+
// --------------------------------------------------------
|
|
264
|
+
|
|
265
|
+
func TestAesGcmEncryptor_WrongKeyCannotDecrypt(t *testing.T) {
|
|
266
|
+
key1 := "0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"
|
|
267
|
+
key2 := "aabbccddeeff00112233445566778899aabbccddeeff001122334455667788aa"
|
|
268
|
+
|
|
269
|
+
enc1, err := NewAesGcmEncryptor(key1)
|
|
270
|
+
require.NoError(t, err)
|
|
271
|
+
|
|
272
|
+
enc2, err := NewAesGcmEncryptor(key2)
|
|
273
|
+
require.NoError(t, err)
|
|
274
|
+
|
|
275
|
+
ciphertext, err := enc1.Encrypt("secret message")
|
|
276
|
+
require.NoError(t, err)
|
|
277
|
+
|
|
278
|
+
_, err = enc2.Decrypt(ciphertext)
|
|
279
|
+
assert.Error(t, err, "用错误密钥解密应返回错误")
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// --------------------------------------------------------
|
|
283
|
+
// NoopEncryptor
|
|
284
|
+
// --------------------------------------------------------
|
|
285
|
+
|
|
286
|
+
func TestNoopEncryptor(t *testing.T) {
|
|
287
|
+
noop := &NoopEncryptor{}
|
|
288
|
+
|
|
289
|
+
tests := []struct {
|
|
290
|
+
name string
|
|
291
|
+
input string
|
|
292
|
+
}{
|
|
293
|
+
{name: "普通字符串", input: "hello"},
|
|
294
|
+
{name: "空字符串", input: ""},
|
|
295
|
+
{name: "Unicode 字符串", input: "你好 🌍"},
|
|
296
|
+
{name: "含特殊字符", input: "!@#$%^&*"},
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
for _, tc := range tests {
|
|
300
|
+
t.Run(tc.name, func(t *testing.T) {
|
|
301
|
+
encrypted, err := noop.Encrypt(tc.input)
|
|
302
|
+
require.NoError(t, err)
|
|
303
|
+
assert.Equal(t, tc.input, encrypted, "NoopEncryptor.Encrypt 应原样返回输入")
|
|
304
|
+
|
|
305
|
+
decrypted, err := noop.Decrypt(tc.input)
|
|
306
|
+
require.NoError(t, err)
|
|
307
|
+
assert.Equal(t, tc.input, decrypted, "NoopEncryptor.Decrypt 应原样返回输入")
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// --------------------------------------------------------
|
|
313
|
+
// ProvideEncryptor
|
|
314
|
+
// --------------------------------------------------------
|
|
315
|
+
|
|
316
|
+
func TestProvideEncryptor(t *testing.T) {
|
|
317
|
+
logger, err := zap.NewDevelopment()
|
|
318
|
+
require.NoError(t, err)
|
|
319
|
+
|
|
320
|
+
t.Run("有效密钥返回 AesGcmEncryptor", func(t *testing.T) {
|
|
321
|
+
cfg := &config.Config{EncryptionKey: validKey}
|
|
322
|
+
enc, err := ProvideEncryptor(cfg, logger)
|
|
323
|
+
require.NoError(t, err)
|
|
324
|
+
require.NotNil(t, enc)
|
|
325
|
+
|
|
326
|
+
// 验证返回的是真正的 AES-GCM 加密器(加密后密文与明文不同)
|
|
327
|
+
plaintext := "probe text"
|
|
328
|
+
ciphertext, err := enc.Encrypt(plaintext)
|
|
329
|
+
require.NoError(t, err)
|
|
330
|
+
assert.NotEqual(t, plaintext, ciphertext)
|
|
331
|
+
|
|
332
|
+
// 可往返解密
|
|
333
|
+
decrypted, err := enc.Decrypt(ciphertext)
|
|
334
|
+
require.NoError(t, err)
|
|
335
|
+
assert.Equal(t, plaintext, decrypted)
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
t.Run("空密钥返回 NoopEncryptor", func(t *testing.T) {
|
|
339
|
+
cfg := &config.Config{EncryptionKey: ""}
|
|
340
|
+
enc, err := ProvideEncryptor(cfg, logger)
|
|
341
|
+
require.NoError(t, err)
|
|
342
|
+
require.NotNil(t, enc)
|
|
343
|
+
|
|
344
|
+
// NoopEncryptor 加密后与明文相同
|
|
345
|
+
plaintext := "noop test"
|
|
346
|
+
ciphertext, err := enc.Encrypt(plaintext)
|
|
347
|
+
require.NoError(t, err)
|
|
348
|
+
assert.Equal(t, plaintext, ciphertext)
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
t.Run("生产环境空密钥返回错误", func(t *testing.T) {
|
|
352
|
+
cfg := &config.Config{App: config.AppConfig{Env: "production"}}
|
|
353
|
+
enc, err := ProvideEncryptor(cfg, logger)
|
|
354
|
+
require.Error(t, err)
|
|
355
|
+
assert.Nil(t, enc)
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
t.Run("非法密钥返回错误", func(t *testing.T) {
|
|
359
|
+
cfg := &config.Config{EncryptionKey: "not-a-valid-hex-key"}
|
|
360
|
+
enc, err := ProvideEncryptor(cfg, logger)
|
|
361
|
+
require.Error(t, err)
|
|
362
|
+
assert.Nil(t, enc)
|
|
363
|
+
})
|
|
364
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
package crypto
|
|
2
|
+
|
|
3
|
+
// Encryptor 加解密接口
|
|
4
|
+
//
|
|
5
|
+
// 所有需要加解密的模块(Identity OAuth token、Tenant 凭证、Storage 凭证、
|
|
6
|
+
// Payment 网关密钥等)统一通过此接口注入。
|
|
7
|
+
type Encryptor interface {
|
|
8
|
+
// Encrypt 加密明文,返回密文字符串
|
|
9
|
+
Encrypt(plaintext string) (string, error)
|
|
10
|
+
// Decrypt 解密密文,返回明文字符串
|
|
11
|
+
Decrypt(ciphertext string) (string, error)
|
|
12
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
package crypto
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"crypto/subtle"
|
|
5
|
+
"encoding/base64"
|
|
6
|
+
"fmt"
|
|
7
|
+
"regexp"
|
|
8
|
+
"strings"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const envelopeCiphertextVersion = "v1"
|
|
12
|
+
|
|
13
|
+
var envelopeKeyIDPattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$`)
|
|
14
|
+
|
|
15
|
+
// EnvelopeEncryptor 定义带关联数据的版本化信封加解密能力。
|
|
16
|
+
type EnvelopeEncryptor interface {
|
|
17
|
+
EncryptWithAssociatedData(plaintext string, associatedData []byte) (EnvelopeCiphertext, error)
|
|
18
|
+
DecryptWithAssociatedData(ciphertext string, associatedData []byte) (EnvelopePlaintext, error)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// EnvelopeCiphertext 包含密文和值所用密钥版本。
|
|
22
|
+
type EnvelopeCiphertext struct {
|
|
23
|
+
// Value 是自描述的版本化密文。
|
|
24
|
+
Value string
|
|
25
|
+
// KeyID 是加密所用密钥版本。
|
|
26
|
+
KeyID string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// EnvelopePlaintext 包含明文和成功解密的密钥版本。
|
|
30
|
+
type EnvelopePlaintext struct {
|
|
31
|
+
// Value 是解密后的明文。
|
|
32
|
+
Value string
|
|
33
|
+
// KeyID 是成功解密的密钥版本。
|
|
34
|
+
KeyID string
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// AESGCMEnvelopeKeyring 使用单一活动写密钥与有限只读历史密钥提供版本化 AEAD。
|
|
38
|
+
type AESGCMEnvelopeKeyring struct {
|
|
39
|
+
activeKeyID string
|
|
40
|
+
keys map[string][]byte
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// NewAESGCMEnvelopeKeyring 构造只向活动版本写入的 AES-256-GCM 密钥环。
|
|
44
|
+
func NewAESGCMEnvelopeKeyring(
|
|
45
|
+
activeKeyID string,
|
|
46
|
+
activeKey string,
|
|
47
|
+
readKeys map[string]string,
|
|
48
|
+
) (*AESGCMEnvelopeKeyring, error) {
|
|
49
|
+
if err := validateEnvelopeKeyID(activeKeyID); err != nil {
|
|
50
|
+
return nil, fmt.Errorf("validate active envelope key ID: %w", err)
|
|
51
|
+
}
|
|
52
|
+
activeMaterial, err := decodeAES256Key(activeKey)
|
|
53
|
+
if err != nil {
|
|
54
|
+
return nil, fmt.Errorf("decode active envelope key: %w", err)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
keys := make(map[string][]byte, len(readKeys)+1)
|
|
58
|
+
for keyID, encodedKey := range readKeys {
|
|
59
|
+
if err := validateEnvelopeKeyID(keyID); err != nil {
|
|
60
|
+
return nil, fmt.Errorf("validate envelope read key ID %q: %w", keyID, err)
|
|
61
|
+
}
|
|
62
|
+
keyMaterial, err := decodeAES256Key(encodedKey)
|
|
63
|
+
if err != nil {
|
|
64
|
+
return nil, fmt.Errorf("decode envelope read key %q: %w", keyID, err)
|
|
65
|
+
}
|
|
66
|
+
keys[keyID] = append([]byte(nil), keyMaterial...)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if existing, ok := keys[activeKeyID]; ok && !equalKeyMaterial(existing, activeMaterial) {
|
|
70
|
+
return nil, fmt.Errorf("active envelope key %q conflicts with read key material", activeKeyID)
|
|
71
|
+
}
|
|
72
|
+
keys[activeKeyID] = append([]byte(nil), activeMaterial...)
|
|
73
|
+
|
|
74
|
+
return &AESGCMEnvelopeKeyring{
|
|
75
|
+
activeKeyID: activeKeyID,
|
|
76
|
+
keys: keys,
|
|
77
|
+
}, nil
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// EncryptWithAssociatedData 使用活动密钥和调用方不可变语义生成密文。
|
|
81
|
+
func (keyring *AESGCMEnvelopeKeyring) EncryptWithAssociatedData(
|
|
82
|
+
plaintext string,
|
|
83
|
+
associatedData []byte,
|
|
84
|
+
) (EnvelopeCiphertext, error) {
|
|
85
|
+
sealed, err := sealAESGCM(keyring.keys[keyring.activeKeyID], []byte(plaintext), associatedData)
|
|
86
|
+
if err != nil {
|
|
87
|
+
return EnvelopeCiphertext{}, fmt.Errorf("encrypt envelope: %w", err)
|
|
88
|
+
}
|
|
89
|
+
encoded := base64.RawURLEncoding.EncodeToString(sealed)
|
|
90
|
+
return EnvelopeCiphertext{
|
|
91
|
+
Value: strings.Join([]string{envelopeCiphertextVersion, keyring.activeKeyID, encoded}, "."),
|
|
92
|
+
KeyID: keyring.activeKeyID,
|
|
93
|
+
}, nil
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// DecryptWithAssociatedData 仅用密文声明的精确密钥版本解密。
|
|
97
|
+
func (keyring *AESGCMEnvelopeKeyring) DecryptWithAssociatedData(
|
|
98
|
+
ciphertext string,
|
|
99
|
+
associatedData []byte,
|
|
100
|
+
) (EnvelopePlaintext, error) {
|
|
101
|
+
prefix := envelopeCiphertextVersion + "."
|
|
102
|
+
lastSeparator := strings.LastIndex(ciphertext, ".")
|
|
103
|
+
if !strings.HasPrefix(ciphertext, prefix) || lastSeparator <= len(prefix) || lastSeparator == len(ciphertext)-1 {
|
|
104
|
+
return EnvelopePlaintext{}, fmt.Errorf("invalid envelope ciphertext format")
|
|
105
|
+
}
|
|
106
|
+
keyID := ciphertext[len(prefix):lastSeparator]
|
|
107
|
+
if err := validateEnvelopeKeyID(keyID); err != nil {
|
|
108
|
+
return EnvelopePlaintext{}, fmt.Errorf("invalid envelope ciphertext key ID: %w", err)
|
|
109
|
+
}
|
|
110
|
+
key, ok := keyring.keys[keyID]
|
|
111
|
+
if !ok {
|
|
112
|
+
return EnvelopePlaintext{}, fmt.Errorf("envelope key %q is not available", keyID)
|
|
113
|
+
}
|
|
114
|
+
sealed, err := base64.RawURLEncoding.DecodeString(ciphertext[lastSeparator+1:])
|
|
115
|
+
if err != nil {
|
|
116
|
+
return EnvelopePlaintext{}, fmt.Errorf("decode envelope ciphertext: %w", err)
|
|
117
|
+
}
|
|
118
|
+
plaintext, err := openAESGCM(key, sealed, associatedData)
|
|
119
|
+
if err != nil {
|
|
120
|
+
return EnvelopePlaintext{}, fmt.Errorf("decrypt envelope with key %q: %w", keyID, err)
|
|
121
|
+
}
|
|
122
|
+
return EnvelopePlaintext{Value: string(plaintext), KeyID: keyID}, nil
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
func validateEnvelopeKeyID(keyID string) error {
|
|
126
|
+
if !envelopeKeyIDPattern.MatchString(keyID) {
|
|
127
|
+
return fmt.Errorf("key ID must match %s", envelopeKeyIDPattern.String())
|
|
128
|
+
}
|
|
129
|
+
return nil
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
func equalKeyMaterial(left, right []byte) bool {
|
|
133
|
+
return subtle.ConstantTimeCompare(left, right) == 1
|
|
134
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
package crypto
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
|
|
7
|
+
"github.com/stretchr/testify/assert"
|
|
8
|
+
"github.com/stretchr/testify/require"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
const (
|
|
12
|
+
envelopeKeyV1 = "1111111111111111111111111111111111111111111111111111111111111111"
|
|
13
|
+
envelopeKeyV2 = "2222222222222222222222222222222222222222222222222222222222222222"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
func TestAESGCMEnvelopeKeyringRoundTrip(t *testing.T) {
|
|
17
|
+
keyring, err := NewAESGCMEnvelopeKeyring("key-v2", envelopeKeyV2, map[string]string{
|
|
18
|
+
"key-v1": envelopeKeyV1,
|
|
19
|
+
})
|
|
20
|
+
require.NoError(t, err)
|
|
21
|
+
|
|
22
|
+
ciphertext, err := keyring.EncryptWithAssociatedData("provider request", []byte("operation:v1"))
|
|
23
|
+
require.NoError(t, err)
|
|
24
|
+
assert.Equal(t, "key-v2", ciphertext.KeyID)
|
|
25
|
+
assert.True(t, strings.HasPrefix(ciphertext.Value, "v1.key-v2."))
|
|
26
|
+
|
|
27
|
+
plaintext, err := keyring.DecryptWithAssociatedData(ciphertext.Value, []byte("operation:v1"))
|
|
28
|
+
require.NoError(t, err)
|
|
29
|
+
assert.Equal(t, EnvelopePlaintext{Value: "provider request", KeyID: "key-v2"}, plaintext)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func TestAESGCMEnvelopeKeyringReadsPriorVersion(t *testing.T) {
|
|
33
|
+
prior, err := NewAESGCMEnvelopeKeyring("key-v1", envelopeKeyV1, nil)
|
|
34
|
+
require.NoError(t, err)
|
|
35
|
+
ciphertext, err := prior.EncryptWithAssociatedData("recoverable", []byte("immutable-aad"))
|
|
36
|
+
require.NoError(t, err)
|
|
37
|
+
|
|
38
|
+
current, err := NewAESGCMEnvelopeKeyring("key-v2", envelopeKeyV2, map[string]string{
|
|
39
|
+
"key-v1": envelopeKeyV1,
|
|
40
|
+
})
|
|
41
|
+
require.NoError(t, err)
|
|
42
|
+
plaintext, err := current.DecryptWithAssociatedData(ciphertext.Value, []byte("immutable-aad"))
|
|
43
|
+
require.NoError(t, err)
|
|
44
|
+
assert.Equal(t, "recoverable", plaintext.Value)
|
|
45
|
+
assert.Equal(t, "key-v1", plaintext.KeyID)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func TestAESGCMEnvelopeKeyringRejectsTampering(t *testing.T) {
|
|
49
|
+
keyring, err := NewAESGCMEnvelopeKeyring("key-v2", envelopeKeyV2, nil)
|
|
50
|
+
require.NoError(t, err)
|
|
51
|
+
ciphertext, err := keyring.EncryptWithAssociatedData("secret", []byte("expected-aad"))
|
|
52
|
+
require.NoError(t, err)
|
|
53
|
+
|
|
54
|
+
tamperedCiphertext := []byte(ciphertext.Value)
|
|
55
|
+
payloadStart := strings.LastIndex(ciphertext.Value, ".") + 1
|
|
56
|
+
if tamperedCiphertext[payloadStart] == 'A' {
|
|
57
|
+
tamperedCiphertext[payloadStart] = 'B'
|
|
58
|
+
} else {
|
|
59
|
+
tamperedCiphertext[payloadStart] = 'A'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
tests := []struct {
|
|
63
|
+
name string
|
|
64
|
+
ciphertext string
|
|
65
|
+
aad []byte
|
|
66
|
+
}{
|
|
67
|
+
{name: "关联数据变化", ciphertext: ciphertext.Value, aad: []byte("different-aad")},
|
|
68
|
+
{name: "未知密钥", ciphertext: strings.Replace(ciphertext.Value, "key-v2", "key-v3", 1), aad: []byte("expected-aad")},
|
|
69
|
+
{name: "版本变化", ciphertext: strings.Replace(ciphertext.Value, "v1.", "v2.", 1), aad: []byte("expected-aad")},
|
|
70
|
+
{name: "密文变化", ciphertext: string(tamperedCiphertext), aad: []byte("expected-aad")},
|
|
71
|
+
{name: "缺少字段", ciphertext: "v1.key-v2", aad: []byte("expected-aad")},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
for _, test := range tests {
|
|
75
|
+
t.Run(test.name, func(t *testing.T) {
|
|
76
|
+
plaintext, err := keyring.DecryptWithAssociatedData(test.ciphertext, test.aad)
|
|
77
|
+
require.Error(t, err)
|
|
78
|
+
assert.Equal(t, EnvelopePlaintext{}, plaintext)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
func TestNewAESGCMEnvelopeKeyringValidation(t *testing.T) {
|
|
84
|
+
tests := []struct {
|
|
85
|
+
name string
|
|
86
|
+
activeID string
|
|
87
|
+
activeKey string
|
|
88
|
+
readKeys map[string]string
|
|
89
|
+
}{
|
|
90
|
+
{name: "空活动版本", activeKey: envelopeKeyV2},
|
|
91
|
+
{name: "活动版本包含冒号", activeID: "key:v2", activeKey: envelopeKeyV2},
|
|
92
|
+
{name: "活动密钥长度错误", activeID: "key-v2", activeKey: "abcd"},
|
|
93
|
+
{name: "历史版本非法", activeID: "key-v2", activeKey: envelopeKeyV2, readKeys: map[string]string{"bad:key": envelopeKeyV1}},
|
|
94
|
+
{name: "历史密钥格式错误", activeID: "key-v2", activeKey: envelopeKeyV2, readKeys: map[string]string{"key-v1": "abcd"}},
|
|
95
|
+
{name: "活动版本材料冲突", activeID: "key-v2", activeKey: envelopeKeyV2, readKeys: map[string]string{"key-v2": envelopeKeyV1}},
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
for _, test := range tests {
|
|
99
|
+
t.Run(test.name, func(t *testing.T) {
|
|
100
|
+
keyring, err := NewAESGCMEnvelopeKeyring(test.activeID, test.activeKey, test.readKeys)
|
|
101
|
+
require.Error(t, err)
|
|
102
|
+
assert.Nil(t, keyring)
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func TestNewAESGCMEnvelopeKeyringAcceptsMatchingActiveReadEntry(t *testing.T) {
|
|
108
|
+
readKeys := map[string]string{"key-v2": envelopeKeyV2}
|
|
109
|
+
keyring, err := NewAESGCMEnvelopeKeyring("key-v2", envelopeKeyV2, readKeys)
|
|
110
|
+
require.NoError(t, err)
|
|
111
|
+
|
|
112
|
+
readKeys["key-v2"] = envelopeKeyV1
|
|
113
|
+
ciphertext, err := keyring.EncryptWithAssociatedData("immutable", nil)
|
|
114
|
+
require.NoError(t, err)
|
|
115
|
+
plaintext, err := keyring.DecryptWithAssociatedData(ciphertext.Value, nil)
|
|
116
|
+
require.NoError(t, err)
|
|
117
|
+
assert.Equal(t, "immutable", plaintext.Value)
|
|
118
|
+
}
|