Skip to content

Commit 98c5345

Browse files
committed
gcgit v1.0.2 release
- Enhanced `init` command: auto git repo + .gitignore with *.toml (protects API keys) - Dependency updates: clap 4.5, reqwest 0.12, git2 0.19, tokio 1.47 + 46 security patches - Fixed import error (GitRepo → GitWrapper), improved build stability, reduced warnings - Backward compatible with existing functionality Signed-off-by: Simon Sigré <simon.sigre@gmail.com>
1 parent dcd5fbd commit 98c5345

9 files changed

Lines changed: 515 additions & 291 deletions

File tree

Binary file not shown.

Cargo.lock

Lines changed: 462 additions & 269 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "gcgit"
3-
version = "1.0.0"
3+
version = "1.0.2"
44
edition = "2021"
55
description = "A Rust-based CLI tool for version-controlling Cortex XSIAM configurations"
66
authors = ["gcgit team"]
@@ -14,15 +14,15 @@ name = "gcgit"
1414
path = "src/main.rs"
1515

1616
[dependencies]
17-
clap = { version = "4.0", features = ["derive"] }
17+
clap = { version = "4.5", features = ["derive"] }
1818
serde = { version = "1.0", features = ["derive"] }
1919
serde_json = "1.0"
2020
serde_yaml = "0.9"
2121
schemars = { version = "0.8", features = ["derive"] }
2222
toml = "0.8"
23-
reqwest = { version = "0.11", features = ["json", "rustls-tls"], default-features = false }
24-
git2 = { version = "0.18", default-features = false, features = ["vendored-openssl"] }
25-
tokio = { version = "1.0", features = ["full"] }
23+
reqwest = { version = "0.12", features = ["json", "rustls-tls"], default-features = false }
24+
git2 = { version = "0.19", default-features = false, features = ["vendored-openssl"] }
25+
tokio = { version = "1.47", features = ["full"] }
2626
anyhow = "1.0"
2727
uuid = { version = "1.0", features = ["v4"] }
2828
chrono = { version = "0.4", features = ["serde"] }

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Go Cortex Git is a Rust-based command-line interface (CLI) tool designed to serve as a lightweight abstraction layer between local Git operations and the Cortex XSIAM REST API. Its purpose is to enable security teams to version-control and deploy Cortex XSIAM configuration objects—such as Correlation Searches, Dashboards, BIOCs, and Scripts—without requiring a full-scale CI/CD pipeline or remote Git hosting. By wrapping standard Git workflows and translating file changes into corresponding API actions, gcgit streamlines content management within XSIAM while keeping everything local and traceable via Git.
44

5+
56
## Quick Start
67

78
### 1. Install gcgit

src/api.rs

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,26 @@ impl XsiamClient {
4242
let endpoint = self.get_delete_endpoint(&object.content_type);
4343
let url = format!("https://{}/public_api/v1/{}", self.config.fqdn, endpoint);
4444

45+
// Get the correct request data format based on content type
46+
let registry = crate::content_types::ContentTypeRegistry::new();
47+
let request_data = if let Some(config) = registry.get(&object.content_type) {
48+
config.get_request_data(&object.id)
49+
} else {
50+
// Fallback for unknown content types
51+
serde_json::json!({
52+
"request_data": {
53+
"id": object.id
54+
}
55+
})
56+
};
57+
4558
let response = self.client
4659
.post(&url)
4760
.header("x-xdr-auth-id", &self.config.api_key_id)
4861
.header("Authorization", &self.config.api_key)
4962
.header("Content-Type", "application/json")
5063
.header("Accept", "application/json")
51-
.json(&serde_json::json!({
52-
"request_data": {
53-
"rule_id": object.id
54-
}
55-
}))
64+
.json(&request_data)
5665
.send()
5766
.await
5867
.with_context(|| format!("Failed to send delete request to {}", url))?;
@@ -516,14 +525,27 @@ impl XsiamClient {
516525
let endpoint = self.get_delete_endpoint(content_type);
517526
let url = format!("https://{}/public_api/v1/{}", self.config.fqdn, endpoint);
518527

519-
// Delete request format: {"request_data": {"objects_count": N, "objects": [id1, id2, ...]}}
520-
let id_num = id.parse::<i64>().unwrap_or(0);
521-
let request_data = serde_json::json!({
522-
"request_data": {
523-
"objects_count": 1,
524-
"objects": [id_num]
528+
// Get the correct request data format based on content type
529+
let registry = crate::content_types::ContentTypeRegistry::new();
530+
let request_data = if let Some(config) = registry.get(content_type) {
531+
config.get_request_data(id)
532+
} else {
533+
// Fallback for unknown content types - try both string and integer IDs
534+
if let Ok(id_num) = id.parse::<i64>() {
535+
serde_json::json!({
536+
"request_data": {
537+
"objects_count": 1,
538+
"objects": [id_num]
539+
}
540+
})
541+
} else {
542+
serde_json::json!({
543+
"request_data": {
544+
"id": id
545+
}
546+
})
525547
}
526-
});
548+
};
527549

528550
let response = self.client
529551
.post(&url)

src/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize};
33
use std::fs;
44
use std::path::Path;
55
use std::env;
6+
use crate::git_wrapper::GitWrapper;
67

78
#[derive(Debug, Deserialize, Serialize)]
89
pub struct XsiamConfig {
@@ -153,6 +154,16 @@ instance_name = "{}"
153154
fs::write(&config_path, config_content)
154155
.with_context(|| format!("Failed to write config file: {}", config_path))?;
155156

157+
// Initialize git repository
158+
let _git_repo = GitWrapper::new(instance_name)
159+
.with_context(|| format!("Failed to initialize git repository in: {}", instance_name))?;
160+
161+
// Create .gitignore file to exclude config.toml from version control
162+
let gitignore_path = format!("{}/.gitignore", instance_name);
163+
let gitignore_content = "*.toml\n";
164+
fs::write(&gitignore_path, gitignore_content)
165+
.with_context(|| format!("Failed to create .gitignore file: {}", gitignore_path))?;
166+
156167
Ok(())
157168
}
158169
}

src/content_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ impl ContentTypeRegistry {
8787
get_endpoint: "authentication-settings/get/settings",
8888
insert_endpoint: "authentication-settings/insert",
8989
delete_endpoint: "authentication-settings/delete",
90-
id_field: "id",
91-
request_id_key: "id",
90+
id_field: "name",
91+
request_id_key: "name",
9292
});
9393

9494
// Example for future content types:

target/CACHEDIR.TAG

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

target/release/.cargo-lock

Whitespace-only changes.

0 commit comments

Comments
 (0)