@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,770 @@
|
|
|
1
|
+
package audit
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"encoding/json"
|
|
6
|
+
"errors"
|
|
7
|
+
"fmt"
|
|
8
|
+
"strings"
|
|
9
|
+
"sync"
|
|
10
|
+
"sync/atomic"
|
|
11
|
+
"time"
|
|
12
|
+
|
|
13
|
+
"go.uber.org/zap"
|
|
14
|
+
"gorm.io/datatypes"
|
|
15
|
+
"gorm.io/gorm"
|
|
16
|
+
|
|
17
|
+
"{{module}}/internal/common/iamscope"
|
|
18
|
+
"{{module}}/pkg/apierror"
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// 写入服务接口
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
// AuditService 审计写入服务(三缓冲区异步批量写入)
|
|
26
|
+
type AuditService interface {
|
|
27
|
+
// LogAccess 异步写入访问日志条目(L1 中间件调用)
|
|
28
|
+
LogAccess(ctx context.Context, entry AccessEntry)
|
|
29
|
+
// LogAudit 异步写入审计日志条目(L2 EventBus 非认证事件 + L3 Enrich)
|
|
30
|
+
LogAudit(ctx context.Context, entry AuditEntry)
|
|
31
|
+
// LogLogin 异步写入登录日志条目(L2 EventBus 认证事件)
|
|
32
|
+
LogLogin(ctx context.Context, entry LoginEntry)
|
|
33
|
+
// LogSync 同步写入审计条目(用于 critical 级别操作)
|
|
34
|
+
LogSync(ctx context.Context, entry AuditEntry) error
|
|
35
|
+
// ProjectEventSync 同步、幂等地把来源事件投影为审计条目。
|
|
36
|
+
ProjectEventSync(ctx context.Context, sourceEventID string, eventName string, entry AuditEntry) error
|
|
37
|
+
// BeginOperation 同步创建操作日志 started 记录
|
|
38
|
+
BeginOperation(ctx context.Context, entry BeginOperationEntry) (int64, error)
|
|
39
|
+
// CompleteOperation 同步补齐操作日志 completed 记录
|
|
40
|
+
CompleteOperation(ctx context.Context, operationLogID int64, entry CompleteOperationEntry) error
|
|
41
|
+
// Flush 手动 flush 全部 buffer
|
|
42
|
+
Flush(ctx context.Context) error
|
|
43
|
+
// Stop 优雅关闭
|
|
44
|
+
Stop()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// 查询服务接口
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
|
|
51
|
+
// AuditQueryService 审计只读查询服务
|
|
52
|
+
type AuditQueryService interface {
|
|
53
|
+
// ListAccessLogs 分页查询访问日志
|
|
54
|
+
ListAccessLogs(ctx context.Context, req *AdminListAccessLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*AccessLog, int64, error)
|
|
55
|
+
// GetAccessLog 查询单条访问日志详情
|
|
56
|
+
GetAccessLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*AccessLog, error)
|
|
57
|
+
// ListAuditLogs 分页查询审计日志
|
|
58
|
+
ListAuditLogs(ctx context.Context, req *AdminListAuditLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*AuditLog, int64, error)
|
|
59
|
+
// GetAuditLog 查询单条审计日志详情
|
|
60
|
+
GetAuditLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*AuditLog, error)
|
|
61
|
+
// ListOperationLogs 分页查询操作日志
|
|
62
|
+
ListOperationLogs(ctx context.Context, req *AdminListOperationLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*OperationLog, int64, error)
|
|
63
|
+
// GetOperationLog 查询单条操作日志详情
|
|
64
|
+
GetOperationLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*OperationLog, error)
|
|
65
|
+
// ListLoginLogs 分页查询登录日志
|
|
66
|
+
ListLoginLogs(ctx context.Context, req *AdminListLoginLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*LoginLog, int64, error)
|
|
67
|
+
// GetLoginLog 查询单条登录日志详情
|
|
68
|
+
GetLoginLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*LoginLog, error)
|
|
69
|
+
// CountFailedLoginsByIP 统计指定 IP 的失败登录次数
|
|
70
|
+
CountFailedLoginsByIP(ctx context.Context, ip string, since time.Time) (int64, error)
|
|
71
|
+
// GetAuditStats 获取审计统计
|
|
72
|
+
GetAuditStats(ctx context.Context, from, to time.Time, scope iamscope.ScopeConstraint, principalID int64) (*StatsResponse, error)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// 常量
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
const (
|
|
80
|
+
// accessBufferCap 访问日志 buffer 容量(L1 高频)
|
|
81
|
+
accessBufferCap = 1024
|
|
82
|
+
// auditBufferCap 审计日志 buffer 容量
|
|
83
|
+
auditBufferCap = 512
|
|
84
|
+
// loginBufferCap 登录日志 buffer 容量(最低频)
|
|
85
|
+
loginBufferCap = 128
|
|
86
|
+
// flushInterval 定期 flush 间隔
|
|
87
|
+
flushInterval = 5 * time.Second
|
|
88
|
+
// batchSize 单次 flush 最大条数
|
|
89
|
+
batchSize = 100
|
|
90
|
+
// dropWarnInterval 控制缓冲区溢出告警频率
|
|
91
|
+
dropWarnInterval = time.Minute
|
|
92
|
+
// synchronousAuditWriteTimeout 高风险审计同步写入的独立超时。
|
|
93
|
+
synchronousAuditWriteTimeout = 5 * time.Second
|
|
94
|
+
// auditErrorMessageMaxLength 对齐 sys_access_logs/sys_audit_logs.error_message 字段长度。
|
|
95
|
+
auditErrorMessageMaxLength = 500
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// 写入服务实现
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
|
|
102
|
+
// auditService 三缓冲区异步写入实现
|
|
103
|
+
type auditService struct {
|
|
104
|
+
accessRepo AccessLogRepository
|
|
105
|
+
auditRepo AuditRepository
|
|
106
|
+
loginRepo LoginLogRepository
|
|
107
|
+
operationRepo OperationLogRepository
|
|
108
|
+
txManager AuditTransactionManager
|
|
109
|
+
accessPolicy AccessLogPolicy
|
|
110
|
+
logger *zap.Logger
|
|
111
|
+
|
|
112
|
+
accessBuffer chan AccessEntry
|
|
113
|
+
auditBuffer chan AuditEntry
|
|
114
|
+
loginBuffer chan LoginEntry
|
|
115
|
+
|
|
116
|
+
accessDrop auditDropState
|
|
117
|
+
auditDrop auditDropState
|
|
118
|
+
loginDrop auditDropState
|
|
119
|
+
|
|
120
|
+
wg sync.WaitGroup
|
|
121
|
+
stopCh chan struct{}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
type auditDropState struct {
|
|
125
|
+
dropped atomic.Int64
|
|
126
|
+
lastWarnUnixNs atomic.Int64
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// NewAuditService 构建 AuditService,启动三个独立 flush goroutine
|
|
130
|
+
func NewAuditService(
|
|
131
|
+
accessRepo AccessLogRepository,
|
|
132
|
+
auditRepo AuditRepository,
|
|
133
|
+
loginRepo LoginLogRepository,
|
|
134
|
+
operationRepo OperationLogRepository,
|
|
135
|
+
txManager AuditTransactionManager,
|
|
136
|
+
accessPolicy AccessLogPolicy,
|
|
137
|
+
logger *zap.Logger,
|
|
138
|
+
) AuditService {
|
|
139
|
+
svc := &auditService{
|
|
140
|
+
accessRepo: accessRepo,
|
|
141
|
+
auditRepo: auditRepo,
|
|
142
|
+
loginRepo: loginRepo,
|
|
143
|
+
operationRepo: operationRepo,
|
|
144
|
+
txManager: txManager,
|
|
145
|
+
accessPolicy: accessPolicy,
|
|
146
|
+
logger: logger.Named("AuditService"),
|
|
147
|
+
accessBuffer: make(chan AccessEntry, accessBufferCap),
|
|
148
|
+
auditBuffer: make(chan AuditEntry, auditBufferCap),
|
|
149
|
+
loginBuffer: make(chan LoginEntry, loginBufferCap),
|
|
150
|
+
stopCh: make(chan struct{}),
|
|
151
|
+
}
|
|
152
|
+
svc.wg.Add(3)
|
|
153
|
+
go svc.flushAccessLoop()
|
|
154
|
+
go svc.flushAuditLoop()
|
|
155
|
+
go svc.flushLoginLoop()
|
|
156
|
+
return svc
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// LogAccess 异步写入访问日志,高频成功读请求由策略降采样。
|
|
160
|
+
func (s *auditService) LogAccess(_ context.Context, entry AccessEntry) {
|
|
161
|
+
if !s.accessPolicy.ShouldRecord(entry) {
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
select {
|
|
165
|
+
case s.accessBuffer <- entry:
|
|
166
|
+
default:
|
|
167
|
+
s.warnDropped(&s.accessDrop, "access",
|
|
168
|
+
zap.String("method", entry.HTTPMethod),
|
|
169
|
+
zap.String("path", entry.HTTPPath),
|
|
170
|
+
)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// LogAudit 写入审计日志;高风险 IAM 治理事件同步落库,其余事件进入异步缓冲。
|
|
175
|
+
func (s *auditService) LogAudit(ctx context.Context, entry AuditEntry) {
|
|
176
|
+
if shouldWriteAuditSynchronously(entry) {
|
|
177
|
+
writeCtx, cancel := detachedAuditWriteContext(ctx)
|
|
178
|
+
defer cancel()
|
|
179
|
+
if err := s.LogSync(writeCtx, entry); err != nil {
|
|
180
|
+
s.logger.Error("write synchronous audit log failed",
|
|
181
|
+
zap.String("action", string(entry.Action)),
|
|
182
|
+
zap.String("category", string(entry.Category)),
|
|
183
|
+
zap.String("riskLevel", string(entry.RiskLevel)),
|
|
184
|
+
zap.String("resourceType", entry.ResourceType),
|
|
185
|
+
zap.Int64("actorId", entry.ActorID.Int64()),
|
|
186
|
+
zap.Error(err),
|
|
187
|
+
)
|
|
188
|
+
}
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
select {
|
|
192
|
+
case s.auditBuffer <- entry:
|
|
193
|
+
default:
|
|
194
|
+
if entry.RiskLevel == RiskLevelCritical || entry.RiskLevel == RiskLevelHigh {
|
|
195
|
+
writeCtx, cancel := detachedAuditWriteContext(ctx)
|
|
196
|
+
defer cancel()
|
|
197
|
+
if err := s.auditRepo.BatchCreate(writeCtx, []*AuditLog{toAuditLog(entry)}); err != nil {
|
|
198
|
+
s.logger.Error("write high risk audit log failed",
|
|
199
|
+
zap.String("action", string(entry.Action)),
|
|
200
|
+
zap.String("category", string(entry.Category)),
|
|
201
|
+
zap.String("riskLevel", string(entry.RiskLevel)),
|
|
202
|
+
zap.Int64("actorId", entry.ActorID.Int64()),
|
|
203
|
+
zap.Error(err),
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
s.warnDropped(&s.auditDrop, "audit",
|
|
209
|
+
zap.String("action", string(entry.Action)),
|
|
210
|
+
zap.String("category", string(entry.Category)),
|
|
211
|
+
zap.String("riskLevel", string(entry.RiskLevel)),
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
func shouldWriteAuditSynchronously(entry AuditEntry) bool {
|
|
217
|
+
if entry.RiskLevel != RiskLevelCritical && entry.RiskLevel != RiskLevelHigh {
|
|
218
|
+
return false
|
|
219
|
+
}
|
|
220
|
+
switch AuditResource(entry.ResourceType) {
|
|
221
|
+
case AuditResourceIAMPolicy,
|
|
222
|
+
AuditResourceIAMPrincipal,
|
|
223
|
+
AuditResourceIAMServiceAccount,
|
|
224
|
+
AuditResourceIAMCredential,
|
|
225
|
+
AuditResourceIAMCredentialTrust,
|
|
226
|
+
AuditResourceIAMRole,
|
|
227
|
+
AuditResourceIAMGroup,
|
|
228
|
+
AuditResourceIAMBinding,
|
|
229
|
+
AuditResourceIAMPageAction,
|
|
230
|
+
AuditResourceOutboxEvent:
|
|
231
|
+
return true
|
|
232
|
+
default:
|
|
233
|
+
return false
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
func detachedAuditWriteContext(ctx context.Context) (context.Context, context.CancelFunc) {
|
|
238
|
+
if ctx == nil {
|
|
239
|
+
ctx = context.Background()
|
|
240
|
+
}
|
|
241
|
+
return context.WithTimeout(context.WithoutCancel(ctx), synchronousAuditWriteTimeout)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// LogLogin 异步写入登录日志,缓冲区满时按频率聚合告警。
|
|
245
|
+
func (s *auditService) LogLogin(_ context.Context, entry LoginEntry) {
|
|
246
|
+
select {
|
|
247
|
+
case s.loginBuffer <- entry:
|
|
248
|
+
default:
|
|
249
|
+
s.warnDropped(&s.loginDrop, "login",
|
|
250
|
+
zap.String("loginAction", string(entry.LoginAction)),
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
func (s *auditService) warnDropped(state *auditDropState, buffer string, fields ...zap.Field) {
|
|
256
|
+
dropped := state.dropped.Add(1)
|
|
257
|
+
now := time.Now().UnixNano()
|
|
258
|
+
last := state.lastWarnUnixNs.Load()
|
|
259
|
+
if now-last < int64(dropWarnInterval) {
|
|
260
|
+
return
|
|
261
|
+
}
|
|
262
|
+
if !state.lastWarnUnixNs.CompareAndSwap(last, now) {
|
|
263
|
+
return
|
|
264
|
+
}
|
|
265
|
+
allFields := []zap.Field{
|
|
266
|
+
zap.String("buffer", buffer),
|
|
267
|
+
zap.Int64("suppressed", dropped),
|
|
268
|
+
}
|
|
269
|
+
allFields = append(allFields, fields...)
|
|
270
|
+
s.logger.Warn("audit buffer overflow", allFields...)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// LogSync 同步写入审计条目(绕过 buffer,直接写库)
|
|
274
|
+
func (s *auditService) LogSync(ctx context.Context, entry AuditEntry) error {
|
|
275
|
+
log := toAuditLog(entry)
|
|
276
|
+
if log.EventID != nil {
|
|
277
|
+
if *log.EventID == "" || log.OccurredAt == nil {
|
|
278
|
+
return fmt.Errorf("event audit requires event_id and occurred_at")
|
|
279
|
+
}
|
|
280
|
+
return s.txManager.WithTransaction(ctx, func(txCtx context.Context) error {
|
|
281
|
+
claimed, err := s.auditRepo.ClaimEventAudit(txCtx, &AuditEventInbox{
|
|
282
|
+
EventID: *log.EventID,
|
|
283
|
+
OccurredAt: *log.OccurredAt,
|
|
284
|
+
ProcessedAt: time.Now().UTC(),
|
|
285
|
+
})
|
|
286
|
+
if err != nil || !claimed {
|
|
287
|
+
return err
|
|
288
|
+
}
|
|
289
|
+
return s.auditRepo.BatchCreate(txCtx, []*AuditLog{log})
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
return s.auditRepo.BatchCreate(ctx, []*AuditLog{log})
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ProjectEventSync 将来源事件幂等键与审计事实放在同一事务中持久化。
|
|
296
|
+
func (s *auditService) ProjectEventSync(
|
|
297
|
+
ctx context.Context,
|
|
298
|
+
sourceEventID string,
|
|
299
|
+
eventName string,
|
|
300
|
+
entry AuditEntry,
|
|
301
|
+
) error {
|
|
302
|
+
if strings.TrimSpace(sourceEventID) == "" || strings.TrimSpace(eventName) == "" {
|
|
303
|
+
return errors.New("audit event projection identity is required")
|
|
304
|
+
}
|
|
305
|
+
entry.EventID = strings.TrimSpace(sourceEventID)
|
|
306
|
+
return s.LogSync(ctx, entry)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// BeginOperation 同步创建控制面操作 started 记录。
|
|
310
|
+
func (s *auditService) BeginOperation(ctx context.Context, entry BeginOperationEntry) (int64, error) {
|
|
311
|
+
log := toOperationLog(entry)
|
|
312
|
+
if err := s.operationRepo.Create(ctx, log); err != nil {
|
|
313
|
+
return 0, err
|
|
314
|
+
}
|
|
315
|
+
return log.ID, nil
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// CompleteOperation 同步补齐控制面操作 completed 记录。
|
|
319
|
+
func (s *auditService) CompleteOperation(ctx context.Context, operationLogID int64, entry CompleteOperationEntry) error {
|
|
320
|
+
completedAt := time.Now().UTC()
|
|
321
|
+
if err := s.operationRepo.Complete(ctx, operationLogID, entry, completedAt); err != nil {
|
|
322
|
+
s.logger.Error("operation log completion failed",
|
|
323
|
+
zap.String("event", "audit.operation.complete"),
|
|
324
|
+
zap.String("table", (OperationLog{}).TableName()),
|
|
325
|
+
zap.String("outcome", "failed"),
|
|
326
|
+
zap.String("errorKind", operationCompletionErrorKind(err)),
|
|
327
|
+
zap.String("expectedRecordStatus", operationRecordStatusStarted),
|
|
328
|
+
zap.Int64("operationLogId", operationLogID),
|
|
329
|
+
zap.String("requestId", entry.RequestID),
|
|
330
|
+
zap.Int("httpStatus", int(entry.HTTPStatus)),
|
|
331
|
+
zap.Bool("isSuccess", entry.IsSuccess),
|
|
332
|
+
zap.Error(err),
|
|
333
|
+
)
|
|
334
|
+
return err
|
|
335
|
+
}
|
|
336
|
+
return nil
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
func operationCompletionErrorKind(err error) string {
|
|
340
|
+
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
341
|
+
return "not_started_or_already_completed"
|
|
342
|
+
}
|
|
343
|
+
return "write_failed"
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Flush 手动 flush 全部 buffer
|
|
347
|
+
func (s *auditService) Flush(ctx context.Context) error {
|
|
348
|
+
var firstErr error
|
|
349
|
+
if err := s.flushAccess(ctx); err != nil && firstErr == nil {
|
|
350
|
+
firstErr = err
|
|
351
|
+
}
|
|
352
|
+
if err := s.flushAudit(ctx); err != nil && firstErr == nil {
|
|
353
|
+
firstErr = err
|
|
354
|
+
}
|
|
355
|
+
if err := s.flushLogin(ctx); err != nil && firstErr == nil {
|
|
356
|
+
firstErr = err
|
|
357
|
+
}
|
|
358
|
+
return firstErr
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Stop 优雅关闭:通知三个 flush goroutine 停止并等待完成
|
|
362
|
+
func (s *auditService) Stop() {
|
|
363
|
+
close(s.stopCh)
|
|
364
|
+
s.wg.Wait()
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ---------------------------------------------------------------------------
|
|
368
|
+
// flush goroutine 循环
|
|
369
|
+
// ---------------------------------------------------------------------------
|
|
370
|
+
|
|
371
|
+
func (s *auditService) flushAccessLoop() {
|
|
372
|
+
defer s.wg.Done()
|
|
373
|
+
ticker := time.NewTicker(flushInterval)
|
|
374
|
+
defer ticker.Stop()
|
|
375
|
+
for {
|
|
376
|
+
select {
|
|
377
|
+
case <-ticker.C:
|
|
378
|
+
_ = s.flushAccess(context.Background()) //nolint:errcheck // 定时 flush 失败已在 flushAccess 内部记录日志
|
|
379
|
+
case <-s.stopCh:
|
|
380
|
+
_ = s.flushAccess(context.Background()) //nolint:errcheck // 关闭时 best-effort flush
|
|
381
|
+
return
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
func (s *auditService) flushAuditLoop() {
|
|
387
|
+
defer s.wg.Done()
|
|
388
|
+
ticker := time.NewTicker(flushInterval)
|
|
389
|
+
defer ticker.Stop()
|
|
390
|
+
for {
|
|
391
|
+
select {
|
|
392
|
+
case <-ticker.C:
|
|
393
|
+
_ = s.flushAudit(context.Background()) //nolint:errcheck // 定时 flush 失败已在 flushAudit 内部记录日志
|
|
394
|
+
case <-s.stopCh:
|
|
395
|
+
_ = s.flushAudit(context.Background()) //nolint:errcheck // 关闭时 best-effort flush
|
|
396
|
+
return
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
func (s *auditService) flushLoginLoop() {
|
|
402
|
+
defer s.wg.Done()
|
|
403
|
+
ticker := time.NewTicker(flushInterval)
|
|
404
|
+
defer ticker.Stop()
|
|
405
|
+
for {
|
|
406
|
+
select {
|
|
407
|
+
case <-ticker.C:
|
|
408
|
+
_ = s.flushLogin(context.Background()) //nolint:errcheck // 定时 flush 失败已在 flushLogin 内部记录日志
|
|
409
|
+
case <-s.stopCh:
|
|
410
|
+
_ = s.flushLogin(context.Background()) //nolint:errcheck // 关闭时 best-effort flush
|
|
411
|
+
return
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
417
|
+
// flush 实现(drain buffer → batch insert)
|
|
418
|
+
// ---------------------------------------------------------------------------
|
|
419
|
+
|
|
420
|
+
func (s *auditService) flushAccess(ctx context.Context) error {
|
|
421
|
+
entries := drainChannel(s.accessBuffer, batchSize)
|
|
422
|
+
if len(entries) == 0 {
|
|
423
|
+
return nil
|
|
424
|
+
}
|
|
425
|
+
logs := make([]*AccessLog, 0, len(entries))
|
|
426
|
+
for i := range entries {
|
|
427
|
+
logs = append(logs, toAccessLog(entries[i]))
|
|
428
|
+
}
|
|
429
|
+
if err := s.accessRepo.BatchCreate(ctx, logs); err != nil {
|
|
430
|
+
s.logger.Error("flush access logs failed",
|
|
431
|
+
zap.Error(err),
|
|
432
|
+
zap.Int("count", len(logs)),
|
|
433
|
+
)
|
|
434
|
+
return err
|
|
435
|
+
}
|
|
436
|
+
s.logger.Debug("access logs flushed", zap.Int("count", len(logs)))
|
|
437
|
+
return nil
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
func (s *auditService) flushAudit(ctx context.Context) error {
|
|
441
|
+
entries := drainChannel(s.auditBuffer, batchSize)
|
|
442
|
+
if len(entries) == 0 {
|
|
443
|
+
return nil
|
|
444
|
+
}
|
|
445
|
+
logs := make([]*AuditLog, 0, len(entries))
|
|
446
|
+
for i := range entries {
|
|
447
|
+
logs = append(logs, toAuditLog(entries[i]))
|
|
448
|
+
}
|
|
449
|
+
if err := s.auditRepo.BatchCreate(ctx, logs); err != nil {
|
|
450
|
+
s.logger.Error("flush audit logs failed",
|
|
451
|
+
zap.Error(err),
|
|
452
|
+
zap.Int("count", len(logs)),
|
|
453
|
+
)
|
|
454
|
+
return err
|
|
455
|
+
}
|
|
456
|
+
s.logger.Debug("audit logs flushed", zap.Int("count", len(logs)))
|
|
457
|
+
return nil
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
func (s *auditService) flushLogin(ctx context.Context) error {
|
|
461
|
+
entries := drainChannel(s.loginBuffer, batchSize)
|
|
462
|
+
if len(entries) == 0 {
|
|
463
|
+
return nil
|
|
464
|
+
}
|
|
465
|
+
logs := make([]*LoginLog, 0, len(entries))
|
|
466
|
+
for i := range entries {
|
|
467
|
+
logs = append(logs, toLoginLog(entries[i]))
|
|
468
|
+
}
|
|
469
|
+
if err := s.loginRepo.BatchCreate(ctx, logs); err != nil {
|
|
470
|
+
s.logger.Error("flush login logs failed",
|
|
471
|
+
zap.Error(err),
|
|
472
|
+
zap.Int("count", len(logs)),
|
|
473
|
+
)
|
|
474
|
+
return err
|
|
475
|
+
}
|
|
476
|
+
s.logger.Debug("login logs flushed", zap.Int("count", len(logs)))
|
|
477
|
+
return nil
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// drainChannel 从 channel 中非阻塞读取最多 limit 条数据
|
|
481
|
+
func drainChannel[T any](ch <-chan T, limit int) []T {
|
|
482
|
+
var items []T
|
|
483
|
+
for {
|
|
484
|
+
select {
|
|
485
|
+
case item := <-ch:
|
|
486
|
+
items = append(items, item)
|
|
487
|
+
if len(items) >= limit {
|
|
488
|
+
return items
|
|
489
|
+
}
|
|
490
|
+
default:
|
|
491
|
+
return items
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// ---------------------------------------------------------------------------
|
|
497
|
+
// 转换函数:Entry → Model
|
|
498
|
+
// ---------------------------------------------------------------------------
|
|
499
|
+
|
|
500
|
+
// toAccessLog 将 AccessEntry 转换为 AccessLog。
|
|
501
|
+
func toAccessLog(e AccessEntry) *AccessLog {
|
|
502
|
+
return &AccessLog{
|
|
503
|
+
TraceID: e.TraceID,
|
|
504
|
+
RequestID: e.RequestID,
|
|
505
|
+
ActorType: e.ActorType,
|
|
506
|
+
ActorID: e.ActorID,
|
|
507
|
+
AuthSubjectType: e.AuthSubjectType,
|
|
508
|
+
IAMPrincipalID: e.IAMPrincipalID,
|
|
509
|
+
CredentialPublicID: e.CredentialPublicID,
|
|
510
|
+
TokenFingerprint: e.TokenFingerprint,
|
|
511
|
+
AuthMechanism: e.AuthMechanism,
|
|
512
|
+
ActorIP: e.ActorIP,
|
|
513
|
+
ActorUserAgent: e.ActorUserAgent,
|
|
514
|
+
HTTPMethod: e.HTTPMethod,
|
|
515
|
+
HTTPPath: e.HTTPPath,
|
|
516
|
+
HTTPStatus: e.HTTPStatus,
|
|
517
|
+
ProductCode: e.ProductCode,
|
|
518
|
+
ResourceType: e.ResourceType,
|
|
519
|
+
ResourceID: e.ResourceID,
|
|
520
|
+
IsSuccess: e.IsSuccess,
|
|
521
|
+
ErrorMessage: normalizeAuditErrorMessage(e.ErrorMessage),
|
|
522
|
+
DurationMS: e.DurationMS,
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// toAuditLog 将 AuditEntry 转换为 AuditLog(含 JSON 序列化)
|
|
527
|
+
func toAuditLog(e AuditEntry) *AuditLog {
|
|
528
|
+
log := &AuditLog{
|
|
529
|
+
TraceID: e.TraceID,
|
|
530
|
+
RequestID: e.RequestID,
|
|
531
|
+
ActorType: e.ActorType,
|
|
532
|
+
ActorID: e.ActorID,
|
|
533
|
+
AuthSubjectType: e.AuthSubjectType,
|
|
534
|
+
IAMPrincipalID: e.IAMPrincipalID,
|
|
535
|
+
CredentialPublicID: e.CredentialPublicID,
|
|
536
|
+
TokenFingerprint: e.TokenFingerprint,
|
|
537
|
+
AuthMechanism: e.AuthMechanism,
|
|
538
|
+
ActorIP: e.ActorIP,
|
|
539
|
+
ActorUserAgent: e.ActorUserAgent,
|
|
540
|
+
Action: e.Action,
|
|
541
|
+
Category: e.Category,
|
|
542
|
+
RiskLevel: e.RiskLevel,
|
|
543
|
+
ResourceType: e.ResourceType,
|
|
544
|
+
ResourceID: e.ResourceID,
|
|
545
|
+
ProductCode: e.ProductCode,
|
|
546
|
+
TenantID: e.TenantID,
|
|
547
|
+
IsSuccess: e.IsSuccess,
|
|
548
|
+
ErrorMessage: normalizeAuditErrorMessage(e.ErrorMessage),
|
|
549
|
+
}
|
|
550
|
+
if e.EventID != "" {
|
|
551
|
+
log.EventID = &e.EventID
|
|
552
|
+
}
|
|
553
|
+
if !e.OccurredAt.IsZero() {
|
|
554
|
+
occurredAt := e.OccurredAt.UTC()
|
|
555
|
+
log.OccurredAt = &occurredAt
|
|
556
|
+
}
|
|
557
|
+
if e.Changes != nil {
|
|
558
|
+
if b, err := json.Marshal(e.Changes); err == nil {
|
|
559
|
+
log.Changes = datatypes.JSON(b)
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if e.Metadata != nil {
|
|
563
|
+
if b, err := json.Marshal(e.Metadata); err == nil {
|
|
564
|
+
log.Metadata = datatypes.JSON(b)
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return log
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
// toOperationLog 将 BeginOperationEntry 转换为 OperationLog。
|
|
571
|
+
func toOperationLog(e BeginOperationEntry) *OperationLog {
|
|
572
|
+
return &OperationLog{
|
|
573
|
+
TraceID: e.TraceID,
|
|
574
|
+
RequestID: e.RequestID,
|
|
575
|
+
ActorType: e.ActorType,
|
|
576
|
+
ActorID: e.ActorID,
|
|
577
|
+
AuthSubjectType: e.AuthSubjectType,
|
|
578
|
+
IAMPrincipalID: e.IAMPrincipalID,
|
|
579
|
+
CredentialPublicID: e.CredentialPublicID,
|
|
580
|
+
TokenFingerprint: e.TokenFingerprint,
|
|
581
|
+
AuthMechanism: e.AuthMechanism,
|
|
582
|
+
ActorIP: e.ActorIP,
|
|
583
|
+
ActorUserAgent: e.ActorUserAgent,
|
|
584
|
+
OperationAction: e.OperationAction,
|
|
585
|
+
OperationCategory: e.OperationCategory,
|
|
586
|
+
RiskLevel: e.RiskLevel,
|
|
587
|
+
SourceModule: e.SourceModule,
|
|
588
|
+
HTTPMethod: e.HTTPMethod,
|
|
589
|
+
HTTPPath: e.HTTPPath,
|
|
590
|
+
ProductCode: e.ProductCode,
|
|
591
|
+
TenantID: e.TenantID,
|
|
592
|
+
ResourceType: e.ResourceType,
|
|
593
|
+
ResourceID: e.ResourceID,
|
|
594
|
+
IsSuccess: true,
|
|
595
|
+
RequestContext: normalizeOperationJSON(e.RequestContext),
|
|
596
|
+
ResponseContext: datatypes.JSON([]byte("{}")),
|
|
597
|
+
OperationMetadata: normalizeOperationJSON(e.OperationMetadata),
|
|
598
|
+
PolicyViolation: datatypes.JSON([]byte("{}")),
|
|
599
|
+
RecordStatus: operationRecordStatusStarted,
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
func normalizeOperationJSON(value datatypes.JSON) datatypes.JSON {
|
|
604
|
+
if len(value) == 0 {
|
|
605
|
+
return datatypes.JSON([]byte("{}"))
|
|
606
|
+
}
|
|
607
|
+
return value
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
func normalizeAuditErrorMessage(value string) string {
|
|
611
|
+
if value == "" {
|
|
612
|
+
return ""
|
|
613
|
+
}
|
|
614
|
+
runes := []rune(value)
|
|
615
|
+
if len(runes) <= auditErrorMessageMaxLength {
|
|
616
|
+
return value
|
|
617
|
+
}
|
|
618
|
+
const suffix = "..."
|
|
619
|
+
return string(runes[:auditErrorMessageMaxLength-len(suffix)]) + suffix
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// toLoginLog 将 LoginEntry 转换为 LoginLog(直接字段映射)
|
|
623
|
+
func toLoginLog(e LoginEntry) *LoginLog {
|
|
624
|
+
return &LoginLog{
|
|
625
|
+
IdentityID: e.IdentityID,
|
|
626
|
+
ActorType: e.ActorType,
|
|
627
|
+
ActorIP: e.ActorIP,
|
|
628
|
+
ActorUserAgent: e.ActorUserAgent,
|
|
629
|
+
LoginAction: e.LoginAction,
|
|
630
|
+
LoginMethod: e.LoginMethod,
|
|
631
|
+
IsSuccess: e.IsSuccess,
|
|
632
|
+
FailureReason: e.FailureReason,
|
|
633
|
+
ProductCode: e.ProductCode,
|
|
634
|
+
SessionID: e.SessionID,
|
|
635
|
+
RequestID: e.RequestID,
|
|
636
|
+
DeviceType: e.DeviceType,
|
|
637
|
+
DeviceFingerprint: e.DeviceFingerprint,
|
|
638
|
+
OSName: e.OSName,
|
|
639
|
+
BrowserName: e.BrowserName,
|
|
640
|
+
GeoCountry: e.GeoCountry,
|
|
641
|
+
GeoCity: e.GeoCity,
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// ---------------------------------------------------------------------------
|
|
646
|
+
// 查询服务实现
|
|
647
|
+
// ---------------------------------------------------------------------------
|
|
648
|
+
|
|
649
|
+
// auditQueryService 审计只读查询服务实现
|
|
650
|
+
type auditQueryService struct {
|
|
651
|
+
accessRepo AccessLogRepository
|
|
652
|
+
auditRepo AuditRepository
|
|
653
|
+
loginRepo LoginLogRepository
|
|
654
|
+
operationRepo OperationLogRepository
|
|
655
|
+
logger *zap.Logger
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// NewAuditQueryService 构建只读查询服务
|
|
659
|
+
func NewAuditQueryService(
|
|
660
|
+
accessRepo AccessLogRepository,
|
|
661
|
+
auditRepo AuditRepository,
|
|
662
|
+
loginRepo LoginLogRepository,
|
|
663
|
+
operationRepo OperationLogRepository,
|
|
664
|
+
logger *zap.Logger,
|
|
665
|
+
) AuditQueryService {
|
|
666
|
+
return &auditQueryService{
|
|
667
|
+
accessRepo: accessRepo,
|
|
668
|
+
auditRepo: auditRepo,
|
|
669
|
+
loginRepo: loginRepo,
|
|
670
|
+
operationRepo: operationRepo,
|
|
671
|
+
logger: logger.Named("AuditQueryService"),
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// ListAccessLogs 分页查询访问日志
|
|
676
|
+
func (s *auditQueryService) ListAccessLogs(ctx context.Context, req *AdminListAccessLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*AccessLog, int64, error) {
|
|
677
|
+
return s.accessRepo.FindByQuery(ctx, req, scope, principalID)
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// GetAccessLog 查询单条访问日志详情
|
|
681
|
+
func (s *auditQueryService) GetAccessLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*AccessLog, error) {
|
|
682
|
+
log, err := s.accessRepo.FindByID(ctx, id, scope, principalID)
|
|
683
|
+
if err != nil {
|
|
684
|
+
return nil, auditNotFoundOrError("access_log", id, err)
|
|
685
|
+
}
|
|
686
|
+
return log, nil
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// ListAuditLogs 分页查询审计日志
|
|
690
|
+
func (s *auditQueryService) ListAuditLogs(ctx context.Context, req *AdminListAuditLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*AuditLog, int64, error) {
|
|
691
|
+
return s.auditRepo.FindByQuery(ctx, req, scope, principalID)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// GetAuditLog 查询单条审计日志详情
|
|
695
|
+
func (s *auditQueryService) GetAuditLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*AuditLog, error) {
|
|
696
|
+
log, err := s.auditRepo.FindByID(ctx, id, scope, principalID)
|
|
697
|
+
if err != nil {
|
|
698
|
+
return nil, auditNotFoundOrError("audit_log", id, err)
|
|
699
|
+
}
|
|
700
|
+
return log, nil
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// ListOperationLogs 分页查询操作日志
|
|
704
|
+
func (s *auditQueryService) ListOperationLogs(ctx context.Context, req *AdminListOperationLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*OperationLog, int64, error) {
|
|
705
|
+
return s.operationRepo.FindByQuery(ctx, req, scope, principalID)
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// GetOperationLog 查询单条操作日志详情
|
|
709
|
+
func (s *auditQueryService) GetOperationLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*OperationLog, error) {
|
|
710
|
+
log, err := s.operationRepo.FindByID(ctx, id, scope, principalID)
|
|
711
|
+
if err != nil {
|
|
712
|
+
return nil, auditNotFoundOrError("operation_log", id, err)
|
|
713
|
+
}
|
|
714
|
+
return log, nil
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// ListLoginLogs 分页查询登录日志
|
|
718
|
+
func (s *auditQueryService) ListLoginLogs(ctx context.Context, req *AdminListLoginLogsRequest, scope iamscope.ScopeConstraint, principalID int64) ([]*LoginLog, int64, error) {
|
|
719
|
+
return s.loginRepo.FindByQuery(ctx, req, scope, principalID)
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// GetLoginLog 查询单条登录日志详情
|
|
723
|
+
func (s *auditQueryService) GetLoginLog(ctx context.Context, id int64, scope iamscope.ScopeConstraint, principalID int64) (*LoginLog, error) {
|
|
724
|
+
log, err := s.loginRepo.FindByID(ctx, id, scope, principalID)
|
|
725
|
+
if err != nil {
|
|
726
|
+
return nil, auditNotFoundOrError("login_log", id, err)
|
|
727
|
+
}
|
|
728
|
+
return log, nil
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
// CountFailedLoginsByIP 统计指定 IP 的失败登录次数
|
|
732
|
+
func (s *auditQueryService) CountFailedLoginsByIP(ctx context.Context, ip string, since time.Time) (int64, error) {
|
|
733
|
+
return s.loginRepo.CountFailedByIP(ctx, ip, since)
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// GetAuditStats 获取审计统计(按分类 + 风险级别汇总)
|
|
737
|
+
func (s *auditQueryService) GetAuditStats(ctx context.Context, from, to time.Time, scope iamscope.ScopeConstraint, principalID int64) (*StatsResponse, error) {
|
|
738
|
+
byCategory, err := s.auditRepo.CountByCategory(ctx, from, to, scope, principalID)
|
|
739
|
+
if err != nil {
|
|
740
|
+
s.logger.Error("count by category failed", zap.Error(err))
|
|
741
|
+
return nil, err
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
byRiskLevel, err := s.auditRepo.CountByRiskLevel(ctx, from, to, scope, principalID)
|
|
745
|
+
if err != nil {
|
|
746
|
+
s.logger.Error("count by risk level failed", zap.Error(err))
|
|
747
|
+
return nil, err
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
var total int64
|
|
751
|
+
for _, item := range byCategory {
|
|
752
|
+
total += item.Count
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
resp := &StatsResponse{
|
|
756
|
+
Total: total,
|
|
757
|
+
ByCategory: byCategory,
|
|
758
|
+
ByRiskLevel: byRiskLevel,
|
|
759
|
+
}
|
|
760
|
+
resp.Period.From = from
|
|
761
|
+
resp.Period.To = to
|
|
762
|
+
return resp, nil
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
func auditNotFoundOrError(resource string, id int64, err error) error {
|
|
766
|
+
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
767
|
+
return apierror.NotFound(resource, id)
|
|
768
|
+
}
|
|
769
|
+
return err
|
|
770
|
+
}
|