-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b47078f
commit ca03f64
Showing
134 changed files
with
218 additions
and
13,319 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# This is an example goreleaser.yaml file with some sane defaults. | ||
# Make sure to check the documentation at http://goreleaser.com | ||
project_name: aws-event-mock | ||
|
||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- darwin | ||
- windows | ||
- linux | ||
binary: aws-event-mock | ||
|
||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
snapshot: | ||
name_template: "{{ .Tag }}" | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' | ||
|
||
release: | ||
disable: false | ||
|
||
brews: | ||
- | ||
tap: | ||
owner: chrispruitt | ||
name: homebrew-tap | ||
folder: Formula | ||
commit_author: | ||
name: goreleaserbot | ||
email: [email protected] | ||
homepage: "https://github.com/chrispruitt/aws-event-mock" | ||
license: "Mozilla Public License Version 2.0" | ||
signs: | ||
- artifacts: checksum | ||
args: | ||
- "--batch" | ||
- "--local-user" | ||
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key | ||
- "--output" | ||
- "${signature}" | ||
- "--detach-sign" | ||
- "${artifact}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,13 @@ | ||
test: | ||
go run main.go create --type cloudwatch-log --message '{"message":"i am a cloudwatch log event. send me to lambda!"}' | ||
go run main.go create --type sns --message '{"message":"i am an sns message. send me to lambda!"}' | ||
|
||
generate-enums: | ||
go-enum --names --file lib/event_type_enum.go | ||
|
||
unit: | ||
# Execute test recursivly | ||
go test -v ./... | ||
go test -v ./... | ||
|
||
release: | ||
goreleaser --rm-dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package lib | ||
|
||
// EventTypeEnum is an enumeration of applicable aws event types. | ||
// ENUM( | ||
// cloudwatch-log | ||
// ) | ||
/* | ||
ENUM( | ||
cloudwatch-log | ||
sns | ||
) | ||
*/ | ||
type EventTypeEnum int |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package lib | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"strings" | ||
"time" | ||
"unicode/utf8" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
) | ||
|
||
func (event *Event) GetSNSEvent() (resp string, err error) { | ||
|
||
// read from file if first char is @ | ||
if string(event.Message[0]) == "@" { | ||
_, i := utf8.DecodeRuneInString(event.Message) | ||
var b []byte | ||
b, err = ioutil.ReadFile(event.Message[i:]) | ||
if err != nil { | ||
err = fmt.Errorf("Error: unable to parse file: %s", err) | ||
return | ||
} | ||
event.Message = string(b) | ||
} | ||
|
||
// Remove whitespaces | ||
event.Message = strings.ReplaceAll(event.Message, "\n", "") | ||
|
||
result := events.SNSEvent{ | ||
Records: []events.SNSEventRecord{ | ||
{ | ||
EventSource: "aws.sns", | ||
EventVersion: "1.0", | ||
EventSubscriptionArn: "arn:aws:sns:us-east-1:{{{accountId}}}:ExampleTopic", | ||
SNS: events.SNSEntity{ | ||
Type: "Notification", | ||
MessageID: "95df01b4-ee98-5cb9-9903-4c221d41eb5e", | ||
TopicArn: "arn:aws:sns:us-east-1:{{{accountId}}}:ExampleTopic", | ||
Subject: "example subject", | ||
Timestamp: time.Now().UTC(), | ||
SignatureVersion: "1", | ||
Signature: "EXAMPLE", | ||
SigningCertURL: "EXAMPLE", | ||
UnsubscribeURL: "EXAMPLE", | ||
MessageAttributes: map[string]interface{}{ | ||
"Test": struct { | ||
Type string `json:"Type"` | ||
Value string `json:"Value"` | ||
}{"String", "teststringvalue"}, | ||
}, | ||
Message: event.Message, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
marshal, err := json.Marshal(result) | ||
if err != nil { | ||
return | ||
} | ||
|
||
resp = string(marshal) | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package lib | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
) | ||
|
||
func TestGetSNSEvent(t *testing.T) { | ||
testMessage := "{\"greet\":\"hello\",\n\"name\":\"bobby bob\"}" | ||
|
||
event := Event{ | ||
Message: testMessage, | ||
} | ||
|
||
response, err := event.GetSNSEvent() | ||
if err != nil { | ||
t.Errorf("Error on GetSNSEvent, %s", err) | ||
} | ||
|
||
var snsEventResponse events.SNSEvent | ||
err = json.Unmarshal([]byte(response), &snsEventResponse) | ||
if err != nil { | ||
t.Errorf("Unable to unmarshal SNS Event string, %s", err) | ||
} | ||
|
||
expected := "{\"greet\":\"hello\",\"name\":\"bobby bob\"}" | ||
|
||
if !reflect.DeepEqual(snsEventResponse.Records[0].SNS.Message, expected) { | ||
fmt.Printf("Expected %v, got %v", expected, snsEventResponse.Records[0].SNS.Message) | ||
t.Error("SNS is not equal to expected response") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.