diff --git a/Cargo.lock b/Cargo.lock index 51fe91b..66647b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4309,7 +4309,6 @@ version = "0.21.0" dependencies = [ "anyhow", "axum", - "base64 0.21.7", "clap", "ctrlc", "dialoguer", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ebc48cd..f9efa70 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -27,7 +27,6 @@ starknet.workspace = true shellexpand = "3.1.0" url.workspace = true rand.workspace = true -base64 = "0.21.7" [[bin]] name = "slot" diff --git a/cli/src/command/deployments/create.rs b/cli/src/command/deployments/create.rs index b785d74..118af4c 100644 --- a/cli/src/command/deployments/create.rs +++ b/cli/src/command/deployments/create.rs @@ -1,7 +1,6 @@ #![allow(clippy::enum_variant_names)] use anyhow::Result; -use base64::Engine; use clap::Args; use slot::api::Client; use slot::credential::Credentials; @@ -11,12 +10,9 @@ use slot::graphql::deployments::create_deployment::CreateDeploymentCreateDeploym use slot::graphql::deployments::create_deployment::*; use slot::graphql::deployments::CreateDeployment; use slot::graphql::GraphQLQuery; -use std::fs; use super::{services::CreateServiceCommands, Tier}; -use base64::engine::general_purpose; - #[derive(Debug, Args)] #[command(next_help_heading = "Create options")] pub struct CreateArgs { @@ -60,21 +56,15 @@ impl CreateArgs { validate_max_steps: config.validate_max_steps, genesis: config.genesis.clone(), dev: config.dev.then_some(true), + config_file: slot::read::read_and_encode_file_as_base64( + config.config_file.as_ref().cloned(), + )?, }), torii: None, saya: None, }), }, CreateServiceCommands::Torii(config) => { - // Read the file and convert to base64 - let config_file_base64 = match &config.config_file { - Some(file_path) => { - let file_contents = fs::read(file_path)?; - Some(general_purpose::STANDARD.encode(file_contents)) - } - None => None, - }; - CreateServiceInput { type_: DeploymentService::torii, version: config.version.clone(), @@ -93,7 +83,9 @@ impl CreateArgs { polling_interval: config.polling_interval, index_transactions: config.index_transactions, index_raw_events: config.index_raw_events, - config_file: config_file_base64, + config_file: slot::read::read_and_encode_file_as_base64( + config.clone().config_file, + )?, }), saya: None, }), diff --git a/cli/src/command/deployments/services/katana.rs b/cli/src/command/deployments/services/katana.rs index 351316f..3cca85b 100644 --- a/cli/src/command/deployments/services/katana.rs +++ b/cli/src/command/deployments/services/katana.rs @@ -55,6 +55,11 @@ pub struct KatanaCreateArgs { #[arg(long)] #[arg(help = "Enable Katana dev mode for specific endpoints.")] pub dev: bool, + + #[arg(long)] + #[arg(help = "A config file ")] + #[arg(value_name = "config-file")] + pub config_file: Option, } #[derive(Debug, Args, serde::Serialize)] @@ -95,6 +100,11 @@ pub struct KatanaUpdateArgs { #[arg(long)] #[arg(help = "Enable Katana dev mode for specific endpoints.")] pub dev: bool, + + #[arg(long)] + #[arg(help = "A config file ")] + #[arg(value_name = "config-file")] + pub config_file: Option, } #[derive(Debug, Args, serde::Serialize)] diff --git a/cli/src/command/deployments/update.rs b/cli/src/command/deployments/update.rs index 639ceda..f40dee8 100644 --- a/cli/src/command/deployments/update.rs +++ b/cli/src/command/deployments/update.rs @@ -3,8 +3,6 @@ use super::services::UpdateServiceCommands; use crate::command::deployments::Tier; use anyhow::Result; -use base64::engine::general_purpose; -use base64::Engine; use clap::Args; use slot::api::Client; use slot::credential::Credentials; @@ -17,7 +15,6 @@ use slot::graphql::deployments::update_deployment::{ }; use slot::graphql::deployments::{update_deployment::*, UpdateDeployment}; use slot::graphql::GraphQLQuery; -use std::fs; #[derive(Debug, Args)] #[command(next_help_heading = "Update options")] @@ -48,30 +45,24 @@ impl UpdateArgs { invoke_max_steps: config.invoke_max_steps, validate_max_steps: config.validate_max_steps, dev: config.dev.then_some(true), + config_file: slot::read::read_and_encode_file_as_base64( + config.config_file.as_ref().cloned(), + )?, }), }), }, - UpdateServiceCommands::Torii(config) => { - // Read the file and convert to base64 - let config_file_base64 = match &config.config_file { - Some(file_path) => { - let file_contents = fs::read(file_path)?; - Some(general_purpose::STANDARD.encode(file_contents)) - } - None => None, - }; - - UpdateServiceInput { - type_: DeploymentService::torii, - version: config.version.clone(), - config: Some(UpdateServiceConfigInput { - katana: None, - torii: Some(UpdateToriiConfigInput { - config_file: config_file_base64, - }), + UpdateServiceCommands::Torii(config) => UpdateServiceInput { + type_: DeploymentService::torii, + version: config.version.clone(), + config: Some(UpdateServiceConfigInput { + katana: None, + torii: Some(UpdateToriiConfigInput { + config_file: slot::read::read_and_encode_file_as_base64( + config.clone().config_file, + )?, }), - } - } + }), + }, UpdateServiceCommands::Saya(config) => UpdateServiceInput { type_: DeploymentService::saya, version: config.version.clone(), diff --git a/slot/schema.json b/slot/schema.json index 3fc2051..0ec61c9 100644 --- a/slot/schema.json +++ b/slot/schema.json @@ -5137,6 +5137,16 @@ "name": "Boolean", "ofType": null } + }, + { + "defaultValue": null, + "description": null, + "name": "configFile", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } } ], "interfaces": [], @@ -10709,6 +10719,18 @@ "ofType": null } } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "configFile", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } } ], "inputFields": [], @@ -16591,6 +16613,16 @@ "name": "Boolean", "ofType": null } + }, + { + "defaultValue": null, + "description": null, + "name": "configFile", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } } ], "interfaces": [], diff --git a/slot/src/graphql/deployments/update.graphql b/slot/src/graphql/deployments/update.graphql index 2e9763e..83d0541 100644 --- a/slot/src/graphql/deployments/update.graphql +++ b/slot/src/graphql/deployments/update.graphql @@ -13,6 +13,7 @@ mutation UpdateDeployment( __typename ... on KatanaConfig { + configFile rpc } diff --git a/slot/src/lib.rs b/slot/src/lib.rs index 6129dac..8eaaa43 100644 --- a/slot/src/lib.rs +++ b/slot/src/lib.rs @@ -5,6 +5,7 @@ pub mod api; pub mod browser; pub mod credential; pub mod graphql; +pub mod read; pub mod server; pub mod session; pub mod vars; diff --git a/slot/src/read.rs b/slot/src/read.rs new file mode 100644 index 0000000..97897a1 --- /dev/null +++ b/slot/src/read.rs @@ -0,0 +1,12 @@ +use base64::{engine, Engine}; + +pub fn read_and_encode_file_as_base64(file_path: Option) -> anyhow::Result> { + if let Some(path) = file_path { + let file_contents = std::fs::read(path)?; + Ok(Some( + engine::general_purpose::STANDARD.encode(file_contents), + )) + } else { + Ok(None) + } +}