Skip to content

Commit cb3b7ce

Browse files
authored
feat(cargo-shuttle): admin flag for admin operations (#2020)
* feat(cargo-shuttle): admin flag for admin operations * new endpoints
1 parent cb7ddbe commit cb3b7ce

File tree

7 files changed

+24
-10
lines changed

7 files changed

+24
-10
lines changed

admin/src/client.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ impl Client {
4848

4949
pub async fn get_project_config(&self, project_id: &str) -> Result<Value> {
5050
self.inner
51-
.get_json(format!("/admin/projects/{project_id}"))
51+
.get_json(format!("/admin/projects/{project_id}/config"))
5252
.await
5353
}
5454

5555
pub async fn upgrade_project_to_lb(&self, project_id: &str) -> Result<Value> {
5656
self.inner
57-
.put_json(format!("/admin/projects/{project_id}"), Option::<()>::None)
57+
.put_json(
58+
format!("/admin/projects/{project_id}/config"),
59+
Option::<()>::None,
60+
)
5861
.await
5962
}
6063

admin/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@ pub mod args;
22
pub mod client;
33
pub mod config;
44

5-
use tracing::trace;
6-
75
use crate::{
86
args::{Args, Command},
97
client::Client,
108
config::get_api_key,
119
};
1210

1311
pub async fn run(args: Args) {
14-
trace!(?args, "starting with args");
12+
tracing::trace!(?args, "starting with args");
1513

1614
let api_key = get_api_key();
17-
let client = Client::new(args.api_url.clone(), api_key, args.client_timeout);
15+
let client = Client::new(
16+
format!("{}/admin", args.api_url),
17+
api_key,
18+
args.client_timeout,
19+
);
1820

1921
match args.command {
2022
Command::ChangeProjectOwner {

cargo-shuttle/src/args.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub struct ShuttleArgs {
2929
/// URL for the Shuttle API to target (mainly for development)
3030
#[arg(global = true, long, env = "SHUTTLE_API", hide = true)]
3131
pub api_url: Option<String>,
32+
/// Modify Shuttle API URL to use admin endpoints
33+
#[arg(global = true, long, env = "SHUTTLE_ADMIN", hide = true)]
34+
pub admin: bool,
3235
/// Disable network requests that are not strictly necessary. Limits some features.
3336
#[arg(global = true, long, env = "SHUTTLE_OFFLINE")]
3437
pub offline: bool,

cargo-shuttle/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,10 @@ impl Shuttle {
156156
// TODO: refactor so that beta local run does not need to know project id / always uses crate name ???
157157
matches!(args.cmd, Command::Run(..))
158158
) {
159-
if let Some(ref url) = args.api_url {
159+
let api_url = args
160+
.api_url
161+
.map(|u| if args.admin { format!("{u}/admin") } else { u });
162+
if let Some(ref url) = api_url {
160163
if url != SHUTTLE_API_URL {
161164
eprintln!(
162165
"{}",
@@ -167,7 +170,7 @@ impl Shuttle {
167170
eprintln!("WARNING: API URL is probably incorrect. Ends with '/': {url}");
168171
}
169172
}
170-
self.ctx.set_api_url(args.api_url);
173+
self.ctx.set_api_url(api_url);
171174

172175
let client = ShuttleApiClient::new(
173176
self.ctx.api_url(),

cargo-shuttle/tests/integration/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ async fn shuttle_command(cmd: Command, working_directory: &str) -> anyhow::Resul
1414
.run(
1515
ShuttleArgs {
1616
api_url: Some("http://shuttle.invalid:80".to_string()),
17+
admin: false,
1718
project_args: ProjectArgs {
1819
working_directory,
1920
name_or_id: None,

cargo-shuttle/tests/integration/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async fn shuttle_run(working_directory: &str, external: bool) -> String {
3030
let runner = Shuttle::new(cargo_shuttle::Binary::Shuttle).unwrap().run(
3131
ShuttleArgs {
3232
api_url: Some("http://shuttle.invalid:80".to_string()),
33+
admin: false,
3334
project_args: ProjectArgs {
3435
working_directory: working_directory.clone(),
3536
name_or_id: None,

runtime/src/telemetry.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,9 @@ pub fn init_tracing_subscriber(
499499

500500
if endpoint.is_none() {
501501
tracing::warn!(
502-
"No value set for `OTEL_EXPORTER_OTLP_ENDPOINT` env var, \
503-
declining to attach OTLP exporter to default tracing subscriber"
502+
"No value set for `{}` env var, \
503+
declining to attach OTLP exporter to default tracing subscriber",
504+
OTEL_EXPORTER_OTLP_ENDPOINT,
504505
);
505506
}
506507

0 commit comments

Comments
 (0)