diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2024-07-10 14:39:34 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-07-17 14:00:03 +0000 |
| commit | a1879195a727d7b90347ed11f86d85fac6541df7 (patch) | |
| tree | ef19423671009552181f759b4a9162e7d91bf82a /internal | |
| parent | 7f8af5845ddec1816f93a2cb013f0818c19caab3 (diff) | |
Client + Discovery: Fetch dscovery at startup using DiscoveryStartup
With a manager that locks and copies such that no race conditions happen
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/api_test.go | 2 | ||||
| -rw-r--r-- | internal/discovery/discovery.go | 21 | ||||
| -rw-r--r-- | internal/server/secureinternet.go | 12 |
3 files changed, 30 insertions, 5 deletions
diff --git a/internal/api/api_test.go b/internal/api/api_test.go index 397dd3c..fcf02e9 100644 --- a/internal/api/api_test.go +++ b/internal/api/api_test.go @@ -196,7 +196,7 @@ func createTestAPI(t *testing.T, tok *eduoauth.Token, gt []string, hps []test.Ha Type: server.TypeCustom, BaseWK: serv.URL, BaseAuthWK: serv.URL, - ProcessAuth: func(ctx context.Context, in string) (string, error) { + ProcessAuth: func(_ context.Context, in string) (string, error) { return in, nil }, DisableAuthorize: false, diff --git a/internal/discovery/discovery.go b/internal/discovery/discovery.go index 30ca801..231c12a 100644 --- a/internal/discovery/discovery.go +++ b/internal/discovery/discovery.go @@ -405,3 +405,24 @@ func (discovery *Discovery) Servers(ctx context.Context) (*Servers, bool, error) } return &discovery.ServerList, true, nil } + +func (discovery *Discovery) UpdateServers(other Discovery) { + if other.ServerList.Version >= discovery.ServerList.Version { + discovery.ServerList = other.ServerList + } +} + +func (discovery *Discovery) Copy() (Discovery, error) { + var dest Discovery + b, err := json.Marshal(discovery) + if err != nil { + return dest, err + } + + err = json.Unmarshal(b, &dest) + if err != nil { + return dest, err + } + + return dest, nil +} diff --git a/internal/server/secureinternet.go b/internal/server/secureinternet.go index f167756..990ceb3 100644 --- a/internal/server/secureinternet.go +++ b/internal/server/secureinternet.go @@ -34,8 +34,10 @@ func (s *Servers) AddSecure(ctx context.Context, disco *discovery.Discovery, org BaseWK: dsrv.BaseURL, BaseAuthWK: dsrv.BaseURL, ProcessAuth: func(ctx context.Context, url string) (string, error) { - disco.Servers(ctx) - disco.Organizations(ctx) + // the only thing we can do is log warn + // this is already done in the functions + disco.Servers(ctx) //nolint:errcheck + disco.Organizations(ctx) //nolint:errcheck updorg, updsrv, err := disco.SecureHomeArgs(orgID) if err != nil { return "", err @@ -104,10 +106,12 @@ func (s *Servers) GetSecure(ctx context.Context, orgID string, disco *discovery. BaseWK: dloc.BaseURL, BaseAuthWK: dhome.BaseURL, ProcessAuth: func(ctx context.Context, url string) (string, error) { + // the only thing we can do is log warn + // this is already done in the functions disco.MarkServersExpired() - disco.Servers(ctx) + disco.Servers(ctx) //nolint:errcheck disco.MarkOrganizationsExpired() - disco.Organizations(ctx) + disco.Organizations(ctx) //nolint:errcheck updorg, updsrv, err := disco.SecureHomeArgs(orgID) if err != nil { return "", err |
