2020-07-20 10:48:05 +02:00
|
|
|
/*
|
2020-09-22 12:13:00 +02:00
|
|
|
Copyright 2020 Docker Compose CLI authors
|
2020-08-17 16:20:02 +02:00
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2020-08-17 16:20:02 +02:00
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2020-08-17 16:20:02 +02:00
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-07-29 15:12:45 +02:00
|
|
|
package ecs
|
2020-07-15 15:09:05 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-09-07 18:23:28 +02:00
|
|
|
|
2020-08-17 17:48:52 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
2020-09-17 10:58:01 +02:00
|
|
|
|
2020-09-07 13:22:08 +02:00
|
|
|
"github.com/docker/compose-cli/api/compose"
|
|
|
|
"github.com/docker/compose-cli/api/containers"
|
|
|
|
"github.com/docker/compose-cli/api/secrets"
|
2020-09-10 14:17:49 +02:00
|
|
|
"github.com/docker/compose-cli/api/volumes"
|
2020-08-21 17:24:53 +02:00
|
|
|
"github.com/docker/compose-cli/backend"
|
|
|
|
apicontext "github.com/docker/compose-cli/context"
|
|
|
|
"github.com/docker/compose-cli/context/cloud"
|
|
|
|
"github.com/docker/compose-cli/context/store"
|
|
|
|
"github.com/docker/compose-cli/errdefs"
|
2020-07-15 15:09:05 +02:00
|
|
|
)
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
const backendType = store.EcsContextType
|
|
|
|
|
2020-07-15 15:09:05 +02:00
|
|
|
// ContextParams options for creating AWS context
|
|
|
|
type ContextParams struct {
|
|
|
|
Description string
|
|
|
|
Region string
|
|
|
|
Profile string
|
|
|
|
|
|
|
|
AwsID string
|
|
|
|
AwsSecret string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-07-20 10:48:05 +02:00
|
|
|
backend.Register(backendType, backendType, service, getCloudService)
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func service(ctx context.Context) (backend.Service, error) {
|
|
|
|
contextStore := store.ContextStore(ctx)
|
|
|
|
currentContext := apicontext.CurrentContext(ctx)
|
2020-07-20 10:48:05 +02:00
|
|
|
var ecsContext store.EcsContext
|
2020-07-15 15:09:05 +02:00
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
if err := contextStore.GetEndpoint(currentContext, &ecsContext); err != nil {
|
2020-07-15 15:09:05 +02:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
return getEcsAPIService(ecsContext)
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func getEcsAPIService(ecsCtx store.EcsContext) (*ecsAPIService, error) {
|
2020-08-17 17:48:52 +02:00
|
|
|
sess, err := session.NewSessionWithOptions(session.Options{
|
|
|
|
Profile: ecsCtx.Profile,
|
|
|
|
SharedConfigState: session.SharedConfigEnable,
|
|
|
|
Config: aws.Config{
|
|
|
|
Region: aws.String(ecsCtx.Region),
|
|
|
|
},
|
|
|
|
})
|
2020-07-15 15:09:05 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-08-17 17:48:52 +02:00
|
|
|
|
2020-09-24 16:11:08 +02:00
|
|
|
sdk := newSDK(sess)
|
2020-07-20 10:48:05 +02:00
|
|
|
return &ecsAPIService{
|
2020-09-29 08:31:11 +02:00
|
|
|
ctx: ecsCtx,
|
|
|
|
Region: ecsCtx.Region,
|
|
|
|
SDK: sdk,
|
2020-07-15 15:09:05 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
type ecsAPIService struct {
|
2020-09-29 08:31:11 +02:00
|
|
|
ctx store.EcsContext
|
|
|
|
Region string
|
|
|
|
SDK sdk
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func (a *ecsAPIService) ContainerService() containers.Service {
|
2020-07-15 15:09:05 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func (a *ecsAPIService) ComposeService() compose.Service {
|
2020-08-17 17:48:52 +02:00
|
|
|
return a
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
func (a *ecsAPIService) SecretsService() secrets.Service {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2020-09-07 14:39:19 +02:00
|
|
|
func (a *ecsAPIService) VolumeService() volumes.Service {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-07-15 15:09:05 +02:00
|
|
|
func getCloudService() (cloud.Service, error) {
|
2020-07-20 10:48:05 +02:00
|
|
|
return ecsCloudService{}, nil
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
type ecsCloudService struct {
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func (a ecsCloudService) Login(ctx context.Context, params interface{}) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func (a ecsCloudService) Logout(ctx context.Context) error {
|
|
|
|
return errdefs.ErrNotImplemented
|
2020-07-15 15:09:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
func (a ecsCloudService) CreateContextData(ctx context.Context, params interface{}) (interface{}, string, error) {
|
2020-07-15 15:09:05 +02:00
|
|
|
contextHelper := newContextCreateHelper()
|
|
|
|
createOpts := params.(ContextParams)
|
|
|
|
return contextHelper.createContextData(ctx, createOpts)
|
|
|
|
}
|