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 Jan 2, 2024
1 parent a7ab8c4 commit dab125f
Show file tree
Hide file tree
Showing 10 changed files with 1,115 additions and 293 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 = "cd4561ab3dddc6a94ae7a6d8db378a62b0a9782a" }

[build-dependencies]
vergen = { version = "^8.2.1", default-features = false, features = [
Expand Down
77 changes: 71 additions & 6 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,8 +36,8 @@ use cloud_openapi::{
CreateAppCommand, CreateChannelCommand, CreateDeviceCodeCommand, CreateKeyValuePairCommand,
CreateSqlDatabaseCommand, CreateVariablePairCommand, Database, DeleteSqlDatabaseCommand,
DeleteVariablePairCommand, DeviceCodeItem, EnvironmentVariableItem,
ExecuteSqlStatementCommand, GetAppLogsVm, GetAppRawLogsVm, GetSqlDatabasesQuery,
GetVariablesQuery, RefreshTokenCommand, RegisterRevisionCommand, ResourceLabel,
ExecuteSqlStatementCommand, GetAppLogsVm, GetAppRawLogsVm, GetVariablesQuery,
KeyValueStoreItem, RefreshTokenCommand, RegisterRevisionCommand, ResourceLabel,
RevisionItemPage, TokenInfo,
},
};
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,66 @@ 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,
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 @@ -465,9 +531,8 @@ 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,
None,
)
.await
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 dab125f

Please sign in to comment.