summaryrefslogtreecommitdiff
path: root/internal/server/custom/custom.go
blob: 14a72a58260a3986132fef062c61f12526710da4 (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
package custom

import (
	"context"

	"github.com/eduvpn/eduvpn-common/internal/server/api"
	"github.com/eduvpn/eduvpn-common/internal/server/base"
	"github.com/eduvpn/eduvpn-common/internal/server/institute"
	"github.com/eduvpn/eduvpn-common/types/server"
)

type (
	Server  = institute.Server
	Servers = institute.Servers
)

func New(ctx context.Context, url string) (*Server, error) {
	b := base.Base{
		URL:         url,
		DisplayName: map[string]string{"en": url},
		Type:        server.TypeCustom,
	}
	if err := api.Endpoints(ctx, &b); err != nil {
		return nil, err
	}
	API := b.Endpoints.API.V3

	s := &Server{Basic: b}
	s.Auth.Init(url, API.Authorization, API.Token)
	return s, nil
}