summaryrefslogtreecommitdiff
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go11
-rw-r--r--internal/config/v1/v1.go98
-rw-r--r--internal/config/v2/convert.go88
3 files changed, 1 insertions, 196 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 4b939b2..cb26f83 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -9,7 +9,6 @@ import (
"path"
"codeberg.org/eduVPN/eduvpn-common/internal/atomicfile"
- "codeberg.org/eduVPN/eduvpn-common/internal/config/v1"
"codeberg.org/eduVPN/eduvpn-common/internal/config/v2"
"codeberg.org/eduVPN/eduvpn-common/internal/discovery"
)
@@ -64,20 +63,12 @@ func (c *Config) Load() error {
if err = json.Unmarshal(bts, &buf); err != nil {
return err
}
- if buf.V2 != nil {
- c.V2 = buf.V2
- return nil
- }
- if buf.V1 != nil {
- c.V2 = v2.FromV1(buf.V1)
- }
+ c.V2 = buf.V2
return nil
}
// Versioned is the final top-level state file that is written to disk
type Versioned struct {
- // V1 is the version 1 state file that is no longer used but converted from
- V1 *v1.V1 `json:"v1,omitempty"`
// V2 is the version 2 state file
V2 *v2.V2 `json:"v2,omitempty"`
}
diff --git a/internal/config/v1/v1.go b/internal/config/v1/v1.go
deleted file mode 100644
index 5f5cd93..0000000
--- a/internal/config/v1/v1.go
+++ /dev/null
@@ -1,98 +0,0 @@
-// Package v1 implements a minimum set of the v1 config to convert it to a v2 config
-// In version 1 of the config we used the internal state as the config
-// This was bad as now if we want to change some internal representation the config also changes
-// This package can be removed when most people have migrated from v1 to v2
-package v1
-
-import (
- "time"
-
- "codeberg.org/eduVPN/eduvpn-common/internal/api/profiles"
- "codeberg.org/eduVPN/eduvpn-common/internal/discovery"
-)
-
-// Profiles is the list of profiles
-type Profiles struct {
- profiles.Info
- Current string `json:"current_profile"`
-}
-
-// Base is the base type of a server
-type Base struct {
- // BaseURL is the base_url from discovery
- BaseURL string `json:"base_url"`
- // profiles is the last of profile
- Profiles Profiles `json:"profiles"`
- // StartTime is the time when we started the connection
- StartTime time.Time `json:"start_time"`
- // StartTimeOAuth is the time when we last started OAuth
- StartTimeOAuth time.Time `json:"start_time_oauth"`
- // ExpireTime is the time when the connection expires
- ExpireTime time.Time `json:"expire_time"`
-}
-
-// InstituteServer is the struct that represents an institute access server
-type InstituteServer struct {
- // Base is the base of the server
- Base Base `json:"base"`
-}
-
-// InstituteServers is a list of institute access servers
-type InstituteServers struct {
- // Map is the map from base url to an institute access server
- Map map[string]InstituteServer `json:"map"`
- // CurrentURL is the URL of the currently configured server
- CurrentURL string `json:"current_url"`
-}
-
-type (
- // CustomServer is an alias to InstituteServer
- CustomServer = InstituteServer
- // CustomServers is an alias to InstituteServers
- CustomServers = InstituteServers
-)
-
-// SecureInternetHome represents a secure internet home server
-type SecureInternetHome struct {
- // BaseMap is the map from country code to a server base
- BaseMap map[string]*Base `json:"base_map"`
- // DisplayName is the map from language code to UI name
- DisplayName map[string]string `json:"display_name"`
- // HomeOrganizationID is the identifier of the home organization
- HomeOrganizationID string `json:"home_organization_id"`
- // CurrentLocation is the country code of the currently configured server
- CurrentLocation string `json:"current_location"`
-}
-
-// Type is the type of server, a server from discovery or one entered manually by typing it in the client
-type Type int8
-
-const (
- // CustomServerType is the type of server that is manually added by typing a URL
- CustomServerType Type = iota
- // InstituteAccessServerType is the type of server that is in the discovery server_list.json with type "institute_access"
- InstituteAccessServerType
- // SecureInternetServerType is the type of server that is in the discovery server_list.json with type "secure_internet"
- SecureInternetServerType
-)
-
-// Servers represents the list of servers
-type Servers struct {
- // Custom are the "custom" servers; the servers that are added by the user
- Custom CustomServers `json:"custom_servers"`
- // Institute are the institute access servers configured from discovery
- Institute InstituteServers `json:"institute_servers"`
- // SecureInternetHome is the secure internet home server
- // Also obtained through discovery
- SecureInternetHome SecureInternetHome `json:"secure_internet_home"`
- // IsType represents which server type was last configured
- IsType Type `json:"is_secure_internet"`
-}
-
-// V1 is the top-level struct for the first version of the state file
-type V1 struct {
- // Discovery is the list of discovery servers
- Discovery discovery.Discovery `json:"discovery"`
- // Servers is the list of servers in the app
- Servers Servers `json:"servers"`
-}
diff --git a/internal/config/v2/convert.go b/internal/config/v2/convert.go
deleted file mode 100644
index 675d274..0000000
--- a/internal/config/v2/convert.go
+++ /dev/null
@@ -1,88 +0,0 @@
-package v2
-
-import (
- "maps"
- "time"
-
- "codeberg.org/eduVPN/eduvpn-common/internal/config/v1"
- "codeberg.org/eduVPN/eduvpn-common/types/server"
-)
-
-func v1AuthTime(st time.Time, ost time.Time) time.Time {
- // OAuth start time can be zero
- if ost.IsZero() {
- return st
- }
- return ost
-}
-
-func convertV1Server(list v1.InstituteServers, iscurrent bool, t server.Type) (map[ServerKey]*Server, *ServerKey) {
- ret := make(map[ServerKey]*Server)
- var lc *ServerKey
- for k, v := range list.Map {
- key := ServerKey{
- T: t,
- ID: k,
- }
- if iscurrent && k == list.CurrentURL {
- lc = &key
- }
- prfs := v.Base.Profiles.Public()
- prfs.Current = v.Base.Profiles.Current
- ret[key] = &Server{
- Profiles: prfs,
- LastAuthorizeTime: v1AuthTime(v.Base.StartTime, v.Base.StartTimeOAuth),
- ExpireTime: v.Base.ExpireTime,
- }
- }
- return ret, lc
-}
-
-// FromV1 converts a version 1 state struct into a v2 one
-func FromV1(ver1 *v1.V1) *V2 {
- gsrvs := ver1.Servers
-
- var lc *ServerKey
- cust, glc := convertV1Server(gsrvs.Custom, gsrvs.IsType == v1.CustomServerType, server.TypeCustom)
- if lc == nil {
- lc = glc
- }
- res, glc := convertV1Server(gsrvs.Institute, gsrvs.IsType == v1.InstituteAccessServerType, server.TypeInstituteAccess)
- if lc == nil {
- lc = glc
- }
-
- maps.Copy(res, cust)
- sec := gsrvs.SecureInternetHome
- // if the home organization ID is filled we have secure internet present
- if sec.HomeOrganizationID == "" {
- return &V2{
- Discovery: ver1.Discovery,
- List: res,
- LastChosen: lc,
- }
- }
- v, ok := sec.BaseMap[sec.CurrentLocation]
- if v != nil && ok {
- t := ServerKey{
- T: server.TypeSecureInternet,
- ID: sec.HomeOrganizationID,
- }
- if gsrvs.IsType == v1.SecureInternetServerType {
- lc = &t
- }
- prfs := v.Profiles.Public()
- prfs.Current = v.Profiles.Current
- res[t] = &Server{
- CountryCode: sec.CurrentLocation,
- Profiles: prfs,
- LastAuthorizeTime: v1AuthTime(v.StartTime, v.StartTimeOAuth),
- ExpireTime: v.ExpireTime,
- }
- }
- return &V2{
- Discovery: ver1.Discovery,
- List: res,
- LastChosen: lc,
- }
-}