summaryrefslogtreecommitdiff
path: root/client/discovery.go
diff options
context:
space:
mode:
Diffstat (limited to 'client/discovery.go')
-rw-r--r--client/discovery.go34
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
}