forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparam_conversion.go
91 lines (83 loc) · 2.33 KB
/
param_conversion.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
package v1beta1
import (
"context"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
)
func (p ParamSpec) convertTo(ctx context.Context, sink *v1.ParamSpec) {
sink.Name = p.Name
if p.Type != "" {
sink.Type = v1.ParamType(p.Type)
} else {
sink.Type = v1.ParamType(ParamTypeString)
}
sink.Description = p.Description
var properties map[string]v1.PropertySpec
if p.Properties != nil {
properties = make(map[string]v1.PropertySpec)
}
for k, v := range p.Properties {
properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)}
}
sink.Properties = properties
if p.Default != nil {
sink.Default = &v1.ParamValue{
Type: v1.ParamType(p.Default.Type), StringVal: p.Default.StringVal,
ArrayVal: p.Default.ArrayVal, ObjectVal: p.Default.ObjectVal,
}
}
}
func (p *ParamSpec) convertFrom(ctx context.Context, source v1.ParamSpec) {
p.Name = source.Name
if source.Type != "" {
p.Type = ParamType(source.Type)
} else {
p.Type = ParamTypeString
}
p.Description = source.Description
var properties map[string]PropertySpec
if source.Properties != nil {
properties = make(map[string]PropertySpec)
}
for k, v := range source.Properties {
properties[k] = PropertySpec{Type: ParamType(v.Type)}
}
p.Properties = properties
if source.Default != nil {
p.Default = &ParamValue{
Type: ParamType(source.Default.Type), StringVal: source.Default.StringVal,
ArrayVal: source.Default.ArrayVal, ObjectVal: source.Default.ObjectVal,
}
}
}
func (p Param) convertTo(ctx context.Context, sink *v1.Param) {
sink.Name = p.Name
newValue := v1.ParamValue{}
p.Value.convertTo(ctx, &newValue)
sink.Value = newValue
}
func (p *Param) convertFrom(ctx context.Context, source v1.Param) {
p.Name = source.Name
newValue := ParamValue{}
newValue.convertFrom(ctx, source.Value)
p.Value = newValue
}
func (v ParamValue) convertTo(ctx context.Context, sink *v1.ParamValue) {
if v.Type != "" {
sink.Type = v1.ParamType(v.Type)
} else {
sink.Type = v1.ParamType(ParamTypeString)
}
sink.StringVal = v.StringVal
sink.ArrayVal = v.ArrayVal
sink.ObjectVal = v.ObjectVal
}
func (v *ParamValue) convertFrom(ctx context.Context, source v1.ParamValue) {
if source.Type != "" {
v.Type = ParamType(source.Type)
} else {
v.Type = ParamTypeString
}
v.StringVal = source.StringVal
v.ArrayVal = source.ArrayVal
v.ObjectVal = source.ObjectVal
}