Skip to content

Commit f1124f7

Browse files
authored
feat: add tabular output (#17)
1 parent 3dfe79e commit f1124f7

File tree

26 files changed

+572
-646
lines changed

26 files changed

+572
-646
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ permissions:
1313
contents: read
1414

1515
env:
16-
GO_VERSION: '1.22.5'
16+
GO_VERSION: '1.23.0'
1717

1818
jobs:
1919
build:
@@ -30,4 +30,4 @@ jobs:
3030
- name: golangci-lint
3131
uses: golangci/golangci-lint-action@v6
3232
with:
33-
version: v1.58
33+
version: v1.60

.github/workflows/release.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ on:
55
tags:
66
- 'v*'
77

8+
permissions:
9+
id-token: write
10+
811
env:
9-
GO_VERSION: '1.22.5'
12+
GO_VERSION: '1.23.0'
1013

1114
jobs:
1215
release:
@@ -25,16 +28,10 @@ jobs:
2528
uses: sigstore/cosign-installer@v3
2629
with:
2730
cosign-release: 'v2.2.3'
28-
- name: Store Cosign private key in a file
29-
run: 'echo "$COSIGN_KEY" > cosign.key'
30-
shell: bash
31-
env:
32-
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
3331
- name: Release Binaries
3432
uses: goreleaser/goreleaser-action@v6
3533
with:
3634
version: latest
3735
args: release --clean
3836
env:
3937
GITHUB_TOKEN: ${{secrets.GH_PAT}}
40-
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}

.github/workflows/vulncheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ permissions:
1212
contents: read
1313

1414
env:
15-
GO_VERSION: '1.22.5'
15+
GO_VERSION: '1.23.0'
1616

1717
jobs:
1818
vulncheck:

.golangci.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
linters:
2+
enable:
3+
- errcheck
4+
- errname
5+
- errorlint
6+
- goconst
7+
- gofumpt
8+
- gosimple
9+
- govet
10+
- ineffassign
11+
- nilerr
12+
- prealloc
13+
- predeclared
14+
- revive
15+
- rowserrcheck
16+
- sqlclosecheck
17+
- staticcheck
18+
- unconvert
19+
- unused
20+
- usestdlibvars
21+
- wastedassign

.goreleaser.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ builds:
1717

1818
signs:
1919
- cmd: cosign
20-
stdin: "{{ .Env.COSIGN_PASSWORD }}"
20+
signature: "${artifact}.sig"
21+
certificate: "${artifact}.pem"
2122
args:
2223
- "sign-blob"
23-
- "--key=cosign.key"
24+
- "--oidc-issuer=https://token.actions.githubusercontent.com"
25+
- "--output-certificate=${certificate}"
2426
- "--output-signature=${signature}"
2527
- "${artifact}"
26-
- "--yes" # needed on cosign 2.0.0+
27-
artifacts: all
28+
- "--yes"
29+
artifacts: checksum
2830

2931
brews:
3032
- name: ecsv

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,3 @@ Using the latter will output HTML that, when served, looks as follows:
8585

8686
Read more about outputting HTML in the [examples](./examples/html_template)
8787
directory.
88-
89-
Acknowledgements
90-
---
91-
92-
`ecsv` is built using the awesome TUI framework [bubbletea][1].
93-
94-
[1]: https://github.com/charmbracelet/bubbletea

cmd/config.go

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
5-
"os"
6-
"os/user"
6+
"path/filepath"
77
"strings"
88

9-
"github.com/dhth/ecsv/ui"
9+
"github.com/dhth/ecsv/internal/types"
1010

1111
"gopkg.in/yaml.v3"
1212
)
1313

