Feature: filter by hostname for Cyberghost servers

This commit is contained in:
Quentin McGaw
2021-05-08 19:05:11 +00:00
parent c0e4d805b1
commit a34769ae02
9 changed files with 182 additions and 121 deletions

View File

@@ -29,11 +29,12 @@ func newCyberghost(servers []models.CyberghostServer, timeNow timeNowFunc) *cybe
}
}
func (c *cyberghost) filterServers(regions []string, group string) (servers []models.CyberghostServer) {
func (c *cyberghost) filterServers(regions, hostnames []string, group string) (servers []models.CyberghostServer) {
for _, server := range c.servers {
switch {
case len(group) > 0 && !strings.EqualFold(group, server.Group),
filterByPossibilities(server.Region, regions):
case group != "" && !strings.EqualFold(group, server.Group),
filterByPossibilities(server.Region, regions),
filterByPossibilities(server.Hostname, hostnames):
default:
servers = append(servers, server)
}
@@ -48,7 +49,7 @@ func (c *cyberghost) GetOpenVPNConnection(selection configuration.ServerSelectio
return models.OpenVPNConnection{IP: selection.TargetIP, Port: httpsPort, Protocol: selection.Protocol}, nil
}
servers := c.filterServers(selection.Regions, selection.Group)
servers := c.filterServers(selection.Regions, selection.Hostnames, selection.Group)
if len(servers) == 0 {
return connection,
fmt.Errorf("no server found for regions %s and group %q", commaJoin(selection.Regions), selection.Group)