Skip to content

Commit

Permalink
feat(cli): Add new command for registering relay with sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
iambriccardo committed Jan 2, 2025
1 parent 826ec7f commit 47ca353
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions relay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ relay-log = { workspace = true, features = ["init"] }
relay-server = { workspace = true }
relay-statsd = { workspace = true }
relay-kafka = { workspace = true, optional = true }
reqwest = { workspace = true }
uuid = { workspace = true }

[target.'cfg(target_os = "linux")'.dependencies]
Expand Down
61 changes: 60 additions & 1 deletion relay/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,63 @@ fn load_config(path: impl AsRef<Path>, require: bool) -> Result<Config> {
}
}

/// Represents the registration request payload
#[derive(Debug)]
struct RegistrationRequest {
auth_token: String,
display_name: String,
description: Option<String>,
public_key: String,
relay_id: String,
}

/// Handle the register command
async fn register(config: &Config, matches: &ArgMatches) -> Result<()> {
if !config.has_credentials() {
bail!("No credentials found. Please run 'relay credentials generate' first");
}

let credentials = config.credentials().unwrap();

let auth_token = matches
.get_one::<String>("auth_token")
.expect("auth_token is required");
let display_name = matches
.get_one::<String>("display_name")
.expect("display_name is required");
let description = matches.get_one::<String>("description").cloned();

let registration = RegistrationRequest {
auth_token: auth_token.clone(),
display_name: display_name.clone(),
description,
public_key: credentials.public_key.to_string(),
relay_id: credentials.id.to_string(),
};

// TODO: Replace with actual endpoint URL from config
let registration_url = "https://sentry.io/api/0/relays/register/";

println!("Registering relay with display name: {}", display_name);

// Create HTTP client
let client = Client::new();

// Prepare the request
// Note: This is just the structure - actual implementation would need proper error handling
let response = client
.post(registration_url)
.json(&registration)
.header("Authorization", format!("Bearer {}", auth_token))
.send()
.await?;

// TODO: Handle the response appropriately
println!("Registration status: {}", response.status());

Ok(())
}

/// Runs the command line application.
pub fn execute() -> Result<()> {
let app = make_app();
Expand All @@ -54,7 +111,9 @@ pub fn execute() -> Result<()> {

relay_log::init(config.logging(), config.sentry());

if let Some(matches) = matches.subcommand_matches("config") {
if let Some(matches) = matches.subcommand_matches("register") {
register(&config, matches)?;
} else if let Some(matches) = matches.subcommand_matches("config") {
manage_config(&config, matches)
} else if let Some(matches) = matches.subcommand_matches("credentials") {
manage_credentials(config, matches)
Expand Down
28 changes: 28 additions & 0 deletions relay/src/cliapp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,32 @@ pub fn make_app() -> Command {
),
),
)
.subcommand(
Command::new("register")
.about("Register this relay instance with Sentry")
.after_help(
"This command registers the relay instance with Sentry using an authentication token. \
The auth token needs to be generated from the Sentry side first."
)
.arg(
Arg::new("auth_token")
.long("token")
.short('t')
.required(true)
.help("The authentication token generated from Sentry"),
)
.arg(
Arg::new("display_name")
.long("name")
.short('n')
.required(true)
.help("Display name for this relay instance"),
)
.arg(
Arg::new("description")
.long("description")
.short('d')
.help("Optional description of this relay instance"),
),
)
}

0 comments on commit 47ca353

Please sign in to comment.