← 返回 Skills 市场
jonasgao

Consul API

作者 JonasGao · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
112
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install consul-api
功能描述
Consul HTTP API operations for service discovery, key-value store, health checks, and service mesh management. Use when working with Consul clusters for: (1)...
使用说明 (SKILL.md)

Consul API

HashiCorp Consul HTTP API 操作指南。提供服务发现、KV 存储、健康检查和服务网格管理能力。

Quick Start

Base URL: http://127.0.0.1:8500/v1/

认证方式:

# 方式 1: X-Consul-Token header (推荐)
curl -H "X-Consul-Token: \x3Ctoken>" http://127.0.0.1:8500/v1/agent/members

# 方式 2: Bearer token
curl -H "Authorization: Bearer \x3Ctoken>" http://127.0.0.1:8500/v1/agent/members

常用查询参数:

  • dc - 指定数据中心
  • ns - 指定命名空间 (Enterprise)
  • pretty - 格式化 JSON 输出
  • wait=\x3Cduration> - 阻塞查询等待时间
  • index=\x3Cnum> - 阻塞查询索引

Service Discovery (Catalog)

列出所有服务

GET /catalog/services
GET /catalog/services?dc=dc1

返回: {"service-name": ["tag1", "tag2"], ...}

查询服务的所有实例

GET /catalog/service/:service_name
GET /catalog/service/redis?dc=dc1&ns=default

列出所有节点

GET /catalog/nodes
GET /catalog/nodes?near=_agent

注册服务

PUT /catalog/register
{
  "Node": "node1",
  "Address": "192.168.1.1",
  "Service": {
    "Service": "redis",
    "ID": "redis-1",
    "Tags": ["primary", "v1"],
    "Address": "127.0.0.1",
    "Port": 6379
  }
}

注销服务

PUT /catalog/deregister
{
  "Node": "node1",
  "ServiceID": "redis-1"
}

Key-Value Store

读取 KV

GET /kv/:key              # 单个 key
GET /kv/:prefix?recurse   # 递归读取前缀下所有 key
GET /kv/:prefix?keys      # 只返回 key 列表
GET /kv/:key?raw          # 返回原始值 (text/plain)

返回值是 base64 编码,需解码:

curl -s http://127.0.0.1:8500/v1/kv/my-key | jq -r '.[0].Value' | base64 -d

写入 KV

PUT /kv/:key
PUT /kv/:key?flags=123    # 附加 flags
PUT /kv/:key?cas=100      # Check-And-Set (乐观锁)

curl -X PUT -d 'my value' http://127.0.0.1:8500/v1/kv/my-key

删除 KV

DELETE /kv/:key           # 删除单个 key
DELETE /kv/:prefix?recurse  # 删除前缀下所有 key
DELETE /kv/:key?cas=100   # Check-And-Set 删除

分布式锁

# 获取锁
PUT /kv/:key?acquire=\x3Csession-id>

# 释放锁
PUT /kv/:key?release=\x3Csession-id>

Health Checks

查询节点健康状态

GET /health/node/:node

查询服务的健康检查

GET /health/checks/:service
GET /health/checks/redis?passing  # 只返回 passing 状态

查询健康的服务实例

GET /health/service/:service
GET /health/service/redis?passing  # 只返回健康实例

按状态查询

GET /health/state/passing
GET /health/state/warning
GET /health/state/critical
GET /health/state/any

健康状态: passing, warning, critical

ACL (Access Control)

创建 Token

PUT /acl/create
{
  "Name": "my-token",
  "Type": "client",
  "Rules": "key \"secret/\" { policy = \"read\" }"
}

列出 Tokens

GET /acl/list
GET /acl/token/self  # 当前 token 信息

读取/更新 Token

GET /acl/token/:accessor_id
PUT /acl/token/:accessor_id

Agent Operations

查看 Agent 成员

GET /agent/members

查看 Agent 自身信息

GET /agent/self

查看本地服务

GET /agent/services
GET /agent/service/:service_id

注册服务 (Agent 端点)

PUT /agent/service/register
{
  "Name": "redis",
  "ID": "redis-1",
  "Tags": ["primary"],
  "Address": "127.0.0.1",
  "Port": 6379,
  "Check": {
    "HTTP": "http://localhost:6379/health",
    "Interval": "10s"
  }
}

注销服务 (Agent 端点)

PUT /agent/service/deregister/:service_id

Service Mesh (Connect)

查询 Connect 服务

