Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli) implement --kong-admin-token flag #489

Merged
merged 1 commit into from
Dec 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cli/ingress-controller/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func TestOverrideViaCLIFlags(t *testing.T) {
"--kong-workspace", "yolo",
"--kong-admin-filter-tag", "foo-tag",
"--admin-header", "foo:bar",
"--kong-admin-token", "my-token",
"--admin-tls-skip-verify",
"--admin-tls-server-name", "kong-admin.example.com",
"--admin-ca-cert-file", "/path/to/ca-cert",
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestOverrideViaCLIFlags(t *testing.T) {
KongAdminConcurrency: 1,
KongWorkspace: "yolo",
KongAdminFilterTags: []string{"foo-tag"},
KongAdminHeaders: []string{"foo:bar"},
KongAdminHeaders: []string{"foo:bar", "kong-admin-token:my-token"},
KongAdminTLSSkipVerify: true,
KongAdminTLSServerName: "kong-admin.example.com",
KongAdminCACertPath: "/path/to/ca-cert",
Expand Down Expand Up @@ -176,6 +177,7 @@ func TestOverrideViaEnvVars(t *testing.T) {
"CONTROLLER_ADMISSION_WEBHOOK_KEY_FILE": "/new-key-path",
"CONTROLLER_ANONYMOUS_REPORTS": "false",
"CONTROLLER_KONG_ADMIN_CONCURRENCY": "100",
"CONTROLLER_KONG_ADMIN_TOKEN": "my-secret-token",
}
for k, v := range envs {
os.Setenv(k, v)
Expand All @@ -193,7 +195,7 @@ func TestOverrideViaEnvVars(t *testing.T) {
KongAdminURL: "http://localhost:8001",
KongAdminConcurrency: 100,
KongWorkspace: "",
KongAdminHeaders: []string{},
KongAdminHeaders: []string{"kong-admin-token:my-secret-token"},
KongAdminTLSSkipVerify: false,
KongAdminTLSServerName: "",
KongAdminCACertPath: "",
Expand Down
10 changes: 10 additions & 0 deletions cli/ingress-controller/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ this flag can be used multiple times to specify multiple headers`)
`add a header (key:value) to every Admin API call,
this flag can be used multiple times to specify multiple headers`)

flags.String("kong-admin-token", "",
`Sets the value of the 'kong-admin-token' header; useful for
authentication/authorization for Kong Enterprise enviornments`)

// deprecated
flags.Bool("admin-tls-skip-verify", false,
`DEPRECATED, use --kong-admin-tls-skip-verify
Expand Down Expand Up @@ -251,6 +255,12 @@ func parseFlags() (cliConfig, error) {
config.KongAdminHeaders = kongAdminHeaders
}

kongAdminToken := viper.GetString("kong-admin-token")
if kongAdminToken != "" {
config.KongAdminHeaders = append(config.KongAdminHeaders,
"kong-admin-token:"+kongAdminToken)
}

config.KongAdminTLSSkipVerify = viper.GetBool("admin-tls-skip-verify")
kongAdminTLSSkipVerify := viper.GetBool("kong-admin-tls-skip-verify")
if kongAdminTLSSkipVerify {
Expand Down