Skip to content

Commit

Permalink
fixed conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun committed Jun 16, 2017
2 parents 0a195c6 + ca43c5e commit dcab68b
Show file tree
Hide file tree
Showing 44 changed files with 2,433 additions and 2,094 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ before_install:
install:
- go get -t -v github.com/daidokoro/qaz

script: go test -v -cover ./commands
script: go test -v ./tests
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
![Go Report Card](https://goreportcard.com/badge/github.com/daidokoro/qaz)


__Qaz__ is a _cloud native_ AWS Cloudformation Template Management CLI tool inspired by the Bora project by [@pkazmierczak](https://github.com/pkazmierczak) that focuses on simplifying the process of deploying infrastructure on AWS via Cloudformation by utilising the Go Templates Library and custom functions to generate diverse and configurable templates.
__Qaz__ is a _cloud native_ AWS Cloudformation Template Management CLI tool that focuses on simplifying the process of deploying infrastructure on AWS via Cloudformation by utilising the Go Templates Library and custom functions to generate diverse and configurable templates.

For Qaz, being _cloud native_ means having no explicit local dependencies and utilising resources within the AWS Ecosystem to extend functionality. As a result Qaz supports various methods for dynamically generating infrastructure via Cloudformation.

Expand Down Expand Up @@ -138,6 +138,11 @@ Qaz is now in __beta__, no more breaking changes to come. The focus from this po

--

## Credits

- [pkazmierczak](https://github.com/pkazmierczak) - _Bora_ was the spark for this project...


# Contributing

Fork -> Patch -> Push -> Pull Request
Expand Down
35 changes: 18 additions & 17 deletions commands/s3.go → bucket/bucket.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package commands
package bucket

import (
"bytes"
"fmt"
"strings"
"time"

"github.com/daidokoro/qaz/logger"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)

// -- Contains all things S3

// S3Read - Reads the content of a given s3 url endpoint and returns the content string.
func S3Read(url string) (string, error) {

sess, err := manager.GetSess(run.profile)
if err != nil {
return "", err
}
// Log define logger
var Log *logger.Logger

// S3Read - Reads the content of a given s3 url endpoint and returns the content string.
func S3Read(url string, sess *session.Session) (string, error) {
svc := s3.New(sess)

// Parse s3 url
Expand All @@ -32,17 +31,18 @@ func S3Read(url string) (string, error) {
Key: aws.String(key),
}

Log(fmt.Sprintln("Calling S3 [GetObject] with parameters:", params), level.debug)
Log.Debug(fmt.Sprintln("Calling S3 [GetObject] with parameters:", params))
resp, err := svc.GetObject(params)
if err != nil {
return "", err
}

buf := new(bytes.Buffer)

Log("Reading from S3 Response Body", level.debug)
Log.Debug("Reading from S3 Response Body")
buf.ReadFrom(resp.Body)
return buf.String(), nil

}

// S3write - Writes a file to s3 and returns the presigned url
Expand All @@ -57,7 +57,7 @@ func S3write(bucket string, key string, body string, sess *session.Session) (str
},
}

Log(fmt.Sprintln("Calling S3 [PutObject] with parameters:", params), level.debug)
Log.Debug(fmt.Sprintln("Calling S3 [PutObject] with parameters:", params))
_, err := svc.PutObject(params)
if err != nil {
return "", err
Expand All @@ -77,15 +77,15 @@ func S3write(bucket string, key string, body string, sess *session.Session) (str

}

// CreateBucket - create s3 bucket
func CreateBucket(bucket string, sess *session.Session) error {
// Create - create s3 bucket
func Create(bucket string, sess *session.Session) error {
svc := s3.New(sess)

params := &s3.CreateBucketInput{
Bucket: &bucket,
}

Log(fmt.Sprintln("Calling S3 [CreateBucket] with parameters:", params), level.debug)
Log.Debug(fmt.Sprintln("Calling S3 [CreateBucket] with parameters:", params))
_, err := svc.CreateBucket(params)
if err != nil {
return err
Expand All @@ -96,16 +96,17 @@ func CreateBucket(bucket string, sess *session.Session) error {
}

return nil

}

// BucketExists - checks if bucket exists - if err, then its assumed that the bucket does not exist.
func BucketExists(bucket string, sess *session.Session) (bool, error) {
// Exists - checks if bucket exists - if err, then its assumed that the bucket does not exist.
func Exists(bucket string, sess *session.Session) (bool, error) {
svc := s3.New(sess)
params := &s3.HeadBucketInput{
Bucket: &bucket,
}

Log(fmt.Sprintln("Calling S3 [HeadBucket] with parameters:", params), level.debug)
Log.Debug(fmt.Sprintln("Calling S3 [HeadBucket] with parameters:", params))
_, err := svc.HeadBucket(params)
if err != nil {
return false, err
Expand Down
40 changes: 38 additions & 2 deletions commands/aws_lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package commands

import (
"fmt"
"github.com/daidokoro/qaz/utils"
"strings"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/lambda"
"github.com/spf13/cobra"
)

type awsLambda struct {
Expand All @@ -25,7 +28,7 @@ func (a *awsLambda) Invoke(sess *session.Session) error {
params.Payload = a.payload
}

Log(fmt.Sprintln("Calling [Invoke] with parameters:", params), level.debug)
log.Debug(fmt.Sprintln("Calling [Invoke] with parameters:", params))
resp, err := svc.Invoke(params)

if err != nil {
Expand All @@ -38,6 +41,39 @@ func (a *awsLambda) Invoke(sess *session.Session) error {

a.response = string(resp.Payload)

Log(fmt.Sprintln("Lambda response:", a.response), level.debug)
log.Debug(fmt.Sprintln("Lambda response:", a.response))
return nil
}

// invoke command
var invokeCmd = &cobra.Command{
Use: "invoke",
Short: "Invoke AWS Lambda Functions",
PreRun: initialise,
Run: func(cmd *cobra.Command, args []string) {

if len(args) < 1 {
fmt.Println("No Lambda Function specified")
return
}

sess, err := manager.GetSess(run.profile)
utils.HandleError(err)

f := awsLambda{name: args[0]}

if run.funcEvent != "" {
f.payload = []byte(run.funcEvent)
}

if err := f.Invoke(sess); err != nil {
if strings.Contains(err.Error(), "Unhandled") {
log.Error(fmt.Sprintf("Unhandled Exception: Potential Issue with Lambda Function Logic: %s...\n", f.name))
}
utils.HandleError(err)
}

fmt.Println(f.response)

},
}
Loading

0 comments on commit dcab68b

Please sign in to comment.