GET /catalog/connect/:service
GET /health/connect/:service?passing

查询 Ingress Gateway

GET /health/ingress/:service

服务意图 (Intentions)

GET /connect/intentions
POST /connect/intention
{
  "SourceName": "web",
  "DestinationName": "db",
  "Action": "allow"
}
DELETE /connect/intention/:id

Sessions (分布式锁)

创建 Session

PUT /session/create
{
  "Name": "my-lock",
  "TTL": "30s",
  "Behavior": "delete"
}

返回: {"ID": "session-uuid"}

查询 Session

GET /session/info/:session-id
GET /session/node/:node

销毁 Session

PUT /session/destroy/:session-id

Transactions

原子操作多个 KV 或 Catalog 操作:

PUT /txn
[
  {"KV": {"Verb": "set", "Key": "key1", "Value": "dGVzdA=="}},
  {"KV": {"Verb": "get", "Key": "key2"}},
  {"Service": {"Verb": "register", "Service": {...}}}
]

支持的 Verb:

  • KV: set, get, delete, check-index, lock, unlock
  • Service: register, deregister

Blocking Queries

使用 indexwait 实现长轮询:

# 等待 key 变化
GET /kv/my-key?index=100
GET /kv/my-key?wait=5m&index=100

响应头 X-Consul-Index 返回当前索引。

Error Handling

常见 HTTP 状态码:

  • 200 - 成功
  • 404 - 资源不存在
  • 400 - 请求格式错误
  • 403 - ACL 权限不足
  • 500 - 服务器错误

响应头:

  • X-Consul-Index - 当前状态索引
  • X-Consul-KnownLeader - 是否有已知 leader
  • X-Consul-LastContact - 最后联系 leader 的时间
  • X-Consul-Default-ACL-Policy - 默认 ACL 策略

References

For detailed API specifications, see:

安全使用建议
This is a documentation-only skill describing the Consul HTTP API. It is internally consistent, but note: many of the shown endpoints (ACL bootstrap, token creation, service deregistration) are powerful and require appropriate Consul tokens — only provide such tokens to trusted code or users. The skill itself does not request credentials, so if you plan to use it interactively or have an agent perform calls, ensure the agent is only given least-privilege Consul tokens and that network access is limited to the intended Consul cluster (avoid exposing tokens to untrusted networks or agents).
功能分析
Type: OpenClaw Skill Name: consul-api Version: 1.0.0 The consul-api skill bundle provides a comprehensive guide for an AI agent to interact with the HashiCorp Consul HTTP API. It includes instructions for service discovery, KV store operations, health checks, and ACL management. The content in SKILL.md and references/api-reference.md consists of standard API documentation and examples using curl against a local Consul agent (127.0.0.1:8500). There is no evidence of malicious intent, data exfiltration, or prompt injection.
能力评估
Purpose & Capability
The name/description match the content: the SKILL.md and api-reference provide Consul HTTP API endpoints and examples. There are no unrelated environment variables, binaries, or installs requested that would be unexpected for a Consul API helper.
Instruction Scope
The instructions are a reference/specification and only show example HTTP endpoints and curl headers (X-Consul-Token / Authorization). They do not direct the agent to read local files, access unrelated services, or exfiltrate data. The doc includes administrative endpoints (ACL, bootstrap, deregister) which are legitimately part of Consul's API.
Install Mechanism
No install spec and no code files — this is instruction-only, so nothing will be fetched or written to disk during install. Lowest-risk install posture.
Credentials
The skill declares no required environment variables or credentials. The documentation shows how Consul tokens are used (X-Consul-Token / Bearer) but does not request or store any credentials itself. This is proportionate for an API reference.
Persistence & Privilege
always:false and no install actions; the skill does not request persistent privileges or modify other skills. Autonomous invocation is allowed (platform default) but is not combined with any other elevated privileges here.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install consul-api
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /consul-api 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release - HTTP API reference for Consul service discovery, KV store, health checks, and service mesh
元数据
Slug consul-api
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Consul API 是什么?

Consul HTTP API operations for service discovery, key-value store, health checks, and service mesh management. Use when working with Consul clusters for: (1)... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 112 次。

如何安装 Consul API?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install consul-api」即可一键安装,无需额外配置。

Consul API 是免费的吗?

是的,Consul API 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Consul API 支持哪些平台?

Consul API 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Consul API?

由 JonasGao(@jonasgao)开发并维护,当前版本 v1.0.0。

💬 留言讨论