with this crate you can leverage all the functionality of monitor through rust code. for example, you can...
you can initialize the client by directly passing args to the various initializers:
```rust use monitor_client::MonitorClient;
let MONITOR_URL: &str = "https://monitor.mogh.tech";
let monitor = MonitorClient::newwithtoken(MONITORURL, jwttoken).await?; // pass a valid jwt let monitor = MonitorClient::newwithpassword(MONITORURL, username, password).await?; // pass local user credentials let monitor = MonitorClient::newwithsecret(MONITORURL, username, secret).await?; // pass api secret ```
or from the application environment / dotenv:
sh
MONITOR_URL=https://monitor.mogh.tech # required
MONITOR_TOKEN=<jwt> # optional. pass the jwt directly.
MONITOR_USERNAME=<username> # required for password / secret login
MONITOR_PASSWORD=<password> # the users password
MONITOR_SECRET=<secret> # the api secret
to log in, you must pass either 1. MONITORTOKEN 2. MONITORUSERNAME and MONITORPASSWORD 3. MONITORUSERNAME and MONITOR_SECRET
you can then initialize the client using this method:
rust
let monitor = MonitorClient::new_from_env().await?;
the following will select a server, build monitor core on it, and deploy it.
```rust let server = monitor .listservers(None) .await? .pop() .okor(anyhow!("no servers"))?;
let build = BuildBuilder::default() .name("monitorcore".into()) .serverid(server.server.id.clone().into()) .repo("mbecker20/monitor".tostring().into()) .branch("main".tostring().into()) .dockerbuildargs( DockerBuildArgs { buildpath: ".".into(), dockerfilepath: "core/Dockerfile".tostring().into(), ..Default::default() } .into(), ) .prebuild( Command { path: "frontend".into(), command: "yarn && yarn build".into(), } .into(), ) .build()?;
let build = monitor.createfullbuild(&build).await?;
println!("{build:#?}");
let build_update = monitor.build(&build.id).await?;
println!("{build_update:#?}");
let deployment = DeploymentBuilder::default() .name("monitorcore1".into()) .serverid(server.server.id.clone()) .buildid(build.id.clone().into()) .dockerrunargs( DockerRunArgsBuilder::default() .volumes(vec![Conversion { local: "/home/max/.monitor/core.config.toml".into(), container: "/config/config.toml".into(), }]) .build()?, ) .build()?;
let deployment = monitor.createfulldeployment(&deployment).await?;
println!("{deployment:#?}");
let deployupdate = monitor.deploycontainer(&deployment.id).await?;
println!("{deploy_update:#?}"); ```
note. this crate re-exports the monitor types crate under the module "types"