Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md file #89

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:&#9; &#9; &#9;Get global values from the instance. <br/>
default-wallet: Get WalletId for an account. <br/>
me: Execute Me query. <br/>
send-intraledger: Do an intraledger transaction. <br/>
request-phone-code: Request a code from a Phone number. <br/>
login: Get JWT of an account. <br/>
batch: Execute a batch payment.

To see the available options for each command, run galoy-client <COMMAND> --help.


### Options
The available options for the Galoy CLI are:

-a, --api <API>: Set the API URL (default: http://localhost:4002/graphql) <br/>
-d, --debug: Enable debug mode<br/>
-t, --token <TOKEN> [env: GALOY_token] <br/>
-h, --help: Display help information <br/>
-V, --version: Display version information


## Contributing
If you would like to contribute to Galoy CLI, please open a pull request on GitHub.
6 changes: 3 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ pub struct GaloyClient {
}

impl GaloyClient {
pub fn new(api: String, jwt: Option<String>) -> Self {
pub fn new(api: String, token: Option<String>) -> 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(),
)
Expand Down
17 changes: 7 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use galoy_client::GaloyClient;

use anyhow::Context;

use jsonwebtoken::decode_header;


use rust_decimal::Decimal;

Expand All @@ -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<String>,
#[clap(short, long, value_parser, env = "GALOY_token", hide_env_values = true)]
token: Option<String>,

#[clap(subcommand)]
command: Commands,
Expand Down Expand Up @@ -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 },
Expand All @@ -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 {} => {
Expand Down
4 changes: 2 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}