Skip to content

Commit c4f1ca7

Browse files
authored
Merge pull request #1 from cruxstack/dev
feat: switch to using aws sso portal urls
2 parents 11c6274 + 4310145 commit c4f1ca7

5 files changed

Lines changed: 103 additions & 77 deletions

File tree

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
APP_DEBUG_ENABLED=true
22
APP_SLACK_CHANNEL=
33
APP_SLACK_TOKEN=
4-
APP_AWS_CONSOLE_URL=https://us-east-1.console.aws.amazon.com
4+
APP_AWS_ACCESS_PORTAL_URL=
5+
APP_AWS_ACCESS_ROLE_NAME=

.github/workflows/release.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
release:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Code
16+
uses: actions/checkout@v3
17+
- name: Bump Version
18+
id: tag_version
19+
uses: mathieudutour/github-tag-action@v6.1
20+
with:
21+
github_token: ${{ secrets.GITHUB_TOKEN }}
22+
default_bump: minor
23+
custom_release_rules: bug:patch:Fixes,chore:patch:Chores,docs:patch:Documentation,feat:minor:Features,refactor:minor:Refactors,test:patch:Tests,ci:patch:Development,dev:patch:Development
24+
- name: Create Release
25+
uses: ncipollo/release-action@v1.12.0
26+
with:
27+
tag: ${{ steps.tag_version.outputs.new_tag }}
28+
name: ${{ steps.tag_version.outputs.new_tag }}
29+
body: ${{ steps.tag_version.outputs.changelog }}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: semantic-check
2+
on:
3+
pull_request_target:
4+
types:
5+
- opened
6+
- edited
7+
- synchronize
8+
9+
permissions:
10+
contents: read
11+
pull-requests: read
12+
13+
jobs:
14+
main:
15+
name: Semantic Commit Message Check
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v3
20+
- uses: amannn/action-semantic-pull-request@v5.2.0
21+
name: Check PR for Semantic Commit Message
22+
env:
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
24+
with:
25+
requireScope: false
26+
validateSingleCommit: true

.gitignore

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,12 @@
1-
# .gitignore
2-
3-
# terraform files
4-
.terraform.lock.hcl
5-
.terraform.tfstate.lock.info
6-
*.tfvars.*
7-
*.tfstate
8-
*.tfstate.*.backup
9-
*.tfstate.backup
10-
*.tfplan
11-
*.terraform/
12-
*.tfvars
13-
.grunt
14-
backend.tf.json
15-
16-
# node.js / typescript
17-
node_modules
18-
npm-debug.log
19-
yarn-error.log
20-
dist
21-
out
22-
*.tsbuildinfo
23-
24-
# logs
25-
logs
26-
*.log
27-
npm-debug.log*
28-
yarn-debug.log*
29-
yarn-error.log*
30-
31-
# runtime data
32-
pids
33-
*.pid
34-
*.seed
35-
*.pid.lock
36-
37-
# coverage directories
38-
coverage
39-
lib-cov
40-
41-
# docker files
42-
*.tar
43-
dockerfile.*.bak
1+
!**/.gitkeep
442

45-
# general
463
tmp/
47-
!**/.gitkeep
4+
dist/
485
.DS_Store
49-
.env
50-
.env.local
51-
.env.development.local
52-
.env.test.local
53-
.env.production.local
546

55-
# ides
56-
.vscode
57-
.idea
58-
*.swp
59-
*.swo
7+
.local/
8+
.env
609

61-
# opa
62-
bundle.tar.gz
10+
cognito-hooks-go
11+
main
6312

