2018-12-17 05:27:07 -05:00
|
|
|
package command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/docker/cli/cli/context/store"
|
|
|
|
)
|
|
|
|
|
|
|
|
// DockerContext is a typed representation of what we put in Context metadata
|
|
|
|
type DockerContext struct {
|
2018-11-09 09:10:41 -05:00
|
|
|
Description string `json:",omitempty"`
|
|
|
|
StackOrchestrator Orchestrator `json:",omitempty"`
|
2018-12-17 05:27:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetDockerContext extracts metadata from stored context metadata
|
2019-04-18 09:12:30 -04:00
|
|
|
func GetDockerContext(storeMetadata store.Metadata) (DockerContext, error) {
|
2018-12-17 05:27:07 -05:00
|
|
|
if storeMetadata.Metadata == nil {
|
|
|
|
// can happen if we save endpoints before assigning a context metadata
|
|
|
|
// it is totally valid, and we should return a default initialized value
|
|
|
|
return DockerContext{}, nil
|
|
|
|
}
|
|
|
|
res, ok := storeMetadata.Metadata.(DockerContext)
|
|
|
|
if !ok {
|
|
|
|
return DockerContext{}, errors.New("context metadata is not a valid DockerContext")
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|