|
1 | 1 | # Enterprise API Layer |
2 | 2 |
|
3 | | -Direct REST access to the Redis Enterprise API. |
| 3 | +Direct REST access to the Redis Enterprise API for scripting and automation. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -The API layer provides raw access to all Redis Enterprise REST endpoints. Use this for: |
8 | | -- Scripting and automation |
9 | | -- Accessing endpoints not yet wrapped in human commands |
10 | | -- CI/CD pipelines |
| 7 | +The API layer lets you call any Redis Enterprise REST endpoint directly. It's like a smart curl with: |
| 8 | +- Automatic authentication |
| 9 | +- Profile support |
| 10 | +- Output formatting |
| 11 | +- SSL handling |
11 | 12 |
|
12 | | -## Authentication |
| 13 | +## Usage |
13 | 14 |
|
14 | | -Uses Basic auth (username/password). Configure via profile or environment variables. |
| 15 | +```bash |
| 16 | +redisctl api enterprise <method> <endpoint> [options] |
| 17 | +``` |
15 | 18 |
|
16 | | -## Usage |
| 19 | +**Methods:** `get`, `post`, `put`, `delete` |
| 20 | + |
| 21 | +## Examples |
| 22 | + |
| 23 | +### GET Requests |
17 | 24 |
|
18 | 25 | ```bash |
19 | | -# GET request |
| 26 | +# Cluster info |
20 | 27 | redisctl api enterprise get /v1/cluster |
21 | 28 |
|
22 | | -# POST request with data |
23 | | -redisctl api enterprise post /v1/bdbs -d '{"name": "test", ...}' |
| 29 | +# List nodes |
| 30 | +redisctl api enterprise get /v1/nodes |
| 31 | + |
| 32 | +# List databases |
| 33 | +redisctl api enterprise get /v1/bdbs |
| 34 | + |
| 35 | +# Get specific database |
| 36 | +redisctl api enterprise get /v1/bdbs/1 |
| 37 | + |
| 38 | +# Get users |
| 39 | +redisctl api enterprise get /v1/users |
| 40 | +``` |
| 41 | + |
| 42 | +### POST Requests |
| 43 | + |
| 44 | +```bash |
| 45 | +# Create database |
| 46 | +redisctl api enterprise post /v1/bdbs -d '{ |
| 47 | + "name": "mydb", |
| 48 | + "memory_size": 1073741824 |
| 49 | +}' |
| 50 | + |
| 51 | +# Create user |
| 52 | +redisctl api enterprise post /v1/users -d @user.json |
| 53 | +``` |
| 54 | + |
| 55 | +### PUT Requests |
| 56 | + |
| 57 | +```bash |
| 58 | +# Update database |
| 59 | +redisctl api enterprise put /v1/bdbs/1 -d '{ |
| 60 | + "memory_size": 2147483648 |
| 61 | +}' |
| 62 | + |
| 63 | +# Update cluster |
| 64 | +redisctl api enterprise put /v1/cluster -d '{"name": "new-name"}' |
| 65 | +``` |
24 | 66 |
|
25 | | -# PUT request |
26 | | -redisctl api enterprise put /v1/bdbs/1 -d '{"name": "updated"}' |
| 67 | +### DELETE Requests |
27 | 68 |
|
28 | | -# DELETE request |
| 69 | +```bash |
| 70 | +# Delete database |
29 | 71 | redisctl api enterprise delete /v1/bdbs/1 |
| 72 | + |
| 73 | +# Remove node |
| 74 | +redisctl api enterprise delete /v1/nodes/3 |
30 | 75 | ``` |
31 | 76 |
|
| 77 | +## Options |
| 78 | + |
| 79 | +| Option | Description | |
| 80 | +|--------|-------------| |
| 81 | +| `-d, --data <JSON>` | Request body (inline or @file) | |
| 82 | +| `-o, --output <FORMAT>` | Output format (json, yaml, table) | |
| 83 | +| `-q, --query <JMESPATH>` | Filter output | |
| 84 | + |
32 | 85 | ## Common Endpoints |
33 | 86 |
|
34 | | -- `/v1/cluster` - Cluster information |
35 | | -- `/v1/nodes` - Node management |
36 | | -- `/v1/bdbs` - Database operations |
37 | | -- `/v1/users` - User management |
38 | | -- `/v1/roles` - Role management |
| 87 | +### Cluster |
| 88 | +- `GET /v1/cluster` - Cluster info |
| 89 | +- `PUT /v1/cluster` - Update cluster |
| 90 | +- `GET /v1/cluster/stats/last` - Cluster stats |
| 91 | +- `GET /v1/cluster/certificates` - Certificates |
| 92 | + |
| 93 | +### Nodes |
| 94 | +- `GET /v1/nodes` - List nodes |
| 95 | +- `GET /v1/nodes/{id}` - Get node |
| 96 | +- `PUT /v1/nodes/{id}` - Update node |
| 97 | +- `DELETE /v1/nodes/{id}` - Remove node |
| 98 | +- `GET /v1/nodes/{id}/stats/last` - Node stats |
| 99 | + |
| 100 | +### Databases |
| 101 | +- `GET /v1/bdbs` - List databases |
| 102 | +- `POST /v1/bdbs` - Create database |
| 103 | +- `GET /v1/bdbs/{id}` - Get database |
| 104 | +- `PUT /v1/bdbs/{id}` - Update database |
| 105 | +- `DELETE /v1/bdbs/{id}` - Delete database |
| 106 | +- `GET /v1/bdbs/{id}/stats/last` - Database stats |
| 107 | + |
| 108 | +### Users & Roles |
| 109 | +- `GET /v1/users` - List users |
| 110 | +- `POST /v1/users` - Create user |
| 111 | +- `GET /v1/roles` - List roles |
| 112 | +- `GET /v1/redis_acls` - List ACLs |
| 113 | + |
| 114 | +### Active-Active |
| 115 | +- `GET /v1/crdbs` - List CRDBs |
| 116 | +- `POST /v1/crdbs` - Create CRDB |
| 117 | +- `GET /v1/crdb_tasks` - List tasks |
| 118 | + |
| 119 | +### Logs & Alerts |
| 120 | +- `GET /v1/logs` - Get logs |
| 121 | +- `GET /v1/cluster/alerts` - Get alerts |
| 122 | + |
| 123 | +### Debug & Support |
| 124 | +- `GET /v1/debuginfo/all` - Full debug info (binary) |
| 125 | +- `GET /v1/debuginfo/node/{id}` - Node debug info |
| 126 | + |
| 127 | +## Scripting Examples |
| 128 | + |
| 129 | +### Export Cluster Config |
| 130 | + |
| 131 | +```bash |
| 132 | +# Save cluster configuration |
| 133 | +redisctl api enterprise get /v1/cluster > cluster-config.json |
| 134 | +redisctl api enterprise get /v1/bdbs > databases.json |
| 135 | +redisctl api enterprise get /v1/users > users.json |
| 136 | +``` |
| 137 | + |
| 138 | +### Bulk Database Creation |
| 139 | + |
| 140 | +```bash |
| 141 | +# Create multiple databases |
| 142 | +for name in cache sessions analytics; do |
| 143 | + redisctl api enterprise post /v1/bdbs -d "{ |
| 144 | + \"name\": \"$name\", |
| 145 | + \"memory_size\": 1073741824 |
| 146 | + }" |
| 147 | +done |
| 148 | +``` |
| 149 | + |
| 150 | +### Health Check |
| 151 | + |
| 152 | +```bash |
| 153 | +#!/bin/bash |
| 154 | +# Check cluster health via API |
| 155 | + |
| 156 | +CLUSTER=$(redisctl api enterprise get /v1/cluster) |
| 157 | +STATUS=$(echo $CLUSTER | jq -r '.status') |
| 158 | + |
| 159 | +if [ "$STATUS" != "active" ]; then |
| 160 | + echo "Cluster unhealthy: $STATUS" |
| 161 | + exit 1 |
| 162 | +fi |
| 163 | + |
| 164 | +# Check nodes |
| 165 | +NODES=$(redisctl api enterprise get /v1/nodes -q '[].{id:uid,status:status}') |
| 166 | +echo "Nodes: $NODES" |
| 167 | +``` |
| 168 | + |
| 169 | +### Watch Stats |
| 170 | + |
| 171 | +```bash |
| 172 | +# Poll stats every 5 seconds |
| 173 | +while true; do |
| 174 | + redisctl api enterprise get /v1/cluster/stats/last \ |
| 175 | + -q '{cpu:cpu_user,memory:free_memory}' |
| 176 | + sleep 5 |
| 177 | +done |
| 178 | +``` |
| 179 | + |
| 180 | +## Binary Responses |
| 181 | + |
| 182 | +Some endpoints return binary data (tar.gz): |
| 183 | + |
| 184 | +```bash |
| 185 | +# Download debug info |
| 186 | +redisctl api enterprise get /v1/debuginfo/all --output debug.tar.gz |
| 187 | +``` |
| 188 | + |
| 189 | +## When to Use API Layer |
| 190 | + |
| 191 | +**Use API layer when:** |
| 192 | +- Endpoint isn't wrapped in human commands |
| 193 | +- You need exact control over the request |
| 194 | +- Building automation scripts |
| 195 | +- Exploring the API |
| 196 | + |
| 197 | +**Use human commands when:** |
| 198 | +- There's a command for what you need |
| 199 | +- You want ergonomic flags |
| 200 | +- You prefer structured output |
| 201 | + |
| 202 | +## API Documentation |
39 | 203 |
|
40 | | -TODO: Move detailed content from enterprise/api-access.md |
| 204 | +The cluster provides built-in API docs at: |
| 205 | +`https://your-cluster:9443/v1/swagger-ui/index.html` |
0 commit comments