github.com/oam-dev/kubevela@v1.9.11/pkg/velaql/context.go (about) 1 /* 2 Copyright 2021. The KubeVela 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 velaql 18 19 import ( 20 "github.com/pkg/errors" 21 corev1 "k8s.io/api/core/v1" 22 23 wfContext "github.com/kubevela/workflow/pkg/context" 24 "github.com/kubevela/workflow/pkg/cue/model/value" 25 ) 26 27 // NewViewContext new view context 28 func NewViewContext() (wfContext.Context, error) { 29 viewContext := &ViewContext{} 30 var err error 31 viewContext.vars, err = value.NewValue("", nil, "") 32 return viewContext, err 33 } 34 35 // ViewContext is view context 36 type ViewContext struct { 37 vars *value.Value 38 } 39 40 // GetVar get variable from workflow context. 41 func (c ViewContext) GetVar(paths ...string) (*value.Value, error) { 42 return c.vars.LookupValue(paths...) 43 } 44 45 // SetVar set variable to workflow context. 46 func (c ViewContext) SetVar(v *value.Value, paths ...string) error { 47 str, err := v.String() 48 if err != nil { 49 return errors.WithMessage(err, "compile var") 50 } 51 if err := c.vars.FillRaw(str, paths...); err != nil { 52 return err 53 } 54 return c.vars.Error() 55 } 56 57 // GetStore get configmap of workflow context. 58 func (c ViewContext) GetStore() *corev1.ConfigMap { 59 return nil 60 } 61 62 // GetMutableValue get mutable data from workflow context. 63 func (c ViewContext) GetMutableValue(_ ...string) string { 64 return "" 65 } 66 67 // SetMutableValue set mutable data in workflow context config map. 68 func (c ViewContext) SetMutableValue(_ string, _ ...string) { 69 } 70 71 // IncreaseCountValueInMemory increase count in workflow context memory store. 72 func (c ViewContext) IncreaseCountValueInMemory(_ ...string) int { 73 return 0 74 } 75 76 // SetValueInMemory set data in workflow context memory store. 77 func (c ViewContext) SetValueInMemory(_ interface{}, _ ...string) { 78 } 79 80 // GetValueInMemory get data in workflow context memory store. 81 func (c ViewContext) GetValueInMemory(_ ...string) (interface{}, bool) { 82 return "", true 83 } 84 85 // DeleteValueInMemory delete data in workflow context memory store. 86 func (c ViewContext) DeleteValueInMemory(_ ...string) { 87 } 88 89 // DeleteMutableValue delete mutable data in workflow context. 90 func (c ViewContext) DeleteMutableValue(_ ...string) { 91 } 92 93 // Commit the workflow context and persist it's content. 94 func (c ViewContext) Commit() error { 95 return errors.New("not support func Commit") 96 } 97 98 // MakeParameter make 'value' with string 99 func (c ViewContext) MakeParameter(parameter string) (*value.Value, error) { 100 if parameter == "" { 101 parameter = "{}" 102 } 103 104 return c.vars.MakeValue(parameter) 105 } 106 107 // StoreRef return the store reference of workflow context. 108 func (c ViewContext) StoreRef() *corev1.ObjectReference { 109 return nil 110 }