diff --git a/README.md b/README.md new file mode 100644 index 0000000..aff3d06 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Galoy CLI +Galoy CLI is a Rust-based CLI client that can interact with the Galoy backend using GraphQL queries and mutations. + +# Rust Installation And Cargo Commands +Go through the installation guide at `https://www.rust-lang.org/learn/get-started`. + +## Installation +To install Galoy CLI locally and set up a local environment: + +1. Clone the /galoy-cli repository using git clone `https://github.com/GaloyMoney/galoy-cli.git`. +2. Install Rust in your local machine and run `cargo build` to build all binary and library targets of the selected packages. +3. Run `cargo run` command to run all tests of the Galoy CLI repository and see the usage, commands, and options available to interact. +4. Interact with the CLI yourself to become familiar with it. + +The Galoy backend can also be run locally by cloning the repository from `https://github.com/GaloyMoney/galoy`. Running the backend locally allows you to test and develop features without needing to fetch data from our staging environment. Additionally, the CAPTCHA feature can be deactivated in the local development environment. + +## Usage +To use the Galoy CLI, you need to run it with the desired command and options. + +### Commands: +getinfo: Get global values from the instance.
+default-wallet: Get WalletId for an account.
+me: Execute Me query.
+send-intraledger: Do an intraledger transaction.
+request-phone-code: Request a code from a Phone number.
+login: Get JWT of an account.
+batch: Execute a batch payment. + +To see the available options for each command, run galoy-client --help. + + +### Options +The available options for the Galoy CLI are: + +-a, --api : Set the API URL (default: http://localhost:4002/graphql)
+-d, --debug: Enable debug mode
+-t, --token [env: GALOY_token]
+-h, --help: Display help information
+-V, --version: Display version information + + +## Contributing +If you would like to contribute to Galoy CLI, please open a pull request on GitHub. \ No newline at end of file diff --git a/src/client/mod.rs b/src/client/mod.rs index 85231ac..23f46bf 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -23,14 +23,14 @@ pub struct GaloyClient { } impl GaloyClient { - pub fn new(api: String, jwt: Option) -> Self { + pub fn new(api: String, token: Option) -> Self { let mut client_builder = Client::builder(); - if let Some(jwt) = jwt { + if let Some(token) = token { client_builder = client_builder.default_headers( std::iter::once(( reqwest::header::AUTHORIZATION, - reqwest::header::HeaderValue::from_str(&format!("Bearer {}", jwt)).unwrap(), + reqwest::header::HeaderValue::from_str(&format!("Bearer {}", token)).unwrap(), )) .collect(), ) diff --git a/src/main.rs b/src/main.rs index d70cdf8..cd5b46d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use galoy_client::GaloyClient; use anyhow::Context; -use jsonwebtoken::decode_header; + use rust_decimal::Decimal; @@ -28,8 +28,8 @@ struct Cli { #[clap(short, long, value_parser, default_value_t = false)] debug: bool, - #[clap(short, long, value_parser, env = "GALOY_JWT", hide_env_values = true)] - jwt: Option, + #[clap(short, long, value_parser, env = "GALOY_token", hide_env_values = true)] + token: Option, #[clap(subcommand)] command: Commands, @@ -61,7 +61,7 @@ enum Commands { #[clap(long, action)] nocaptcha: bool, }, - /// get JWT of an account + /// get token of an account Login { phone: String, code: String }, /// execute a batch payment Batch { filename: String, price: Decimal }, @@ -79,14 +79,11 @@ fn main() -> anyhow::Result<()> { Url::parse(&api).context(format!("API: {api} is not valid"))?; - let jwt = cli.jwt; + let token = cli.token; - if let Some(jwt) = &jwt { - decode_header(jwt).context("jwt syntax issue")?; - } - info!("using api: {api} and jwt: {:?}", &jwt); - let galoy_client = GaloyClient::new(api, jwt); + info!("using api: {api} and token: {:?}", &token); + let galoy_client = GaloyClient::new(api, token); match cli.command { Commands::Getinfo {} => { diff --git a/tests/common/mod.rs b/tests/common/mod.rs index a54a935..30a4f65 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -13,9 +13,9 @@ pub fn auth_client() -> galoy_client::GaloyClient { let phone = "+16505554321".to_string(); let code = "321321".to_string(); - let jwt = galoy_client + let token = galoy_client .user_login(phone, code) .expect("request should succeed"); - GaloyClient::new(api, Some(jwt)) + GaloyClient::new(api, Some(token)) }