Skip to content

Commit 24bf35a

Browse files
committed
avalanche-kms: support chunks for outputs
Signed-off-by: Gyuho Lee <[email protected]>
1 parent f2ad9b4 commit 24bf35a

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

avalanche-kms/src/create/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ pub fn command() -> Command {
128128
.required(false)
129129
.num_args(1),
130130
)
131+
.arg(
132+
Arg::new("KEYS_FILE_CHUNKS")
133+
.long("keys-file-chunks")
134+
.help("Sets the number of keys-file chunks")
135+
.required(false)
136+
.num_args(1)
137+
.value_parser(value_parser!(usize))
138+
.default_value("1"),
139+
)
131140

132141
// optional for cross-account grants
133142
.arg(
@@ -184,6 +193,7 @@ pub async fn execute(
184193
key_name_prefix: &str,
185194
keys: usize,
186195
keys_file_output: &str,
196+
keys_file_chunks: usize,
187197
grantee_principal: &str,
188198
evm_chain_rpc_url: &str,
189199
evm_funding_hotkey: &str,
@@ -385,5 +395,19 @@ pub async fn execute(
385395
let keys = Keys(entries);
386396
keys.sync(keys_file_output)?;
387397

398+
if keys_file_chunks > 1 {
399+
execute!(
400+
stdout(),
401+
SetForegroundColor(Color::Green),
402+
Print(format!("\nWrote keys in chunk\n",)),
403+
ResetColor
404+
)?;
405+
for (cursor, chunk) in keys.0.chunks(keys_file_chunks).enumerate() {
406+
let chunk_file_output_path = format!("{keys_file_output}.{}.yaml", cursor + 1);
407+
let chunk_keys = Keys(chunk.to_vec());
408+
chunk_keys.sync(&chunk_file_output_path)?;
409+
}
410+
}
411+
388412
Ok(())
389413
}

avalanche-kms/src/main.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ async fn main() -> io::Result<()> {
5959
} else {
6060
id_manager::time::with_prefix("avalanche-kms")
6161
};
62-
let keys = sub_matches.get_one::<usize>("KEYS").unwrap_or(&0).clone();
6362

6463
let grantee_principal = sub_matches
6564
.get_one::<String>("GRANTEE_PRINCIPAL")
@@ -115,8 +114,12 @@ async fn main() -> io::Result<()> {
115114
.clone(),
116115
&sub_matches.get_one::<String>("REGION").unwrap().clone(),
117116
&key_name_prefix,
118-
keys,
117+
sub_matches.get_one::<usize>("KEYS").unwrap_or(&1).clone(),
119118
&keys_file_output,
119+
sub_matches
120+
.get_one::<usize>("KEYS_FILE_CHUNKS")
121+
.unwrap_or(&1)
122+
.clone(),
120123
&grantee_principal,
121124
&evm_chain_rpc_url,
122125
&evm_funding_hotkey,

0 commit comments

Comments
 (0)