Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz committed Nov 21, 2024
0 parents commit 5facf7b
Show file tree
Hide file tree
Showing 14 changed files with 886 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
27 changes: 27 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: golangci-lint
on:
push:
branches:
- main
- master
pull_request:

permissions:
contents: read
pull-requests: read
checks: write

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
86 changes: 86 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
name: goreleaser

on:
push:
tags:
- "v*.*.*"
workflow_dispatch:

permissions:
contents: write
id-token: write
packages: write

jobs:
prepare:
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
env:
flags: ""
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: 1.21
cache: true
- shell: bash
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- uses: actions/cache@v4
if: matrix.os == 'ubuntu-latest'
with:
path: dist/linux
key: linux-${{ env.sha_short }}
- if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: echo "flags=--nightly" >> $GITHUB_ENV
- uses: goreleaser/goreleaser-action@v6
if: steps.cache.outputs.cache-hit != 'true' # do not run if cache hit
with:
distribution: goreleaser-pro
version: latest
args: release --clean --split ${{ env.flags }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
AUR_KEY: ${{ secrets.AUR_KEY }}

release:
runs-on: ubuntu-latest
needs: prepare
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5
with:
go-version: 1.22
cache: true

# copy the cashes from prepare
- shell: bash
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- uses: actions/cache@v4
with:
path: dist/linux
key: linux-${{ env.sha_short }}

# release
- uses: goreleaser/goreleaser-action@v6
if: steps.cache.outputs.cache-hit != 'true' # do not run if cache hit
with:
version: latest
distribution: goreleaser-pro
args: continue --merge
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
AUR_KEY: ${{ secrets.AUR_KEY }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
awoolt.yml
22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
tests: false

issues:
max-issues-per-linter: 0
max-same-issues: 0

linters:
enable:
- bodyclose
- copyloopvar
- goimports
- gosec
- nilerr
- predeclared
- revive
- rowserrcheck
- sqlclosecheck
- tparallel
- unconvert
- unparam
- whitespace
100 changes: 100 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
variables:
main: "."
binary_name: "awoolt"
description: "interactively browse vault/openbao in the terminal."
github_url: "https://github.com/jon4hz/awoolt"
maintainer: "jonah <me@jon4hz.io>"
license: "MIT"
homepage: "https://jon4hz.io"
aur_package: |-
# bin
install -Dm755 "./awoolt" "${pkgdir}/usr/bin/awoolt"
# license
install -Dm644 "./LICENSE" "${pkgdir}/usr/share/licenses/awoolt/LICENSE"
before:
hooks:
- go mod tidy

builds:
- id: default
env:
- CGO_ENABLED=0
main: "{{ .Var.main }}"
binary: "{{ .Var.binary_name }}"
ldflags:
- -s
- -w
- -X github.com/jon4hz/{{ .Var.binary_name }}/version.Version={{ .Version }}
- -X github.com/jon4hz/{{ .Var.binary_name }}/version.Commit={{ .Commit }}
- -X github.com/jon4hz/{{ .Var.binary_name }}/version.Date={{ .Date }}
- -X github.com/jon4hz/{{ .Var.binary_name }}/version.BuiltBy=goreleaser
flags:
- -trimpath
goos:
- linux
goarch:
- amd64

archives:
- id: default
name_template: "{{ .Var.binary_name }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}-{{ .Mips }}{{ end }}"
builds:
- default
files:
- LICENSE*
- README*
- CHANGELOG*

checksum:
name_template: "checksums.txt"

nfpms:
- file_name_template: "{{ .Var.binary_name }}-v{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}{{ if .Mips }}-{{ .Mips }}{{ end }}"
vendor: jon4hz
homepage: "{{ .Var.homepage }}"
maintainer: "{{ .Var.maintainer }}"
description: "{{ .Var.description }}"
license: "{{ .Var.license }}"
formats:
- apk
- deb
- rpm

aurs:
- name: "{{ .Var.binary_name }}-bin"
homepage: "{{ .Var.homepage }}"
description: "{{ .Var.description }}"
maintainers:
- "{{ .Var.maintainer }}"
license: "{{ .Var.license }}"
private_key: "{{ .Env.AUR_KEY }}"
git_url: "ssh://aur@aur.archlinux.org/{{ .Var.binary_name }}-bin.git"
package: "{{ .Var.aur_package }}"

source:
enabled: true

snapshot:
name_template: "{{ incpatch .Version }}-devel"

changelog:
sort: asc
use: github
filters:
exclude:
- "^docs:"
- "^test:"
groups:
- title: "New Features"
regexp: "^.*feat[(\\w)]*:+.*$"
order: 0
- title: "Bug fixes"
regexp: "^.*fix[(\\w)]*:+.*$"
order: 10
- title: Others
order: 999

furies:
- account: jon4hz
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 🐺 Awoolt
[![Go Report Card](https://goreportcard.com/badge/github.com/jon4hz/awoolt)](https://goreportcard.com/report/github.com/jon4hz/awoolt)
[![lint](https://github.com/jon4hz/awoolt/actions/workflows/lint.yml/badge.svg)](https://github.com/jon4hz/awoolt/actions/workflows/lint.yml)
[![goreleaser](https://github.com/jon4hz/awoolt/actions/workflows/release.yml/badge.svg)](https://github.com/jon4hz/awoolt/actions/workflows/release.yml)

Interactively browse vault/openbao in the terminal.

## 🚀 Installation

```bash
# using go directly
$ go install github.com/jon4hz/awoolt@latest

# from aur (btw)
$ yay -S awoolt-bin

# local pkg manager
$ export VERSION=v0.1.0

## debian / ubuntu
$ dpkg -i awoolt-$VERSION-linux-amd64.deb

## rhel / sles
$ rpm -i awoolt-$VERSION-linux-amd64.rpm

## alpine
$ apk add --allow-untrusted awoolt-$VERSION-linux-amd64.apk
```
All releases can be found [here](https://github.com/jon4hz/awoolt/releases)

## 📝 Config

`awoolt` searches for a config file in the following locations:
1. `./awoolt.yml`
2. `~/.config/awoolt/awoolt.yml`
3. `/etc/awoolt/awoolt.yml`

### 🥁 Example
```yaml
# ~/.config/awoolt/awoolt.yml
---
engine: my-vault-kv
```
## 🔑 Authentication
Make sure you have a valid vault token on your system. Try `vault login`.

## ✨ Usage
```
$ awoolt --help
interactively browse vault/openbao in the terminal.

Usage:
awoolt [flags]

Flags:
-e, --engine string secret engine to use
-h, --help help for awoolt
-p, --path string secret path
```
56 changes: 56 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package config

import (
"errors"
"os"
"path"

"github.com/adrg/xdg"
"github.com/spf13/viper"
)

type Config struct {
Engine string `mapstructure:"engine"`
}

func Load(path string) (cfg *Config, err error) {
if path != "" {
return load(path)
}
for _, f := range [...]string{
".config.yml",
"config.yml",
".config.yaml",
"config.yaml",
"awoolt.yml",
"awoolt.yaml",
} {
cfg, err = load(f)
if err != nil && os.IsNotExist(err) {
err = nil
continue
} else if err != nil && errors.As(err, &viper.ConfigFileNotFoundError{}) {
err = nil
continue
}
}
if cfg == nil {
return cfg, viper.Unmarshal(&cfg)
}
return
}

func load(file string) (cfg *Config, err error) {
viper.SetConfigName(file)
viper.SetConfigType("yaml")
viper.AddConfigPath("./")
viper.AddConfigPath(path.Join(xdg.ConfigHome, "awoolt"))
viper.AddConfigPath("/etc/awoolt/")
if err = viper.ReadInConfig(); err != nil {
return
}
if err = viper.Unmarshal(&cfg); err != nil {
return
}
return
}
Loading

0 comments on commit 5facf7b

Please sign in to comment.