refactor!: consolidate SSH handling
Some checks failed
continuous-integration/drone/push Build is failing

Closes coop-cloud/organising#389.
Closes coop-cloud/organising#341.
Closes coop-cloud/organising#326.
Closes coop-cloud/organising#380.
Closes coop-cloud/organising#360.
This commit is contained in:
2023-01-31 16:09:09 +01:00
committed by Gitea
parent f20fbbc913
commit 7c1a97be72
23 changed files with 253 additions and 1249 deletions

View File

@ -2,7 +2,6 @@ package context
import (
"errors"
"fmt"
"github.com/docker/cli/cli/command"
dConfig "github.com/docker/cli/cli/config"
@ -43,68 +42,3 @@ func GetContextEndpoint(ctx contextStore.Metadata) (string, error) {
func newContextStore(dir string, config contextStore.Config) contextStore.Store {
return contextStore.New(dir, config)
}
// missingContextMsg helps end-user debug missing docker context issues. This
// version of the message has no app domain name included. This is due to the
// code paths being unable to determine which app is requesting a server
// connection at certain points. It is preferred to use
// missingContextWithAppMsg where possible and only use missingContextMsg when
// the call path is located too deep in the SSH stack.
var missingContextMsg = `unable to find Docker context for %s?
Please run "abra server ls -p" to confirm. If you see "unknown" in the table
output then you need to run the following command:
abra server add %s <args>
See "abra server add --help" for more.
`
// missingContextWithAppMsg helps end-users debug missing docker context
// issues. The app name is included in this message for extra clarity. See
// missingContextMsg docs for alternative usage.
var missingContextWithAppMsg = `unable to find Docker context for %s?
%s (app) is deployed on %s (server).
Please run "abra server ls -p" to confirm. If you see "unknown" in the table
output then you need to run the following command:
abra server add %s <args>
See "abra server add --help" for more.
`
// HasDockerContext figures out if a local setup has a working docker context
// configuration or not. This usually tells us if they'll be able to make a SSH
// connection to a server or not and can be a useful way to signal to end-users
// that they need to fix something up if missing.
func HasDockerContext(appName, serverName string) error {
dockerContextStore := NewDefaultDockerContextStore()
contexts, err := dockerContextStore.Store.List()
if err != nil {
return err
}
for _, ctx := range contexts {
if ctx.Name == serverName {
return nil
}
}
if appName != "" {
return fmt.Errorf(
missingContextWithAppMsg,
serverName,
appName,
serverName,
serverName,
)
}
return fmt.Errorf(
missingContextMsg,
serverName,
serverName,
)
}