Skip to content

Commit

Permalink
Merge pull request #162 from kate-goldenring/kv-links
Browse files Browse the repository at this point in the history
Add command for managing key value stores and links
  • Loading branch information
kate-goldenring authored Jan 18, 2024
2 parents 6239fe3 + c4d0aec commit f53b8ad
Show file tree
Hide file tree
Showing 10 changed files with 1,105 additions and 294 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ openssl = { version = "0.10" }

[workspace.dependencies]
tracing = { version = "0.1", features = ["log"] }
cloud-openapi = { git = "https://github.com/fermyon/cloud-openapi", rev = "ce1e916110b9a9e59a1171ac364f0b6e23908428" }
cloud-openapi = { git = "https://github.com/fermyon/cloud-openapi", rev = "a461b586e35a0175810d6da80a8e8ffeb2d517a4" }

[build-dependencies]
vergen = { version = "^8.2.1", default-features = false, features = [
Expand Down
81 changes: 74 additions & 7 deletions crates/cloud/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use cloud_openapi::{
configuration::{ApiKey, Configuration},
device_codes_api::api_device_codes_post,
key_value_pairs_api::api_key_value_pairs_post,
key_value_stores_api::{
api_key_value_stores_get, api_key_value_stores_store_delete,
api_key_value_stores_store_links_delete, api_key_value_stores_store_links_post,
api_key_value_stores_store_post,
},
revisions_api::{api_revisions_get, api_revisions_post},
sql_databases_api::{
api_sql_databases_create_post, api_sql_databases_database_links_delete,
Expand All @@ -26,8 +31,8 @@ use cloud_openapi::{
CreateDeviceCodeCommand, CreateKeyValuePairCommand, CreateSqlDatabaseCommand,
CreateVariablePairCommand, Database, DeleteSqlDatabaseCommand, DeleteVariablePairCommand,
DeviceCodeItem, EnvironmentVariableItem, ExecuteSqlStatementCommand, GetAppLogsVm,
GetAppRawLogsVm, GetSqlDatabasesQuery, GetVariablesQuery, RefreshTokenCommand,
RegisterRevisionCommand, ResourceLabel, RevisionItemPage, TokenInfo,
GetAppRawLogsVm, GetSqlDatabasesQuery, GetVariablesQuery, KeyValueStoreItem,
RefreshTokenCommand, RegisterRevisionCommand, ResourceLabel, RevisionItemPage, TokenInfo,
},
};
use reqwest::header;
Expand Down Expand Up @@ -232,6 +237,7 @@ impl CloudClientInterface for Client {
.map_err(format_response_error)
}

// Key value API methods
async fn add_key_value_pair(
&self,
app_id: Uuid,
Expand All @@ -242,17 +248,78 @@ impl CloudClientInterface for Client {
api_key_value_pairs_post(
&self.configuration,
CreateKeyValuePairCommand {
app_id,
store_name,
app_id: Some(app_id),
store_name: Some(store_name),
key,
value,
label: None,
},
None,
)
.await
.map_err(format_response_error)
}

async fn create_key_value_store(
&self,
store_name: &str,
resource_label: Option<ResourceLabel>,
) -> anyhow::Result<()> {
api_key_value_stores_store_post(&self.configuration, store_name, None, resource_label)
.await
.map_err(format_response_error)
}

async fn delete_key_value_store(&self, store_name: &str) -> anyhow::Result<()> {
api_key_value_stores_store_delete(&self.configuration, store_name, None)
.await
.map_err(format_response_error)
}

async fn get_key_value_stores(
&self,
app_id: Option<Uuid>,
) -> anyhow::Result<Vec<KeyValueStoreItem>> {
let list = api_key_value_stores_get(
&self.configuration,
app_id.map(|id| id.to_string()).as_deref(),
None,
)
.await
.map_err(format_response_error)?;
Ok(list.key_value_stores)
}

async fn create_key_value_store_link(
&self,
key_value_store: &str,
resource_label: ResourceLabel,
) -> anyhow::Result<()> {
api_key_value_stores_store_links_post(
&self.configuration,
key_value_store,
resource_label,
None,
)
.await
.map_err(format_response_error)
}

async fn remove_key_value_store_link(
&self,
key_value_store: &str,
resource_label: ResourceLabel,
) -> anyhow::Result<()> {
api_key_value_stores_store_links_delete(
&self.configuration,
key_value_store,
resource_label,
None,
)
.await
.map_err(format_response_error)
}

async fn add_variable_pair(
&self,
app_id: Uuid,
Expand Down Expand Up @@ -335,10 +402,10 @@ impl CloudClientInterface for Client {
async fn get_databases(&self, app_id: Option<Uuid>) -> anyhow::Result<Vec<Database>> {
let list = api_sql_databases_get(
&self.configuration,
GetSqlDatabasesQuery {
app_id: Some(app_id),
},
app_id.map(|id| id.to_string()).as_deref(),
None,
// TODO: set to None when the API is updated to not require a body
Some(GetSqlDatabasesQuery { app_id: None }),
)
.await
.map_err(format_response_error)?;
Expand Down
29 changes: 27 additions & 2 deletions crates/cloud/src/client_interface.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anyhow::Result;
use async_trait::async_trait;
use cloud_openapi::models::{
AppItem, AppItemPage, Database, DeviceCodeItem, GetAppLogsVm, GetAppRawLogsVm, ResourceLabel,
RevisionItemPage, TokenInfo,
AppItem, AppItemPage, Database, DeviceCodeItem, GetAppLogsVm, GetAppRawLogsVm,
KeyValueStoreItem, ResourceLabel, RevisionItemPage, TokenInfo,
};

use std::string::String;
Expand Down Expand Up @@ -55,6 +55,31 @@ pub trait CloudClientInterface: Send + Sync {
value: String,
) -> anyhow::Result<()>;

async fn create_key_value_store(
&self,
store_name: &str,
resource_label: Option<ResourceLabel>,
) -> anyhow::Result<()>;

async fn delete_key_value_store(&self, store_name: &str) -> anyhow::Result<()>;

async fn get_key_value_stores(
&self,
app_id: Option<Uuid>,
) -> anyhow::Result<Vec<KeyValueStoreItem>>;

async fn create_key_value_store_link(
&self,
key_value_store: &str,
resource_label: ResourceLabel,
) -> anyhow::Result<()>;

async fn remove_key_value_store_link(
&self,
key_value_store: &str,
resource_label: ResourceLabel,
) -> anyhow::Result<()>;

async fn add_variable_pair(
&self,
app_id: Uuid,
Expand Down
Loading

0 comments on commit f53b8ad

Please sign in to comment.