-
Notifications
You must be signed in to change notification settings - Fork 394
/
ecs.go
52 lines (44 loc) · 1.5 KB
/
ecs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package ecs contains utility functions for dealing with ECS repos.
package ecs
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/ecs"
)
type ecsClient interface {
DescribeTaskDefinition(input *ecs.DescribeTaskDefinitionInput) (*ecs.DescribeTaskDefinitionOutput, error)
}
// Service wraps an AWS ECS client.
type Service struct {
ecs ecsClient
}
// New returns a Service configured against the input session.
func New(s *session.Session) *Service {
return &Service{
ecs: ecs.New(s),
}
}
// TaskDefinition calls ECS API and returns the task definition.
func (s Service) TaskDefinition(taskDefName string) (*TaskDefinition, error) {
resp, err := s.ecs.DescribeTaskDefinition(&ecs.DescribeTaskDefinitionInput{
TaskDefinition: aws.String(taskDefName),
})
if err != nil {
return nil, fmt.Errorf("describe task definition %s: %w", taskDefName, err)
}
td := TaskDefinition(*resp.TaskDefinition)
return &td, nil
}
// TaskDefinition wraps up ECS TaskDefinition struct.
type TaskDefinition ecs.TaskDefinition
// EnvironmentVariables returns environment variables of the task definition.
func (t *TaskDefinition) EnvironmentVariables() map[string]string {
envs := make(map[string]string)
for _, env := range t.ContainerDefinitions[0].Environment {
envs[aws.StringValue(env.Name)] = aws.StringValue(env.Value)
}
return envs
}