Skip to content

Commit 8216790

Browse files
committed
Add workflows
1 parent a689aa6 commit 8216790

File tree

7 files changed

+122
-10
lines changed

7 files changed

+122
-10
lines changed

.github/workflows/build.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Build
2+
3+
on:
4+
- push
5+
- pull_request
6+
7+
jobs:
8+
test-build:
9+
name: Test & Build
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Set up Go 1.17
14+
uses: actions/setup-go@v2
15+
with:
16+
go-version: '1.17.1'
17+
18+
- name: Set GOPATH and PATH
19+
run: |
20+
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
21+
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
22+
shell: bash
23+
24+
- name: Check out code
25+
uses: actions/checkout@v2
26+
27+
- name: Update build dependencies
28+
run: make setup
29+
30+
- name: Build
31+
run: make bin
32+

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
jobs:
7+
build:
8+
name: Create Release
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Set up Go 1.17
13+
uses: actions/setup-go@v2
14+
with:
15+
go-version: '1.17.1'
16+
17+
- name: Set GOPATH and PATH
18+
run: |
19+
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
20+
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
21+
shell: bash
22+
23+
- name: Check out code into the Go module directory
24+
uses: actions/checkout@v2
25+
26+
- name: Generate releases
27+
run: make releases
28+
29+
- name: Create Release
30+
id: create_release
31+
uses: actions/create-release@v1
32+
env:
33+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
34+
with:
35+
tag_name: ${{ github.ref }}
36+
release_name: ${{ github.ref }}
37+
draft: false
38+
prerelease: false
39+
40+
- name: GitHub Release
41+
uses: softprops/action-gh-release@v1
42+
if: success()
43+
with:
44+
draft: true
45+
files: |
46+
dist/vault-backup_darwin-amd64
47+
dist/vault-backup_linux-amd64
48+
dist/vault-backup_windows-amd64
49+
name: ${{ github.ref }}
50+
env:
51+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
vault-backup
22
vault.backup*
3+
dist/

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/make
2+
3+
.DEFAULT_GOAL := all
4+
PLATFORMS := linux/amd64 darwin/amd64 windows/amd64
5+
6+
temp = $(subst /, ,$@)
7+
os = $(word 1, $(temp))
8+
arch = $(word 2, $(temp))
9+
10+
.PHONY: setup
11+
setup:
12+
@go mod download
13+
14+
.PHONY: bin
15+
bin:
16+
go build -o ./dist/vault-backup
17+
18+
.PHONY: releases
19+
releases: $(PLATFORMS)
20+
21+
$(PLATFORMS):
22+
GOOS=$(os) GOARCH=$(arch) go build -o 'dist/vault-backup_$(os)-$(arch)'
23+
24+
.PHONY: all
25+
all:
26+
@make -s bin
27+

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/hashicorp/vault/api v1.3.0
77
github.com/imdario/mergo v0.3.12
88
github.com/pkg/errors v0.9.1
9-
gopkg.in/yaml.v2 v2.3.0
9+
gopkg.in/yaml.v2 v2.4.0
1010
)
1111

1212
require (

go.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,9 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
327327
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
328328
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
329329
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
330-
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
331330
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
331+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
332+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
332333
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
333334
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
334335
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

main.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
type fnEncode func(interface{}) string
2020

21+
// VaultBackup is all ths information required to make a backup
2122
type VaultBackup struct {
2223
client *vault.Client
2324
paths []string
@@ -36,6 +37,7 @@ var encode = map[string]fnEncode{
3637
},
3738
}
3839

40+
// NewBackup creates a new backup
3941
func NewBackup() (*VaultBackup, error) {
4042
config := vault.DefaultConfig()
4143

@@ -56,7 +58,7 @@ func (b *VaultBackup) store(src map[string]string) error {
5658
return nil
5759
}
5860

59-
func (b *VaultBackup) walk(parent string, paths []string) error {
61+
func (b *VaultBackup) walk(parent string, paths []string) {
6062
for _, p := range paths {
6163
if p != "" {
6264
p = fmt.Sprintf("%s%s", parent, p)
@@ -70,7 +72,9 @@ func (b *VaultBackup) walk(parent string, paths []string) error {
7072
log.Printf("[ERROR] unable to read secret '%s' (%v). \n", p, err)
7173
}
7274

73-
b.store(secrets)
75+
if err := b.store(secrets); err != nil {
76+
log.Printf("[ERROR] unabled to merge the secrets (%v)", err)
77+
}
7478

7579
continue
7680
}
@@ -91,8 +95,6 @@ func (b *VaultBackup) walk(parent string, paths []string) error {
9195
b.walk(p, keys)
9296
}
9397
}
94-
95-
return nil
9698
}
9799

98100
func (b *VaultBackup) read(path string) (map[string]string, error) {
@@ -153,7 +155,7 @@ func (b *VaultBackup) write() error {
153155
return err
154156
}
155157

156-
return os.WriteFile(b.filename, out, 0644)
158+
return os.WriteFile(b.filename, out, 0600)
157159
}
158160

159161
func main() {
@@ -184,9 +186,7 @@ func main() {
184186
client.encode = "base64"
185187
}
186188

187-
if err := client.walk("", client.paths); err != nil {
188-
log.Fatal(err)
189-
}
189+
client.walk("", client.paths)
190190

191191
if err = client.write(); err != nil {
192192
log.Fatal(err)

0 commit comments

Comments
 (0)