2020-07-20 10:48:05 +02:00
|
|
|
/*
|
|
|
|
Copyright 2020 Docker, Inc.
|
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-08-18 11:38:23 +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-08-18 11:38:23 +02:00
|
|
|
|
2020-08-18 09:13:58 +02:00
|
|
|
"github.com/docker/api/secrets"
|
2020-07-16 11:05:31 +02:00
|
|
|
|
2020-07-15 15:09:05 +02:00
|
|
|
"github.com/docker/api/backend"
|
|
|
|
"github.com/docker/api/compose"
|
|
|
|
"github.com/docker/api/containers"
|
|
|
|
apicontext "github.com/docker/api/context"
|
|
|
|
"github.com/docker/api/context/cloud"
|
|
|
|
"github.com/docker/api/context/store"
|
2020-07-20 10:48:05 +02:00
|
|
|
"github.com/docker/api/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-07-20 10:48:05 +02:00
|
|
|
return &ecsAPIService{
|
2020-08-18 09:40:57 +02:00
|
|
|
ctx: ecsCtx,
|
2020-08-17 17:48:52 +02:00
|
|
|
Region: ecsCtx.Region,
|
2020-08-18 16:56:42 +02:00
|
|
|
SDK: newSDK(sess),
|
2020-07-15 15:09:05 +02:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-07-20 10:48:05 +02:00
|
|
|
type ecsAPIService struct {
|
2020-08-18 09:40:57 +02:00
|
|
|
ctx store.EcsContext
|
2020-08-17 17:48:52 +02:00
|
|
|
Region string
|
2020-08-18 09:40:57 +02:00
|
|
|
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-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)
|
|
|
|
}
|