feat: added error to GetContextEndpoint

this ill make the progam not fail if there is a non-docker swarm context
This commit is contained in:
2021-07-18 06:34:22 +01:00
parent a2bb0ed027
commit 37c06c82bf
2 changed files with 15 additions and 4 deletions

View File

@ -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 {