summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/client.go8
-rw-r--r--client/server.go12
-rw-r--r--types/protocol/protocol.go23
-rw-r--r--types/types.go17
4 files changed, 34 insertions, 26 deletions
diff --git a/client/client.go b/client/client.go
index 0cc6b3e..49c8bc1 100644
--- a/client/client.go
+++ b/client/client.go
@@ -15,6 +15,7 @@ import (
"github.com/eduvpn/eduvpn-common/internal/oauth"
"github.com/eduvpn/eduvpn-common/internal/server"
"github.com/eduvpn/eduvpn-common/types"
+ "github.com/eduvpn/eduvpn-common/types/protocol"
"github.com/go-errors/errors"
)
@@ -309,9 +310,10 @@ func (c *Client) ExpiryTimes() (*types.Expiry, error) {
func convertProfiles(profiles server.ProfileInfo) types.Profiles {
m := make(map[string]types.Profile)
for _, p := range profiles.Info.ProfileList {
- var protocols []types.Protocol
- for _, protocol := range p.VPNProtoList {
- protocols = append(protocols, getProtocol(protocol))
+ var protocols []protocol.Protocol
+ // loop through all protocol strings
+ for _, ps := range p.VPNProtoList {
+ protocols = append(protocols, protocol.New(ps))
}
m[p.ID] = types.Profile{
DisplayName: map[string]string{
diff --git a/client/server.go b/client/server.go
index 6e399c9..74f441a 100644
--- a/client/server.go
+++ b/client/server.go
@@ -9,18 +9,10 @@ import (
"github.com/eduvpn/eduvpn-common/internal/oauth"
"github.com/eduvpn/eduvpn-common/internal/server"
"github.com/eduvpn/eduvpn-common/types"
+ "github.com/eduvpn/eduvpn-common/types/protocol"
"github.com/go-errors/errors"
)
-func getProtocol(protocol string) types.Protocol {
- if protocol == "openvpn" {
- return types.PROTOCOL_OPENVPN
- } else if protocol == "wireguard" {
- return types.PROTOCOL_WIREGUARD
- }
- return types.PROTOCOL_UNKNOWN
-}
-
// TODO: This should not be reliant on an internal type
func getTokens(tok oauth.Token) types.Tokens {
return types.Tokens{
@@ -68,7 +60,7 @@ func (c *Client) getConfigAuth(srv server.Server, preferTCP bool, t types.Tokens
pCfg := &types.Configuration{
VPNConfig: cfg.Config,
- Protocol: getProtocol(cfg.Type),
+ Protocol: protocol.New(cfg.Type),
DefaultGateway: p.DefaultGateway,
Tokens: getTokens(cfg.Tokens),
}
diff --git a/types/protocol/protocol.go b/types/protocol/protocol.go
new file mode 100644
index 0000000..d165105
--- /dev/null
+++ b/types/protocol/protocol.go
@@ -0,0 +1,23 @@
+package protocol
+
+type Protocol int8
+
+const (
+ // Unknown indicates that the protocol is not known
+ Unknown Protocol = iota
+ // OpenVPN indicates that the protocol is OpenVPN
+ OpenVPN
+ // WireGuard indicates that the protocol is WireGuard
+ WireGuard
+)
+
+func New(p string) Protocol {
+ switch(p) {
+ case "openvpn":
+ return OpenVPN
+ case "wireguard":
+ return WireGuard
+ default:
+ return Unknown
+ }
+}
diff --git a/types/types.go b/types/types.go
index 237668b..99b997e 100644
--- a/types/types.go
+++ b/types/types.go
@@ -4,6 +4,8 @@ package types
import (
"encoding/json"
"time"
+
+ "github.com/eduvpn/eduvpn-common/types/protocol"
)
// TODO: Discovery here is the same as the upstream discovery format, should we separate this as well?
@@ -75,21 +77,10 @@ type Expiry struct {
NotificationTimes []int64 `json:"notification_times"`
}
-type Protocol int8
-
-const (
- // PROTOCOL_UNKNOWN indicates that the protocol is not known
- PROTOCOL_UNKNOWN Protocol = iota
- // PROTOCOL_OPENVPN indicates that the protocol is OpenVPN
- PROTOCOL_OPENVPN
- // PROTOCOL_WIREGUARD indicates that the protocol is WireGuard
- PROTOCOL_WIREGUARD
-)
-
type Profile struct {
Identifier string `json:"identifier"`
DisplayName map[string]string `json:"display_name,omitempty"`
- Protocols []Protocol `json:"supported_protocols"`
+ Protocols []protocol.Protocol `json:"supported_protocols"`
}
type Profiles struct {
@@ -128,7 +119,7 @@ type ServerList struct {
type Configuration struct {
VPNConfig string `json:"config"`
- Protocol Protocol `json:"protocol"`
+ Protocol protocol.Protocol `json:"protocol"`
DefaultGateway bool `json:"default_gateway"`
Tokens Tokens `json:"tokens"`
}