blob: 1da2d1eb7640d032726080fa8d9b9315b3b33af8 (
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
|
package server
import (
"fmt"
"github.com/jwijenbergh/eduvpn-common/internal/fsm"
"github.com/jwijenbergh/eduvpn-common/internal/oauth"
"github.com/jwijenbergh/eduvpn-common/internal/types"
)
// An instute access server
type InstituteAccessServer struct {
// An instute access server has its own OAuth
OAuth oauth.OAuth `json:"oauth"`
// Embed the server base
Base ServerBase `json:"base"`
}
type InstituteAccessServers struct {
Map map[string]*InstituteAccessServer `json:"map"`
CurrentURL string `json:"current_url"`
}
// For an institute, we can simply get the OAuth
func (institute *InstituteAccessServer) GetOAuth() *oauth.OAuth {
return &institute.OAuth
}
func (institute *InstituteAccessServer) GetTemplateAuth() func(string) string {
return func(authURL string) string {
return authURL
}
}
func (institute *InstituteAccessServer) GetBase() (*ServerBase, error) {
return &institute.Base, nil
}
func (institute *InstituteAccessServer) init(url string, displayName map[string]string, serverType string, supportContact []string, fsm *fsm.FSM) error {
errorMessage := fmt.Sprintf("failed initializing institute server %s", url)
institute.Base.URL = url
institute.Base.DisplayName = displayName
institute.Base.SupportContact = supportContact
institute.Base.FSM = fsm
institute.Base.Type = serverType
endpoints, endpointsErr := APIGetEndpoints(url)
if endpointsErr != nil {
return &types.WrappedErrorMessage{Message: errorMessage, Err: endpointsErr}
}
institute.OAuth.Init(endpoints.API.V3.Authorization, endpoints.API.V3.Token, fsm)
institute.Base.Endpoints = *endpoints
return nil
}
|