diff --git a/client/client.go b/client/client.go index 2901ca98..4b909390 100644 --- a/client/client.go +++ b/client/client.go @@ -16,7 +16,6 @@ import ( "github.com/eduvpn/eduvpn-common/internal/fsm" "github.com/eduvpn/eduvpn-common/internal/http" "github.com/eduvpn/eduvpn-common/internal/log" - "github.com/eduvpn/eduvpn-common/internal/oauth" "github.com/eduvpn/eduvpn-common/internal/server" "github.com/eduvpn/eduvpn-common/types/cookie" discotypes "github.com/eduvpn/eduvpn-common/types/discovery" diff --git a/internal/api/profiles/profiles.go b/internal/api/profiles/profiles.go index 4e382793..b141037b 100644 --- a/internal/api/profiles/profiles.go +++ b/internal/api/profiles/profiles.go @@ -17,7 +17,7 @@ type Info struct { Info ListInfo `json:"info"` } -func (i Info) Len() bool { +func (i Info) Len() int { return len(i.Info.ProfileList) } @@ -52,16 +52,15 @@ func HasWireGuard(protos []string) bool { } func (i Info) FilterWireGuard() Info { - list := i.Info.ProfileList var ret []Profile for _, p := range i.Info.ProfileList { - if !hasOpenVPN(p.VPNProtoList) { + if !HasOpenVPN(p.VPNProtoList) { continue } } return Info{ Info: ListInfo{ ProfileList: ret, - } + }, } } diff --git a/internal/api/profiles/profiles_test.go b/internal/api/profiles/profiles_test.go index e246b5c1..5e8da670 100644 --- a/internal/api/profiles/profiles_test.go +++ b/internal/api/profiles/profiles_test.go @@ -1,4 +1,4 @@ -package profile +package profiles import "testing" diff --git a/internal/config/v2/v2.go b/internal/config/v2/v2.go index 74cd8053..db5b5dc9 100644 --- a/internal/config/v2/v2.go +++ b/internal/config/v2/v2.go @@ -31,8 +31,8 @@ type Servers struct { } type Connection struct { - // LastConnectedType is the identifier of the server that was last connected to - LastConnectedType string `json:"last_connected_type,omitempty"` + // LastConnectedType is the type of server that was last connected to + LastConnectedType server.Type `json:"last_connected_type,omitempty"` // LastAuthorizeTime is the last time the user authorized the client manually in the browser LastAuthorizeTime time.Time `json:"start_time,omitempty"` // ExpireTime is the time when the connection expires @@ -73,68 +73,69 @@ type Joined struct { V2 *V2 `json:"v2"` } -func convertV1Server(list v1.InstituteServers, iscurrent bool, t server.Type, m map[string]Server) *Connection { +func convertV1Server(list v1.InstituteServers, iscurrent bool, t server.Type) (ServerList, *Connection) { + ret := ServerList{LastChosenID: list.CurrentURL, List: make(map[string]Server)} var conn *Connection for k, v := range list.Map { - if list.CurrentURL == k && iscurrent { + if iscurrent && k == list.CurrentURL { conn = &Connection{ - LastConnectedID: k, - StartTime: v.Base.StartTime, - EndTime: v.Base.EndTime, + LastConnectedType: t, + ExpireTime: v.Base.EndTime, } } - var currP *string = nil - if v.Base.Profiles.Current != "" { - currP = &v.Base.Profiles.Current - } - m[k] = Server{ - ProfileID: currP, - Type: t, + ret.List[k] = Server{ + ProfileID: v.Base.Profiles.Current, } } - return conn + return ret, conn } func fromV1(ver1 *v1.V1) *V2 { - srvs := make(map[string]Server) + var inst ServerList + var cust ServerList gsrvs := ver1.Servers - conn := convertV1Server(gsrvs.Custom, gsrvs.IsType == server.TypeCustom, server.TypeCustom, srvs) - conn = convertV1Server(gsrvs.Institute, gsrvs.IsType == server.TypeInstituteAccess, server.TypeInstituteAccess, srvs) + var conn *Connection + cust, gconn := convertV1Server(gsrvs.Custom, gsrvs.IsType == server.TypeCustom, server.TypeCustom) + if conn == nil { + conn = gconn + } + inst, gconn = convertV1Server(gsrvs.Institute, gsrvs.IsType == server.TypeInstituteAccess, server.TypeInstituteAccess) + if conn == nil { + conn = gconn + } sec := gsrvs.SecureInternetHome // if the home organization ID is filled we have secure internet present if sec.HomeOrganizationID == "" { return &V2{ Servers: Servers{ - List: srvs, + InstituteAccess: inst, + Custom: cust, }, Connection: conn, } } - sh := &sec.HomeOrganizationID - k := sec.CurrentLocation - v, ok := sec.BaseMap[k] + var secRet *SecureInternet + v, ok := sec.BaseMap[sec.CurrentLocation] if v != nil && ok { - var currP *string = nil - if v.Profiles.Current != "" { - currP = &v.Profiles.Current - } - srvs[k] = Server{ - ProfileID: currP, - Type: server.TypeSecureInternet, + secRet = &SecureInternet{ + Server: Server{ + ProfileID: v.Profiles.Current, + }, + SecureHome: sec.HomeOrganizationID, } if gsrvs.IsType == server.TypeSecureInternet { conn = &Connection{ - LastConnectedID: k, - StartTime: v.StartTime, - EndTime: v.EndTime, + LastConnectedType: server.TypeSecureInternet, + ExpireTime: v.EndTime, } } } return &V2{ Servers: Servers{ - List: srvs, - SecureHome: sh, + InstituteAccess: inst, + Custom: cust, + SecureInternet: secRet, }, Connection: conn, }