Skip to content

Commit 7b3ca7e

Browse files
bercianordieppa
authored andcommitted
feat: allow cli to connect to a couchbase auditstore (#726)
1 parent f69dc74 commit 7b3ca7e

File tree

16 files changed

+517
-94
lines changed

16 files changed

+517
-94
lines changed

cli/flamingock-cli/CLI-README.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ After building, `flamingock-cli-dist/` contains:
7676
- **`flamingock-cli.jar`** - Self-contained executable JAR with all dependencies
7777
- **`flamingock`** - Unix/Linux/macOS executable shell script
7878
- **`flamingock.bat`** - Windows executable batch file
79-
- **`flamingock.yml`** - Sample configuration file
79+
- **`flamingock-cli.yml`** - Sample configuration file
8080

8181
## Configuration
8282

@@ -115,9 +115,22 @@ flamingock:
115115
# secret-key: "your-secret" # Optional, uses AWS credential chain
116116
```
117117

118+
### Couchbase Example
119+
```yaml
120+
flamingock:
121+
service-identifier: "flamingock-cli"
122+
audit:
123+
couchbase:
124+
endpoint: "http://localhost:8000"
125+
username: "your-username"
126+
password: "your-password"
127+
bucket-name: "test"
128+
table: "flamingockAuditLog" # Optional, defaults to "flamingockAuditLog"
129+
```
130+
118131
### Configuration File Resolution
119132
1. Command line argument: `--config /path/to/file.yml`
120-
2. Default: `flamingock.yml` in current directory
133+
2. Default: `flamingock-cli.yml` in bin directory
121134

122135
## Architecture
123136

@@ -144,6 +157,7 @@ client.markAsRolledBack(changeId);
144157
### Database Support
145158
- **MongoDB**: Uses MongoDB Sync driver (not Spring Data)
146159
- **DynamoDB**: Uses AWS SDK v2
160+
- **Couchbase**: Uses Couchbase driver v3.7.3
147161
- **Auto-detection**: Based on YAML configuration structure
148162
- **Validation**: Connection testing during client creation
149163

@@ -179,12 +193,12 @@ Uses SLF4J with simple implementation for clean, professional output.
179193
## Build System Integration
180194

181195
### Gradle Tasks
182-
| Task | Description |
183-
|------|-------------|
184-
| `:cli:flamingock-cli:build` | Full build with distribution |
185-
| `:cli:flamingock-cli:uberJar` | Create self-contained JAR only |
196+
| Task | Description |
197+
|--------------------------------------------|----------------------------------|
198+
| `:cli:flamingock-cli:build` | Full build with distribution |
199+
| `:cli:flamingock-cli:uberJar` | Create self-contained JAR only |
186200
| `:cli:flamingock-cli:generateDistribution` | Generate executable scripts only |
187-
| `:cli:flamingock-cli:clean` | Remove all CLI artifacts |
201+
| `:cli:flamingock-cli:clean` | Remove all CLI artifacts |
188202

189203
### Automatic Distribution
190204
The build process automatically:

cli/flamingock-cli/CLI_SPECIFICATION.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ flamingock [command] [operation] [options]
88

99
## General Principles
1010

11-
- The CLI is **lightweight**:
12-
- It only builds an `OpsClient` via the `OpsClientBuilder`.
13-
- All business logic is delegated to the `OpsClient` (or components it delegates to).
11+
- The CLI is **lightweight**:
12+
- It only builds an `OpsClient` via the `OpsClientBuilder`.
13+
- All business logic is delegated to the `OpsClient` (or components it delegates to).
1414
- The CLI only parses input, calls `OpsClient`, and formats output.
15-
16-
- Default behavior:
17-
- `flamingock audit list` (with no flags) → shows the **current snapshot** (latest state per change).
15+
16+
- Default behavior:
17+
- `flamingock audit list` (with no flags) → shows the **current snapshot** (latest state per change).
1818
- Flags modify or filter the behavior.
1919

2020
---
@@ -31,11 +31,11 @@ flamingock audit list
3131
```
3232

3333
**Options:**
34-
- `--issues` (boolean, no value) → only audits with issues
35-
- `--history` (boolean, no value) → full chronological audit history (all states, ordered by time)
36-
- `--since <date>` (string, ISO-8601, e.g. `2025-01-01T00:00:00`) → list audits since a given date
37-
- `--limit <n>` (integer) → pagination limit
38-
- `--page <n>` (integer) → pagination page
34+
- `--issues` (boolean, no value) → only audits with issues
35+
- `--history` (boolean, no value) → full chronological audit history (all states, ordered by time)
36+
- `--since <date>` (string, ISO-8601, e.g. `2025-01-01T00:00:00`) → list audits since a given date
37+
- `--limit <n>` (integer) → pagination limit
38+
- `--page <n>` (integer) → pagination page
3939

4040
**Examples:**
4141
```bash
@@ -58,8 +58,8 @@ flamingock audit mark --change-unit <id> --state <state>
5858
```
5959

6060
**Options:**
61-
- `--change-unit <id>` / `-c <id>` → the changeId (required)
62-
- `--state <state>` / `-s <state>` → the state to mark (`APPLIED` or `ROLLED_BACK`) (required)
61+
- `--change-unit <id>` / `-c <id>` → the changeId (required)
62+
- `--state <state>` / `-s <state>` → the state to mark (`APPLIED` or `ROLLED_BACK`) (required)
6363

6464
**Examples:**
6565
```bash
@@ -71,7 +71,7 @@ flamingock audit mark -c CU123 -s ROLLED_BACK
7171

7272
## Global Options
7373

74-
- `--config <file>` / `-c <file>` → path to configuration file (default: `flamingock.yml`)
74+
- `--config <file>` / `-c <file>` → path to configuration file (default: `flamingock-cli.yml`)
7575
- `--help` / `-h` → show help information
7676
- `--version` / `-V` → show version information
7777

@@ -80,8 +80,8 @@ flamingock audit mark -c CU123 -s ROLLED_BACK
8080
## Summary
8181

8282
- Command structure: `flamingock [command] [operation] [options]`
83-
- For now, only the `audit` command is implemented with:
84-
- `list` (default snapshot, optional filters `--issues`, `--history`, `--since`, pagination)
83+
- For now, only the `audit` command is implemented with:
84+
- `list` (default snapshot, optional filters `--issues`, `--history`, `--since`, pagination)
8585
- `mark` (force a state for a change)
8686
- The CLI is a thin layer: config → build OpsClient → call → format result.
8787

@@ -93,4 +93,4 @@ flamingock audit mark -c CU123 -s ROLLED_BACK
9393
- **History flag**: Use `--history` to get the full chronological audit history.
9494
- **Issues flag**: Use `--issues` to filter for only entries with problems.
9595
- **Since flag**: Use `--since` with ISO-8601 format to filter by date.
96-
- **Pagination**: Client-side pagination is supported with `--limit` and `--page` flags.
96+
- **Pagination**: Client-side pagination is supported with `--limit` and `--page` flags.

cli/flamingock-cli/DEVELOPMENT.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ curl http://localhost:8000/shell/
213213
**"Configuration file not found"**
214214
```bash
215215
# Debug: Check working directory
216-
./gradlew :cli:flamingock-cli:debugCli --args="--config $PWD/flamingock-cli-dist/flamingock.yml audit list"
216+
./gradlew :cli:flamingock-cli:debugCli --args="--config $PWD/flamingock-cli-dist/flamingock-cli.yml audit list"
217217
```
218218

219219
**"Failed to create OpsClient"**
@@ -226,7 +226,7 @@ export JAVA_OPTS="-Dorg.mongodb.driver.level=DEBUG"
226226
**"Multiple database configurations"**
227227
```bash
228228
# Validate YAML structure
229-
cat flamingock-cli-dist/flamingock.yml | grep -A5 "audit:"
229+
cat flamingock-cli-dist/flamingock-cli.yml | grep -A5 "audit:"
230230
```
231231

232232
#### Debug Log Analysis

cli/flamingock-cli/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ cd flamingock-java
4747
```bash
4848
# Linux/macOS
4949
tar -xzf flamingock-cli-{version}.tar.gz
50-
50+
5151
# Windows (or use any ZIP tool)
5252
unzip flamingock-cli-{version}.zip
5353
```
@@ -56,7 +56,7 @@ cd flamingock-java
5656
```bash
5757
# Linux/macOS
5858
./flamingock-cli-{version}/bin/flamingock --help
59-
59+
6060
# Windows
6161
flamingock-cli-{version}\bin\flamingock.bat --help
6262
```
@@ -81,18 +81,18 @@ java -jar flamingock-cli.jar --help
8181

8282
## Configuration
8383

84-
Create a `flamingock.yml` configuration file (see `flamingock-sample.yml` for reference):
84+
Modify `flamingock-cli.yml` configuration file:
8585

8686
```yaml
8787
flamingock:
8888
service-identifier: "my-service"
89-
89+
9090
# For MongoDB
9191
audit:
9292
mongodb:
9393
connection-string: "mongodb://localhost:27017"
9494
database: "myapp"
95-
95+
9696
# For DynamoDB
9797
# audit:
9898
# dynamodb:
@@ -112,7 +112,7 @@ flamingock audit list # List all audit entries
112112
flamingock audit get -c <change-id> # Get specific audit entry
113113
flamingock audit fix -c <change-id> # Fix audit issue
114114

115-
# Issue operations
115+
# Issue operations
116116
flamingock issue list # List all issues
117117
flamingock issue get # Get next issue (or specific with -c)
118118
flamingock issue get -c <change-id> # Get specific issue
@@ -206,7 +206,7 @@ cli/flamingock-cli/
206206
│ │ ├── config/ # Configuration handling
207207
│ │ └── util/ # Utilities
208208
│ └── dist/ # Distribution resources
209-
│ └── flamingock-sample.yml # Sample configuration
209+
│ └── flamingock-cli.yml # Sample configuration
210210
└── build.gradle.kts # Build configuration
211211
```
212212

@@ -264,4 +264,4 @@ Apache License 2.0 - See [LICENSE](../../LICENSE) file for details.
264264

265265
- Documentation: https://docs.flamingock.io/cli
266266
- Issues: https://github.com/flamingock/flamingock-java/issues
267-
- Discussions: https://github.com/flamingock/flamingock-java/discussions
267+
- Discussions: https://github.com/flamingock/flamingock-java/discussions

cli/flamingock-cli/build.gradle.kts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ dependencies {
2323
// Database clients (community edition)
2424
implementation("org.mongodb:mongodb-driver-sync:4.9.1")
2525
implementation("software.amazon.awssdk:dynamodb:2.20.0")
26+
implementation ("com.couchbase.client:java-client:3.7.3")
2627

2728
// SLF4J API - needed for interface compatibility (provided by flamingock-core)
2829
// implementation("org.slf4j:slf4j-api:1.7.36") // Already provided by core dependencies
@@ -36,6 +37,7 @@ dependencies {
3637
testImplementation("org.assertj:assertj-core:3.24.2")
3738
testImplementation("org.testcontainers:junit-jupiter:1.19.3")
3839
testImplementation("org.testcontainers:mongodb:1.19.3")
40+
testImplementation("org.testcontainers:couchbase:1.21.3")
3941
testImplementation("com.github.stefanbirkner:system-lambda:1.2.1")
4042

4143
}
@@ -86,7 +88,7 @@ val distImage by tasks.registering(Sync::class) {
8688
into("lib")
8789
}
8890
from("src/dist") {
89-
into(".")
91+
into("bin")
9092
}
9193
}
9294

@@ -95,7 +97,9 @@ val distZip by tasks.registering(Zip::class) {
9597
description = "Builds the ZIP distribution"
9698
dependsOn(distImage)
9799

98-
from(distImage.get().destinationDir)
100+
from(distImage.get().destinationDir) {
101+
into("flamingock-cli")
102+
}
99103

100104
archiveBaseName.set("flamingock-cli")
101105
archiveVersion.set("")
@@ -109,7 +113,9 @@ val distTar by tasks.registering(Tar::class) {
109113
description = "Builds the TAR distribution"
110114
dependsOn(distImage)
111115

112-
from(distImage.get().destinationDir)
116+
from(distImage.get().destinationDir) {
117+
into("flamingock-cli")
118+
}
113119

114120
archiveBaseName.set("flamingock-cli")
115121
archiveVersion.set("")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Flamingock CLI Configuration Sample
2+
# Modify this file as needed
3+
4+
flamingock:
5+
service-identifier: "flamingock-cli"
6+
audit:
7+
8+
# MongoDB Configuration (comment to use other or modify to use)
9+
mongodb:
10+
connection-string: "mongodb://localhost:27017"
11+
database: "test"
12+
collection: "flamingockAuditLog" # Optional, defaults to "flamingockAuditLog"
13+
14+
# DynamoDB Configuration (uncomment and modify to use)
15+
# dynamodb:
16+
# region: "us-east-1"
17+
# table: "flamingockAuditLog" # Optional, defaults to "flamingockAuditLog"
18+
# # endpoint: "http://localhost:8000" # Optional for local DynamoDB
19+
# # access-key: "your-access-key" # Optional if using IAM roles
20+
# # secret-key: "your-secret-key" # Optional if using IAM roles
21+
22+
# Couchbase Configuration (uncomment and modify to use)
23+
# couchbase:
24+
# endpoint: "couchbase://localhost:12110"
25+
# username: "your-username"
26+
# password: "your-password"
27+
# bucket-name: "test"
28+
# table: "flamingockAuditLog" # Optional, defaults to "flamingockAuditLog"

cli/flamingock-cli/src/dist/flamingock-sample.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

cli/flamingock-cli/src/main/java/io/flamingock/cli/FlamingockCli.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,26 @@
4747
)
4848
public class FlamingockCli implements Runnable {
4949

50-
@Option(names = {"-c", "--config"},
51-
description = "Path to configuration file. Global option - must be placed before commands. (default: flamingock.yml)",
50+
@Option(names = {"-c", "--config"},
51+
description = "Path to configuration file. Global option - must be placed before commands. (default: flamingock-cli.yml)",
5252
order = 0)
53-
private String configFile = "flamingock.yml";
54-
53+
private String configFile = "flamingock-cli.yml";
54+
5555
@Mixin
5656
private LoggingMixin loggingMixin;
5757

5858
public static void main(String[] args) {
5959
FlamingockCli cli = new FlamingockCli();
6060
CommandLine cmd = new CommandLine(cli);
61-
61+
6262
cmd.setExecutionStrategy(parseResult -> {
6363
cli.loggingMixin.initializeLogging();
6464
return new CommandLine.RunLast().execute(parseResult);
6565
});
66-
66+
6767
// Use custom exception handler for better error messages
6868
cmd.setExecutionExceptionHandler(new CliExceptionHandler());
69-
69+
7070
int exitCode = cmd.execute(args);
7171
System.exit(exitCode);
7272
}
@@ -75,12 +75,12 @@ public static void main(String[] args) {
7575
public void run() {
7676
// Initialize logging when any command is about to run
7777
loggingMixin.initializeLogging();
78-
78+
7979
// This runs when no subcommand is specified - show help
8080
new CommandLine(this).usage(System.out);
8181
}
82-
82+
8383
public String getConfigFile() {
8484
return configFile;
8585
}
86-
}
86+
}

0 commit comments

Comments
 (0)