summaryrefslogtreecommitdiff
path: root/internal/server/instituteaccess.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-19 08:30:46 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-07-19 08:30:46 +0200
commit3f7a95dea59ce05ff9cd620fd51a25dd72b3827b (patch)
tree9cc27b0b2f2ccc62c094ca3de879b270c21691c0 /internal/server/instituteaccess.go
parentb3b78558e3d5d369f76a696e7f1b30559a16d3c7 (diff)
Server: Split CustomServer and split types into multiple files
Diffstat (limited to 'internal/server/instituteaccess.go')
-rw-r--r--internal/server/instituteaccess.go56
1 files changed, 56 insertions, 0 deletions
diff --git a/internal/server/instituteaccess.go b/internal/server/instituteaccess.go
new file mode 100644
index 0000000..9e712bd
--- /dev/null
+++ b/internal/server/instituteaccess.go
@@ -0,0 +1,56 @@
+package server
+
+import (
+ "fmt"
+
+ "github.com/jwijenbergh/eduvpn-common/internal/fsm"
+ "github.com/jwijenbergh/eduvpn-common/internal/log"
+ "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, logger *log.FileLogger) 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.Logger = logger
+ 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, logger)
+ institute.Base.Endpoints = *endpoints
+ return nil
+}