proxy.go 2.0 KB

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