Skip to content

Commit a97cc42

Browse files
committed
Add IAM client
1 parent c5300d2 commit a97cc42

File tree

11 files changed

+37161
-0
lines changed

11 files changed

+37161
-0
lines changed

ecs-cli/Gopkg.lock

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package iam
15+
16+
import (
17+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients"
18+
"github.com/aws/amazon-ecs-cli/ecs-cli/modules/config"
19+
"github.com/aws/aws-sdk-go/aws"
20+
"github.com/aws/aws-sdk-go/service/iam"
21+
"github.com/aws/aws-sdk-go/service/iam/iamiface"
22+
)
23+
24+
// Client defines methods for interacting with the IAMAPI interface
25+
type Client interface {
26+
AttachRolePolicy(policyArn, roleName string) (*iam.AttachRolePolicyOutput, error)
27+
CreateRole(iam.CreateRoleInput) (*iam.CreateRoleOutput, error)
28+
CreatePolicy(iam.CreatePolicyInput) (*iam.CreatePolicyOutput, error)
29+
}
30+
31+
type iamClient struct {
32+
client iamiface.IAMAPI
33+
}
34+
35+
// NewIAMClient creates an instance of iamClient
36+
func NewIAMClient(config *config.CommandConfig) Client {
37+
client := iam.New(config.Session)
38+
client.Handlers.Build.PushBackNamed(clients.CustomUserAgentHandler())
39+
40+
return newClient(client)
41+
}
42+
43+
func newClient(client iamiface.IAMAPI) Client {
44+
return &iamClient{
45+
client: client,
46+
}
47+
}
48+
49+
func (c *iamClient) AttachRolePolicy(policyArn, roleName string) (*iam.AttachRolePolicyOutput, error) {
50+
request := iam.AttachRolePolicyInput{
51+
PolicyArn: aws.String(policyArn),
52+
RoleName: aws.String(roleName),
53+
}
54+
55+
output, err := c.client.AttachRolePolicy(&request)
56+
if err != nil {
57+
return nil, err
58+
}
59+
60+
return output, nil
61+
}
62+
63+
func (c *iamClient) CreateRole(input iam.CreateRoleInput) (*iam.CreateRoleOutput, error) {
64+
output, err := c.client.CreateRole(&input)
65+
if err != nil {
66+
return nil, err
67+
}
68+
69+
return output, nil
70+
}
71+
72+
func (c *iamClient) CreatePolicy(input iam.CreatePolicyInput) (*iam.CreatePolicyOutput, error) {
73+
output, err := c.client.CreatePolicy(&input)
74+
if err != nil {
75+
return nil, err
76+
}
77+
78+
return output, nil
79+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package iam
15+
16+
//go:generate mockgen.sh github.com/aws/aws-sdk-go/service/iam/iamiface IAMAPI mock/sdk/iamiface_mock.go
17+
//go:generate mockgen.sh github.com/aws/amazon-ecs-cli/ecs-cli/modules/clients/aws/iam Client mock/client.go

ecs-cli/modules/clients/aws/iam/mock/client.go

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)