Skip to content

Commit c0bdace

Browse files
Fetch API keys from dedicated endpoint instead of apps response (spiceai#9767)
The cloud API no longer returns api_key in the apps response. Update spidapter and the Spice CLI to call GET /v1/apps/{appId}/api-keys to retrieve API keys separately. - Remove api_key field from App struct in spice-cloud-client types - Change ensure_spice_cloud_app to return only the app ID - Add cloud.get_api_keys(app_id) call in spidapter setup flow - Update CLI create app command to fetch API key from dedicated endpoint
1 parent efdfd88 commit c0bdace

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

bin/spice/src/commands/cloud/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,10 @@ async fn execute_create(cmd: &CreateCommands) -> Result<()> {
939939
return write_json(&app);
940940
}
941941
println!("\x1b[32m✓ Created app {}\x1b[0m", app.full_name());
942-
if let Some(api_key) = app.api_key {
942+
let org_app = app.full_name();
943+
if let Ok(api_keys) = client.get_api_keys(&org_app).await
944+
&& let Some(api_key) = api_keys.api_key
945+
{
943946
println!("\nAPI Key: {api_key}");
944947
println!("\nSave this key - it won't be shown again.");
945948
}

crates/spice-cloud-client/src/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub struct App {
3535
pub created_at: Option<String>,
3636
pub region: Option<String>,
3737
pub production_branch: Option<String>,
38-
pub api_key: Option<String>,
3938
#[serde(default)]
4039
pub config: Option<AppConfig>,
4140
}

tools/spidapter/src/commands/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ fn env_var_resources_over(
148148
pub(crate) async fn ensure_spice_cloud_app(
149149
cloud: &CloudClient,
150150
app_name: &str,
151-
) -> anyhow::Result<(i64, Option<String>)> {
151+
) -> anyhow::Result<i64> {
152152
let apps = cloud.list_apps().await?;
153153
if let Some(app) = apps.into_iter().find(|a| a.name == app_name) {
154-
return Ok((app.id, app.api_key));
154+
return Ok(app.id);
155155
}
156156

157157
let cname = resolve_default_cname(cloud).await?;
@@ -196,12 +196,12 @@ pub(crate) async fn ensure_spice_cloud_app(
196196
.await;
197197

198198
match create_result {
199-
Ok(app) => Ok((app.id, app.api_key)),
199+
Ok(app) => Ok(app.id),
200200
Err(spice_cloud_client::error::Error::Conflict { .. }) => {
201201
// Race condition — another caller created it; re-fetch
202202
let apps = cloud.list_apps().await?;
203203
if let Some(app) = apps.into_iter().find(|a| a.name == app_name) {
204-
return Ok((app.id, app.api_key));
204+
return Ok(app.id);
205205
}
206206
Err(anyhow::anyhow!(
207207
"App '{app_name}' not found after conflict on create"

tools/spidapter/src/stdio_server.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,15 @@ async fn provision_spice_cloud_app(
649649
eprintln!("[stdio] Flight endpoint: {flight_url}");
650650
eprintln!("[stdio] App name: {app_name}");
651651

652-
let (app_id, app_api_key) = commands::ensure_spice_cloud_app(&cloud, &app_name).await?;
652+
let app_id = commands::ensure_spice_cloud_app(&cloud, &app_name).await?;
653653

654-
let api_key = app_api_key.ok_or_else(|| {
654+
// Fetch API key from the dedicated api-keys endpoint
655+
let api_keys = cloud
656+
.get_api_keys(app_id)
657+
.await
658+
.map_err(|e| anyhow::anyhow!("Failed to fetch API keys for app '{app_name}': {e}"))?;
659+
660+
let api_key = api_keys.api_key.ok_or_else(|| {
655661
anyhow::anyhow!("Spice Cloud did not return an API key for app '{app_name}'")
656662
})?;
657663

0 commit comments

Comments
 (0)