/
transfer_endpoint_common.go
128 lines (117 loc) Β· 3.88 KB
/
transfer_endpoint_common.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
package provider
import (
"github.com/doublecloud/go-genproto/doublecloud/transfer/v1/endpoint"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type endpointTLSMode struct {
CACertificate types.String `tfsdk:"ca_certificate"`
}
func convertSliceTFStrings(s []types.String) []string {
if s == nil {
return nil
}
ret := make([]string, len(s))
for i := 0; i < len(s); i++ {
ret[i] = s[i].ValueString()
}
return ret
}
func convertSliceToTFStrings(s []string) []types.String {
if s == nil {
return nil
}
ret := make([]types.String, len(s))
for i := 0; i < len(s); i++ {
ret[i] = types.StringValue(s[i])
}
return ret
}
func transferEndpointCleanupPolicyValidator() validator.String {
names := make([]string, len(endpoint.CleanupPolicy_name))
for i, v := range endpoint.CleanupPolicy_name {
names[i] = v
}
return stringvalidator.OneOfCaseInsensitive(names...)
}
//nolint:unused
func transferEndpointParserSchema() schema.Block {
return schema.SingleNestedBlock{
Blocks: map[string]schema.Block{
"json_parser": transferEndpointGenericParserSchema(),
"tskv_parser": transferEndpointGenericParserSchema(),
},
}
}
func transferEndpointTLSMode() schema.Block {
return schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
"ca_certificate": schema.StringAttribute{
Optional: true,
MarkdownDescription: "X.509 certificate of the certificate authority which issued the server's certificate, in PEM format. When CA certificate is specified TLS is used to connect to the server",
},
},
}
}
func convertTLSMode(m *endpointTLSMode) *endpoint.TLSMode {
if m == nil {
return &endpoint.TLSMode{TlsMode: &endpoint.TLSMode_Disabled{}}
}
if m.CACertificate.IsNull() {
return &endpoint.TLSMode{TlsMode: &endpoint.TLSMode_Enabled{Enabled: &endpoint.TLSConfig{}}}
}
return &endpoint.TLSMode{TlsMode: &endpoint.TLSMode_Enabled{Enabled: &endpoint.TLSConfig{CaCertificate: m.CACertificate.ValueString()}}}
}
//nolint:unused
func transferEndpointGenericParserSchema() schema.SingleNestedBlock {
return schema.SingleNestedBlock{
Attributes: map[string]schema.Attribute{
// "data_schema": ...endpoint
"null_keys_allowed": schema.BoolAttribute{
MarkdownDescription: "Allow null keys. If false, null keys are put to unparsed data",
Optional: true,
},
"add_rest_column": schema.BoolAttribute{
MarkdownDescription: "Add the `_rest` column for all unknown fields",
Optional: true,
},
},
}
}
func transferEndpointSerializerSchemaBlock() schema.SingleNestedBlock {
return schema.SingleNestedBlock{
MarkdownDescription: "Data serialization format",
Blocks: map[string]schema.Block{
"auto": schema.SingleNestedBlock{MarkdownDescription: "Select the serialization format automatically"},
"json": schema.SingleNestedBlock{MarkdownDescription: "Serialize data in the JSON format"},
"debezium": schema.SingleNestedBlock{
MarkdownDescription: "Serialize data in the JSON format",
Blocks: map[string]schema.Block{
"parameter": schema.ListNestedBlock{
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"key": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Key",
},
"value": schema.StringAttribute{
Optional: true,
MarkdownDescription: "Value",
},
},
},
},
},
},
},
}
}
func transferObjectTransferStageValidator() validator.String {
names := make([]string, len(endpoint.ObjectTransferStage_name))
for i, v := range endpoint.ObjectTransferStage_name {
names[i] = v
}
return stringvalidator.OneOfCaseInsensitive(names...)
}