forked from toolshed/abra
		
	refactor: actual context getting
This commit is contained in:
		| @ -97,8 +97,10 @@ var appPsCommand = &cli.Command{ | |||||||
| 	Name: "ps", | 	Name: "ps", | ||||||
| 	Action: func(c *cli.Context) error { | 	Action: func(c *cli.Context) error { | ||||||
| 		ctx := context.Background() | 		ctx := context.Background() | ||||||
| 		fmt.Println(Context) | 		cl, err := client.NewClientWithContext(Context) | ||||||
| 		cl := client.NewClientWithContext(Context) | 		if err != nil { | ||||||
|  | 			logrus.Fatal(err) | ||||||
|  | 		} | ||||||
| 		tasks, err := cl.TaskList(ctx, types.TaskListOptions{}) | 		tasks, err := cl.TaskList(ctx, types.TaskListOptions{}) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logrus.Fatal(err) | 			logrus.Fatal(err) | ||||||
|  | |||||||
| @ -14,8 +14,16 @@ import ( | |||||||
| 	"github.com/sirupsen/logrus" | 	"github.com/sirupsen/logrus" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func NewClientWithContext(contextURL string) *dClient.Client { | func NewClientWithContext(contextName string) (*dClient.Client, error) { | ||||||
| 	helper := newConnectionHelper(contextURL) | 	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{ | 	httpClient := &http.Client{ | ||||||
| 		// No tls | 		// No tls | ||||||
| 		// No proxy | 		// No proxy | ||||||
| @ -46,7 +54,21 @@ func NewClientWithContext(contextURL string) *dClient.Client { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logrus.Fatalf("unable to create Docker client: %s", err) | 		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) { | func GetContextEndpoint(ctx dCliContextStore.Metadata) (string, error) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user