Skip to content

Commit 68543d3

Browse files
committed
Initialize Open Source Project tencentcloud-vault
1 parent 6a54633 commit 68543d3

35 files changed

+2165
-2687
lines changed

LICENSE

-373
This file was deleted.

Makefile

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1-
TOOL?=vault-tencentcloud-secrets-plugin
2-
TEST?=$$(go list ./... | grep -v /vendor/)
1+
TOOL?=vault-plugin-secrets-tencentcloud
2+
TEST?=$$(go list ./... | grep -v /vendor/ | grep -v teamcity)
33
VETARGS?=-asmdecl -atomic -bool -buildtags -copylocks -methods -nilfunc -printf -rangeloops -shift -structtags -unsafeptr
44
EXTERNAL_TOOLS=\
55
github.com/mitchellh/gox \
6-
github.com/kardianos/govendor
6+
github.com/golang/dep/cmd/dep
77
BUILD_TAGS?=${TOOL}
88
GOFMT_FILES?=$$(find . -name '*.go' | grep -v vendor)
9-
TEST_ARGS?=./...
109

11-
# bin generates the releasable binaries for this plugin
10+
# bin generates the releaseable binaries for this plugin
1211
bin: fmtcheck generate
1312
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' sh -c "'$(CURDIR)/scripts/build.sh'"
1413

1514
default: dev
1615

1716
# dev creates binaries for testing Vault locally. These are put
18-
# into ./bin/ as well as $GOPATH/bin, except for quickdev which
19-
# is only put into /bin/
20-
quickdev: generate
21-
@CGO_ENABLED=0 go build -i -tags='$(BUILD_TAGS)' -o bin/vault-tencentcloud-auth-plugin
17+
# into ./bin/ as well as $GOPATH/bin.
2218
dev: fmtcheck generate
2319
@CGO_ENABLED=0 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
24-
dev-dynamic: generate
25-
@CGO_ENABLED=1 BUILD_TAGS='$(BUILD_TAGS)' VAULT_DEV_BUILD=1 sh -c "'$(CURDIR)/scripts/build.sh'"
20+
21+
# test runs the unit tests and vets the code
22+
test: fmtcheck generate
23+
CGO_ENABLED=0 VAULT_TOKEN= VAULT_ACC= go test -v -tags='$(BUILD_TAGS)' $(TEST) $(TESTARGS) -count=1 -timeout=20m -parallel=4
24+
25+
test-acc:
26+
@VAULT_ACC=1 go test -parallel=40 ./... $(TESTARGS)
2627

2728
testcompile: fmtcheck generate
2829
@for pkg in $(TEST) ; do \
2930
go test -v -c -tags='$(BUILD_TAGS)' $$pkg -parallel=4 ; \
3031
done
3132

32-
test:
33-
@go test -short -parallel=40 ./... $(TESTARGS)
34-
35-
test-acc:
36-
@VAULT_ACC=1 go test -parallel=40 ./... $(TESTARGS)
3733
# generate runs `go generate` to build the dynamically generated
3834
# source files.
3935
generate:
40-
@go generate $(go list ./... | grep -v /vendor/)
36+
go generate $(go list ./... | grep -v /vendor/)
4137

4238
# bootstrap the build by downloading additional tools
4339
bootstrap:
@@ -52,12 +48,7 @@ fmtcheck:
5248
fmt:
5349
gofmt -w $(GOFMT_FILES)
5450

55-
update-resources:
56-
pushd $(CURDIR)/plugin/iamutil && \
57-
go build -o generate ./internal && \
58-
./generate && \
59-
rm generate && \
60-
popd
61-
51+
proto:
52+
protoc *.proto --go_out=plugins=grpc:.
6253

63-
.PHONY: bin default generate test vet bootstrap fmt fmtcheck update-resources
54+
.PHONY: bin default generate test vet bootstrap fmt fmtcheck

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Please note: We take Vault's security and our users' trust very seriously. If yo
1414

