Add open vpn builder with validation#326
Add open vpn builder with validation#326stoutes wants to merge 6 commits intocachebag:dev-openvpnfrom
Conversation
…ation with unit tests
There was a problem hiding this comment.
Also just wanted to ask once again that you please name the prefixes of this commit category as feat, NOT feature. Ik it's minor, but I've never used feature in my commits and would like to keep style consistent
We could also probably do without the AI generated PR descriptions. Just a short sentence and a line of what issue this closes is good enough! :)
| proxy: Option<OpenVpnProxy>, | ||
| autoconnect: bool, | ||
| autoconnect_priority: Option<i32>, | ||
| } |
There was a problem hiding this comment.
Why do you build these and never use them?
| #[must_use] | ||
| pub fn new(name: impl Into<String>) -> Self { | ||
| Self { | ||
| name: name.into(), |
There was a problem hiding this comment.
This happily produces a config with an empty name...The WireGuardBuilder runs validate_connection_name in its build(), so this builder should too.
Especially since from_ovpn_file and connect_vpn both validate the name downstream, so an invalid name would just blow up later with a less helpful error.
| fn builds_static_key_connection() { | ||
| let config = OpenVpnBuilder::new("TestVPN") | ||
| .remote("vpn.example.com") | ||
| .auth_type(OpenVpnAuthType::StaticKey) |
There was a problem hiding this comment.
There's zero validation on StaticKey here. You can build a StaticKey config with just a name and remote, no key path, no nothing?
That's probably not a usable connection. Even if you don't know exactly what StaticKey requires yet, a comment or todo!() acknowledging it would be better than silently accepting an empty config.
There was a problem hiding this comment.
I'm questionable on your claims that you modeled this after the existing WireGuardBuilder. They're fundamentally different. WireGuardBuilder::build() returns HashMap<String, HashMap<String, Value>> (whcih are NM-ready D-Bus settings), while OpenVpnBuilder::build() returns Result<OpenVpnConfig, ConnectionError> (a domain struct).
This isn't necessarily wrong, OpenVpnConfig already has build_openvpn_connection to produce NM settings, but it DOES mean the two builders aren't interchangeable patterns.
Worth a sentence in the module doc or PR description acknowledging this so future contributors aren't confused.
|
ping @stoutes lmk if you can't finish so i can take over and close the PR |
Summary
Part of #288. Depends on
OpenVpnConfigbeing merged intodev-openvpn.Adds
OpenVpnBuilder— a fluent, validated builder forOpenVpnConfigmodelledafter the existing
WireGuardBuilder.Changes
api/builders/openvpn_builder.rs(new file)Fluent builder that constructs
OpenVpnConfigwith validation atbuild()time:remotemust be set and non-emptyauth_typemust be setPasswordorPasswordTls:usernamerequiredTlsorPasswordTls:ca_cert,client_cert,client_keyrequiredMethods:
new(name),remote(),auth_type(),username(),password(),ca_cert(),client_cert(),client_key(),key_password(),port(),tcp(),cipher(),auth(),dns(),mtu(),uuid(),autoconnect(),options(),build() -> Result<OpenVpnConfig>api/builders/mod.rspub mod openvpn_builderOpenVpnBuilderTests
17 unit tests mirroring
wireguard_builder.rsstructure: