Skip to content

Commit

Permalink
fix: move cluster config to rivet config (#1295)
Browse files Browse the repository at this point in the history
<!-- Please make sure there is an issue that this PR is correlated to. -->

## Changes

<!-- If there are frontend changes, please include screenshots. -->
  • Loading branch information
MasterPtato committed Oct 31, 2024
1 parent f42c814 commit 472c54f
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 210 deletions.
17 changes: 15 additions & 2 deletions packages/api/admin/src/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,72 @@ define_router! {
"login": {
POST: login::login(
body: models::AdminLoginRequest,
internal_endpoint: true,
),
},

"clusters": {
GET: clusters::list(),
GET: clusters::list(
internal_endpoint: true,
),
POST: clusters::create(
body: models::AdminClustersCreateClusterRequest,
internal_endpoint: true,
),
},

"clusters" / Uuid / "servers": {
GET: clusters::servers::list(
query: clusters::servers::ServerFilterQuery,
internal_endpoint: true,
),
},

"clusters" / Uuid / "servers" / "taint": {
POST: clusters::servers::taint(
query: clusters::servers::ServerFilterQuery,
body: serde_json::Value,
internal_endpoint: true,
),
},

"clusters" / Uuid / "servers" / "destroy": {
POST: clusters::servers::destroy(
query: clusters::servers::ServerFilterQuery,
body: serde_json::Value,
internal_endpoint: true,
),
},

"clusters" / Uuid / "servers" / "lost": {
GET: clusters::servers::list_lost(
query: clusters::servers::ServerFilterQuery,
internal_endpoint: true,
),
},

"clusters" / Uuid / "servers" / "prune": {
POST: clusters::servers::prune(
query: clusters::servers::ServerFilterQuery,
body: serde_json::Value,
internal_endpoint: true,
),
},

"clusters" / Uuid / "datacenters": {
GET: clusters::datacenters::list(),
GET: clusters::datacenters::list(
internal_endpoint: true,
),
POST: clusters::datacenters::create(
body: models::AdminClustersCreateDatacenterRequest,
internal_endpoint: true,
),
},

"clusters" / Uuid / "datacenters" / Uuid : {
PATCH: clusters::datacenters::update(
body: models::AdminClustersUpdateDatacenterRequest,
internal_endpoint: true,
),
},

Expand Down
1 change: 1 addition & 0 deletions packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ colored_json = "5.0.0"
global-error = { path = "../common/global-error" }
include_dir = "0.7.4"
indoc = "2.0.5"
rivet-api = { path = "../../sdks/full/rust" }
rivet-migrate = { path = "../common/migrate" }
rivet-pools = { version = "0.1.0", path = "../common/pools" }
rivet-runtime = { version = "0.1.0", path = "../common/runtime" }
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/commands/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::*;
use clap::{Parser, ValueEnum};
use std::path::PathBuf;

use crate::run_config::RunConfig;

Expand Down
12 changes: 3 additions & 9 deletions packages/cli/src/commands/wf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ mod signal;
#[derive(Parser)]
pub enum SubCommand {
/// Prints the given workflow(s).
Get {
workflow_ids: Vec<Uuid>,
},
Get { workflow_ids: Vec<Uuid> },
/// Finds workflows with the given tags, name and state.
List {
tags: Vec<KvPair>,
Expand All @@ -28,13 +26,9 @@ pub enum SubCommand {
pretty: bool,
},
/// Silences a workflow from showing up as dead or running again.
Ack {
workflow_ids: Vec<Uuid>,
},
Ack { workflow_ids: Vec<Uuid> },
/// Sets the wake immediate property of a workflow to true.
Wake {
workflow_ids: Vec<Uuid>,
},
Wake { workflow_ids: Vec<Uuid> },
/// Lists the entire event history of a workflow.
History {
#[clap(index = 1)]
Expand Down
8 changes: 2 additions & 6 deletions packages/cli/src/commands/wf/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ use crate::util::{
#[derive(Parser)]
pub enum SubCommand {
/// Prints the given signal(s).
Get {
signal_ids: Vec<Uuid>,
},
Get { signal_ids: Vec<Uuid> },
/// Finds signals that match the given tags.
List {
tags: Vec<KvPair>,
Expand All @@ -28,9 +26,7 @@ pub enum SubCommand {
pretty: bool,
},
/// Silences a signal from showing up as dead or running again.
Ack {
signal_ids: Vec<Uuid>,
},
Ack { signal_ids: Vec<Uuid> },
}

impl SubCommand {
Expand Down
42 changes: 17 additions & 25 deletions packages/cli/src/util/api.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
use anyhow::*;
use serde_json::json;
use rivet_api::{
apis::{admin_api, configuration::Configuration},
models,
};

/// Creates a login link for the hub.
pub async fn admin_login_url(config: &rivet_config::Config, username: String) -> Result<String> {
pub fn private_api_config(config: &rivet_config::Config) -> Result<Configuration> {
let server_config = config.server().map_err(|err| anyhow!("{err}"))?;
let admin_token =
server_config.rivet.token.admin.as_ref().context(
"admin api not enabled. configure this by setting server.rivet.token.admin.",
)?;
let api_private_config = &server_config.rivet.api_private;

let response = reqwest::Client::new()
.post(format!(
"http://{}:{}/admin/login",
api_private_config.host(),
api_private_config.port()
))
.bearer_auth(admin_token.read())
.json(&json!({
"name": username,
}))
.send()
.await?;

if !response.status().is_success() {
bail!(
"failed to login ({}):\n{:#?}",
response.status().as_u16(),
response.json::<serde_json::Value>().await?
);
}
Ok(Configuration {
base_path: api_private_config.internal_origin().to_string().trim_end_matches("/").to_string(),
bearer_access_token: Some(admin_token.read().clone()),
..Default::default()
})
}

let body = response.json::<serde_json::Value>().await?;
let url = body.get("url").expect("url in login body").to_string();
/// Creates a login link for the hub.
pub async fn admin_login_url(config: &rivet_config::Config, username: String) -> Result<String> {
let api_config = private_api_config(config)?;
let url = admin_api::admin_login(&api_config, models::AdminLoginRequest { name: username })
.await?
.url;

Ok(url)
}
2 changes: 1 addition & 1 deletion packages/cli/src/util/wf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cmp::Ordering;

use anyhow::*;
use chrono::{Utc, TimeZone};
use chrono::{TimeZone, Utc};
use clap::ValueEnum;
use indoc::indoc;
use rivet_pools::CrdbPool;
Expand Down
Loading

0 comments on commit 472c54f

Please sign in to comment.