{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anguskit.com/schema/anguscopilot/1.0.0/credentials.json",
  "title": "Credentials Section",
  "description": "凭证引用映射。YAML 中绝不允许明文密钥；本节仅声明引用，由 CredentialBroker 在运行时解析。W12 增量字段：rotation 详细配置 + rbacGate（凭证守门员）。",
  "type": "object",
  "minProperties": 0,
  "additionalProperties": {
    "type": "object",
    "required": ["secretRef"],
    "properties": {
      "secretRef": {
        "description": "凭证引用（强制 vault: / env: / aws: / aliyun: / gcp: / azure: / file: 前缀）。 [stable]",
        "$ref": "common.json#/$defs/SecretRef"
      },
      "type": {
        "description": "凭证类型，提示 CredentialBroker 如何解析。 [stable]",
        "type": "string",
        "enum": ["api-key", "bearer-token", "oauth2", "basic-auth", "mtls", "kubeconfig", "custom"],
        "default": "api-key"
      },
      "ttl": {
        "description": "凭证短时缓存 TTL，到期自动重新解析。 [stable]",
        "$ref": "common.json#/$defs/Duration"
      },
      "backend": {
        "description": "凭证后端（W12 新增；与 §4.11.1 对齐）。 [beta]",
        "type": "string",
        "enum": ["vault", "env", "aws", "aliyun", "gcp", "azure", "file"]
      },
      "rotationPolicy": {
        "description": "[deprecated W12] 旧字段；建议改用 rotation 子段。 [stable]",
        "type": "string",
        "enum": ["none", "auto", "manual"],
        "default": "none"
      },
      "rotation": {
        "description": "凭证轮转详细配置（W12 新增；与 §4.11.3 对齐）。 [beta]",
        "type": "object",
        "properties": {
          "enabled": { "type": "boolean", "default": false },
          "gracePeriod": {
            "description": "轮转后旧凭证保留的过渡期（E11 约束：enabled=true 时必须 ≥ 30s）。 [beta]",
            "$ref": "common.json#/$defs/Duration",
            "default": "60s"
          },
          "interval": {
            "description": "自动轮转周期（仅当后端支持自动轮转时生效）。 [beta]",
            "$ref": "common.json#/$defs/Duration"
          }
        },
        "patternProperties": { "^x-": true },
        "$comment": "E11 跨字段约束：enabled=true 时 gracePeriod 必填，且必须表达 ≥ 30 秒（接受 30s+ / 任意分/时/日 / ISO PT30S+ 等格式）。",
        "if": {
          "properties": { "enabled": { "const": true } },
          "required": ["enabled"]
        },
        "then": {
          "required": ["gracePeriod"],
          "properties": {
            "gracePeriod": {
              "type": "string",
              "pattern": "^(?:[3-9][0-9]s|[1-9][0-9]{2,}s|[1-9][0-9]*[mhd]|PT(?:[1-9][0-9]*H|[1-9][0-9]*M|(?:[3-9][0-9]|[1-9][0-9]{2,})S))$"
            }
          }
        },
        "unevaluatedProperties": false
      },
      "rbacGate": {
        "description": "凭证守门员（W12 新增；与 §4.11.4 对齐）。 [beta]",
        "type": "object",
        "properties": {
          "allowedAgents": {
            "description": "允许使用本凭证的 Agent 名单（E12 约束：每项必须符合 Identifier 模式）。 [beta]",
            "type": "array",
            "items": { "$ref": "common.json#/$defs/Identifier" },
            "uniqueItems": true
          },
          "deniedAgents": {
            "description": "拒绝使用本凭证的 Agent 名单。 [beta]",
            "type": "array",
            "items": { "$ref": "common.json#/$defs/Identifier" },
            "uniqueItems": true
          },
          "requiredRoles": {
            "description": "调用方必须具备的角色集合。 [beta]",
            "type": "array",
            "items": { "type": "string", "minLength": 1 },
            "uniqueItems": true
          }
        },
        "patternProperties": { "^x-": true },
        "unevaluatedProperties": false
      }
    },
    "patternProperties": { "^x-": true },
    "unevaluatedProperties": false
  },
  "propertyNames": {
    "$ref": "common.json#/$defs/Identifier"
  }
}
