summaryrefslogtreecommitdiff
path: root/types/discovery/discovery.go
blob: 390cb43c17c0a65b373f9012817fc51aa4eae3d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package discovery

import (
	"encoding/json"
	"time"
)

// TODO: Discovery here is the same as the upstream discovery format, should we separate this as well?
// Defined in URL: "https://disco.eduvpn.org/v2/organization_list.json"
type Organizations struct {
	Version   uint64         `json:"v"`
	List      []Organization `json:"organization_list,omitempty"`
	Timestamp time.Time      `json:"go_timestamp"`
}

type Organization struct {
	DisplayName        MapOrString `json:"display_name,omitempty"`
	OrgID              string      `json:"org_id"`
	SecureInternetHome string      `json:"secure_internet_home,omitempty"`
	KeywordList        MapOrString `json:"keyword_list,omitempty"`
}

// Structs that define the json format for
// url: "https://disco.eduvpn.org/v2/server_list.json"
type Servers struct {
	Version   uint64    `json:"v"`
	List      []Server  `json:"server_list,omitempty"`
	Timestamp time.Time `json:"go_timestamp"`
}

type MapOrString map[string]string

// The display name can either be a map or a string in the server list
// Unmarshal it by first trying a string and then the map.
func (displayName *MapOrString) UnmarshalJSON(data []byte) error {
	var displayNameString string

	err := json.Unmarshal(data, &displayNameString)

	if err == nil {
		*displayName = map[string]string{"en": displayNameString}
		return nil
	}

	var resultingMap map[string]string

	err = json.Unmarshal(data, &resultingMap)

	if err == nil {
		*displayName = resultingMap
		return nil
	}
	return err
}

type Server struct {
	AuthenticationURLTemplate string      `json:"authentication_url_template"`
	BaseURL                   string      `json:"base_url"`
	CountryCode               string      `json:"country_code"`
	DisplayName               MapOrString `json:"display_name,omitempty"`
	KeywordList               MapOrString `json:"keyword_list,omitempty"`
	PublicKeyList             []string    `json:"public_key_list"`
	Type                      string      `json:"server_type"`
	SupportContact            []string    `json:"support_contact"`
}