Debian Codegraph @

pkg/cel/library/libraries.go

raw
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 library
18
19 import (
20 "github.com/google/cel-go/cel"
21 )
22
23 // Library represents a CEL library used by kubernetes.
24 type Library interface {
25 // SingletonLibrary provides the library name and ensures the library can be safely registered into environments.
26 cel.SingletonLibrary
27
28 // Types provides all custom types introduced by the library.
29 Types() []*cel.Type
30
31 // declarations returns all function declarations provided by the library.
32 declarations() map[string][]cel.FunctionOpt
33 }
34
35 // KnownLibraries returns all libraries used in Kubernetes.
36 func KnownLibraries() []Library {
37 return []Library{
38 authzLib,
39 authzSelectorsLib,
40 listsLib,
41 regexLib,
42 urlsLib,
43 quantityLib,
44 ipLib,
45 cidrsLib,
46 formatLib,
47 semverLib,
48 jsonPatchLib,
49 }
50 }
51
52 func isRegisteredType(typeName string) bool {
53 for _, lib := range KnownLibraries() {
54 for _, rt := range lib.Types() {
55 if rt.TypeName() == typeName {
56 return true
57 }
58 }
59 }
60 return false
61 }