1515
This is a [Vault plugin](https://www.vaultproject.io/docs/internals/plugins.html)
1616
and is meant to work with Vault. This guide assumes you have already installed Vault
17-
and have a basic understanding of how Vault works. Otherwise, first read this guide on
17+
and have a basic understanding of how Vault works. Otherwise, first read this guide on
1818
how to [get started with Vault](https://www.vaultproject.io/intro/getting-started/install.html).
1919

2020
If you are using Vault 11.0.1 or above, this plugin is packaged with Vault
@@ -26,19 +26,19 @@ $ vault secrets enable tencentcloud
2626
Success! Enabled the tencentcloud secrets engine at: tencentcloud/
2727

2828
```
29-
30-
If you are testing this plugin in an earlier version of Vault or
29+
30+
If you are testing this plugin in an earlier version of Vault or
3131
want to develop, see the next section.
32-
32+
3333
## Developing
34-
35-
If you wish to work on this plugin, you'll first need [Go](https://www.golang.org)
34+
35+
If you wish to work on this plugin, you'll first need [Go](https://www.golang.org)
3636
installed on your machine (whichever version is required by Vault).
37-
37+
3838
Make sure Go is properly installed, including setting up a [GOPATH](https://golang.org/doc/code.html#GOPATH).
39-
40-
### Get Plugin
41-
Clone this repository:
39+
40+
### Get Plugin
41+
Clone this repository:
4242

4343
```sh
4444

@@ -115,12 +115,12 @@ $ make test
115115
#### Run the acceptance tests:
116116
117117
- provide your credentials via `TENCENTCLOUD_SECRET_ID` and `TENCENTCLOUD_SECRET_KEY` environment variables
118-
and set your CAM role arn via `TENCENTCLOUD_ARN` environment variables
118+
and set your CAM role arn via `TENCENTCLOUD_ARN` environment variables
119119
120120
```sh
121121
export TENCENTCLOUD_SECRET_ID=AKID12l4j5ljqatgaljgalg
122122
export TENCENTCLOUD_SECRET_KEY=alkfj23lkraljq5lj532lr32l4
123-
export TENCENTCLOUD_ARN=qcs::cam::uin/12345678:roleName/test
123+
export TENCENTCLOUD_ROLE_ARN=qcs::cam::uin/12345678:roleName/test
124124
```
125125
126126
- Run acceptance tests
@@ -132,4 +132,4 @@ make test-acc
132132
## Other Docs
133133
134134
See up-to-date [docs](https://www.vaultproject.io/docs/secrets/tencentcloud/index.html)
135-
and general [API docs](https://www.vaultproject.io/api/secret/tencentcloud/index.html).
135+
and general [API docs](https://www.vaultproject.io/api/secret/tencentcloud/index.html).

acceptance_test.go

+31-108
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,75 @@
1-
package vault_plugin_secrets_tencentcloud
1+
package tencentcloud
22

33
import (
44
"context"
55
"os"
6-
"strings"
76
"testing"
87
"time"
98

10-
"github.com/hashicorp/vault-plugin-secrets-tencentcloud/sdk"
119
"github.com/hashicorp/vault/sdk/logical"
1210
)
1311

14-
func newAcceptanceTestEnv(t *testing.T) (*testEnv, error) {
15-
id := os.Getenv("TENCENTCLOUD_SECRET_ID")
16-
if id == "" {
17-
t.Fatal("miss TENCENTCLOUD_SECRET_ID")
18-
}
19-
20-
key := os.Getenv("TENCENTCLOUD_SECRET_KEY")
21-
if key == "" {
22-
t.Fatal("miss TENCENTCLOUD_SECRET_KEY")
23-
}
24-
25-
arn := os.Getenv("TENCENTCLOUD_ARN")
26-
if arn == "" {
27-
t.Fatal("miss TENCENTCLOUD_ARN")
28-
}
29-
30-
b := newBackend(&sdk.LogRoundTripper{Debug: true})
31-
conf := &logical.BackendConfig{
32-
System: &logical.StaticSystemView{
33-
DefaultLeaseTTLVal: 7200 * time.Second,
34-
MaxLeaseTTLVal: 7200 * time.Second,
35-
},
36-
}
37-
if err := b.Setup(context.Background(), conf); err != nil {
38-
return nil, err
39-
}
40-
41-
return &testEnv{
42-
AccessKey: id,
43-
SecretKey: key,
44-
RoleARN: arn,
45-
Backend: b,
46-
Context: context.Background(),
47-
Storage: &logical.InmemStorage{},
48-
}, nil
49-
}
50-
51-
func runAcceptanceTest() bool {
52-
env := strings.ToLower(os.Getenv("VAULT_ACC"))
53-
54-
return env == "1" || env == "true"
55-
}
56-
57-
func TestAcceptanceConfig(t *testing.T) {
58-
if !runAcceptanceTest() {
59-
t.SkipNow()
60-
}
61-
62-
t.Parallel()
63-
64-
acceptanceTestEnv, err := newAcceptanceTestEnv(t)
65-
if err != nil {
66-
t.Fatal(err)
67-
}
12+
const (
13+
envVarRunAccTests = "VAULT_ACC"
14+
envVarSecretId = "TENCENTCLOUD_SECRET_ID"
15+
envVarSecretKey = "TENCENTCLOUD_SECRET_KEY"
16+
envVarRoleARN = "TENCENTCLOUD_ROLE_ARN"
17+
)
6818

69-
t.Run("add config", acceptanceTestEnv.AddConfig)
70-
t.Run("read config", acceptanceTestEnv.ReadConfig)
71-
t.Run("update config", acceptanceTestEnv.UpdateConfig)
72-
t.Run("read updated config", acceptanceTestEnv.ReadUpdatedConfig)
73-
t.Run("delete config", acceptanceTestEnv.DeleteConfig)
74-
t.Run("read empty config", acceptanceTestEnv.ReadEmptyConfig)
75-
}
19+
var runAcceptanceTests = os.Getenv(envVarRunAccTests) == "1"
7620

77-
func TestAcceptanceCamUserCreds(t *testing.T) {
78-
if !runAcceptanceTest() {
21+
func TestAcceptanceDynamicPolicyBasedCreds(t *testing.T) {
22+
if !runAcceptanceTests {
7923
t.SkipNow()
8024
}
8125

82-
t.Parallel()
83-
84-
acceptanceTestEnv, err := newAcceptanceTestEnv(t)
26+
acceptanceTestEnv, err := newAcceptanceTestEnv()
8527
if err != nil {
8628
t.Fatal(err)
8729
}
8830

8931
t.Run("add config", acceptanceTestEnv.AddConfig)
90-
91-
t.Run("add policy-based role", acceptanceTestEnv.AddPolicyBasedRole)
92-
t.Run("read policy-based role", acceptanceTestEnv.ReadPolicyBasedRole)
93-
t.Run("update policy-based role", acceptanceTestEnv.UpdatePolicyBasedRole)
94-
t.Run("read updated policy-based role", acceptanceTestEnv.ReadUpdatedPolicyBasedRole)
95-
t.Run("delete policy-based role", acceptanceTestEnv.DeletePolicyBasedRole)
96-
9732
t.Run("add policy-based role", acceptanceTestEnv.AddPolicyBasedRole)
9833
t.Run("read policy-based creds", acceptanceTestEnv.ReadPolicyBasedCreds)
9934
t.Run("renew policy-based creds", acceptanceTestEnv.RenewPolicyBasedCreds)
10035
t.Run("revoke policy-based creds", acceptanceTestEnv.RevokePolicyBasedCreds)
10136
}
10237

103-
func TestAcceptanceAssumedRoleBasedCreds(t *testing.T) {
104-
if !runAcceptanceTest() {
38+
func TestAcceptanceDynamicRoleBasedCreds(t *testing.T) {
39+
if !runAcceptanceTests {
10540
t.SkipNow()
10641
}
10742

108-
t.Parallel()
109-
110-
acceptanceTestEnv, err := newAcceptanceTestEnv(t)
43+
acceptanceTestEnv, err := newAcceptanceTestEnv()
11144
if err != nil {
11245
t.Fatal(err)
11346
}
11447

11548
t.Run("add config", acceptanceTestEnv.AddConfig)
116-
117-
t.Run("add arn-based role", acceptanceTestEnv.AddARNBasedRole)
118-
t.Run("read arn-based role", acceptanceTestEnv.ReadARNBasedRole)
119-
t.Run("update arn-based role", acceptanceTestEnv.UpdateARNBasedRole)
120-
t.Run("read updated arn-based role", acceptanceTestEnv.ReadUpdatedARNBasedRole)
121-
t.Run("delete arn-based role", acceptanceTestEnv.DeleteARNBasedRole)
122-
12349
t.Run("add arn-based role", acceptanceTestEnv.AddARNBasedRole)
12450
t.Run("read arn-based creds", acceptanceTestEnv.ReadARNBasedCreds)
12551
t.Run("renew arn-based creds", acceptanceTestEnv.RenewARNBasedCreds)
12652
t.Run("revoke arn-based creds", acceptanceTestEnv.RevokeARNBasedCreds)
12753
}
12854

129-
func TestAcceptanceMultiRoles(t *testing.T) {
130-
if !runAcceptanceTest() {
131-
t.SkipNow()
55+
func newAcceptanceTestEnv() (*testEnv, error) {
56+
ctx := context.Background()
57+
conf := &logical.BackendConfig{
58+
System: &logical.StaticSystemView{
59+
DefaultLeaseTTLVal: time.Hour,
60+
MaxLeaseTTLVal: time.Hour,
61+
},
13262
}
133-
134-
t.Parallel()
135-
136-
acceptanceTestEnv, err := newAcceptanceTestEnv(t)
63+
b, err := Factory(ctx, conf)
13764
if err != nil {
138-
t.Fatal(err)
65+
return nil, err
13966
}
140-
141-
t.Run("add config", acceptanceTestEnv.AddConfig)
142-
143-
t.Run("add policy-based role", acceptanceTestEnv.AddPolicyBasedRole)
144-
t.Run("read policy-based role", acceptanceTestEnv.ReadPolicyBasedRole)
145-
146-
t.Run("add arn-based role", acceptanceTestEnv.AddARNBasedRole)
147-
t.Run("read arn-based creds", acceptanceTestEnv.ReadARNBasedCreds)
148-
149-
t.Run("list two roles", acceptanceTestEnv.ListTwoRoles)
150-
t.Run("delete arn-based role", acceptanceTestEnv.DeleteARNBasedRole)
151-
t.Run("list one role", acceptanceTestEnv.ListOneRole)
67+
return &testEnv{
68+
SecretId: os.Getenv(envVarSecretId),
69+
SecretKey: os.Getenv(envVarSecretKey),
70+
RoleARN: os.Getenv(envVarRoleARN),
71+
Backend: b,
72+
Context: ctx,
73+
Storage: &logical.InmemStorage{},
74+
}, nil
15275
}

0 commit comments

Comments
 (0)