refactor: actual context getting
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a4a8997f57
commit
fe86b50ee3
|
@ -97,8 +97,10 @@ var appPsCommand = &cli.Command{
|
|||
Name: "ps",
|
||||
Action: func(c *cli.Context) error {
|
||||
ctx := context.Background()
|
||||
fmt.Println(Context)
|
||||
cl := client.NewClientWithContext(Context)
|
||||
cl, err := client.NewClientWithContext(Context)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
tasks, err := cl.TaskList(ctx, types.TaskListOptions{})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
|
|
|
@ -14,8 +14,16 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func NewClientWithContext(contextURL string) *dClient.Client {
|
||||
helper := newConnectionHelper(contextURL)
|
||||
func NewClientWithContext(contextName string) (*dClient.Client, error) {
|
||||
context, err := GetContext(contextName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ctxEndpoint, err := GetContextEndpoint(context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
helper := newConnectionHelper(ctxEndpoint)
|
||||
httpClient := &http.Client{
|
||||
// No tls
|
||||
// No proxy
|
||||
|
@ -46,7 +54,21 @@ func NewClientWithContext(contextURL string) *dClient.Client {
|
|||
if err != nil {
|
||||
logrus.Fatalf("unable to create Docker client: %s", err)
|
||||
}
|
||||
return cl
|
||||
return cl, nil
|
||||
}
|
||||
|
||||
func GetContext(contextName string) (dCliContextStore.Metadata, error) {
|
||||
ctxs, err := NewDefaultDockerContextStore().Store.List()
|
||||
if err != nil {
|
||||
return dCliContextStore.Metadata{}, err
|
||||
}
|
||||
var context dCliContextStore.Metadata
|
||||
for _, ctx := range ctxs {
|
||||
if ctx.Name == contextName {
|
||||
context = ctx
|
||||
}
|
||||
}
|
||||
return context, nil
|
||||
}
|
||||
|
||||
func GetContextEndpoint(ctx dCliContextStore.Metadata) (string, error) {
|
||||
|
|
Loading…
Reference in New Issue