Skip to content

Commit

Permalink
Merge pull request #45 from AGScheduler/dev
Browse files Browse the repository at this point in the history
fix: use plaintext password
  • Loading branch information
kwkwc committed Jun 9, 2024
2 parents 8f5c346 + 4895e26 commit ab1cc04
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 62 deletions.
81 changes: 80 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "agscheduler-cli"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
description = "Command line interface for AGScheduler"
license = "MIT"
Expand All @@ -18,9 +18,11 @@ chrono = "0.4.38"
clap = { version = "4.5.4", features = ["derive"] }
comfy-table = "7.1.1"
dialoguer = "0.11.0"
hex = "0.4.3"
iana-time-zone = "0.1.60"
mockall = "0.12.1"
mockito = "1.4.0"
reqwest = { version = "0.12.4", default-features = false, features = ["rustls-tls"] }
serde_json = "1.0.117"
sha2 = "0.10.8"
tokio = { version = "1.38.0", features = ["full"] }
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ cargo install agscheduler-cli
## Usage

```bash
$ agscheduler-cli -h
$ agscheduler-cli -h
Command line interface for AGScheduler

Usage: agscheduler-cli [OPTIONS]

Options:
-e, --endpoint <ENDPOINT> AGScheduler HTTP endpoint [default: http://127.0.0.1:36370]
-p, --password-sha2 <PASSWORD_SHA2> SHA256 encrypted authorization password, e.g. here is admin: `echo -n admin | shasum -a 256` -> `8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918` [default: ]
-p, --password <PASSWORD> AGScheduler password
You can also use the AGSCHEDULERCLI_AUTH environment variable to pass this password more safely [default: ]
-h, --help Print help
-V, --version Print version


$ agscheduler-cli
$ agscheduler-cli
Connecting to `http://127.0.0.1:36370`...
? Select your operation › [Page 1/3]
? Select your operation › [Page 1/3]
Add Job
Get Job
❯ Get All Jobs
Expand Down
58 changes: 10 additions & 48 deletions src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@ use crate::{datetime, http};

pub struct AGScheduler {
pub endpoint: String,
pub password_sha2: String,
}

impl AGScheduler {
pub async fn get_info(&self) {
http::fetch_show_json(
format!("{}{}", &self.endpoint, "/info"),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await;
}

pub async fn get_funcs(&self) {
match http::fetch(
format!("{}{}", &self.endpoint, "/funcs"),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -91,10 +84,7 @@ impl AGScheduler {
let mut fn_selections: Vec<String> = vec![];
match http::fetch(
format!("{}{}", &self.endpoint, "/funcs"),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -139,7 +129,6 @@ impl AGScheduler {
http::Options {
method,
body: body.to_string(),
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand Down Expand Up @@ -173,10 +162,7 @@ impl AGScheduler {
let mut data = HashMap::new();
match http::fetch(
format!("{}{}/{}", &self.endpoint, "/scheduler/job", id),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -212,21 +198,15 @@ impl AGScheduler {

http::fetch_show_json(
format!("{}{}/{}", &self.endpoint, "/scheduler/job", id),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await;
}

pub async fn get_all_jobs(&self) {
match http::fetch(
format!("{}{}", &self.endpoint, "/scheduler/jobs"),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -301,7 +281,6 @@ impl AGScheduler {
format!("{}{}/{id}", &self.endpoint, "/scheduler/job"),
http::Options {
method: Method::DELETE,
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -317,7 +296,6 @@ impl AGScheduler {
format!("{}{}", &self.endpoint, "/scheduler/jobs"),
http::Options {
method: Method::DELETE,
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -331,7 +309,6 @@ impl AGScheduler {
format!("{}{}/{}/{}", &self.endpoint, "/scheduler/job", id, action),
http::Options {
method: Method::POST,
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -343,10 +320,7 @@ impl AGScheduler {

match http::fetch(
format!("{}{}/{}", &self.endpoint, "/scheduler/job", id),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -375,7 +349,6 @@ impl AGScheduler {
http::Options {
method: Method::POST,
body: body.to_string(),
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -392,7 +365,6 @@ impl AGScheduler {
format!("{}{}/{}", &self.endpoint, "/scheduler", action),
http::Options {
method: Method::POST,
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -411,10 +383,7 @@ impl AGScheduler {
url_path = format!("{}?{}", url_path, query);
match http::fetch(
format!("{}{}", &self.endpoint, url_path),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -497,7 +466,6 @@ impl AGScheduler {
format!("{}{}", &self.endpoint, url_path),
http::Options {
method: Method::DELETE,
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
)
Expand All @@ -516,10 +484,7 @@ impl AGScheduler {
pub async fn get_cluster_nodes(&self) {
match http::fetch(
format!("{}{}", &self.endpoint, "/cluster/nodes"),
http::Options {
password_sha2: String::from(&self.password_sha2),
..Default::default()
},
http::Options::default(),
)
.await
{
Expand Down Expand Up @@ -932,10 +897,7 @@ mod tests {
mock.expect_select_func_name()
.return_const("github.com/agscheduler/agscheduler/examples.PrintMsg");

let ags = AGScheduler {
endpoint: url,
password_sha2: String::new(),
};
let ags = AGScheduler { endpoint: url };

ags.get_info().await;
ags.get_funcs().await;
Expand Down
Loading

0 comments on commit ab1cc04

Please sign in to comment.