main.go

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"errors"
1616
"fmt"
1717
"log"
18+
"net/url"
1819
"os"
1920
"path/filepath"
2021
"sync"
@@ -28,26 +29,35 @@ import (
2829
// ------------------------------------------------------------------ config ---
2930

3031
type Config struct {
31-
DebugEnabled bool
32-
AwsConsoleURL string
33-
SlackToken string
34-
SlackChannel string
32+
DebugEnabled bool
33+
AwsAccessPortalURL string
34+
AwsAccessRoleName string
35+
AwsConsoleURL string
36+
SlackToken string
37+
SlackChannel string
3538
}
3639

3740
func BuildConfig() (Config, error) {
3841
cfg := Config{
39-
DebugEnabled: os.Getenv("APP_DEBUG_ENABLED") == "true",
40-
AwsConsoleURL: os.Getenv("APP_AWS_CONSOLE_URL"),
41-
SlackToken: os.Getenv("APP_SLACK_TOKEN"),
42-
SlackChannel: os.Getenv("APP_SLACK_CHANNEL"),
42+
DebugEnabled: os.Getenv("APP_DEBUG_ENABLED") == "true",
43+
AwsConsoleURL: os.Getenv("APP_AWS_CONSOLE_URL"),
44+
AwsAccessPortalURL: os.Getenv("APP_AWS_ACCESS_PORTAL_URL"),
45+
AwsAccessRoleName: os.Getenv("APP_AWS_ACCESS_ROLE_NAME"),
46+
SlackToken: os.Getenv("APP_SLACK_TOKEN"),
47+
SlackChannel: os.Getenv("APP_SLACK_CHANNEL"),
4348
}
4449
switch {
4550
case cfg.SlackToken == "":
4651
return Config{}, errors.New("missing env var APP_SLACK_TOKEN")
4752
case cfg.SlackChannel == "":
4853
return Config{}, errors.New("missing env var APP_SLACK_CHANNEL")
49-
case cfg.AwsConsoleURL == "":
50-
return Config{}, errors.New("missing env var APP_AWS_CONSOLE_URL")
54+
case cfg.AwsAccessPortalURL == "":
55+
return Config{}, errors.New("missing env var APP_AWS_ACCESS_PORTAL_URL")
56+
case cfg.AwsAccessRoleName == "":
57+
return Config{}, errors.New("missing env var APP_AWS_ACCESS_ROLE_NAME")
58+
}
59+
if cfg.AwsConsoleURL == "" {
60+
cfg.AwsConsoleURL = "https://console.aws.amazon.com"
5161
}
5262
return cfg, nil
5363
}
@@ -66,22 +76,33 @@ func NewApp(cfg Config) *App {
6676
}
6777
}
6878

69-
func (a *App) ParseFindingData(raw json.RawMessage) (Finding, error) {
79+
// https://mytech.awsapps.com/start/#/console?account_id=883776786067&role_name=AdministratorAccess
80+
// https://console.aws.amazon.com/guardduty/home?region=us-east-1#/findings?macros=current&fId=5ecc8a2d96f2c23bde37397e4cec0cd0
81+
func (a *App) BuildConsoleURL(gdAccountId string, f *Finding) string {
82+
dst := fmt.Sprintf(
83+
"%s/guardduty/home?region=%s#/findings?&macros=current&fId=%s",
84+
a.cfg.AwsConsoleURL, f.Region, f.ID,
85+
)
86+
dstEncoded := url.QueryEscape(dst)
87+
return fmt.Sprintf(
88+
"%s/#/console?account_id=%s&role_name=%s&destination=%s",
89+
a.cfg.AwsAccessPortalURL, gdAccountId, a.cfg.AwsAccessRoleName, dstEncoded,
90+
)
91+
}
92+
93+
func (a *App) ParseFindingData(gdAccountId string, raw json.RawMessage) (Finding, error) {
7094
var f Finding
7195
if err := json.Unmarshal(raw, &f); err != nil {
7296
return Finding{}, err
7397
}
74-
f.ConsoleURL = fmt.Sprintf(
75-
"%s/guardduty/home?region=%s#/findings?&macros=current&fId=%s",
76-
a.cfg.AwsConsoleURL, f.Region, f.ID,
77-
)
98+
f.ConsoleURL = a.BuildConsoleURL(gdAccountId, &f)
7899
f.Raw = raw
79100
f.SeverityLabel = f.ToSeverityLevel()
80101
return f, nil
81102
}
82103

83-
func (a *App) Process(raw json.RawMessage) error {
84-
f, err := a.ParseFindingData(raw)
104+
func (a *App) Process(gdAccountId string, raw json.RawMessage) error {
105+
f, err := a.ParseFindingData(gdAccountId, raw)
85106
if err != nil {
86107
return err
87108
}
@@ -187,7 +208,7 @@ func LambdaHandler(_ context.Context, evt events.CloudWatchEvent) error {
187208
}
188209
log.Print(string(evtJson))
189210

190-
return app.Process(evt.Detail)
211+
return app.Process(evt.AccountID, evt.Detail)
191212
}
192213

193214
// ------------------------------------------------------------- cmd: sample ---
@@ -220,7 +241,7 @@ func ProcessSamples(a *App) error {
220241
}
221242

222243
for _, e := range events {
223-
if err := a.Process(e.Detail); err != nil {
244+
if err := a.Process(e.AccountID, e.Detail); err != nil {
224245
return fmt.Errorf("process id=%s: %w", e.ID, err)
225246
}
226247
}

0 commit comments

Comments
 (0)