backend.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package amazon
  2. import (
  3. "context"
  4. "github.com/docker/api/backend"
  5. "github.com/docker/api/compose"
  6. "github.com/docker/api/containers"
  7. apicontext "github.com/docker/api/context"
  8. "github.com/docker/api/context/cloud"
  9. "github.com/docker/api/context/store"
  10. aws "github.com/docker/ecs-plugin/pkg/amazon/backend"
  11. )
  12. // ContextParams options for creating AWS context
  13. type ContextParams struct {
  14. Description string
  15. Region string
  16. Profile string
  17. Cluster string
  18. AwsID string
  19. AwsSecret string
  20. }
  21. func init() {
  22. backend.Register("aws", "aws", service, getCloudService)
  23. }
  24. func service(ctx context.Context) (backend.Service, error) {
  25. contextStore := store.ContextStore(ctx)
  26. currentContext := apicontext.CurrentContext(ctx)
  27. var awsContext store.AwsContext
  28. if err := contextStore.GetEndpoint(currentContext, &awsContext); err != nil {
  29. return nil, err
  30. }
  31. return getAwsAPIService(awsContext)
  32. }
  33. func getAwsAPIService(awsCtx store.AwsContext) (*awsAPIService, error) {
  34. backend, err := aws.NewBackend(awsCtx.Profile, awsCtx.Cluster, awsCtx.Region)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &awsAPIService{
  39. ctx: awsCtx,
  40. composeBackend: backend,
  41. }, nil
  42. }
  43. type awsAPIService struct {
  44. ctx store.AwsContext
  45. composeBackend *aws.Backend
  46. }
  47. func (a *awsAPIService) ContainerService() containers.Service {
  48. return nil
  49. }
  50. func (a *awsAPIService) ComposeService() compose.Service {
  51. return a.composeBackend
  52. }
  53. func getCloudService() (cloud.Service, error) {
  54. return awsCloudService{}, nil
  55. }
  56. type awsCloudService struct {
  57. }
  58. func (a awsCloudService) Login(ctx context.Context, params interface{}) error {
  59. return nil
  60. }
  61. func (a awsCloudService) Logout(ctx context.Context) error {
  62. return nil
  63. }
  64. func (a awsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
  65. contextHelper := newContextCreateHelper()
  66. createOpts := params.(ContextParams)
  67. return contextHelper.createContextData(ctx, createOpts)
  68. }