From 37c06c82bfdf08b90d6a4651f5d08a241ad8d852 Mon Sep 17 00:00:00 2001 From: Roxie Gibson Date: Sun, 18 Jul 2021 06:34:22 +0100 Subject: [PATCH] feat: added error to GetContextEndpoint this ill make the progam not fail if there is a non-docker swarm context --- cli/server.go | 8 +++++++- client/client.go | 11 ++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cli/server.go b/cli/server.go index a72662c4..c6c8473b 100644 --- a/cli/server.go +++ b/cli/server.go @@ -26,10 +26,16 @@ var serverListCommand = &cli.Command{ serverNames := config.ReadServerNames() for _, serverName := range serverNames { + var row []string for _, ctx := range contexts { + endpoint, err := client.GetContextEndpoint(ctx) + if err != nil { + // This most likely means its a non-docker swarm context and we can ignore + continue + } if ctx.Name == serverName { - row = []string{serverName, client.GetContextEndpoint(ctx)} + row = []string{serverName, endpoint} } } if len(row) == 0 { diff --git a/client/client.go b/client/client.go index 3c769920..ce85567d 100644 --- a/client/client.go +++ b/client/client.go @@ -1,6 +1,7 @@ package client import ( + "errors" "fmt" "net/http" "os" @@ -49,10 +50,14 @@ func NewClientWithContext(contextURL string) *dClient.Client { return cl } -func GetContextEndpoint(ctx dCliContextStore.Metadata) string { +func GetContextEndpoint(ctx dCliContextStore.Metadata) (string, error) { // safe to use docker key hardcoded since abra doesn't use k8s... yet... - endpointmeta := ctx.Endpoints["docker"].(dContext.EndpointMetaBase) - return endpointmeta.Host + endpointmeta, ok := ctx.Endpoints["docker"].(dContext.EndpointMetaBase) + if !ok { + err := errors.New("context lacks Docker endpoint") + return "", err + } + return endpointmeta.Host, nil } func NewDefaultDockerContextStore() *dCliCommand.ContextStoreWithDefault {