From e71636896ea0c24fdf4fbff03ca082190c5a6569 Mon Sep 17 00:00:00 2001 From: Nikolai Rodionov Date: Sun, 5 May 2024 21:07:12 +0200 Subject: [PATCH] Add a search string to envs --- go.mod | 2 +- go.sum | 4 ++-- internal/controllers/environments.go | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1d7f339..e5a9266 100644 --- a/go.mod +++ b/go.mod @@ -148,7 +148,7 @@ require ( ) require ( - git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10 + git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11 github.com/golang/protobuf v1.5.4 golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect diff --git a/go.sum b/go.sum index 189ea43..c69c10a 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10 h1:vyI425BM85gyUi23HXJQtMw/pC81wYhWgBKgmG3Lc2w= -git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.10/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI= +git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11 h1:Kjdz7HUOhg5f8wktvf+QG6SNv0sN3OXfz9yErwrfl38= +git.badhouseplants.net/softplayer/softplayer-go-proto v0.1.11/go.mod h1:OU+833cHwvecr+gsnPEKQYlAJbpL8bqSJVLobdw63qI= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8= github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= diff --git a/internal/controllers/environments.go b/internal/controllers/environments.go index 207bda5..96e0e89 100644 --- a/internal/controllers/environments.go +++ b/internal/controllers/environments.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "log" + "strings" "github.com/google/uuid" "github.com/joho/godotenv" @@ -213,7 +214,7 @@ func (env *Environemnt) Delete(ctx context.Context) error { return nil } -func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) { +func (env *Environemnt) ListEnvs(ctx context.Context, searchString string) ([]*Environemnt, error) { env.Controller.GetClient() conf := &rest.Config{ Host: "https://kubernetes.default.svc.cluster.local:443", @@ -244,7 +245,16 @@ func (env *Environemnt) ListEnvs(ctx context.Context) ([]*Environemnt, error) { if err := i.Get(ctx); err != nil { return nil, err } - result = append(result, i) + if len(searchString) > 0 { + if strings.Contains(i.Data.Name, searchString) { + result = append(result, i) + } + if strings.Contains(i.Data.Description, searchString) { + result = append(result, i) + } + } else { + result = append(result, i) + } } return result, nil }