-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: move cluster config to rivet config (#1295)
<!-- 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
1 parent
f42c814
commit 472c54f
Showing
14 changed files
with
185 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.