-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
537 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
resolver = "2" | ||
members = [ | ||
"autonomi", | ||
"autonomi_cli", | ||
"evmlib", | ||
"evm_testnet", | ||
"sn_auditor", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[package] | ||
name = "autonomi_cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[features] | ||
default = ["metrics"] | ||
local-discovery = ["sn_peers_acquisition/local-discovery"] | ||
metrics = ["sn_logging/process-metrics"] | ||
network-contacts = ["sn_peers_acquisition/network-contacts"] | ||
|
||
[dependencies] | ||
autonomi = { path = "../autonomi", version = "0.1.0" } | ||
clap = { version = "4.2.1", features = ["derive"] } | ||
color-eyre = "~0.6" | ||
dirs-next = "~2.0.0" | ||
indicatif = { version = "0.17.5", features = ["tokio"] } | ||
tokio = { version = "1.32.0", features = [ | ||
"io-util", | ||
"macros", | ||
"parking_lot", | ||
"rt", | ||
"sync", | ||
"time", | ||
"fs", | ||
] } | ||
tracing = { version = "~0.1.26" } | ||
sn_peers_acquisition = { path = "../sn_peers_acquisition", version = "0.5.0" } | ||
sn_build_info = { path = "../sn_build_info", version = "0.1.11" } | ||
sn_logging = { path = "../sn_logging", version = "0.2.33" } | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# A CLI for the Autonomi Network | ||
|
||
``` | ||
Usage: autonomi_cli [OPTIONS] <COMMAND> | ||
Commands: | ||
file Operations related to file handling | ||
register Operations related to register management | ||
vault Operations related to vault management | ||
help Print this message or the help of the given subcommand(s) | ||
Options: | ||
--log-output-dest <LOG_OUTPUT_DEST> | ||
Specify the logging output destination. [default: data-dir] | ||
--log-format <LOG_FORMAT> | ||
Specify the logging format. | ||
--peer <multiaddr> | ||
Peer(s) to use for bootstrap, in a 'multiaddr' format containing the peer ID [env: SAFE_PEERS=] | ||
--timeout <CONNECTION_TIMEOUT> | ||
The maximum duration to wait for a connection to the network before timing out | ||
-x, --no-verify | ||
Prevent verification of data storage on the network | ||
-h, --help | ||
Print help (see more with '--help') | ||
-V, --version | ||
Print version | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2024 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
mod file; | ||
mod register; | ||
mod vault; | ||
|
||
use clap::Subcommand; | ||
use color_eyre::Result; | ||
|
||
use crate::opt::Opt; | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum SubCmd { | ||
/// Operations related to file handling. | ||
File { | ||
#[command(subcommand)] | ||
command: FileCmd, | ||
}, | ||
|
||
/// Operations related to register management. | ||
Register { | ||
#[command(subcommand)] | ||
command: RegisterCmd, | ||
}, | ||
|
||
/// Operations related to vault management. | ||
Vault { | ||
#[command(subcommand)] | ||
command: VaultCmd, | ||
}, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum FileCmd { | ||
/// Estimate cost to upload a file. | ||
Cost { | ||
/// The file to estimate cost for. | ||
file: String, | ||
}, | ||
|
||
/// Upload a file and pay for it. | ||
Upload { | ||
/// The file to upload. | ||
file: String, | ||
}, | ||
|
||
/// Download a file from the given address. | ||
Download { | ||
/// The address of the file to download. | ||
addr: String, | ||
/// The destination file path. | ||
dest_file: String, | ||
}, | ||
|
||
/// List previous uploads | ||
List, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum RegisterCmd { | ||
/// Estimate cost to register a name. | ||
Cost { | ||
/// The name to register. | ||
name: String, | ||
}, | ||
|
||
/// Create a new register with the given name and value. | ||
Create { | ||
/// The name of the register. | ||
name: String, | ||
/// The value to store in the register. | ||
value: String, | ||
}, | ||
|
||
/// Edit an existing register. | ||
Edit { | ||
/// The name of the register. | ||
name: String, | ||
/// The new value to store in the register. | ||
value: String, | ||
}, | ||
|
||
/// Get the value of a register. | ||
Get { | ||
/// The name of the register. | ||
name: String, | ||
}, | ||
|
||
/// List previous registers | ||
List, | ||
} | ||
|
||
#[derive(Subcommand, Debug)] | ||
pub enum VaultCmd { | ||
/// Estimate cost to create a vault. | ||
Cost, | ||
|
||
/// Create a vault at a deterministic address based on your `SECRET_KEY`. | ||
Create, | ||
|
||
/// Sync vault with the network, including registers and files. | ||
Sync, | ||
} | ||
|
||
pub fn handle_subcommand(opt: Opt) -> Result<()> { | ||
let peers = crate::utils::get_peers(opt.peers)?; | ||
let cmd = opt.command; | ||
|
||
match cmd { | ||
SubCmd::File { command } => match command { | ||
FileCmd::Cost { file } => file::cost(&file, peers), | ||
FileCmd::Upload { file } => file::upload(&file, peers), | ||
FileCmd::Download { addr, dest_file } => file::download(&addr, &dest_file, peers), | ||
FileCmd::List => file::list(peers), | ||
}, | ||
SubCmd::Register { command } => match command { | ||
RegisterCmd::Cost { name } => register::cost(&name, peers), | ||
RegisterCmd::Create { name, value } => register::create(&name, &value, peers), | ||
RegisterCmd::Edit { name, value } => register::edit(&name, &value, peers), | ||
RegisterCmd::Get { name } => register::get(&name, peers), | ||
RegisterCmd::List => register::list(peers), | ||
}, | ||
SubCmd::Vault { command } => match command { | ||
VaultCmd::Cost => vault::cost(peers), | ||
VaultCmd::Create => vault::create(peers), | ||
VaultCmd::Sync => vault::sync(peers), | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2024 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use autonomi::Multiaddr; | ||
use color_eyre::eyre::Context; | ||
use color_eyre::eyre::Result; | ||
|
||
pub fn cost(file: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("Estimate cost to upload file: {file}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn upload(file: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
let secret_key = crate::utils::get_secret_key() | ||
.wrap_err("The secret key is required to perform this action")?; | ||
println!("Uploading file: {file} with secret key: {secret_key}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn download(addr: &str, dest_file: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("Downloading file from {addr} to {dest_file}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn list(peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("Listing previous uploads..."); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2024 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use autonomi::Multiaddr; | ||
use color_eyre::eyre::Context; | ||
use color_eyre::eyre::Result; | ||
|
||
pub fn cost(name: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
let register_key = crate::utils::get_register_signing_key() | ||
.wrap_err("The register key is required to perform this action")?; | ||
println!("Estimate cost to register name: {name} with register key: {register_key}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn create(name: &str, value: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
let secret_key = crate::utils::get_secret_key() | ||
.wrap_err("The secret key is required to perform this action")?; | ||
let register_key = crate::utils::get_register_signing_key() | ||
.wrap_err("The register key is required to perform this action")?; | ||
println!( | ||
"Creating register: {name} with value: {value} using secret key: {secret_key} and register key: {register_key}" | ||
); | ||
Ok(()) | ||
} | ||
|
||
pub fn edit(name: &str, value: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
let register_key = crate::utils::get_register_signing_key() | ||
.wrap_err("The register key is required to perform this action")?; | ||
println!("Editing register: {name} with value: {value} using register key: {register_key}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn get(name: &str, peers: Vec<Multiaddr>) -> Result<()> { | ||
let register_key = crate::utils::get_register_signing_key() | ||
.wrap_err("The register key is required to perform this action")?; | ||
println!("Getting value of register: {name} with register key: {register_key}"); | ||
Ok(()) | ||
} | ||
|
||
pub fn list(peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("Listing previous registers..."); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2024 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use autonomi::Multiaddr; | ||
use color_eyre::eyre::Result; | ||
|
||
pub fn cost(_peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("The vault feature is coming soon!"); | ||
Ok(()) | ||
} | ||
|
||
pub fn create(_peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("The vault feature is coming soon!"); | ||
Ok(()) | ||
} | ||
|
||
pub fn sync(_peers: Vec<Multiaddr>) -> Result<()> { | ||
println!("The vault feature is coming soon!"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2024 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use color_eyre::Result; | ||
#[cfg(feature = "metrics")] | ||
use sn_logging::{metrics::init_metrics, Level, LogBuilder, LogFormat}; | ||
|
||
use crate::opt::Opt; | ||
|
||
pub fn init_logging_and_metrics(opt: &Opt) -> Result<()> { | ||
let logging_targets = vec![ | ||
("sn_networking".to_string(), Level::INFO), | ||
("sn_build_info".to_string(), Level::TRACE), | ||
("autonomi".to_string(), Level::TRACE), | ||
("sn_logging".to_string(), Level::TRACE), | ||
("sn_peers_acquisition".to_string(), Level::TRACE), | ||
("sn_protocol".to_string(), Level::TRACE), | ||
("sn_registers".to_string(), Level::TRACE), | ||
("sn_evm".to_string(), Level::TRACE), | ||
]; | ||
let mut log_builder = LogBuilder::new(logging_targets); | ||
log_builder.output_dest(opt.log_output_dest.clone()); | ||
log_builder.format(opt.log_format.unwrap_or(LogFormat::Default)); | ||
let _log_handles = log_builder.initialize()?; | ||
|
||
#[cfg(feature = "metrics")] | ||
std::thread::spawn(|| { | ||
let rt = tokio::runtime::Runtime::new().expect("Failed to create tokio runtime to spawn metrics thread"); | ||
rt.spawn(async { | ||
init_metrics(std::process::id()).await; | ||
}); | ||
}); | ||
Ok(()) | ||
} |
Oops, something went wrong.