6 releases

0.1.5 Dec 3, 2022
0.1.4 Nov 18, 2022
0.1.3 Mar 16, 2022
0.1.2 Nov 23, 2020
0.1.1 Jun 25, 2020

#572 in Authentication

Download history 4/week @ 2024-12-10 5/week @ 2024-12-31 24/week @ 2025-01-07 20/week @ 2025-01-14 2/week @ 2025-01-21 8/week @ 2025-01-28 11/week @ 2025-02-04 24/week @ 2025-02-11 21/week @ 2025-02-18 48/week @ 2025-02-25 30/week @ 2025-03-04 16/week @ 2025-03-11 27/week @ 2025-03-18 18/week @ 2025-03-25

100 downloads per month

MIT/Apache

13KB
123 lines

myloginrs

Build status Maintenance

Read and parse MySQL's .mylogin.cnf file.

Installation

Add myloginrs to Cargo.toml:

[dependencies]
myloginrs = "0.1"

Examples

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).

Other Stuff

Thanks to

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~2.9–4MB
~81K SLoC