diff options
Diffstat (limited to 'client')
| -rw-r--r-- | client/client.go | 62 | ||||
| -rw-r--r-- | client/server.go | 34 |
2 files changed, 48 insertions, 48 deletions
diff --git a/client/client.go b/client/client.go index 78b451d..295fa04 100644 --- a/client/client.go +++ b/client/client.go @@ -14,7 +14,7 @@ import ( "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" + srvtypes "github.com/eduvpn/eduvpn-common/types/server" discotypes "github.com/eduvpn/eduvpn-common/types/discovery" "github.com/eduvpn/eduvpn-common/types/protocol" "github.com/go-errors/errors" @@ -283,7 +283,7 @@ func (c *Client) DiscoServers() (dss *discotypes.Servers, err error) { // - The time starting at which the countdown button should be shown, less than 24 hours // - The list of times where notifications should be shown // These times are reset when the VPN gets disconnected -func (c *Client) ExpiryTimes() (*types.Expiry, error) { +func (c *Client) ExpiryTimes() (*srvtypes.Expiry, error) { // Get current expiry time srv, err := c.Servers.GetCurrentServer() if err != nil { @@ -299,7 +299,7 @@ func (c *Client) ExpiryTimes() (*types.Expiry, error) { bT := b.RenewButtonTime() cT := b.CountdownTime() nT := b.NotificationTimes() - return &types.Expiry{ + return &srvtypes.Expiry{ StartTime: b.StartTime.Unix(), EndTime: b.EndTime.Unix(), ButtonTime: bT, @@ -308,30 +308,30 @@ func (c *Client) ExpiryTimes() (*types.Expiry, error) { }, nil } -func convertProfiles(profiles server.ProfileInfo) types.Profiles { - m := make(map[string]types.Profile) +func convertProfiles(profiles server.ProfileInfo) srvtypes.Profiles { + m := make(map[string]srvtypes.Profile) for _, p := range profiles.Info.ProfileList { 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{ + m[p.ID] = srvtypes.Profile{ DisplayName: map[string]string{ "en": p.DisplayName, }, Protocols: protocols, } } - return types.Profiles{Map: m, Current: profiles.Current} + return srvtypes.Profiles{Map: m, Current: profiles.Current} } -func convertGeneric(server server.InstituteAccessServer) (*types.GenericServer, error) { +func convertGeneric(server server.InstituteAccessServer) (*srvtypes.Server, error) { b, err := server.Base() if err != nil { return nil, err } - return &types.GenericServer{ + return &srvtypes.Server{ DisplayName: b.DisplayName, Identifier: b.URL, Profiles: convertProfiles(b.Profiles), @@ -339,9 +339,9 @@ func convertGeneric(server server.InstituteAccessServer) (*types.GenericServer, } // TODO: CLEAN THIS UP -func (c *Client) ServerList() (*types.ServerList, error) { +func (c *Client) ServerList() (*srvtypes.List, error) { custom := c.Servers.CustomServers - var customServers []types.GenericServer + var customServers []srvtypes.Server for _, v := range custom.Map { if v == nil { return nil, errors.New("found nil value in custom server map") @@ -353,7 +353,7 @@ func (c *Client) ServerList() (*types.ServerList, error) { customServers = append(customServers, *conv) } institute := c.Servers.InstituteServers - var instituteServers []types.InstituteServer + var instituteServers []srvtypes.Institute for _, v := range institute.Map { if v == nil { return nil, errors.New("found nil value in institute server map") @@ -362,25 +362,25 @@ func (c *Client) ServerList() (*types.ServerList, error) { if err != nil { return nil, errors.Errorf("failed to convert institute server for public type: %v", err) } - instituteServers = append(instituteServers, types.InstituteServer{ - GenericServer: *conv, + instituteServers = append(instituteServers, srvtypes.Institute{ + Server: *conv, // TODO: delisted Delisted: false, }) } - var secureInternet *types.SecureInternetServer + var secureInternet *srvtypes.SecureInternet if c.Servers.HasSecureInternet() { b, err := c.Servers.SecureInternetHomeServer.Base() if err == nil { - generic := types.GenericServer{ + generic := srvtypes.Server{ DisplayName: b.DisplayName, Identifier: b.URL, Profiles: convertProfiles(b.Profiles), } cc := c.Servers.SecureInternetHomeServer.CurrentLocation - secureInternet = &types.SecureInternetServer{ - GenericServer: generic, + secureInternet = &srvtypes.SecureInternet{ + Server: generic, CountryCode: cc, // TODO: delisted Delisted: false, @@ -388,7 +388,7 @@ func (c *Client) ServerList() (*types.ServerList, error) { } } - return &types.ServerList{ + return &srvtypes.List{ Institutes: instituteServers, SecureInternet: secureInternet, Custom: customServers, @@ -396,7 +396,7 @@ func (c *Client) ServerList() (*types.ServerList, error) { } // TODO: CLEAN THIS UP -func (c *Client) CurrentServer() (*types.CurrentServer, error) { +func (c *Client) CurrentServer() (*srvtypes.Current, error) { srvs := c.Servers switch srvs.IsType { @@ -409,13 +409,13 @@ func (c *Client) CurrentServer() (*types.CurrentServer, error) { if err != nil { return nil, err } - return &types.CurrentServer{ - Institute: &types.InstituteServer{ - GenericServer: *conv, + return &srvtypes.Current{ + Institute: &srvtypes.Institute{ + Server: *conv, // TODO: delisted Delisted: false, }, - Type: types.SERVER_INSTITUTE_ACCESS, + Type: srvtypes.TypeInstituteAccess, }, nil case server.CustomServerType: curr, err := srvs.GetCustomServer(srvs.CustomServers.CurrentURL) @@ -426,29 +426,29 @@ func (c *Client) CurrentServer() (*types.CurrentServer, error) { if err != nil { return nil, err } - return &types.CurrentServer{ + return &srvtypes.Current{ Custom: conv, - Type: types.SERVER_CUSTOM, + Type: srvtypes.TypeCustom, }, nil case server.SecureInternetServerType: b, err := c.Servers.SecureInternetHomeServer.Base() if err != nil { return nil, err } - generic := types.GenericServer{ + generic := srvtypes.Server{ DisplayName: b.DisplayName, Identifier: c.Servers.SecureInternetHomeServer.HomeOrganizationID, Profiles: convertProfiles(b.Profiles), } cc := c.Servers.SecureInternetHomeServer.CurrentLocation - return &types.CurrentServer{ - SecureInternet: &types.SecureInternetServer{ - GenericServer: generic, + return &srvtypes.Current{ + SecureInternet: &srvtypes.SecureInternet{ + Server: generic, CountryCode: cc, // TODO: delisted Delisted: false, }, - Type: types.SERVER_SECURE_INTERNET, + Type: srvtypes.TypeSecureInternet, }, nil default: return nil, errors.New("current server not found") diff --git a/client/server.go b/client/server.go index 74caff1..684d780 100644 --- a/client/server.go +++ b/client/server.go @@ -8,15 +8,15 @@ import ( "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" discotypes "github.com/eduvpn/eduvpn-common/types/discovery" + srvtypes "github.com/eduvpn/eduvpn-common/types/server" "github.com/eduvpn/eduvpn-common/types/protocol" "github.com/go-errors/errors" ) // TODO: This should not be reliant on an internal type -func getTokens(tok oauth.Token) types.Tokens { - return types.Tokens{ +func getTokens(tok oauth.Token) srvtypes.Tokens { + return srvtypes.Tokens{ Access: tok.Access, Refresh: tok.Refresh, Expires: tok.ExpiredTimestamp.Unix(), @@ -25,7 +25,7 @@ func getTokens(tok oauth.Token) types.Tokens { // getConfigAuth gets a config with authorization and authentication. // It also asks for a profile if no valid profile is found. -func (c *Client) getConfigAuth(srv server.Server, preferTCP bool, t types.Tokens) (*types.Configuration, error) { +func (c *Client) getConfigAuth(srv server.Server, preferTCP bool, t srvtypes.Tokens) (*srvtypes.Configuration, error) { err := c.ensureLogin(srv, t) if err != nil { return nil, err @@ -59,7 +59,7 @@ func (c *Client) getConfigAuth(srv server.Server, preferTCP bool, t types.Tokens return nil, err } - pCfg := &types.Configuration{ + pCfg := &srvtypes.Configuration{ VPNConfig: cfg.Config, Protocol: protocol.New(cfg.Type), DefaultGateway: p.DefaultGateway, @@ -71,7 +71,7 @@ func (c *Client) getConfigAuth(srv server.Server, preferTCP bool, t types.Tokens // retryConfigAuth retries the getConfigAuth function if the tokens are invalid. // If OAuth is cancelled, it makes sure that we only forward the error as additional info. -func (c *Client) retryConfigAuth(srv server.Server, preferTCP bool, t types.Tokens) (*types.Configuration, error) { +func (c *Client) retryConfigAuth(srv server.Server, preferTCP bool, t srvtypes.Tokens) (*srvtypes.Configuration, error) { cfg, err := c.getConfigAuth(srv, preferTCP, t) if err == nil { return cfg, nil @@ -80,7 +80,7 @@ func (c *Client) retryConfigAuth(srv server.Server, preferTCP bool, t types.Toke tErr := &oauth.TokensInvalidError{} if errors.As(err, &tErr) { // TODO: Is passing empty tokens correct here? - cfg, err = c.getConfigAuth(srv, preferTCP, types.Tokens{}) + cfg, err = c.getConfigAuth(srv, preferTCP, srvtypes.Tokens{}) if err == nil { return cfg, nil } @@ -90,7 +90,7 @@ func (c *Client) retryConfigAuth(srv server.Server, preferTCP bool, t types.Toke } // getConfig gets an OpenVPN/WireGuard configuration by contacting the server, moving the FSM towards the DISCONNECTED state and then saving the local configuration file. -func (c *Client) getConfig(srv server.Server, preferTCP bool, t types.Tokens) (*types.Configuration, error) { +func (c *Client) getConfig(srv server.Server, preferTCP bool, t srvtypes.Tokens) (*srvtypes.Configuration, error) { if c.InFSMState(StateDeregistered) { return nil, errors.Errorf("getConfig attempt in '%v'", StateDeregistered) } @@ -121,7 +121,7 @@ func (c *Client) getConfig(srv server.Server, preferTCP bool, t types.Tokens) (* } // Cleanup cleans up the VPN connection by sending a /disconnect to the server -func (c *Client) Cleanup(ct types.Tokens) error { +func (c *Client) Cleanup(ct srvtypes.Tokens) error { srv, err := c.Servers.GetCurrentServer() if err != nil { c.logError(err) @@ -290,7 +290,7 @@ func (c *Client) AddInstituteServer(url string) (err error) { c.FSM.GoTransition(StateChosenServer) // Authorize it - if err = c.ensureLogin(srv, types.Tokens{}); err != nil { + if err = c.ensureLogin(srv, srvtypes.Tokens{}); err != nil { // Removing is best effort _ = c.RemoveInstituteAccess(url) return err @@ -355,7 +355,7 @@ func (c *Client) AddSecureInternetHomeServer(orgID string) (err error) { c.FSM.GoTransition(StateChosenServer) // Authorize it - if err = c.ensureLogin(srv, types.Tokens{}); err != nil { + if err = c.ensureLogin(srv, srvtypes.Tokens{}); err != nil { // Removing is best effort _ = c.RemoveSecureInternet() return err @@ -402,7 +402,7 @@ func (c *Client) AddCustomServer(url string) (err error) { c.FSM.GoTransition(StateChosenServer) // Authorize it - if err = c.ensureLogin(srv, types.Tokens{}); err != nil { + if err = c.ensureLogin(srv, srvtypes.Tokens{}); err != nil { // removing is best effort _ = c.RemoveCustomServer(url) return err @@ -415,7 +415,7 @@ func (c *Client) AddCustomServer(url string) (err error) { // GetConfigInstituteAccess gets a configuration for an Institute Access Server. // It ensures that the Institute Access Server exists by creating or using an existing one with the url. // `preferTCP` indicates that the client wants to use TCP (through OpenVPN) to establish the VPN tunnel. -func (c *Client) GetConfigInstituteAccess(url string, preferTCP bool, t types.Tokens) (cfg *types.Configuration, err error) { +func (c *Client) GetConfigInstituteAccess(url string, preferTCP bool, t srvtypes.Tokens) (cfg *srvtypes.Configuration, err error) { defer func() { if err != nil { c.logError(err) @@ -457,7 +457,7 @@ func (c *Client) GetConfigInstituteAccess(url string, preferTCP bool, t types.To // GetConfigSecureInternet gets a configuration for a Secure Internet Server. // It ensures that the Secure Internet Server exists by creating or using an existing one with the orgID. // `preferTCP` indicates that the client wants to use TCP (through OpenVPN) to establish the VPN tunnel. -func (c *Client) GetConfigSecureInternet(orgID string, preferTCP bool, t types.Tokens) (cfg *types.Configuration, err error) { +func (c *Client) GetConfigSecureInternet(orgID string, preferTCP bool, t srvtypes.Tokens) (cfg *srvtypes.Configuration, err error) { defer func() { if err != nil { c.logError(err) @@ -500,7 +500,7 @@ func (c *Client) GetConfigSecureInternet(orgID string, preferTCP bool, t types.T // GetConfigCustomServer gets a configuration for a Custom Server. // It ensures that the Custom Server exists by creating or using an existing one with the url. // `preferTCP` indicates that the client wants to use TCP (through OpenVPN) to establish the VPN tunnel. -func (c *Client) GetConfigCustomServer(url string, preferTCP bool, t types.Tokens) (cfg *types.Configuration, err error) { +func (c *Client) GetConfigCustomServer(url string, preferTCP bool, t srvtypes.Tokens) (cfg *srvtypes.Configuration, err error) { defer func() { if err != nil { c.logError(err) @@ -584,7 +584,7 @@ func (c *Client) RenewSession() (err error) { } server.MarkTokensForRenew(srv) - return c.ensureLogin(srv, types.Tokens{}) + return c.ensureLogin(srv, srvtypes.Tokens{}) } // ShouldRenewButton returns true if the renew button should be shown @@ -602,7 +602,7 @@ func (c *Client) ShouldRenewButton() bool { // ensureLogin logs the user back in if needed. // It runs the FSM transitions to ask for user input. -func (c *Client) ensureLogin(srv server.Server, t types.Tokens) (err error) { +func (c *Client) ensureLogin(srv server.Server, t srvtypes.Tokens) (err error) { // Relogin with oauth // This moves the state to authorized if !server.NeedsRelogin(srv) { |
