Skip to content

Commit ec80e21

Browse files
author
Manatsawin Hanmongkolchai
committed
Added --auth-k8s-mount
1 parent 936bea9 commit ec80e21

7 files changed

Lines changed: 47 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ and this project adheres to [0ver](https://0ver.org) (more or less).
103103
- LICENSE
104104
- README
105105

106-
[Unreleased]: https://github.com/mvisonneau/vac/compare/v0.0.8...HEAD
107-
[v0.0.8]: https://github.com/mvisonneau/vac/tree/v0.0.8
106+
[Unreleased]: https://github.com/mvisonneau/vac/compare/v0.0.7...HEAD
108107
[v0.0.7]: https://github.com/mvisonneau/vac/tree/v0.0.7
109108
[v0.0.6]: https://github.com/mvisonneau/vac/tree/v0.0.6
110109
[v0.0.5]: https://github.com/mvisonneau/vac/tree/v0.0.5

Makefile

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ COVERAGE_FILE := coverage.out
33
REPOSITORY := mvisonneau/$(NAME)
44
.DEFAULT_GOAL := help
55

6+
.PHONY: setup
7+
setup: ## Install required libraries/tools for build tasks
8+
@command -v gofumpt 2>&1 >/dev/null || go install mvdan.cc/gofumpt@v0.2.1
9+
@command -v gosec 2>&1 >/dev/null || go install github.com/securego/gosec/v2/cmd/gosec@v2.9.6
10+
@command -v ineffassign 2>&1 >/dev/null || go install github.com/gordonklaus/ineffassign@v0.0.0-20210914165742-4cc7213b9bc8
11+
@command -v misspell 2>&1 >/dev/null || go install github.com/client9/misspell/cmd/misspell@v0.3.4
12+
@command -v revive 2>&1 >/dev/null || go install github.com/mgechev/revive@v1.1.3
13+
614
.PHONY: fmt
715
fmt: ## Format source code
816
go run mvdan.cc/gofumpt@v0.6.0 -w $(shell git ls-files **/*.go)
@@ -14,13 +22,7 @@ lint: ## Run all lint related tests upon the codebase
1422

1523
.PHONY: test
1624
test: ## Run the tests against the codebase
17-
@rm -rf $(COVERAGE_FILE)
18-
go test -v -count=1 -race ./... -coverprofile=$(COVERAGE_FILE)
19-
@go tool cover -func $(COVERAGE_FILE) | awk '/^total/ {print "coverage: " $$3}'
20-
21-
.PHONY: coverage
22-
coverage: ## Prints coverage report
23-
go tool cover -func $(COVERAGE_FILE)
25+
go test -v -count=1 -race ./...
2426

2527
.PHONY: install
2628
install: ## Build and install locally the binary (dev purpose)
@@ -47,6 +49,28 @@ prerelease: ## Build & prerelease the binaries (edge)
4749
clean: ## Remove binary if it exists
4850
rm -f $(NAME)
4951

52+
.PHONY: coverage
53+
coverage: ## Generates coverage report
54+
rm -rf *.out
55+
go test -count=1 -race -v ./... -coverpkg=./... -coverprofile=coverage.out
56+
57+
.PHONY: coverage-html
58+
coverage-html: ## Generates coverage report and displays it in the browser
59+
go tool cover -html=coverage.out
60+
61+
.PHONY: dev-env
62+
dev-env: ## Build a local development environment using Docker
63+
@docker run -it --rm \
64+
-v $(shell pwd):/go/src/github.com/mvisonneau/$(NAME) \
65+
-w /go/src/github.com/mvisonneau/$(NAME) \
66+
golang:1.17 \
67+
/bin/bash -c 'make setup; make install; bash'
68+
69+
.PHONY: is-git-dirty
70+
is-git-dirty: ## Tests if git is in a dirty state
71+
@git status --porcelain
72+
@test $(shell git status --porcelain | grep -c .) -eq 0
73+
5074
.PHONY: all
5175
all: lint test build coverage ## Test, builds and ship package for all supported platforms
5276

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ GLOBAL OPTIONS:
130130
--log-format format log format (json,text) (default: "text") [$VAC_LOG_FORMAT]
131131
--auth value auth method (token, kubernetes) (default: "token") [$VAC_AUTH]
132132
--auth-k8s-role value Kubernetes role to authenticate to (for --auth kubernetes) [$VAC_AUTH_K8S_ROLE]
133+
--auth-k8s-mount value Kubernetes auth mount path (for --auth kubernetes) (default: "kubernetes") [$VAC_AUTH_K8S_MOUNT]
133134
--help, -h show help
134135
```
135136

internal/cli/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewApp(version string, start time.Time) (app *cli.App) {
3636
flags.State,
3737
flags.Auth,
3838
flags.AuthK8sRole,
39+
flags.AuthK8sMount,
3940
}
4041

4142
app.Action = cmd.ExecWrapper(cmd.Switch)

internal/cli/flags/flags.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@ var (
7373
EnvVars: []string{"VAC_AUTH_K8S_ROLE"},
7474
Usage: "Kubernetes role to authenticate to (for --auth kubernetes)",
7575
}
76+
77+
AuthK8sMount = &cli.StringFlag{
78+
Name: "auth-k8s-mount",
79+
EnvVars: []string{"VAC_AUTH_K8S_MOUNT"},
80+
Usage: "Kubernetes auth mount path (for --auth kubernetes)",
81+
Value: "kubernetes",
82+
}
7683
)

internal/cmd/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ func configure(ctx *cli.Context) (*Config, error) {
5050
LockPath: fmt.Sprintf("%s.lock", statePath),
5151

5252
AuthInfo: client.AuthInfo{
53-
Method: ctx.String("auth"),
54-
RoleName: ctx.String("auth-k8s-role"),
53+
Method: ctx.String("auth"),
54+
MountPath: ctx.String("auth-k8s-mount"),
55+
RoleName: ctx.String("auth-k8s-role"),
5556
},
5657
}, nil
5758
}

pkg/client/vault.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ func getVaultClient() (*vault.Client, error) {
4545
type AuthInfo struct {
4646
Method string
4747

48-
RoleName string
48+
MountPath string
49+
RoleName string
4950
}
5051

5152
func (c *Client) Authenticate(info AuthInfo) error {
5253
switch info.Method {
5354
case "kubernetes":
54-
authMethod, err := k8sauth.NewKubernetesAuth(info.RoleName)
55+
authMethod, err := k8sauth.NewKubernetesAuth(info.RoleName, k8sauth.WithMountPath(info.MountPath))
5556
if err != nil {
5657
return err
5758
}

0 commit comments

Comments
 (0)