New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated to use v2 of AWS SDK. #19

Merged
merged 1 commit into from Jan 2, 2018
Jump to file or symbol
Failed to load files and symbols.
+319 −202
Diff settings

Always

Just for now

Updated to use v2 of AWS SDK.

  • Loading branch information...
Skarlso committed Dec 31, 2017
commit fdbc610260f3f9c8f7e02d926263ba0a4ef287d7
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -48,3 +48,7 @@
[[constraint]]
branch = "v1"
name = "gopkg.in/yaml.v1"
[[constraint]]
name = "github.com/aws/aws-sdk-go-v2"
version = "2.0.0-preview.1"
View
@@ -156,8 +156,8 @@ The default for a push is to locate a sample application on Github which will th
For this, the following two options need to be defined:
```bash
export FURNACE_GIT_REVISION=b80ea5b9dfefcd21e27a3e0f149ec73519d5a6f1
export FURNACE_GIT_ACCOUNT=skarlso/furnace-codedeploy-app
export AWS_FURNACE_GIT_REVISION=b80ea5b9dfefcd21e27a3e0f149ec73519d5a6f1
export AWS_FURNACE_GIT_ACCOUNT=skarlso/furnace-codedeploy-app
```
##### S3
View
@@ -8,15 +8,18 @@ import (
"strings"
config "github.com/Skarlso/go-furnace/config/common"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/fatih/color"
)
func gatherParameters(source *os.File, params *cloudformation.ValidateTemplateOutput) []*cloudformation.Parameter {
var stackParameters []*cloudformation.Parameter
func gatherParameters(source *os.File, params *cloudformation.ValidateTemplateOutput) []cloudformation.Parameter {
var stackParameters []cloudformation.Parameter
defaultValue := color.New(color.FgHiBlack, color.Italic).SprintFunc()
log.Println("Gathering parameters.")
if params == nil {
return stackParameters
}
for _, v := range params.Parameters {
var param cloudformation.Parameter
fmt.Printf("%s - '%s'(%s):", aws.StringValue(v.Description), keyName(aws.StringValue(v.ParameterKey)), defaultValue(aws.StringValue(v.DefaultValue)))
@@ -28,7 +31,7 @@ func gatherParameters(source *os.File, params *cloudformation.ValidateTemplateOu
} else {
param.SetParameterValue(*v.DefaultValue)
}
stackParameters = append(stackParameters, &param)
stackParameters = append(stackParameters, param)
}
return stackParameters
}
@@ -40,7 +43,8 @@ func readInputFrom(source *os.File) string {
}
func (cf *CFClient) describeStacks(descStackInput *cloudformation.DescribeStacksInput) *cloudformation.DescribeStacksOutput {
descResp, err := cf.Client.DescribeStacks(descStackInput)
req := cf.Client.DescribeStacksRequest(descStackInput)
descResp, err := req.Send()
config.CheckError(err)
return descResp
}
@@ -50,7 +54,8 @@ func (cf *CFClient) validateTemplate(template []byte) *cloudformation.ValidateTe
validateParams := &cloudformation.ValidateTemplateInput{
TemplateBody: aws.String(string(template)),
}
resp, err := cf.Client.ValidateTemplate(validateParams)
req := cf.Client.ValidateTemplateRequest(validateParams)
resp, err := req.Send()
config.CheckError(err)
return resp
}
View
@@ -8,9 +8,9 @@ import (
awsconfig "github.com/Skarlso/go-furnace/config/aws"
config "github.com/Skarlso/go-furnace/config/common"
"github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/fatih/color"
)
@@ -21,8 +21,9 @@ type Create struct {
// Execute defines what this command does.
func (c *Create) Execute(opts *commander.CommandHelper) {
log.Println("Creating cloud formation session.")
sess := session.New(&aws.Config{Region: aws.String(awsconfig.REGION)})
cfClient := cloudformation.New(sess, nil)
cfg, err := external.LoadDefaultAWSConfig()
config.CheckError(err)
cfClient := cloudformation.New(cfg)
client := CFClient{cfClient}
createExecute(opts, &client)
}
@@ -41,31 +42,32 @@ func createExecute(opts *commander.CommandHelper, client *CFClient) {
}
var red = color.New(color.FgRed).SprintFunc()
if stacks != nil {
log.Println("Stack state is: ", red(*stacks[0].StackStatus))
log.Println("Stack state is: ", red(stacks[0].StackStatus))
} else {
config.HandleFatal(fmt.Sprintf("No stacks found with name: %s", keyName(stackname)), nil)
}
}
// create will create a full stack and encapsulate the functionality of
// the create command.
func create(stackname string, template []byte, cfClient *CFClient) []*cloudformation.Stack {
func create(stackname string, template []byte, cfClient *CFClient) []cloudformation.Stack {
validResp := cfClient.validateTemplate(template)
stackParameters := gatherParameters(os.Stdin, validResp)
stackInputParams := &cloudformation.CreateStackInput{
StackName: aws.String(stackname),
Capabilities: []*string{
aws.String("CAPABILITY_IAM"),
},
StackName: aws.String(stackname),
Capabilities: []cloudformation.Capability{cloudformation.CapabilityCapabilityIam},
Parameters: stackParameters,
TemplateBody: aws.String(string(template)),
}
resp := cfClient.createStack(stackInputParams)
log.Println("Create stack response: ", resp.GoString())
log.Println("Create stack response: ", resp)
cfClient.waitForStackCreateCompleteStatus(stackname)
descResp := cfClient.describeStacks(&cloudformation.DescribeStacksInput{StackName: aws.String(stackname)})
fmt.Println()
return descResp.Stacks
if descResp != nil {
return descResp.Stacks
}
return nil
}
func (cf *CFClient) waitForStackCreateCompleteStatus(stackname string) {
@@ -79,7 +81,8 @@ func (cf *CFClient) waitForStackCreateCompleteStatus(stackname string) {
func (cf *CFClient) createStack(stackInputParams *cloudformation.CreateStackInput) *cloudformation.CreateStackOutput {
log.Println("Creating Stack with name: ", keyName(*stackInputParams.StackName))
resp, err := cf.Client.CreateStack(stackInputParams)
req := cf.Client.CreateStackRequest(stackInputParams)
resp, err := req.Send()
config.CheckError(err)
return resp
}
@@ -15,9 +15,9 @@ import (
awsconfig "github.com/Skarlso/go-furnace/config/aws"
config "github.com/Skarlso/go-furnace/config/common"
commander "github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/cloudformationiface"
)
type fakeCreateCFClient struct {
@@ -30,29 +30,47 @@ func init() {
config.LogFatalf = log.Fatalf
}
func (fc *fakeCreateCFClient) ValidateTemplate(input *cloudformation.ValidateTemplateInput) (*cloudformation.ValidateTemplateOutput, error) {
if fc.stackname == "ValidationError" {
return &cloudformation.ValidateTemplateOutput{}, fc.err
func (fc *fakeCreateCFClient) ValidateTemplateRequest(input *cloudformation.ValidateTemplateInput) cloudformation.ValidateTemplateRequest {
return cloudformation.ValidateTemplateRequest{
Request: &aws.Request{
Data: &cloudformation.ValidateTemplateOutput{},
Error: fc.err,
},
Input: input,
}
return &cloudformation.ValidateTemplateOutput{}, nil
}
func (fc *fakeCreateCFClient) CreateStack(input *cloudformation.CreateStackInput) (*cloudformation.CreateStackOutput, error) {
if fc.stackname == "NotEmptyStack" {
return &cloudformation.CreateStackOutput{StackId: aws.String("DummyID")}, fc.err
func (fc *fakeCreateCFClient) CreateStackRequest(input *cloudformation.CreateStackInput) cloudformation.CreateStackRequest {
return cloudformation.CreateStackRequest{
Request: &aws.Request{
Data: &cloudformation.CreateStackOutput{
StackId: aws.String("DummyID"),
},
Error: fc.err,
},
Input: input,
}
return &cloudformation.CreateStackOutput{}, nil
}
func (fc *fakeCreateCFClient) WaitUntilStackCreateComplete(input *cloudformation.DescribeStacksInput) error {
return nil
}
func (fc *fakeCreateCFClient) DescribeStacks(input *cloudformation.DescribeStacksInput) (*cloudformation.DescribeStacksOutput, error) {
func (fc *fakeCreateCFClient) DescribeStacksRequest(input *cloudformation.DescribeStacksInput) cloudformation.DescribeStacksRequest {
if fc.stackname == "NotEmptyStack" || fc.stackname == "DescribeStackFailed" {
return NotEmptyStack, fc.err
return cloudformation.DescribeStacksRequest{
Request: &aws.Request{
Data: &NotEmptyStack,
Error: fc.err,
},
}
}
return cloudformation.DescribeStacksRequest{
Request: &aws.Request{
Data: &cloudformation.DescribeStacksOutput{},
},
}
return &cloudformation.DescribeStacksOutput{}, nil
}
func TestCreateExecute(t *testing.T) {
@@ -183,7 +201,7 @@ func TestGatheringParametersWithoutSpecifyingUserInputShouldUseDefaultValue(t *t
}
defer in.Close()
validOutput := &cloudformation.ValidateTemplateOutput{
Parameters: []*cloudformation.TemplateParameter{
Parameters: []cloudformation.TemplateParameter{
{
DefaultValue: aws.String("DefaultValue"),
Description: aws.String("Description"),
@@ -220,7 +238,7 @@ func TestGatheringParametersWithUserInputShouldUseInput(t *testing.T) {
}
// Setup the input
validOutput := &cloudformation.ValidateTemplateOutput{
Parameters: []*cloudformation.TemplateParameter{
Parameters: []cloudformation.TemplateParameter{
{
DefaultValue: aws.String("DefaultValue"),
Description: aws.String("Description"),
View
@@ -6,9 +6,9 @@ import (
awsconfig "github.com/Skarlso/go-furnace/config/aws"
config "github.com/Skarlso/go-furnace/config/common"
"github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/fatih/color"
)
@@ -18,8 +18,9 @@ type Delete struct {
// Execute defines what this command does.
func (c *Delete) Execute(opts *commander.CommandHelper) {
sess := session.New(&aws.Config{Region: aws.String(awsconfig.REGION)})
cfClient := cloudformation.New(sess, nil)
cfg, err := external.LoadDefaultAWSConfig()
config.CheckError(err)
cfClient := cloudformation.New(cfg)
client := CFClient{cfClient}
deleteExecute(opts, &client)
}
@@ -43,7 +44,8 @@ func deleteStack(stackname string, cfClient *CFClient) {
params := &cloudformation.DeleteStackInput{
StackName: aws.String(stackname),
}
_, err := cfClient.Client.DeleteStack(params)
req := cfClient.Client.DeleteStackRequest(params)
_, err := req.Send()
config.CheckError(err)
describeStackInput := &cloudformation.DescribeStacksInput{
StackName: aws.String(stackname),
View
@@ -3,12 +3,11 @@ package awscommands
import (
"log"
awsconfig "github.com/Skarlso/go-furnace/config/aws"
config "github.com/Skarlso/go-furnace/config/common"
"github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
"github.com/fatih/color"
)
@@ -22,18 +21,20 @@ func (c *DeleteApp) Execute(opts *commander.CommandHelper) {
if len(appName) < 1 {
appName = config.STACKNAME
}
sess := session.New(&aws.Config{Region: aws.String(awsconfig.REGION)})
cdClient := codedeploy.New(sess, nil)
cfg, err := external.LoadDefaultAWSConfig()
config.CheckError(err)
cdClient := codedeploy.New(cfg)
client := CDClient{cdClient}
deleteApplication(appName, &client)
}
func deleteApplication(appName string, client *CDClient) {
var yellow = color.New(color.FgYellow).SprintFunc()
log.Println("Deleting: ", yellow(appName))
_, err := client.Client.DeleteApplication(&codedeploy.DeleteApplicationInput{
req := client.Client.DeleteApplicationRequest(&codedeploy.DeleteApplicationInput{
ApplicationName: aws.String(appName),
})
_, err := req.Send()
config.CheckError(err)
}
@@ -4,9 +4,10 @@ import (
"reflect"
"testing"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/codedeploy"
"github.com/aws/aws-sdk-go/service/codedeploy/codedeployiface"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/awserr"
"github.com/aws/aws-sdk-go-v2/service/codedeploy"
"github.com/aws/aws-sdk-go-v2/service/codedeploy/codedeployiface"
)
type fakeDeleteAppCDClient struct {
@@ -15,8 +16,12 @@ type fakeDeleteAppCDClient struct {
awsErr awserr.Error
}
func (fd *fakeDeleteAppCDClient) DeleteApplication(*codedeploy.DeleteApplicationInput) (*codedeploy.DeleteApplicationOutput, error) {
return &codedeploy.DeleteApplicationOutput{}, fd.err
func (fd *fakeDeleteAppCDClient) DeleteApplicationRequest(*codedeploy.DeleteApplicationInput) codedeploy.DeleteApplicationRequest {
return codedeploy.DeleteApplicationRequest{
Request: &aws.Request{
Data: &codedeploy.DeleteApplicationOutput{},
},
}
}
func TestDeletingApplication(t *testing.T) {
@@ -7,8 +7,10 @@ import (
awsconfig "github.com/Skarlso/go-furnace/config/aws"
config "github.com/Skarlso/go-furnace/config/common"
commander "github.com/Yitsushi/go-commander"
"github.com/aws/aws-sdk-go/service/cloudformation"
"github.com/aws/aws-sdk-go/service/cloudformation/cloudformationiface"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/aws/aws-sdk-go-v2/service/cloudformation/cloudformationiface"
)
type fakeDeleteCFClient struct {
@@ -17,8 +19,12 @@ type fakeDeleteCFClient struct {
err error
}
func (fc *fakeDeleteCFClient) DeleteStack(*cloudformation.DeleteStackInput) (*cloudformation.DeleteStackOutput, error) {
return &cloudformation.DeleteStackOutput{}, fc.err
func (fc *fakeDeleteCFClient) DeleteStackRequest(*cloudformation.DeleteStackInput) cloudformation.DeleteStackRequest {
return cloudformation.DeleteStackRequest{
Request: &aws.Request{
Data: &cloudformation.DeleteStackOutput{},
},
}
}
func (fc *fakeDeleteCFClient) WaitUntilStackDeleteComplete(input *cloudformation.DescribeStacksInput) error {
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.