diff options
| author | Jeroen Wijenbergh <jeroenwijenbergh@protonmail.com> | 2024-04-30 13:12:41 +0200 |
|---|---|---|
| committer | Jeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com> | 2024-05-29 14:36:10 +0200 |
| commit | b1033a6a39fe21fec99be5318ba3536af148a79b (patch) | |
| tree | b7f8032f4b8efd3bee4d447b262155ac3e95d221 /client/discovery.go | |
| parent | 67df2767c1edd64eed4ea1aa1a2628576de40e3f (diff) | |
Discovery: Return a subset to the client
Diffstat (limited to 'client/discovery.go')
| -rw-r--r-- | client/discovery.go | 34 |
1 files changed, 28 insertions, 6 deletions
diff --git a/client/discovery.go b/client/discovery.go index ccd8f0a..a1df585 100644 --- a/client/discovery.go +++ b/client/discovery.go @@ -17,32 +17,54 @@ func (c *Client) hasDiscovery() bool { // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#organization-list. -func (c *Client) DiscoOrganizations(ck *cookie.Cookie) (orgs *discotypes.Organizations, err error) { +func (c *Client) DiscoOrganizations(ck *cookie.Cookie) (*discotypes.Organizations, error) { // Not supported with Let's Connect! & govVPN if !c.hasDiscovery() { return nil, i18nerr.NewInternal("Server/organization discovery with this client ID is not supported") } - orgs, err = c.cfg.Discovery().Organizations(ck.Context()) + orgs, err := c.cfg.Discovery().Organizations(ck.Context()) if err != nil { err = i18nerr.Wrap(err, "An error occurred after getting the discovery files for the list of organizations") } - return + if orgs == nil { + return nil, err + } + + // convert to public subset + retOrgs := make([]discotypes.Organization, len(orgs.List)) + for i, v := range orgs.List { + retOrgs[i] = v.Organization + } + return &discotypes.Organizations{ + List: retOrgs, + }, err } // DiscoServers gets the servers list from the discovery server // If the list cannot be retrieved an error is returned. // If this is the case then a previous version of the list is returned if there is any. // This takes into account the frequency of updates, see: https://github.com/eduvpn/documentation/blob/v3/SERVER_DISCOVERY.md#server-list. -func (c *Client) DiscoServers(ck *cookie.Cookie) (dss *discotypes.Servers, err error) { +func (c *Client) DiscoServers(ck *cookie.Cookie) (*discotypes.Servers, error) { // Not supported with Let's Connect! & govVPN if !c.hasDiscovery() { return nil, i18nerr.NewInternal("Server/organization discovery with this client ID is not supported") } - dss, err = c.cfg.Discovery().Servers(ck.Context()) + servs, err := c.cfg.Discovery().Servers(ck.Context()) if err != nil { err = i18nerr.Wrap(err, "An error occurred after getting the discovery files for the list of servers") } - return + if servs == nil { + return nil, err + } + + // convert to public subset + retServs := make([]discotypes.Server, len(servs.List)) + for i, v := range servs.List { + retServs[i] = v.Server + } + return &discotypes.Servers{ + List: retServs, + }, err } |
