ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

authelia-gen docs data misc 命令详解:Authelia 文档站点 misc.json 数据文件的生成机制

authelia-gen docs data misc 命令详解:Authelia 文档站点 misc.json 数据文件的生成机制 authelia-gen docs data misc 命令详解Authelia 文档站点 misc.json 数据文件的生成机制【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/authelia本篇技术指南围绕 Authelia 仓库中的authelia-gen docs data misc命令展开讲解该命令如何为 Hugo 文档站点生成misc.json数据文件涵盖命令用法、全部参数、输出文件结构、数据来源以及文档站点中的消费方式。读者学完后将能理解 Authelia 文档构建工具链中数据生成 — 模板消费的完整链路并能按需定制生成路径与内容。命令定位authelia-gen 文档数据生成器的一员authelia-gen是 Authelia 仓库自带的 Go 代码/文档生成工具入口位于 cmd/authelia-gen/main.go其子命令体系由 Cobra 构建。docs data misc是其中负责生成杂项文档数据的命令authelia-gen docs生成各类文档见 authelia-gen_docs.mdauthelia-gen docs data生成文档数据文件见 authelia-gen_docs_data.mdauthelia-gen docs data misc生成misc.json文档数据文件authelia-gen docs data keys生成配置键数据文件configkeys.json。在源码中newDocsDataCmd()将misc与keys两个子命令同时挂载到data命令之下见 cmd/authelia-gen/cmd_docs_data.go。命令用法与选项基本语法authelia-gen docs data misc [flags]本命令专属选项-h, --help help for misc从父命令继承的选项以下选项由docs data、docs及根命令authelia-gen逐级继承而来misc子命令可直接使用。其中与misc.json生成强相关的选项是-C/--cwd、-d/--dir.root、--dir.docs.data、--file.docs.data.misc、--dir.web与--file.web.package-C, --cwd string Sets the CWD for git commands --dir.authentication string The authentication directory in relation to the root (default internal/authentication) --dir.docs string The directory with the docs (default docs) --dir.docs.adr string The directory with the ADR data (default reference/architecture-decision-log) --dir.docs.cli-reference string The directory to store the markdown in (default reference/cli) --dir.docs.content string The directory with the docs content (default content) --dir.docs.data string The directory with the docs data (default data) --dir.docs.static string The directory with the docs static files (default static) --dir.docs.static.json-schemas string The directory with the docs static JSONSchema files (default schemas) --dir.locales string The locales directory in relation to the root (default internal/server/locales) -d, --dir.root string The repository root (default ./) --dir.schema string The schema directory in relation to the root (default internal/configuration/schema) --dir.web string The repository web directory in relation to the root directory (default web) -X, --exclude strings Sets the names of excluded generators --file.bug-report string Sets the path of the bug report issue template file (default .github/ISSUE_TEMPLATE/bug-report.yml) --file.commit-lint-config string The commit lint javascript configuration file in relation to the root (default commitlint.config.mjs) --file.configuration-keys string Sets the path of the keys file (default internal/configuration/schema/keys.go) --file.docs-commit-msg-guidelines string The commit message guidelines documentation file in relation to the root (default docs/content/contributing/guidelines/commit-message.md) --file.docs.data.keys string Sets the path of the docs keys file (default configkeys.json) --file.docs.data.languages string The languages docs data file in relation to the docs data folder (default languages.json) --file.docs.data.misc string The misc docs data file in relation to the docs data folder (default misc.json) --file.docs.static.json-schemas.configuration string Sets the path of the configuration JSONSchema (default configuration) --file.docs.static.json-schemas.exports.identifiers string Sets the path of the identifiers export JSONSchema (default exports.identifiers) --file.docs.static.json-schemas.exports.totp string Sets the path of the TOTP export JSONSchema (default exports.totp) --file.docs.static.json-schemas.exports.webauthn string Sets the path of the WebAuthn export JSONSchema (default exports.webauthn) --file.docs.static.json-schemas.user-database string Sets the path of the user database JSONSchema (default user-database) --file.feature-request string Sets the path of the feature request issue template file (default .github/ISSUE_TEMPLATE/feature-request.yml) --file.scripts.gen string Sets the path of the authelia-scripts gen file (default cmd/authelia-scripts/cmd/gen.go) --file.server.generated string Sets the path of the server generated file (default internal/server/gen.go) --file.web.i18n string The i18n typescript configuration file in relation to the web directory (default src/i18n/index.ts) --file.web.package string The node package configuration file in relation to the web directory (default package.json) --latest Enables latest functionality with several generators like the JSON Schema generator --next Enables next functionality with several generators like the JSON Schema generator --package.configuration.keys string Sets the package name of the keys file (default schema) --package.scripts.gen string Sets the package name of the authelia-scripts gen file (default cmd) --version-count int the maximum number of minor versions to list in output templates (default 5) --versions strings The versions to run the generator for, the special versions current and next are mutually exclusive这些 flag 的常量名如cmdFlagDocsDataMisc、cmdFlagDocsData、cmdFlagRoot统一定义在 cmd/authelia-gen/const.go 中并注册于根命令 cmd/authelia-gen/cmd_root.go。输出文件docs/data/misc.json 的结构详解命令默认将结果写入docs/data/misc.json。该文件是 Authelia 文档站点的全局数据源当前内容如下摘录自仓库 docs/data/misc.json{ csp: { default: default-src self; base-uri self; connect-src self; frame-ancestors none; frame-src none; object-src none; script-src self; style-src self nonce-${NONCE}, development: default-src self unsafe-eval; base-uri self; frame-ancestors none; frame-src none; object-src none; style-src self nonce-${NONCE}, nonce: ${NONCE} }, latest: 4.39.24, support: { traefik: [ v3.7.13, v2.11.57 ] }, hashing_algorithms: { pbkdf2: { variants: { sha1: { fips: Approved only for Legacy Systems, default_iterations: 1600000 }, sha224: { fips: Approved, default_iterations: 900000 }, sha256: { fips: Approved, default_iterations: 700000 }, sha384: { fips: Approved (Recommended), default_iterations: 280000 }, sha512: { fips: Approved, default_iterations: 310000 } } } } }四个顶层键对应数据结构DocsDataMisc定义于 cmd/authelia-gen/types.goJSON 键类型含义cspTemplateCSP文档站点的 Content-Security-Policy 模板default/development及 nonce 占位符lateststring当前最新版本号supportDocsDataMiscSupport官方支持的第三方组件及版本目前为 Traefik 版本列表hashing_algorithmsDocsDataMiscHashingAlgorithmsPBKDF2 各哈希变体的 FIPS 状态与默认迭代次数生成流程四类数据的来源与底层实现docsDataMiscRunE是misc子命令的执行函数位于 cmd/authelia-gen/cmd_docs_data.go。它按以下步骤组装数据并写出 JSON1. CSP 模板由代码常量拼装CSP 模板并非写死在 JSON 中而是由代码常量动态构建codeCSPSelfself、codeCSPNonenone、codeCSPNonce${NONCE}以及codeCSPValuesCommon/codeCSPValuesProduction/codeCSPValuesDevelopment等指令集定义于 cmd/authelia-gen/const.gobuildCSP()将指令集合并、去重并把default-src固定排序到最前最终以;拼接为完整策略实现见 cmd/authelia-gen/helpers.go拼装后的字符串再通过strings.ReplaceAll(..., %s, codeCSPNonce)将style-src中的%s替换为${NONCE}占位符见cmd_docs_data.go第 56-57 行。因此misc.json中的csp.default代表生产环境的严格 CSPcsp.development额外放行unsafe-eval以便前端开发调试。这套模板同样被authelia-gen code server见 cmd/authelia-gen/cmd_code.go与 JSON Schema 生成器cmd/authelia-gen/cmd_docs_jsonschema.go复用体现了单一事实来源的设计。2. latest 版本号读取 web/package.jsonreadVersion()依据--dir.root、--dir.web、--file.web.package三个 flag 拼接出web/package.json的路径并解析其version字段实现见 cmd/authelia-gen/helpers.go。这保证了文档中展示的最新版本始终与前端包版本保持同步。3. support.traefik解析套件 compose 文件的镜像标签readComposeTag()读取internal/suites/example/compose/traefik/compose.v3.yml与compose.v2.yml默认路径见 internal/suites/example/compose/traefik/compose.v3.yml从中提取traefik服务的镜像标签如traefik:v3.7.13中的v3.7.13实现见 cmd/authelia-gen/helpers.go。也就是说文档所声明的受支持 Traefik 版本直接来源于自动化测试套件实际使用的镜像版本二者不会脱节。4. hashing_algorithms引用配置 Schema 的权威默认值PBKDF2 各变体的default_iterations并非硬编码在生成器中而是调用schema.PBKDF2VariantDefaultIterations(variant)获取该函数定义于 internal/configuration/schema/util.go其默认值由 internal/configuration/schema 包内的常量defaultIterationsPBKDF2SHA512等维护。每个变体的 FIPS 状态标注Approved、Approved (Recommended)、Approved only for Legacy Systems同样在此处写入。相关默认迭代次数有单元测试覆盖见 internal/configuration/schema/util_test.go。输出写入最终输出路径由getPFlagPath(cmd.Flags(), cmdFlagRoot, cmdFlagDocs, cmdFlagDocsData, cmdFlagDocsDataMisc)拼接得到默认即docs/data/misc.json随后以0600权限创建/截断文件并通过带两级缩进的 JSON Encoder 写出见cmd_docs_data.go第 94-118 行。数据消费端Hugo Shortcode 如何读取 misc.jsonmisc.json存放在docs/data/目录下Hugo 会自动将其加载为全局数据hugo.Data.misc。仓库中的 shortcode 直接消费这些字段例如docs/layouts/_shortcodes/csp.html输出hugo.Data.misc.csp.nonce、hugo.Data.misc.csp.default用于文档页展示 CSP 模板docs/layouts/_shortcodes/latest.html输出hugo.Data.misc.latest自动显示最新版本号docs/layouts/_shortcodes/github-link.html以v{{ hugo.Data.misc.latest }}拼接分支名生成指向对应版本源码的链接docs/layouts/_shortcodes/hashing-pbkdf2-iterations.html 与 docs/layouts/_shortcodes/hashing-pbkdf2-variants.html遍历hugo.Data.misc.hashing_algorithms.pbkdf2.variants自动渲染 PBKDF2 各变体的默认迭代次数与 FIPS 状态表格。正是这种代码常量/配置文件 → 生成器 →misc.json→ Hugo 数据 → 页面渲染的链路保证了文档中版本号、支持矩阵与安全参数始终与仓库真实状态一致避免了手工维护文档造成的漂移。常见使用场景全量重建文档数据在仓库根目录直接执行authelia-gen docs data misc即可按默认路径重新生成docs/data/misc.json指定仓库根目录在仓库外部执行时通过-d /path/to/authelia指定根目录所有相对路径 flag 均以该根目录为基准调整输出位置通过--dir.docs.data与--file.docs.data.misc组合改变输出目录与文件名联动其他生成器misc通常与docs data keys、docs cli等命令配合使用共同产出文档站点所需的完整数据文件。相关命令misc命令的上一级命令为authelia-gen docs data见 authelia-gen_docs_data.md后者同时包含keys子命令生成configkeys.json。若需查看authelia-gen的完整命令树可参考 authelia-gen.md 及其他docs/content/reference/cli/authelia-gen/目录下的命令参考文档。【免费下载链接】autheliaThe Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready.项目地址: https://gitcode.com/GitHub_Trending/au/authelia创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表