mirror of
https://github.com/hashicorp/vault.git
synced 2025-12-16 15:01:13 +01:00
add gofmt checks to Vault and format existing code (#2745)
This commit is contained in:
parent
3ba9486ba9
commit
38ffde5a9d
22
Makefile
22
Makefile
@ -3,11 +3,12 @@ VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf
|
|||||||
EXTERNAL_TOOLS=\
|
EXTERNAL_TOOLS=\
|
||||||
github.com/mitchellh/gox
|
github.com/mitchellh/gox
|
||||||
BUILD_TAGS?=vault
|
BUILD_TAGS?=vault
|
||||||
|
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
|
||||||
|
|
||||||
default: dev
|
default: dev
|
||||||
|
|
||||||
# bin generates the releaseable binaries for Vault
|
# bin generates the releaseable binaries for Vault
|
||||||
bin: generate
|
bin: fmtcheck generate
|
||||||
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
|
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||||
|
|
||||||
# dev creates binaries for testing Vault locally. These are put
|
# dev creates binaries for testing Vault locally. These are put
|
||||||
@ -15,22 +16,22 @@ bin: generate
|
|||||||
# is only put into /bin/
|
# is only put into /bin/
|
||||||
quickdev: generate
|
quickdev: generate
|
||||||
@CGO_ENABLED=0 go build -i -tags='$(BUILD_TAGS)' -o bin/vault
|
@CGO_ENABLED=0 go build -i -tags='$(BUILD_TAGS)' -o bin/vault
|
||||||
dev: generate
|
dev: fmtcheck generate
|
||||||
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||||
dev-dynamic: generate
|
dev-dynamic: generate
|
||||||
@CGO_ENABLED=1 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
@CGO_ENABLED=1 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
|
||||||
|
|
||||||
# test runs the unit tests and vets the code
|
# test runs the unit tests and vets the code
|
||||||
test: generate
|
test: fmtcheck generate
|
||||||
CGO_ENABLED=0 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' $(TEST) $(TESTARGS) -timeout=20m -parallel=4
|
CGO_ENABLED=0 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' $(TEST) $(TESTARGS) -timeout=20m -parallel=4
|
||||||
|
|
||||||
testcompile: generate
|
testcompile: fmtcheck generate
|
||||||
@for pkg in $(TEST) ; do \
|
@for pkg in $(TEST) ; do \
|
||||||
go test -v -c -tags='$(BUILD_TAGS)' $$pkg -parallel=4 ; \
|
go test -v -c -tags='$(BUILD_TAGS)' $$pkg -parallel=4 ; \
|
||||||
done
|
done
|
||||||
|
|
||||||
# testacc runs acceptance tests
|
# testacc runs acceptance tests
|
||||||
testacc: generate
|
testacc: fmtcheck generate
|
||||||
@if [ "$(TEST)" = "./..." ]; then \
|
@if [ "$(TEST)" = "./..." ]; then \
|
||||||
echo "ERROR: Set TEST to a specific package"; \
|
echo "ERROR: Set TEST to a specific package"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
@ -38,7 +39,7 @@ testacc: generate
|
|||||||
VAULT_ACC=1 go test -tags='$(BUILD_TAGS)' $(TEST) -v $(TESTARGS) -timeout 45m
|
VAULT_ACC=1 go test -tags='$(BUILD_TAGS)' $(TEST) -v $(TESTARGS) -timeout 45m
|
||||||
|
|
||||||
# testrace runs the race checker
|
# testrace runs the race checker
|
||||||
testrace: generate
|
testrace: fmtcheck generate
|
||||||
CGO_ENABLED=1 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' -race $(TEST) $(TESTARGS) -timeout=20m -parallel=4
|
CGO_ENABLED=1 VAULT_TOKEN= VAULT_ACC= go test -tags='$(BUILD_TAGS)' -race $(TEST) $(TESTARGS) -timeout=20m -parallel=4
|
||||||
|
|
||||||
cover:
|
cover:
|
||||||
@ -71,4 +72,11 @@ proto:
|
|||||||
protoc -I helper/forwarding -I vault -I ../../.. vault/*.proto --go_out=plugins=grpc:vault
|
protoc -I helper/forwarding -I vault -I ../../.. vault/*.proto --go_out=plugins=grpc:vault
|
||||||
protoc -I helper/forwarding -I vault -I ../../.. helper/forwarding/types.proto --go_out=plugins=grpc:helper/forwarding
|
protoc -I helper/forwarding -I vault -I ../../.. helper/forwarding/types.proto --go_out=plugins=grpc:helper/forwarding
|
||||||
|
|
||||||
.PHONY: bin default generate test vet bootstrap
|
fmtcheck:
|
||||||
|
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
gofmt -w $(GOFMT_FILES)
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: bin default generate test vet bootstrap fmt fmtcheck
|
||||||
|
|||||||
@ -6,11 +6,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"path"
|
|
||||||
|
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
|
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/structs"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/logical/framework"
|
"github.com/hashicorp/vault/logical/framework"
|
||||||
"github.com/fatih/structs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func pathConfig(b *backend) *framework.Path {
|
func pathConfig(b *backend) *framework.Path {
|
||||||
@ -37,7 +37,7 @@ API-compatible authentication server.`,
|
|||||||
|
|
||||||
Callbacks: map[logical.Operation]framework.OperationFunc{
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
||||||
logical.UpdateOperation: b.pathConfigWrite,
|
logical.UpdateOperation: b.pathConfigWrite,
|
||||||
logical.ReadOperation: b.pathConfigRead,
|
logical.ReadOperation: b.pathConfigRead,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,10 +77,10 @@ func (b *backend) pathConfigWrite(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entry, err := logical.StorageEntryJSON("config", config{
|
entry, err := logical.StorageEntryJSON("config", config{
|
||||||
Organization: organization,
|
Organization: organization,
|
||||||
BaseURL: baseURL,
|
BaseURL: baseURL,
|
||||||
TTL: ttl,
|
TTL: ttl,
|
||||||
MaxTTL: maxTTL,
|
MaxTTL: maxTTL,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -61,14 +61,14 @@ func (b *backend) pathCredsCreateRead(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set consistency
|
// Set consistency
|
||||||
if role.Consistency != "" {
|
if role.Consistency != "" {
|
||||||
consistencyValue, err := gocql.ParseConsistencyWrapper(role.Consistency)
|
consistencyValue, err := gocql.ParseConsistencyWrapper(role.Consistency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
session.SetConsistency(consistencyValue)
|
session.SetConsistency(consistencyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -72,7 +72,7 @@ func (c *AuditEnableCommand) Run(args []string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = client.Sys().EnableAuditWithOptions(path, &api.EnableAuditOptions{
|
err = client.Sys().EnableAuditWithOptions(path, &api.EnableAuditOptions{
|
||||||
Type: auditType,
|
Type: auditType,
|
||||||
Description: desc,
|
Description: desc,
|
||||||
Options: opts,
|
Options: opts,
|
||||||
Local: local,
|
Local: local,
|
||||||
|
|||||||
@ -10,8 +10,8 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/errwrap"
|
"github.com/hashicorp/errwrap"
|
||||||
"github.com/hashicorp/vault/helper/consts"
|
"github.com/hashicorp/vault/helper/consts"
|
||||||
"github.com/hashicorp/vault/helper/parseutil"
|
|
||||||
"github.com/hashicorp/vault/helper/jsonutil"
|
"github.com/hashicorp/vault/helper/jsonutil"
|
||||||
|
"github.com/hashicorp/vault/helper/parseutil"
|
||||||
"github.com/hashicorp/vault/logical"
|
"github.com/hashicorp/vault/logical"
|
||||||
"github.com/hashicorp/vault/vault"
|
"github.com/hashicorp/vault/vault"
|
||||||
)
|
)
|
||||||
|
|||||||
11
scripts/gofmtcheck.sh
Executable file
11
scripts/gofmtcheck.sh
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
echo "==> Checking that code complies with gofmt requirements..."
|
||||||
|
|
||||||
|
gofmt_files=$(gofmt -l `find . -name '*.go' | grep -v vendor`)
|
||||||
|
if [[ -n ${gofmt_files} ]]; then
|
||||||
|
echo 'gofmt needs running on the following files:'
|
||||||
|
echo "${gofmt_files}"
|
||||||
|
echo "You can use the command: \`make fmt\` to reformat code."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@ -98,7 +98,6 @@ func (v *BarrierView) Delete(key string) error {
|
|||||||
return logical.ErrReadOnly
|
return logical.ErrReadOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return v.barrier.Delete(expandedKey)
|
return v.barrier.Delete(expandedKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user