summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/discovery/discovery.go8
-rw-r--r--internal/server/common.go103
-rw-r--r--internal/types/server.go1
3 files changed, 17 insertions, 95 deletions
diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go
index 21125cb..b3b438c 100644
--- a/internal/discovery/discovery.go
+++ b/internal/discovery/discovery.go
@@ -182,15 +182,15 @@ func (discovery *Discovery) GetOrganizationsList() (*types.DiscoveryOrganization
}
// Get the server list
-func (discovery *Discovery) GetServersList() (string, error) {
+func (discovery *Discovery) GetServersList() (*types.DiscoveryServers, error) {
if !discovery.DetermineServersUpdate() {
- return discovery.Servers.RawString, nil
+ return &discovery.Servers, nil
}
file := "server_list.json"
body, bodyErr := getDiscoFile(file, discovery.Servers.Version, &discovery.Servers)
if bodyErr != nil {
// Return previous with an error
- return discovery.Servers.RawString, &types.WrappedErrorMessage{
+ return &discovery.Servers, &types.WrappedErrorMessage{
Message: "failed getting servers in Discovery",
Err: bodyErr,
}
@@ -198,7 +198,7 @@ func (discovery *Discovery) GetServersList() (string, error) {
// Update servers timestamp
discovery.Servers.RawString = body
discovery.Servers.Timestamp = util.GetCurrentTime()
- return discovery.Servers.RawString, nil
+ return &discovery.Servers, nil
}
type GetOrgByIDNotFoundError struct {
diff --git a/internal/server/common.go b/internal/server/common.go
index 64b8079..9c941cf 100644
--- a/internal/server/common.go
+++ b/internal/server/common.go
@@ -64,6 +64,18 @@ type ServerProfileInfo struct {
} `json:"info"`
}
+func (info ServerProfileInfo) GetCurrentProfileIndex() int {
+ index := 0
+ for _, profile := range info.Info.ProfileList {
+ if profile.ID == info.Current {
+ return index
+ }
+ index += 1
+ }
+ // Default is 'first' profile
+ return 0
+}
+
type ServerEndpointList struct {
API string `json:"api_endpoint"`
Authorization string `json:"authorization_endpoint"`
@@ -118,97 +130,6 @@ func (servers *Servers) GetCurrentServer() (Server, error) {
return server, nil
}
-type ServersConfiguredScreen struct {
- CustomServers []ServerInfoScreen `json:"custom_servers"`
- InstituteAccessServers []ServerInfoScreen `json:"institute_access_servers"`
- SecureInternetServer *ServerInfoScreen `json:"secure_internet_server"`
-}
-
-type ServerInfoScreen struct {
- Identifier string `json:"identifier"`
- DisplayName map[string]string `json:"display_name"`
- CountryCode string `json:"country_code,omitempty"`
- SupportContact []string `json:"support_contact"`
- Profiles ServerProfileInfo `json:"profiles"`
- ExpireTime int64 `json:"expire_time"`
- Type string `json:"server_type"`
-}
-
-func getServerInfoScreen(base ServerBase) ServerInfoScreen {
- serverInfoScreen := ServerInfoScreen{}
- serverInfoScreen.Identifier = base.URL
- serverInfoScreen.DisplayName = base.DisplayName
- serverInfoScreen.SupportContact = base.SupportContact
- serverInfoScreen.Profiles = base.Profiles
-
- // If we still have the default end time, return 0
- // Such that clients will still be able to parse it correctly
- if base.EndTime.IsZero() {
- serverInfoScreen.ExpireTime = 0
- } else {
- serverInfoScreen.ExpireTime = base.EndTime.Unix()
- }
- serverInfoScreen.Type = base.Type
-
- return serverInfoScreen
-}
-
-func (servers *Servers) GetServersConfigured() *ServersConfiguredScreen {
- customServersInfo := []ServerInfoScreen{}
- instituteServersInfo := []ServerInfoScreen{}
- var secureInternetServerInfo *ServerInfoScreen = nil
-
- for _, server := range servers.CustomServers.Map {
- serverInfoScreen := getServerInfoScreen(server.Base)
- customServersInfo = append(customServersInfo, serverInfoScreen)
- }
-
- for _, server := range servers.InstituteServers.Map {
- serverInfoScreen := getServerInfoScreen(server.Base)
- instituteServersInfo = append(instituteServersInfo, serverInfoScreen)
- }
-
- secureInternetBase, secureInternetBaseErr := servers.SecureInternetHomeServer.GetBase()
-
- if secureInternetBaseErr == nil && secureInternetBase != nil {
- // FIXME: log error?
- secureInternetServerInfoReturned := getServerInfoScreen(*secureInternetBase)
- secureInternetServerInfo = &secureInternetServerInfoReturned
- secureInternetServerInfo.Identifier = servers.SecureInternetHomeServer.HomeOrganizationID
- secureInternetServerInfo.CountryCode = servers.SecureInternetHomeServer.CurrentLocation
- }
-
- return &ServersConfiguredScreen{
- CustomServers: customServersInfo,
- InstituteAccessServers: instituteServersInfo,
- SecureInternetServer: secureInternetServerInfo,
- }
-}
-
-func (servers *Servers) GetCurrentServerInfo() (*ServerInfoScreen, error) {
- errorMessage := "failed getting current server info"
-
- currentServer, currentServerErr := servers.GetCurrentServer()
- if currentServerErr != nil {
- return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: currentServerErr}
- }
-
- base, baseErr := currentServer.GetBase()
-
- if baseErr != nil {
- return nil, &types.WrappedErrorMessage{Message: errorMessage, Err: baseErr}
- }
-
- serverInfoScreen := getServerInfoScreen(*base)
-
- if servers.IsType == SecureInternetServerType {
- serverInfoScreen.Identifier = servers.SecureInternetHomeServer.HomeOrganizationID
- serverInfoScreen.CountryCode = servers.SecureInternetHomeServer.CurrentLocation
- }
-
- return &serverInfoScreen, nil
-}
-
func (servers *Servers) addInstituteAndCustom(
discoServer *types.DiscoveryServer,
isCustom bool,
diff --git a/internal/types/server.go b/internal/types/server.go
index 33a6e9c..48f94fb 100644
--- a/internal/types/server.go
+++ b/internal/types/server.go
@@ -62,6 +62,7 @@ type DiscoveryServer struct {
BaseURL string `json:"base_url"`
CountryCode string `json:"country_code"`
DisplayName DiscoMapOrString `json:"display_name,omitempty"`
+ KeywordList DiscoMapOrString `json:"keyword_list"`
PublicKeyList []string `json:"public_key_list"`
Type string `json:"server_type"`
SupportContact []string `json:"support_contact"`