Skip to content

Commit 5ac3f33

Browse files
authored
Merge pull request #1 from mittwald/task/gitlab-to-github
Migrate Gitlab to Github
2 parents 7930a3a + b42121a commit 5ac3f33

File tree

16 files changed

+230
-62
lines changed

16 files changed

+230
-62
lines changed

.github/workflows/build.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Compile & Test
2+
3+
on: [push]
4+
jobs:
5+
test:
6+
name: Run tests
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
go: [ '1.14', '1.13' ]
11+
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v1
17+
with:
18+
go-version: ${{ matrix.go }}
19+
20+
- name: Run unit tests
21+
run: go test -v -count=1 -failfast ./...
22+
golangci:
23+
name: lint
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: golangci-lint
28+
uses: golangci/golangci-lint-action@v1
29+
with:
30+
version: v1.27
31+
args: --config=build/ci/.golangci.yml

.github/workflows/godoc.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: GoDoc
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
7+
env:
8+
GOPROXY: https://proxy.golang.org
9+
10+
jobs:
11+
update:
12+
name: Update
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Test successful curl against module mirror
16+
run : test $(curl -s -o /dev/null -w "%{http_code}" ${GOPROXY}/github.com/mittwald/go-helm-client/@v/${GITHUB_REF/refs\/tags\//}.info) -eq 200

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Initialize a new Vault Client using your token and endpoint:
2525
package main
2626

2727
import (
28-
vault "gitlab.mittwald.it/coab-0x7e7/libraries/vaultgo/pkg/vault"
28+
"github.com/mittwald/vaultGO/pkg/vault"
2929
"log"
3030
)
3131

@@ -47,7 +47,7 @@ func main() {
4747
package main
4848

4949
import (
50-
vault "gitlab.mittwald.it/coab-0x7e7/libraries/vaultgo/pkg/vault"
50+
"github.com/mittwald/vaultGO/pkg/vault"
5151
"log"
5252
)
5353

build/ci/.golangci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
linters-settings:
2+
govet:
3+
check-shadowing: true
4+
golint:
5+
min-confidence: 0
6+
gocyclo:
7+
min-complexity: 20
8+
maligned:
9+
suggest-new: true
10+
dupl:
11+
threshold: 100
12+
goconst:
13+
min-len: 2
14+
min-occurrences: 2
15+
depguard:
16+
list-type: blacklist
17+
packages:
18+
# logging is allowed only by logutils.Log, logrus
19+
# is allowed to use only in logutils package
20+
#- github.com/sirupsen/logrus
21+
misspell:
22+
locale: US
23+
lll:
24+
line-length: 180
25+
funlen:
26+
lines: 100
27+
statements: 60
28+
gocritic:
29+
enabled-tags:
30+
- performance
31+
- style
32+
#- experimental
33+
disabled-checks:
34+
- wrapperFunc
35+
- commentFormatting # https://github.com/go-critic/go-critic/issues/755
36+
- unnamedResult
37+
- ifElseChain
38+
39+
linters:
40+
enable-all: true
41+
42+
issues:
43+
# Excluding configuration per-path, per-linter, per-text and per-source
44+
exclude-rules:
45+
- path: _test\.go
46+
linters:
47+
- gomnd
48+
49+
run:
50+
skip-dirs:
51+
- test/
52+
- examples/
53+
- deployments/
54+
skip-files:
55+
- .*_test.go
56+
deadline: 60m
57+
58+
service:
59+
golangci-lint-version: 1.27.x

client.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package vault
22

33
import (
44
"encoding/json"
5-
"github.com/hashicorp/vault/api"
65
"io/ioutil"
76
"net/url"
7+
8+
"github.com/hashicorp/vault/api"
89
)
910

1011
type Client struct {
11-
api.Client
12+
*api.Client
1213
}
1314

1415
type TLSConfig struct {
@@ -29,19 +30,22 @@ func WithCaPath(path string) *TLSConfig {
2930

3031
func NewClient(addr string, tlsConf *TLSConfig, opts ...ClientOpts) (*Client, error) {
3132
conf := api.DefaultConfig()
33+
3234
conf.Address = addr
35+
3336
if tlsConf != nil {
3437
if err := conf.ConfigureTLS(tlsConf.TLSConfig); err != nil {
3538
return nil, err
3639
}
37-
3840
}
3941

4042
vaultClient, err := api.NewClient(conf)
4143
if err != nil {
4244
return nil, err
4345
}
44-
client := &Client{Client: *vaultClient}
46+
47+
client := &Client{Client: vaultClient}
48+
4549
for _, opt := range opts {
4650
err := opt(client)
4751
if err != nil {
@@ -82,21 +86,22 @@ func (c *Client) Request(method string, path []string, body interface{}, paramet
8286
return err
8387
}
8488
}
89+
8590
return nil
8691
}
8792

8893
func (c *Client) Read(path []string, parameters url.Values, response interface{}) error {
8994
return c.Request("GET", path, nil, parameters, response)
9095
}
9196

92-
func (c *Client) Write(path []string, body interface{}, response interface{}) error {
97+
func (c *Client) Write(path []string, body, response interface{}) error {
9398
return c.Request("POST", path, body, nil, response)
9499
}
95100

96-
func (c *Client) Delete(path []string, body interface{}, response interface{}) error {
101+
func (c *Client) Delete(path []string, body, response interface{}) error {
97102
return c.Request("DELETE", path, body, nil, response)
98103
}
99104

100-
func (c *Client) List(path []string, body interface{}, response interface{}) error {
105+
func (c *Client) List(path []string, body, response interface{}) error {
101106
return c.Request("LIST", path, body, nil, response)
102107
}

client_opts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ type ClientOpts func(c *Client) error
55
func WithAuthProvider(p AuthProvider, autoRenew bool, renewErrs chan<- error) ClientOpts {
66
return func(c *Client) error {
77
a := NewTokenAuth(c, p)
8+
89
err := a.Auth()
910
if err != nil {
1011
return err
1112
}
13+
1214
if autoRenew {
1315
a.EnableAutoRenew(renewErrs)
1416
}
17+
1518
return nil
1619
}
1720
}
@@ -24,6 +27,7 @@ func WithKubernetesAuth(role string, autoRenew bool, renewErrs chan<- error, opt
2427
}
2528

2629
withProviderFunc := WithAuthProvider(k8AuthProvider, autoRenew, renewErrs)
30+
2731
return withProviderFunc(c)
2832
}
2933
}

deployments/vault/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: '3.6'
22
services:
33
vault:
4-
image: vault:latest
4+
image: vault:1.4.2
55
container_name: vault
66
restart: unless-stopped
77
ports:

examples/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package main
22

33
import (
44
"fmt"
5-
"gitlab.mittwald.it/coab-0x7e7/libraries/vaultgo"
5+
"github.com/mittwald/vaultGO"
66
"gopkg.in/guregu/null.v3"
77
"log"
88
)
@@ -19,7 +19,7 @@ func main() {
1919

2020
key := "test123bacd"
2121

22-
err = transit.Create(key, vault.TransitCreateOptions{
22+
err = transit.Create(key, &vault.TransitCreateOptions{
2323
Exportable: null.BoolFrom(true),
2424
})
2525
if err != nil {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module gitlab.mittwald.it/coab-0x7e7/libraries/vaultgo
1+
module github.com/mittwald/vaultGO
22

3-
go 1.13
3+
go 1.14
44

55
require (
66
github.com/Microsoft/hcsshim v0.8.9 // indirect

kubernetes_auth.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package vault
22

33
import (
4-
"github.com/pkg/errors"
54
"io/ioutil"
5+
6+
"github.com/pkg/errors"
67
)
78

8-
const defaultServiceAccountTokenPath = "/run/secrets/kubernetes.io/serviceaccount/token"
9+
const (
10+
// nolint:gosec // this is not a hardcoded credential
11+
defaultServiceAccountTokenPath = "/run/secrets/kubernetes.io/serviceaccount/token"
12+
)
913

1014
func NewKubernetesAuth(c *Client, role string, opts ...KubernetesAuthOpt) (AuthProvider, error) {
1115
k := &kubernetesAuth{
1216
Client: c,
1317
mountPoint: "kubernetes",
1418
}
19+
1520
for _, opt := range opts {
1621
err := opt(k)
1722
if err != nil {
@@ -26,6 +31,7 @@ func NewKubernetesAuth(c *Client, role string, opts ...KubernetesAuthOpt) (AuthP
2631
return nil, err
2732
}
2833
}
34+
2935
return k, nil
3036
}
3137

@@ -41,6 +47,7 @@ func loadJwt(path string) (string, error) {
4147
if err != nil {
4248
return "", errors.Wrap(err, "could not load jwt from file")
4349
}
50+
4451
return string(content), nil
4552
}
4653

@@ -56,7 +63,7 @@ type authResponse struct {
5663
ServiceAccountName string `json:"service_account_name"`
5764
ServiceAccountNamespace string `json:"service_account_namespace"`
5865
ServiceAccountSecretName string `json:"service_account_secret_name"`
59-
ServiceAccountUid string `json:"service_account_uid"`
66+
ServiceAccountUID string `json:"service_account_uid"`
6067
} `json:"metadata"`
6168
} `json:"auth"`
6269
}
@@ -73,9 +80,11 @@ func (k kubernetesAuth) Auth() (*authResponse, error) {
7380
}
7481

7582
res := &authResponse{}
83+
7684
err := k.Client.Write([]string{"v1", "auth", k.mountPoint, "login"}, conf, res)
7785
if err != nil {
7886
return nil, err
7987
}
88+
8089
return res, nil
8190
}

0 commit comments

Comments
 (0)