-
Notifications
You must be signed in to change notification settings - Fork 883
/
context.go
132 lines (106 loc) · 3.69 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
Copyright 2021. The KubeVela Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package velaql
import (
"encoding/json"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"github.com/oam-dev/kubevela/pkg/cue/model/value"
wfContext "github.com/oam-dev/kubevela/pkg/workflow/context"
)
// NewViewContext new view context
func NewViewContext() (wfContext.Context, error) {
viewContext := &ViewContext{}
var err error
viewContext.vars, err = value.NewValue("", nil, "")
return viewContext, err
}
// ViewContext is view context
type ViewContext struct {
vars *value.Value
}
// GetComponent Get ComponentManifest from workflow context.
func (c ViewContext) GetComponent(name string) (*wfContext.ComponentManifest, error) {
return nil, errors.New("not support func GetComponent")
}
// GetComponents Get All ComponentManifest from workflow context.
func (c ViewContext) GetComponents() map[string]*wfContext.ComponentManifest {
return nil
}
// PatchComponent patch component with value.
func (c ViewContext) PatchComponent(name string, patchValue *value.Value) error {
return errors.New("not support func PatchComponent")
}
// GetVar get variable from workflow context.
func (c ViewContext) GetVar(paths ...string) (*value.Value, error) {
return c.vars.LookupValue(paths...)
}
// SetVar set variable to workflow context.
func (c ViewContext) SetVar(v *value.Value, paths ...string) error {
str, err := v.String()
if err != nil {
return errors.WithMessage(err, "compile var")
}
if err := c.vars.FillRaw(str, paths...); err != nil {
return err
}
return c.vars.Error()
}
// GetStore get configmap of workflow context.
func (c ViewContext) GetStore() *corev1.ConfigMap {
return nil
}
// GetMutableValue get mutable data from workflow context.
func (c ViewContext) GetMutableValue(paths ...string) string {
return ""
}
// SetMutableValue set mutable data in workflow context config map.
func (c ViewContext) SetMutableValue(data string, paths ...string) {
}
// IncreaseCountValueInMemory increase count in workflow context memory store.
func (c ViewContext) IncreaseCountValueInMemory(paths ...string) int {
return 0
}
// SetValueInMemory set data in workflow context memory store.
func (c ViewContext) SetValueInMemory(data interface{}, paths ...string) {
}
// GetValueInMemory get data in workflow context memory store.
func (c ViewContext) GetValueInMemory(paths ...string) (interface{}, bool) {
return "", true
}
// DeleteValueInMemory delete data in workflow context memory store.
func (c ViewContext) DeleteValueInMemory(paths ...string) {
}
// DeleteMutableValue delete mutable data in workflow context.
func (c ViewContext) DeleteMutableValue(paths ...string) {
}
// Commit the workflow context and persist it's content.
func (c ViewContext) Commit() error {
return errors.New("not support func Commit")
}
// MakeParameter make 'value' with interface{}
func (c ViewContext) MakeParameter(parameter interface{}) (*value.Value, error) {
var s = "{}"
if parameter != nil {
bt, err := json.Marshal(parameter)
if err != nil {
return nil, err
}
s = string(bt)
}
return c.vars.MakeValue(s)
}
// StoreRef return the store reference of workflow context.
func (c ViewContext) StoreRef() *corev1.ObjectReference {
return nil
}