From 9e75f1b0213d8fec5cf6a878a557e07ec8562c3d Mon Sep 17 00:00:00 2001 From: steebchen Date: Sun, 10 Nov 2024 00:38:39 +0700 Subject: [PATCH] feat(cli): add config file support for Torii service Added the ability to specify a config file for the Torii service. The file is read and encoded in base64 for the update process. --- cli/src/command/deployments/services/torii.rs | 5 +++ cli/src/command/deployments/update.rs | 36 +++++++++++++++---- slot/schema.json | 31 ++++++++++++++++ slot/src/graphql/deployments/update.graphql | 1 + 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/cli/src/command/deployments/services/torii.rs b/cli/src/command/deployments/services/torii.rs index f3b074f..50d996b 100644 --- a/cli/src/command/deployments/services/torii.rs +++ b/cli/src/command/deployments/services/torii.rs @@ -57,4 +57,9 @@ pub struct ToriiUpdateArgs { #[arg(long, short, value_name = "version")] #[arg(help = "Service version to use.")] pub version: Option, + + #[arg(long)] + #[arg(help = "A config file ")] + #[arg(value_name = "config-file")] + pub config_file: Option, } diff --git a/cli/src/command/deployments/update.rs b/cli/src/command/deployments/update.rs index 6d67695..639ceda 100644 --- a/cli/src/command/deployments/update.rs +++ b/cli/src/command/deployments/update.rs @@ -3,6 +3,8 @@ 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; @@ -11,9 +13,11 @@ use slot::graphql::deployments::update_deployment::UpdateDeploymentUpdateDeploym }; use slot::graphql::deployments::update_deployment::{ self, UpdateKatanaConfigInput, UpdateServiceConfigInput, UpdateServiceInput, + UpdateToriiConfigInput, }; use slot::graphql::deployments::{update_deployment::*, UpdateDeployment}; use slot::graphql::GraphQLQuery; +use std::fs; #[derive(Debug, Args)] #[command(next_help_heading = "Update options")] @@ -36,6 +40,7 @@ impl UpdateArgs { type_: DeploymentService::katana, version: config.version.clone(), config: Some(UpdateServiceConfigInput { + torii: None, katana: Some(UpdateKatanaConfigInput { block_time: config.block_time, disable_fee: config.disable_fee, @@ -46,15 +51,34 @@ impl UpdateArgs { }), }), }, - UpdateServiceCommands::Torii(config) => UpdateServiceInput { - type_: DeploymentService::torii, - version: config.version.clone(), - config: Some(UpdateServiceConfigInput { katana: None }), - }, + 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::Saya(config) => UpdateServiceInput { type_: DeploymentService::saya, version: config.version.clone(), - config: Some(UpdateServiceConfigInput { katana: None }), + config: Some(UpdateServiceConfigInput { + katana: None, + torii: None, + }), }, }; diff --git a/slot/schema.json b/slot/schema.json index ae2cad9..3fc2051 100644 --- a/slot/schema.json +++ b/slot/schema.json @@ -16612,6 +16612,16 @@ "name": "UpdateKatanaConfigInput", "ofType": null } + }, + { + "defaultValue": null, + "description": null, + "name": "torii", + "type": { + "kind": "INPUT_OBJECT", + "name": "UpdateToriiConfigInput", + "ofType": null + } } ], "interfaces": [], @@ -16664,6 +16674,27 @@ "name": "UpdateServiceInput", "possibleTypes": [] }, + { + "description": null, + "enumValues": [], + "fields": [], + "inputFields": [ + { + "defaultValue": null, + "description": null, + "name": "configFile", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + ], + "interfaces": [], + "kind": "INPUT_OBJECT", + "name": "UpdateToriiConfigInput", + "possibleTypes": [] + }, { "description": "The `Upload` scalar type represents a multipart file upload.", "enumValues": [], diff --git a/slot/src/graphql/deployments/update.graphql b/slot/src/graphql/deployments/update.graphql index b01d9b8..2e9763e 100644 --- a/slot/src/graphql/deployments/update.graphql +++ b/slot/src/graphql/deployments/update.graphql @@ -17,6 +17,7 @@ mutation UpdateDeployment( } ... on ToriiConfig { + configFile graphql grpc rpc