github.com/inspektor-gadget/inspektor-gadget@v0.28.1/pkg/runtime/catalog.go (about) 1 // Copyright 2023 The Inspektor Gadget 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 runtime 16 17 import ( 18 "github.com/inspektor-gadget/inspektor-gadget/pkg/gadgets" 19 "github.com/inspektor-gadget/inspektor-gadget/pkg/operators" 20 "github.com/inspektor-gadget/inspektor-gadget/pkg/params" 21 ) 22 23 // GadgetInfo is used to store GadgetDesc information in a serializable way 24 type GadgetInfo struct { 25 ID string `json:"id"` 26 Name string `json:"name"` 27 Category string `json:"category"` 28 Type string `json:"type"` 29 Description string `json:"description"` 30 Params params.ParamDescs `json:"params"` 31 ColumnsDefinition any `json:"columnsDefinition"` 32 OperatorParamsCollection params.DescCollection `json:"operatorParamsCollection"` 33 } 34 35 // OperatorInfo is used to store operator information in a serializable way 36 type OperatorInfo struct { 37 Name string `json:"name"` 38 Description string `json:"description"` 39 } 40 41 // Catalog stores both data about gadgets and operators in a serializable way. This is used to handle 42 // gadgets and operators, even if they aren't run locally (and their code is not or only partially available) 43 type Catalog struct { 44 Gadgets []*GadgetInfo 45 Operators []*OperatorInfo 46 } 47 48 func GadgetInfoFromGadgetDesc(gadgetDesc gadgets.GadgetDesc) *GadgetInfo { 49 return &GadgetInfo{ 50 Name: gadgetDesc.Name(), 51 Category: gadgetDesc.Category(), 52 Type: string(gadgetDesc.Type()), 53 Description: gadgetDesc.Description(), 54 Params: gadgetDesc.ParamDescs(), 55 OperatorParamsCollection: operators.GetOperatorsForGadget(gadgetDesc).ParamDescCollection(), 56 } 57 } 58 59 func OperatorToOperatorInfo(operator operators.Operator) *OperatorInfo { 60 return &OperatorInfo{ 61 Name: operator.Name(), 62 Description: operator.Description(), 63 } 64 }