proxy.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package proxy
  2. import (
  3. "context"
  4. "github.com/docker/api/client"
  5. v1 "github.com/docker/api/containers/v1"
  6. )
  7. type clientKey struct{}
  8. func WithClient(ctx context.Context, c *client.Client) (context.Context, error) {
  9. return context.WithValue(ctx, clientKey{}, c), nil
  10. }
  11. func Client(ctx context.Context) *client.Client {
  12. c, _ := ctx.Value(clientKey{}).(*client.Client)
  13. return c
  14. }
  15. func NewContainerApi() v1.ContainersServer {
  16. return &proxyContainerApi{}
  17. }
  18. type proxyContainerApi struct{}
  19. func (p *proxyContainerApi) List(ctx context.Context, _ *v1.ListRequest) (*v1.ListResponse, error) {
  20. client := Client(ctx)
  21. c, err := client.ContainerService().List(ctx)
  22. if err != nil {
  23. return &v1.ListResponse{}, nil
  24. }
  25. response := &v1.ListResponse{
  26. Containers: []*v1.Container{},
  27. }
  28. for _, container := range c {
  29. response.Containers = append(response.Containers, &v1.Container{
  30. Id: container.ID,
  31. Image: container.Image,
  32. })
  33. }
  34. return response, nil
  35. }
  36. func (p *proxyContainerApi) Create(_ context.Context, _ *v1.CreateRequest) (*v1.CreateResponse, error) {
  37. panic("not implemented") // TODO: Implement
  38. }
  39. func (p *proxyContainerApi) Start(_ context.Context, _ *v1.StartRequest) (*v1.StartResponse, error) {
  40. panic("not implemented") // TODO: Implement
  41. }
  42. func (p *proxyContainerApi) Stop(_ context.Context, _ *v1.StopRequest) (*v1.StopResponse, error) {
  43. panic("not implemented") // TODO: Implement
  44. }
  45. func (p *proxyContainerApi) Kill(_ context.Context, _ *v1.KillRequest) (*v1.KillResponse, error) {
  46. panic("not implemented") // TODO: Implement
  47. }
  48. func (p *proxyContainerApi) Delete(_ context.Context, _ *v1.DeleteRequest) (*v1.DeleteResponse, error) {
  49. panic("not implemented") // TODO: Implement
  50. }
  51. func (p *proxyContainerApi) Update(_ context.Context, _ *v1.UpdateRequest) (*v1.UpdateResponse, error) {
  52. panic("not implemented") // TODO: Implement
  53. }
  54. func (p *proxyContainerApi) Exec(_ context.Context, _ *v1.ExecRequest) (*v1.ExecResponse, error) {
  55. panic("not implemented") // TODO: Implement
  56. }