Skip to content

Commit

Permalink
Publish changes to SNS (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
aidansteele committed Oct 24, 2019
1 parent a3c4535 commit 97a0d6f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
jq -V
- name: Run it
run: go run main.go
run: go run main.go -- generate
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/upstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
jq -V
- name: Run it
run: go run main.go
run: go run main.go -- generate
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
Expand All @@ -45,3 +45,5 @@ jobs:
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push "${remote_repo}" HEAD:master
go run main.go -- publish
22 changes: 22 additions & 0 deletions generator/publish_sns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package generator

import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sns"
)

func Publish() {
sess := session.Must(session.NewSession())
api := sns.New(sess)

_, err := api.PublishWithContext(context.Background(), &sns.PublishInput{
Message: aws.String("something changed"), // TODO: implement
TopicArn: aws.String("arn:aws:sns:us-east-1:258739955926:trackiam"),
})
if err != nil {
panic(fmt.Sprintf("%+v", err))
}
}
3 changes: 3 additions & 0 deletions generator/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
func printStats(acts actions, policies []*policyFile) ([]byte, error) {
tmpl, err := template.New("").Parse(`# AWS IAM by the numbers
Changes (i.e. new IAM actions, new AWS APIs, new managed policies, modifications, etc)
are published to a public SNS topic: {{ .Backtick }}arn:aws:sns:us-east-1:258739955926:trackiam{{ .Backtick }}
* Unique services: {{ .ServiceCount }}
* Unique actions: {{ .ActionCount }}
* Managed policies: {{ .PolicyCount }}
Expand Down
23 changes: 21 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,27 @@
package main

import "github.com/glassechidna/trackiam/generator"
import (
"fmt"
"github.com/glassechidna/trackiam/generator"
"os"
)

func main() {
generator.Generate()
if len(os.Args) == 1 {
usage()
}

switch os.Args[2] {
case "generate":
generator.Generate()
case "publish":
generator.Publish()
default:
usage()
}
}

func usage() {
fmt.Printf("usage: %s generate|publish\n", os.Args[0])
os.Exit(1)
}

0 comments on commit 97a0d6f

Please sign in to comment.