istio.io/istio@v0.0.0-20240520182934-d79c90f27776/pkg/test/framework/components/jwt/server.go (about) 1 // Copyright Istio Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package jwt 16 17 import ( 18 "istio.io/istio/pkg/test/framework" 19 "istio.io/istio/pkg/test/framework/components/namespace" 20 "istio.io/istio/pkg/test/framework/resource" 21 ) 22 23 // Server for JWT tokens. 24 type Server interface { 25 Namespace() namespace.Instance 26 FQDN() string 27 HTTPPort() int 28 HTTPSPort() int 29 JwksURI() string 30 } 31 32 // New creates a new JWT Server. 33 func New(ctx resource.Context, ns namespace.Instance) (Server, error) { 34 return newKubeServer(ctx, ns) 35 } 36 37 // NewOrFail calls New and fails if an error occurs. 38 func NewOrFail(t framework.TestContext, ns namespace.Instance) Server { 39 t.Helper() 40 s, err := New(t, ns) 41 if err != nil { 42 t.Fatal(err) 43 } 44 return s 45 } 46 47 // Setup is a utility function for configuring a jwt Server. 48 func Setup(server *Server, ns namespace.Getter) resource.SetupFn { 49 if ns == nil { 50 ns = namespace.NilGetter 51 } 52 53 return func(ctx resource.Context) error { 54 s, err := New(ctx, ns()) 55 if err != nil { 56 return err 57 } 58 59 // Store the server. 60 *server = s 61 return err 62 } 63 }