Skip to content

Commit 1bc413b

Browse files
committed
Add secret support for credentials
When flags are not given for username/password, the code will now read this from Kubernetes secrets on disk. Signed-off-by: Alex Ellis <[email protected]>
1 parent ffd86e8 commit 1bc413b

29 files changed

+1432
-27
lines changed

Gopkg.toml

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
# Gopkg.toml example
2-
#
3-
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
4-
# for detailed Gopkg.toml documentation.
5-
#
6-
# required = ["github.com/user/thing/cmd/thing"]
7-
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8-
#
9-
# [[constraint]]
10-
# name = "github.com/user/project"
11-
# version = "1.0.0"
12-
#
13-
# [[constraint]]
14-
# name = "github.com/user/project2"
15-
# branch = "dev"
16-
# source = "github.com/myfork/project2"
17-
#
18-
# [[override]]
19-
# name = "github.com/x/y"
20-
# version = "2.4.0"
21-
#
22-
# [prune]
23-
# non-go = false
24-
# go-tests = true
25-
# unused-packages = true
26-
27-
281
[prune]
292
go-tests = true
303
unused-packages = true
@@ -36,3 +9,7 @@
369
[[constraint]]
3710
name = "github.com/vmware/govmomi"
3811
version = "0.19.0"
12+
13+
[[constraint]]
14+
name = "github.com/openfaas/openfaas-cloud"
15+
version = "0.9.4"

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ The following event types (incl. their subtypes) are supported and can be used t
2626

2727
For further details and naming see the [vSphere Web Services API](https://code.vmware.com/apis/358/vsphere#/doc/vim.event.Event.html) documentation.
2828

29+
## Other configuration
30+
31+
### Credentials
32+
33+
You can pass credentials via arguments (not recommended).
34+
35+
Or use a secret and pass the name:
36+
37+
```sh
38+
./vcenter-connector \
39+
-vc-user-secret-name=vcenter1-username \
40+
-vc-password-secret-name=vcenter1-password
41+
```
42+
43+
Use `kubectl` to create the secrets you need ahead of time in the namespace where you deploy the connector.
44+
45+
```sh
46+
kubectl create secret generic vcenter-secrets \
47+
--from-literal vcenter1-username=admin \
48+
--from-literal vcenter1-password=test1234
49+
```
50+
51+
Now mount your secret at `/var/openfaas/secrets/` in your Kubernetes Deployment YAML file.
52+
2953
## Example
3054

3155
You can find a detailed example using vSphere tags for `VmPoweredOnEvent` [here](docs/example.md). You might also want to check out Robert Guske's [blog](https://rguske.github.io/post/event-driven-interactions-with-vsphere-using-functions-as-a-service/) post on how he automated the integration between several VMware products with OpenFaaS and this vcenter-connector.

main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,51 @@ import (
1313

1414
"github.com/openfaas-incubator/connector-sdk/types"
1515
"github.com/openfaas/faas-provider/auth"
16+
"github.com/openfaas/openfaas-cloud/sdk"
1617
)
1718

1819
func main() {
1920
var gatewayURL string
2021
var vcenterURL string
2122
var vcUser string
2223
var vcPass string
24+
var vcUserSecret string
25+
var vcPasswordSecret string
26+
2327
var insecure bool
2428

2529
// TODO: add secrets management, verbosity level
2630
flag.StringVar(&gatewayURL, "gateway", "http://127.0.0.1:8080", "URL for OpenFaaS gateway")
2731
flag.StringVar(&vcenterURL, "vcenter", "http://127.0.0.1:8989/sdk", "URL for vCenter")
2832
flag.StringVar(&vcUser, "vc-user", "", "User to connect to vCenter")
2933
flag.StringVar(&vcPass, "vc-pass", "", "Password to connect to vCenter")
34+
35+
flag.StringVar(&vcUserSecret, "vc-user-secret-name", "", "Secret file to use for username")
36+
flag.StringVar(&vcPasswordSecret, "vc-pass-secret-name", "", "Secret file to use for password")
37+
3038
flag.BoolVar(&insecure, "insecure", false, "use an insecure connection to vCenter (default false)")
3139
flag.Parse()
3240

3341
if len(vcenterURL) == 0 {
3442
log.Fatal("vcenterURL not provided")
3543
}
3644

45+
if len(vcUserSecret) > 0 {
46+
val, err := sdk.ReadSecret("vc-secret-user")
47+
if err != nil {
48+
panic(err.Error())
49+
}
50+
vcUser = val
51+
}
52+
53+
if len(vcPasswordSecret) > 0 {
54+
val, err := sdk.ReadSecret("vc-secret-pass")
55+
if err != nil {
56+
panic(err.Error())
57+
}
58+
vcPass = val
59+
}
60+
3761
vcenterClient, err := events.NewVCenterClient(context.Background(), vcUser, vcPass, vcenterURL, insecure)
3862
if err != nil {
3963
log.Fatalf("could not connect to vCenter: %v", err)

vendor/github.com/openfaas/openfaas-cloud/sdk/Gopkg.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/Gopkg.toml

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/audit.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/auth.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/auth_test.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/build.go

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/openfaas/openfaas-cloud/sdk/constants.go

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)