Skip to content

Commit

Permalink
feat(katana): add config file support for katana (#124)
Browse files Browse the repository at this point in the history
Introduced a config file option in deployment commands to
allow users to specify and encode configuration files in base64.
  • Loading branch information
steebchen authored Nov 9, 2024
1 parent b219ea3 commit 3436079
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 39 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ starknet.workspace = true
shellexpand = "3.1.0"
url.workspace = true
rand.workspace = true
base64 = "0.21.7"

[[bin]]
name = "slot"
Expand Down
20 changes: 6 additions & 14 deletions cli/src/command/deployments/create.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
}),
Expand Down
10 changes: 10 additions & 0 deletions cli/src/command/deployments/services/katana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

#[derive(Debug, Args, serde::Serialize)]
Expand Down Expand Up @@ -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<String>,
}

#[derive(Debug, Args, serde::Serialize)]
Expand Down
37 changes: 14 additions & 23 deletions cli/src/command/deployments/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")]
Expand Down Expand Up @@ -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(),
Expand Down
32 changes: 32 additions & 0 deletions slot/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5137,6 +5137,16 @@
"name": "Boolean",
"ofType": null
}
},
{
"defaultValue": null,
"description": null,
"name": "configFile",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
],
"interfaces": [],
Expand Down Expand Up @@ -10709,6 +10719,18 @@
"ofType": null
}
}
},
{
"args": [],
"deprecationReason": null,
"description": null,
"isDeprecated": false,
"name": "configFile",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
],
"inputFields": [],
Expand Down Expand Up @@ -16591,6 +16613,16 @@
"name": "Boolean",
"ofType": null
}
},
{
"defaultValue": null,
"description": null,
"name": "configFile",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
}
],
"interfaces": [],
Expand Down
1 change: 1 addition & 0 deletions slot/src/graphql/deployments/update.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mutation UpdateDeployment(
__typename

... on KatanaConfig {
configFile
rpc
}

Expand Down
1 change: 1 addition & 0 deletions slot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions slot/src/read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use base64::{engine, Engine};

pub fn read_and_encode_file_as_base64(file_path: Option<String>) -> anyhow::Result<Option<String>> {
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)
}
}

0 comments on commit 3436079

Please sign in to comment.