Skip to content

Commit

Permalink
Add command for managing key value stores and links
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <kate.goldenring@fermyon.com>
  • Loading branch information
kate-goldenring committed Dec 7, 2023
1 parent a7ab8c4 commit 8ad5015
Show file tree
Hide file tree
Showing 10 changed files with 1,115 additions and 291 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/kate-goldenring/cloud-openapi", rev = "089e08c48ee60a84fb35654fe2a4311c026beced" }

[build-dependencies]
vergen = { version = "^8.2.1", default-features = false, features = [
Expand Down
76 changes: 72 additions & 4 deletions crates/cloud/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -31,9 +36,9 @@ use cloud_openapi::{
CreateAppCommand, CreateChannelCommand, CreateDeviceCodeCommand, CreateKeyValuePairCommand,
CreateSqlDatabaseCommand, CreateVariablePairCommand, Database, DeleteSqlDatabaseCommand,
DeleteVariablePairCommand, DeviceCodeItem, EnvironmentVariableItem,
ExecuteSqlStatementCommand, GetAppLogsVm, GetAppRawLogsVm, GetSqlDatabasesQuery,
GetVariablesQuery, RefreshTokenCommand, RegisterRevisionCommand, ResourceLabel,
RevisionItemPage, TokenInfo,
ExecuteSqlStatementCommand, GetAppLogsVm, GetAppRawLogsVm, GetKeyValueStoresQuery,
GetSqlDatabasesQuery, GetVariablesQuery, KeyValueStoreItem, RefreshTokenCommand,
RegisterRevisionCommand, ResourceLabel, RevisionItemPage, TokenInfo,
},
};
use reqwest::header;
Expand Down Expand Up @@ -362,6 +367,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 @@ -372,7 +378,7 @@ impl CloudClientInterface for Client {
api_key_value_pairs_post(
&self.configuration,
CreateKeyValuePairCommand {
app_id,
app_id: Some(app_id),
store_name,
key,
value,
Expand All @@ -383,6 +389,68 @@ impl CloudClientInterface for Client {
.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,
GetKeyValueStoresQuery {
app_id: Some(app_id),
},
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
29 changes: 27 additions & 2 deletions crates/cloud/src/client_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use async_trait::async_trait;
use cloud_openapi::models::{
AppItem, AppItemPage, ChannelItem, ChannelItemPage, ChannelRevisionSelectionStrategy, Database,
DeviceCodeItem, EnvironmentVariableItem, GetAppLogsVm, GetAppRawLogsVm, ResourceLabel,
RevisionItemPage, TokenInfo,
DeviceCodeItem, EnvironmentVariableItem, GetAppLogsVm, GetAppRawLogsVm, KeyValueStoreItem,
ResourceLabel, RevisionItemPage, TokenInfo,
};

use std::string::String;
Expand Down Expand Up @@ -83,6 +83,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 8ad5015

Please sign in to comment.