14-
type T struct {
14+
var errInvalidConfigSourceProvided = errors.New("invalid aws-system-source provided")
15+
16+
type Config struct {
1517
EnvSequence []string `yaml:"env-sequence"`
1618
Systems []struct {
1719
Key string `yaml:"key"`
@@ -26,54 +28,46 @@ type T struct {
2628
} `yaml:"systems"`
2729
}
2830

29-
func expandTilde(path string) string {
30-
if strings.HasPrefix(path, "~") {
31-
usr, err := user.Current()
32-
if err != nil {
33-
return path
34-
}
35-
return strings.Replace(path, "~", usr.HomeDir, 1)
31+
func expandTilde(path string, homeDir string) string {
32+
if strings.HasPrefix(path, "~/") {
33+
return filepath.Join(homeDir, path[2:])
3634
}
3735
return path
3836
}
3937

40-
func readConfig(filePath string) ([]string, []ui.System, error) {
41-
localFile, err := os.ReadFile(filePath)
42-
if err != nil {
43-
os.Exit(1)
44-
}
45-
t := T{}
46-
err = yaml.Unmarshal(localFile, &t)
38+
func readConfig(configBytes []byte) ([]string, []types.System, error) {
39+
cfg := Config{}
40+
err := yaml.Unmarshal(configBytes, &cfg)
4741
if err != nil {
4842
return nil, nil, err
4943
}
5044

51-
systems := make([]ui.System, 0)
45+
var systems []types.System
5246

53-
for _, system := range t.Systems {
47+
for _, system := range cfg.Systems {
5448
for _, env := range system.Envs {
5549

56-
var awsConfigType ui.AWSConfigSourceType
50+
var awsConfigType types.AWSConfigSourceType
5751
var awsConfigSource string
5852
switch {
5953
case env.AwsConfigSource == "default":
60-
awsConfigType = ui.DefaultCfgType
54+
awsConfigType = types.DefaultCfgType
6155
case strings.HasPrefix(env.AwsConfigSource, "profile:::"):
6256
configElements := strings.Split(env.AwsConfigSource, "profile:::")
6357
awsConfigSource = configElements[len(configElements)-1]
64-
awsConfigType = ui.SharedCfgProfileType
58+
awsConfigType = types.SharedCfgProfileType
6559
case strings.HasPrefix(env.AwsConfigSource, "assume-role:::"):
6660
configElements := strings.Split(env.AwsConfigSource, "assume-role:::")
6761
awsConfigSource = configElements[len(configElements)-1]
68-
awsConfigType = ui.AssumeRoleCfgType
62+
awsConfigType = types.AssumeRoleCfgType
6963
default:
7064
return nil,
7165
nil,
72-
fmt.Errorf("system with key %s doesn't have a valid aws-config-source for env %s",
66+
fmt.Errorf("%w: system: %s env: %s", errInvalidConfigSourceProvided,
7367
system.Key,
7468
env.Name)
7569
}
76-
systems = append(systems, ui.System{
70+
systems = append(systems, types.System{
7771
Key: system.Key,
7872
Env: env.Name,
7973
AWSConfigSourceType: awsConfigType,
@@ -85,6 +79,5 @@ func readConfig(filePath string) ([]string, []ui.System, error) {
8579
})
8680
}
8781
}
88-
return t.EnvSequence, systems, err
89-
82+
return cfg.EnvSequence, systems, nil
9083
}

cmd/help.go

Lines changed: 0 additions & 65 deletions
This file was deleted.

cmd/render.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/dhth/ecsv/internal/awshelpers"
7+
"github.com/dhth/ecsv/internal/types"
8+
"github.com/dhth/ecsv/ui"
9+
)
10+
11+
func render(systems []types.System, config ui.Config, awsConfigs map[string]awshelpers.Config) error {
12+
results := make(map[string]map[string]types.SystemResult)
13+
resultChannel := make(chan types.SystemResult)
14+
15+
counter := 0
16+
for _, s := range systems {
17+
awsConfig := awsConfigs[s.AWSConfigKey()]
18+
if results[s.Key] == nil {
19+
results[s.Key] = make(map[string]types.SystemResult)
20+
}
21+
results[s.Key][s.Env] = types.SystemResult{}
22+
23+
if awsConfig.Err != nil {
24+
results[s.Key][s.Env] = types.SystemResult{
25+
SystemKey: s.Key,
26+
Env: s.Env,
27+
Err: awsConfig.Err,
28+
}
29+
continue
30+
}
31+
go func(system types.System) {
32+
resultChannel <- awshelpers.FetchSystemVersion(system, awsConfig)
33+
}(s)
34+
counter++
35+
}
36+
37+
for range counter {
38+
r := <-resultChannel
39+
results[r.SystemKey][r.Env] = r
40+
}
41+
42+
output, err := ui.GetOutput(config, results)
43+
if err != nil {
44+
return err
45+
}
46+
fmt.Print(output)
47+
return nil
48+
}

0 commit comments

Comments
 (0)