diff options
| author | Franck Cuny <franck@fcuny.net> | 2022-11-19 18:48:12 -0800 |
|---|---|---|
| committer | Franck Cuny <franck@fcuny.net> | 2022-11-19 19:01:01 -0800 |
| commit | d78070d130c32227a2788591d3efd321da702658 (patch) | |
| tree | 55e34a15a8ff3b53714c55974bd738e48a5bbcb9 /src/config.rs | |
| parent | meta: ignore artifact created by `nix build` (diff) | |
| download | sendsms-d78070d130c32227a2788591d3efd321da702658.tar.gz | |
feat: a CLI to send sms via twilio's API
I want to get an SMS when some of my machines are rebooted. This tool
let me do just that. The CLI takes as argument the path to a
configuration file that contains credentials to the API. It also has a
number of sub commands, and each sub command is associated with a
specific action.
For each action, a section in the configuration file is expected. The
two actions currently supported are:
- `reboot`
- `hello`
`hello` is a simple one used for testing, it sends "hello world".
`reboot` is used to create a message that contains the host's name and
the IP address of the network interface specified in the configuration
file.
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..29145b8 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,27 @@ +use serde::Deserialize; +use std::path::PathBuf; + +#[derive(Deserialize, Debug)] +pub struct Config { + pub to: String, + pub from: String, + pub account_sid: String, + pub auth_token: String, + pub reboot: RebootConfig, + pub hello: HelloConfig, +} + +#[derive(Deserialize, Debug)] +pub struct RebootConfig { + pub ifname: String, +} + +#[derive(Deserialize, Debug)] +pub struct HelloConfig {} + +impl Config { + pub fn load_from_file(filename: &PathBuf) -> std::io::Result<Config> { + let content = std::fs::read_to_string(filename)?; + Ok(toml::from_str(&content)?) + } +} |
