diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-02-12 19:18:05 +0100 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-02-19 14:15:07 +0100 |
| commit | 74e36f0ead717105f26087c2cab08b41ba5a7ce8 (patch) | |
| tree | 1eb2b7516bea705c9b5a50ce0965e170414ed880 /internal/api/profiles | |
| parent | 682d70091af2044ff6d8b350da9dff13163232e2 (diff) | |
All: Document everything to pass revive lint
Diffstat (limited to 'internal/api/profiles')
| -rw-r--r-- | internal/api/profiles/profiles.go | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/internal/api/profiles/profiles.go b/internal/api/profiles/profiles.go index 111a835..d31bbcc 100644 --- a/internal/api/profiles/profiles.go +++ b/internal/api/profiles/profiles.go @@ -1,3 +1,5 @@ +// Package profiles defines a wrapper around the various profiles +// returned by the /info endpoint package profiles import ( @@ -5,27 +7,43 @@ import ( "github.com/eduvpn/eduvpn-common/types/server" ) +// Profile is the information for a profile type Profile struct { - ID string `json:"profile_id"` - DisplayName string `json:"display_name"` - VPNProtoList []string `json:"vpn_proto_list"` + // ID is the identifier of the profile + // Used to select a profile + ID string `json:"profile_id"` + // DisplayName defines the UI friendly name for the profile + DisplayName string `json:"display_name"` + // VPNProtoList defines the list of VPN protocols + // E.g. wireguard, openvpn + VPNProtoList []string `json:"vpn_proto_list"` + // VPNProtoTransportList defines the list of VPN protocols including their transport values + // E.g. wireguard+udp, openvpn+tcp VPNProtoTransportList []string `json:"vpn_proto_transport_list"` - DefaultGateway bool `json:"default_gateway"` - DNSSearchDomains []string `json:"dns_search_domain_list"` + // DefaultGateway specifies whether or not this profile is a default gateway profile + DefaultGateway bool `json:"default_gateway"` + // DNSSearchDomains specifies the list of dns search domains + // This is provided for a Linux client issue + // See: https://github.com/eduvpn/python-eduvpn-client/issues/550 + DNSSearchDomains []string `json:"dns_search_domain_list"` } +// ListInfo is the struct that has the profile list type ListInfo struct { ProfileList []Profile `json:"profile_list"` } +// Info is the top-level struct for the info endpoint type Info struct { Info ListInfo `json:"info"` } +// Len returns the length of the profile list func (i Info) Len() int { return len(i.Info.ProfileList) } +// Get returns a profile with id `id`, it returns nil if it is not found func (i Info) Get(id string) *Profile { for _, p := range i.Info.ProfileList { if p.ID == id { @@ -35,6 +53,8 @@ func (i Info) Get(id string) *Profile { return nil } +// MustIndex gets a profile by index +// This index must be in the bounds func (i Info) MustIndex(n int) Profile { return i.Info.ProfileList[n] } @@ -48,6 +68,11 @@ func hasProtocol(protos []string, proto protocol.Protocol) bool { return false } +// ShouldFailover returns whether or not this VPN profile should start a failover procedure +// This is true when the profile supports a TCP connection +// If we cannot determine whether it supports a TCP connection +// (because the server doesn't provide the VPN transport list function yet), +// we will just check if it supports OpenVPN func (p *Profile) ShouldFailover() bool { // old servers don't support it, only failover in case OpenVPN is supported if len(p.VPNProtoTransportList) == 0 { @@ -65,14 +90,17 @@ func (p *Profile) ShouldFailover() bool { return false } +// HasOpenVPN returns whether or not the profile has OpenVPN support func (p *Profile) HasOpenVPN() bool { return hasProtocol(p.VPNProtoList, protocol.OpenVPN) } +// HasWireGuard returns whether or not the profile has WireGuard support func (p *Profile) HasWireGuard() bool { return hasProtocol(p.VPNProtoList, protocol.WireGuard) } +// FilterWireGuard gets a profile list but without WireGuard profiles func (i Info) FilterWireGuard() *Info { var ret []Profile for _, p := range i.Info.ProfileList { @@ -87,6 +115,7 @@ func (i Info) FilterWireGuard() *Info { } } +// Public gets the server list as a structure that we return to clients func (i Info) Public() server.Profiles { m := make(map[string]server.Profile) for _, p := range i.Info.ProfileList { |
