From 0cbcaa246f288c5ca08c7bfebe68236ba96dc651 Mon Sep 17 00:00:00 2001 From: Sam Batschelet Date: Fri, 4 May 2018 16:16:39 -0400 Subject: [PATCH] auth: add type checking of tokenProvider --- auth/store.go | 2 +- auth/util.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 auth/util.go diff --git a/auth/store.go b/auth/store.go index 3f305a1a0882..0efd9bf4a2be 100644 --- a/auth/store.go +++ b/auth/store.go @@ -1284,7 +1284,7 @@ func NewTokenProvider( } func (as *authStore) WithRoot(ctx context.Context) context.Context { - if !as.IsAuthEnabled() { + if tt := tokenProviderType(as); tt != "simple" || !as.IsAuthEnabled() { return ctx } diff --git a/auth/util.go b/auth/util.go new file mode 100644 index 000000000000..60ba8b179d60 --- /dev/null +++ b/auth/util.go @@ -0,0 +1,26 @@ +// Copyright 2018 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package auth + +func tokenProviderType(as *authStore) string { + switch as.tokenProvider.(type) { + case *tokenSimple: + return "simple" + case *tokenJWT: + return "jwt" + default: + return "" + } +}