-
Notifications
You must be signed in to change notification settings - Fork 32
/
function.go
102 lines (80 loc) · 2.34 KB
/
function.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package toproto
import (
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
)
func CallFunction_Response(in *tfprotov5.CallFunctionResponse) *tfplugin5.CallFunction_Response {
if in == nil {
return nil
}
resp := &tfplugin5.CallFunction_Response{
Diagnostics: Diagnostics(in.Diagnostics),
Result: DynamicValue(in.Result),
}
return resp
}
func Function(in *tfprotov5.Function) *tfplugin5.Function {
if in == nil {
return nil
}
resp := &tfplugin5.Function{
Description: in.Description,
DescriptionKind: StringKind(in.DescriptionKind),
DeprecationMessage: in.DeprecationMessage,
Parameters: make([]*tfplugin5.Function_Parameter, 0, len(in.Parameters)),
Return: Function_Return(in.Return),
Summary: in.Summary,
VariadicParameter: Function_Parameter(in.VariadicParameter),
}
for _, parameter := range in.Parameters {
resp.Parameters = append(resp.Parameters, Function_Parameter(parameter))
}
return resp
}
func Function_Parameter(in *tfprotov5.FunctionParameter) *tfplugin5.Function_Parameter {
if in == nil {
return nil
}
resp := &tfplugin5.Function_Parameter{
AllowNullValue: in.AllowNullValue,
AllowUnknownValues: in.AllowUnknownValues,
Description: in.Description,
DescriptionKind: StringKind(in.DescriptionKind),
Name: in.Name,
Type: CtyType(in.Type),
}
return resp
}
func Function_Return(in *tfprotov5.FunctionReturn) *tfplugin5.Function_Return {
if in == nil {
return nil
}
resp := &tfplugin5.Function_Return{
Type: CtyType(in.Type),
}
return resp
}
func GetFunctions_Response(in *tfprotov5.GetFunctionsResponse) *tfplugin5.GetFunctions_Response {
if in == nil {
return nil
}
resp := &tfplugin5.GetFunctions_Response{
Diagnostics: Diagnostics(in.Diagnostics),
Functions: make(map[string]*tfplugin5.Function, len(in.Functions)),
}
for name, function := range in.Functions {
resp.Functions[name] = Function(function)
}
return resp
}
func GetMetadata_FunctionMetadata(in *tfprotov5.FunctionMetadata) *tfplugin5.GetMetadata_FunctionMetadata {
if in == nil {
return nil
}
resp := &tfplugin5.GetMetadata_FunctionMetadata{
Name: in.Name,
}
return resp
}