k8s.io/apiserver@v0.31.1/pkg/cel/mutation/common/interface.go (about)

     1  /*
     2  Copyright 2024 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package common
    18  
    19  import (
    20  	"github.com/google/cel-go/common/types"
    21  	"github.com/google/cel-go/common/types/ref"
    22  )
    23  
    24  // TypeResolver resolves a type by a given name.
    25  type TypeResolver interface {
    26  	// Resolve resolves the type by its name, starting with "Object" as its root.
    27  	// The type that the name refers to must be an object.
    28  	// This function returns false if the name does not refer to a known object type.
    29  	Resolve(name string) (TypeRef, bool)
    30  }
    31  
    32  // TypeRef refers an object type that can be looked up for its fields.
    33  type TypeRef interface {
    34  	ref.Type
    35  
    36  	// CELType wraps the TypeRef to be a type that is understood by CEL.
    37  	CELType() *types.Type
    38  
    39  	// Field finds the field by the field name, or false if the field is not known.
    40  	// This function directly return a FieldType that is known to CEL to be more customizable.
    41  	Field(name string) (*types.FieldType, bool)
    42  
    43  	// Val creates an instance for the TypeRef, given its fields and their values.
    44  	Val(fields map[string]ref.Val) ref.Val
    45  }