summaryrefslogtreecommitdiff
path: root/client/discovery.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-05-07 11:51:34 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-05-29 14:36:10 +0200
commit3ecfc012e2db8b464596faf2c3bd4db1cab8697b (patch)
treeb234ee9aa6729e56232786fee83f92cc5bbb63e3 /client/discovery.go
parentb1033a6a39fe21fec99be5318ba3536af148a79b (diff)
Discovery: Implement search and do not return keywords
This patch implements search by adding a second argument to DiscoOrganizations and DiscoServers. A search string of = "" returns everything. This also makes the subset that is returned to the client even fewer, no keywords.
Diffstat (limited to 'client/discovery.go')
-rw-r--r--client/discovery.go26
1 files changed, 16 insertions, 10 deletions
diff --git a/client/discovery.go b/client/discovery.go
index a1df585..49df8b2 100644
--- a/client/discovery.go
+++ b/client/discovery.go
@@ -13,11 +13,11 @@ func (c *Client) hasDiscovery() bool {
return strings.HasPrefix(c.Name, "org.eduvpn.app")
}
-// DiscoOrganizations gets the organizations list from the discovery server
+// DiscoOrganizations gets the organizations list from the discovery server with search string `search`
// 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) (*discotypes.Organizations, error) {
+func (c *Client) DiscoOrganizations(ck *cookie.Cookie, search string) (*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")
@@ -32,20 +32,23 @@ func (c *Client) DiscoOrganizations(ck *cookie.Cookie) (*discotypes.Organization
}
// convert to public subset
- retOrgs := make([]discotypes.Organization, len(orgs.List))
- for i, v := range orgs.List {
- retOrgs[i] = v.Organization
+ var retOrgs []discotypes.Organization
+ for _, v := range orgs.List {
+ if !v.Matches(search) {
+ continue
+ }
+ retOrgs = append(retOrgs, v.Organization)
}
return &discotypes.Organizations{
List: retOrgs,
}, err
}
-// DiscoServers gets the servers list from the discovery server
+// DiscoServers gets the servers list from the discovery server with search string `search`
// 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) (*discotypes.Servers, error) {
+func (c *Client) DiscoServers(ck *cookie.Cookie, search string) (*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")
@@ -60,9 +63,12 @@ func (c *Client) DiscoServers(ck *cookie.Cookie) (*discotypes.Servers, error) {
}
// convert to public subset
- retServs := make([]discotypes.Server, len(servs.List))
- for i, v := range servs.List {
- retServs[i] = v.Server
+ var retServs []discotypes.Server
+ for _, v := range servs.List {
+ if !v.Matches(search) {
+ continue
+ }
+ retServs = append(retServs, v.Server)
}
return &discotypes.Servers{
List: retServs,