| Crates.io | myloginrs |
| lib.rs | myloginrs |
| version | 0.1.5 |
| created_at | 2020-06-18 00:55:05.560836+00 |
| updated_at | 2022-12-03 15:47:23.929168+00 |
| description | Read and parse MySQL's .mylogin.cnf file. |
| homepage | |
| repository | https://github.com/rjcortese/myloginrs |
| max_upload_size | |
| id | 255129 |
| size | 24,386 |
Read and parse MySQL's .mylogin.cnf file.
Add myloginrs to Cargo.toml:
[dependencies]
myloginrs = "0.1"
To get a HashMap of login info for "client" just use the parse function:
let file_path = PathBuf::from(
"tests/test_mylogin.cnf",
);
let client_info = myloginrs::parse("client", Some(&file_path));
Then you can use that HashMap with an OptsBuilder or other structs
from the mysql:
let opts = OptsBuilder::new()
.ip_or_hostname(Some(&client_info["host"]))
.tcp_port(u16::from_str_radix(&client_info["port"], 10)?)
.user(Some(&client_info["user"]))
.pass(Some(&client_info["password"]));
let _conn = Conn::new(opts);
Starting with mysql 20.1.0, you can do the even simpler:
let opts = OptsBuilder::new().from_hash_map(&client_info).unwrap();
let _conn = Conn::new(opts);
If you would rather get a String that contains the whole file, use read:
let mylogin_plaintext = myloginrs::read(None);
println!("{}", mylogin_plaintext);
This second example passes None as the path to use the
default .mylogin.cnf location (%APPDATA%\MySQL\.mylogin.cnf on windows or
~/.mylogin.cnf on everything else).
Thanks to
github.com/ocelot-inc for doing all the hard work and from whom I port.
Licensed under either of
at your option.
Pull requests welcome. :)
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.