Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add tabular output #17

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
contents: read

env:
GO_VERSION: '1.22.5'
GO_VERSION: '1.23.0'

jobs:
build:
Expand All @@ -30,4 +30,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.58
version: v1.60
11 changes: 4 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ on:
tags:
- 'v*'

permissions:
id-token: write

env:
GO_VERSION: '1.22.5'
GO_VERSION: '1.23.0'

jobs:
release:
Expand All @@ -25,16 +28,10 @@ jobs:
uses: sigstore/cosign-installer@v3
with:
cosign-release: 'v2.2.3'
- name: Store Cosign private key in a file
run: 'echo "$COSIGN_KEY" > cosign.key'
shell: bash
env:
COSIGN_KEY: ${{secrets.COSIGN_KEY}}
- name: Release Binaries
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{secrets.GH_PAT}}
COSIGN_PASSWORD: ${{secrets.COSIGN_PASSWORD}}
2 changes: 1 addition & 1 deletion .github/workflows/vulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ permissions:
contents: read

env:
GO_VERSION: '1.22.5'
GO_VERSION: '1.23.0'

jobs:
vulncheck:
Expand Down
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
enable:
- errcheck
- errname
- errorlint
- goconst
- gofumpt
- gosimple
- govet
- ineffassign
- nilerr
- prealloc
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- staticcheck
- unconvert
- unused
- usestdlibvars
- wastedassign
10 changes: 6 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ builds:

signs:
- cmd: cosign
stdin: "{{ .Env.COSIGN_PASSWORD }}"
signature: "${artifact}.sig"
certificate: "${artifact}.pem"
args:
- "sign-blob"
- "--key=cosign.key"
- "--oidc-issuer=https://token.actions.githubusercontent.com"
- "--output-certificate=${certificate}"
- "--output-signature=${signature}"
- "${artifact}"
- "--yes" # needed on cosign 2.0.0+
artifacts: all
- "--yes"
artifacts: checksum

brews:
- name: ecsv
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,3 @@ Using the latter will output HTML that, when served, looks as follows:

Read more about outputting HTML in the [examples](./examples/html_template)
directory.

Acknowledgements
---

`ecsv` is built using the awesome TUI framework [bubbletea][1].

[1]: https://github.com/charmbracelet/bubbletea
49 changes: 21 additions & 28 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package cmd

import (
"errors"
"fmt"
"os"
"os/user"
"path/filepath"
"strings"

"github.com/dhth/ecsv/ui"
"github.com/dhth/ecsv/internal/types"

"gopkg.in/yaml.v3"
)

type T struct {
var errInvalidConfigSourceProvided = errors.New("invalid aws-system-source provided")

type Config struct {
EnvSequence []string `yaml:"env-sequence"`
Systems []struct {
Key string `yaml:"key"`
Expand All @@ -26,54 +28,46 @@ type T struct {
} `yaml:"systems"`
}

func expandTilde(path string) string {
if strings.HasPrefix(path, "~") {
usr, err := user.Current()
if err != nil {
return path
}
return strings.Replace(path, "~", usr.HomeDir, 1)
func expandTilde(path string, homeDir string) string {
if strings.HasPrefix(path, "~/") {
return filepath.Join(homeDir, path[2:])
}
return path
}

func readConfig(filePath string) ([]string, []ui.System, error) {
localFile, err := os.ReadFile(filePath)
if err != nil {
os.Exit(1)
}
t := T{}
err = yaml.Unmarshal(localFile, &t)
func readConfig(configBytes []byte) ([]string, []types.System, error) {
cfg := Config{}
err := yaml.Unmarshal(configBytes, &cfg)
if err != nil {
return nil, nil, err
}

systems := make([]ui.System, 0)
var systems []types.System

for _, system := range t.Systems {
for _, system := range cfg.Systems {
for _, env := range system.Envs {

var awsConfigType ui.AWSConfigSourceType
var awsConfigType types.AWSConfigSourceType
var awsConfigSource string
switch {
case env.AwsConfigSource == "default":
awsConfigType = ui.DefaultCfgType
awsConfigType = types.DefaultCfgType
case strings.HasPrefix(env.AwsConfigSource, "profile:::"):
configElements := strings.Split(env.AwsConfigSource, "profile:::")
awsConfigSource = configElements[len(configElements)-1]
awsConfigType = ui.SharedCfgProfileType
awsConfigType = types.SharedCfgProfileType
case strings.HasPrefix(env.AwsConfigSource, "assume-role:::"):
configElements := strings.Split(env.AwsConfigSource, "assume-role:::")
awsConfigSource = configElements[len(configElements)-1]
awsConfigType = ui.AssumeRoleCfgType
awsConfigType = types.AssumeRoleCfgType
default:
return nil,
nil,
fmt.Errorf("system with key %s doesn't have a valid aws-config-source for env %s",
fmt.Errorf("%w: system: %s env: %s", errInvalidConfigSourceProvided,
system.Key,
env.Name)
}
systems = append(systems, ui.System{
systems = append(systems, types.System{
Key: system.Key,
Env: env.Name,
AWSConfigSourceType: awsConfigType,
Expand All @@ -85,6 +79,5 @@ func readConfig(filePath string) ([]string, []ui.System, error) {
})
}
}
return t.EnvSequence, systems, err

return cfg.EnvSequence, systems, nil
}
65 changes: 0 additions & 65 deletions cmd/help.go

This file was deleted.

48 changes: 48 additions & 0 deletions cmd/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cmd

import (
"fmt"

"github.com/dhth/ecsv/internal/awshelpers"
"github.com/dhth/ecsv/internal/types"
"github.com/dhth/ecsv/ui"
)

func render(systems []types.System, config ui.Config, awsConfigs map[string]awshelpers.Config) error {
results := make(map[string]map[string]types.SystemResult)
resultChannel := make(chan types.SystemResult)

counter := 0
for _, s := range systems {
awsConfig := awsConfigs[s.AWSConfigKey()]
if results[s.Key] == nil {
results[s.Key] = make(map[string]types.SystemResult)
}
results[s.Key][s.Env] = types.SystemResult{}

if awsConfig.Err != nil {
results[s.Key][s.Env] = types.SystemResult{
SystemKey: s.Key,
Env: s.Env,
Err: awsConfig.Err,
}
continue
}
go func(system types.System) {
resultChannel <- awshelpers.FetchSystemVersion(system, awsConfig)
}(s)
counter++
}

for range counter {
r := <-resultChannel
results[r.SystemKey][r.Env] = r
}

output, err := ui.GetOutput(config, results)
if err != nil {
return err
}
fmt.Print(output)
return nil
}
Loading