summaryrefslogtreecommitdiff
path: root/internal/server/institute
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-02-06 16:26:05 +0100
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-02-19 14:15:07 +0100
commit819d7f9914cbb34abb76b932c05b030a34986ec2 (patch)
tree7da743c1a0363e800a041e0310ca8cf441bc3f90 /internal/server/institute
parent4d26c8489b09acc98128715e9a2ed67558eb8105 (diff)
Server: Delete old files to prepare for new internal API
Diffstat (limited to 'internal/server/institute')
-rw-r--r--internal/server/institute/institute.go133
1 files changed, 0 insertions, 133 deletions
diff --git a/internal/server/institute/institute.go b/internal/server/institute/institute.go
deleted file mode 100644
index 82e51e6..0000000
--- a/internal/server/institute/institute.go
+++ /dev/null
@@ -1,133 +0,0 @@
-package institute
-
-import (
- "context"
-
- "github.com/eduvpn/eduvpn-common/internal/discovery"
- "github.com/eduvpn/eduvpn-common/internal/oauth"
- "github.com/eduvpn/eduvpn-common/internal/server/api"
- "github.com/eduvpn/eduvpn-common/internal/server/base"
- "github.com/eduvpn/eduvpn-common/types/server"
- "github.com/go-errors/errors"
-)
-
-type Server struct {
- // An instute access server has its own OAuth
- Auth oauth.OAuth `json:"oauth"`
-
- // Embed the server base
- Basic base.Base `json:"base"`
-}
-
-type Servers struct {
- Map map[string]*Server `json:"map"`
- CurrentURL string `json:"current_url"`
-}
-
-func New(
- ctx context.Context,
- clientID string,
- url string,
- name map[string]string,
- supportContact []string,
-) (*Server, error) {
- b := base.Base{
- URL: url,
- DisplayName: name,
- SupportContact: supportContact,
- Type: server.TypeInstituteAccess,
- }
- if err := api.Endpoints(ctx, &b); err != nil {
- return nil, err
- }
- API := b.Endpoints.API.V3
-
- s := &Server{Basic: b}
-
- if url == "" {
- return nil, errors.New("URL passed to OAuth is empty")
- }
- s.Auth.Init(clientID, url, API.Authorization, API.Token)
- return s, nil
-}
-
-func (s *Servers) Current() (*Server, error) {
- if s.Map == nil {
- return nil, errors.Errorf("No map is found when getting the current server")
- }
-
- srv, ok := s.Map[s.CurrentURL]
- if !ok || srv == nil {
- return nil, errors.Errorf("server not found")
- }
- return srv, nil
-}
-
-func (s *Servers) Remove(url string) error {
- // check if it is in the map to begin with
- if _, ok := s.Map[url]; ok {
- delete(s.Map, url)
- } else {
- return errors.Errorf("cannot remove URL: %v, not found in list", url)
- }
-
- // Reset the current url
- if s.CurrentURL == url {
- s.CurrentURL = ""
- }
- return nil
-}
-
-func (s *Servers) Add(srv *Server) {
- if s.Map == nil {
- s.Map = make(map[string]*Server)
- }
- s.Map[srv.Basic.URL] = srv
-}
-
-func (s *Server) TemplateAuth() func(string) string {
- return func(authURL string) string {
- return authURL
- }
-}
-
-func (s *Server) Base() (*base.Base, error) {
- return &s.Basic, nil
-}
-
-func (s *Server) OAuth() *oauth.OAuth {
- return &s.Auth
-}
-
-func (s *Server) NeedsLocation() bool {
- return false
-}
-
-func (s *Server) RefreshEndpoints(ctx context.Context, _ *discovery.Discovery) error {
- // Re-initialize the endpoints
- b, err := s.Base()
- if err != nil {
- return err
- }
-
- err = api.Endpoints(ctx, b)
- if err != nil {
- return err
- }
-
- // update OAuth
- auth := s.OAuth()
- if auth != nil {
- auth.BaseAuthorizationURL = b.Endpoints.API.V3.Authorization
- auth.TokenURL = b.Endpoints.API.V3.Token
- }
- return nil
-}
-
-func (s *Server) Public() (interface{}, error) {
- return &server.Server{
- DisplayName: s.Basic.DisplayName,
- Identifier: s.Basic.URL,
- Profiles: s.Basic.Profiles.Public(),
- }, nil
-}