-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinesis.go
175 lines (149 loc) · 7.52 KB
/
kinesis.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//go:build gen
package main
import (
"context"
"fmt"
"os"
"reflect"
"strings"
"text/template"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
)
const tmpl = `// Code generated by go generate; DO NOT EDIT.
package aws
import (
"context"
"github.com/grafana/sobek"
"github.com/aws/aws-sdk-go-v2/service/kinesis"
)
type KinesisClient struct {
*AWS
sdk *kinesis.Client
}
func (a *AWS) newKinesisClient(call sobek.ConstructorCall) *sobek.Object {
awsCfg := a.constructorCallToConfig("KinesisClient", call)
sdk := kinesis.NewFromConfig(awsCfg)
client := &KinesisClient{
AWS: a,
sdk: sdk,
}
return a.vu.Runtime().ToValue(client).ToObject(a.vu.Runtime())
}
{{ range . }}
func (c *KinesisClient) {{ .Name }}({{ .FunctionCall }}) sobek.Value {
in := &{{.InputType}}{}
if err := fromSobekObject(c.vu.Runtime(), obj, in); err != nil {
panic(err)
}
out, err := c.sdk.{{ .InnerFunctionCall }}
if err != nil {
panic(err)
}
val, err := toSobekObject(c.vu, out)
if err != nil {
panic(err)
}
return val
}
{{ end }}
`
type KinesisClient interface {
AddTagsToStream(context.Context, *kinesis.AddTagsToStreamInput, ...func(*kinesis.Options)) (*kinesis.AddTagsToStreamOutput, error)
CreateStream(context.Context, *kinesis.CreateStreamInput, ...func(*kinesis.Options)) (*kinesis.CreateStreamOutput, error)
DecreaseStreamRetentionPeriod(context.Context, *kinesis.DecreaseStreamRetentionPeriodInput, ...func(*kinesis.Options)) (*kinesis.DecreaseStreamRetentionPeriodOutput, error)
DeleteResourcePolicy(context.Context, *kinesis.DeleteResourcePolicyInput, ...func(*kinesis.Options)) (*kinesis.DeleteResourcePolicyOutput, error)
DeleteStream(context.Context, *kinesis.DeleteStreamInput, ...func(*kinesis.Options)) (*kinesis.DeleteStreamOutput, error)
DeregisterStreamConsumer(context.Context, *kinesis.DeregisterStreamConsumerInput, ...func(*kinesis.Options)) (*kinesis.DeregisterStreamConsumerOutput, error)
DescribeLimits(context.Context, *kinesis.DescribeLimitsInput, ...func(*kinesis.Options)) (*kinesis.DescribeLimitsOutput, error)
DescribeStream(context.Context, *kinesis.DescribeStreamInput, ...func(*kinesis.Options)) (*kinesis.DescribeStreamOutput, error)
DescribeStreamConsumer(context.Context, *kinesis.DescribeStreamConsumerInput, ...func(*kinesis.Options)) (*kinesis.DescribeStreamConsumerOutput, error)
DescribeStreamSummary(context.Context, *kinesis.DescribeStreamSummaryInput, ...func(*kinesis.Options)) (*kinesis.DescribeStreamSummaryOutput, error)
DisableEnhancedMonitoring(context.Context, *kinesis.DisableEnhancedMonitoringInput, ...func(*kinesis.Options)) (*kinesis.DisableEnhancedMonitoringOutput, error)
EnableEnhancedMonitoring(context.Context, *kinesis.EnableEnhancedMonitoringInput, ...func(*kinesis.Options)) (*kinesis.EnableEnhancedMonitoringOutput, error)
GetRecords(context.Context, *kinesis.GetRecordsInput, ...func(*kinesis.Options)) (*kinesis.GetRecordsOutput, error)
GetResourcePolicy(context.Context, *kinesis.GetResourcePolicyInput, ...func(*kinesis.Options)) (*kinesis.GetResourcePolicyOutput, error)
GetShardIterator(context.Context, *kinesis.GetShardIteratorInput, ...func(*kinesis.Options)) (*kinesis.GetShardIteratorOutput, error)
IncreaseStreamRetentionPeriod(context.Context, *kinesis.IncreaseStreamRetentionPeriodInput, ...func(*kinesis.Options)) (*kinesis.IncreaseStreamRetentionPeriodOutput, error)
ListShards(context.Context, *kinesis.ListShardsInput, ...func(*kinesis.Options)) (*kinesis.ListShardsOutput, error)
ListStreamConsumers(context.Context, *kinesis.ListStreamConsumersInput, ...func(*kinesis.Options)) (*kinesis.ListStreamConsumersOutput, error)
ListStreams(context.Context, *kinesis.ListStreamsInput, ...func(*kinesis.Options)) (*kinesis.ListStreamsOutput, error)
ListTagsForStream(context.Context, *kinesis.ListTagsForStreamInput, ...func(*kinesis.Options)) (*kinesis.ListTagsForStreamOutput, error)
MergeShards(context.Context, *kinesis.MergeShardsInput, ...func(*kinesis.Options)) (*kinesis.MergeShardsOutput, error)
PutRecord(context.Context, *kinesis.PutRecordInput, ...func(*kinesis.Options)) (*kinesis.PutRecordOutput, error)
PutRecords(context.Context, *kinesis.PutRecordsInput, ...func(*kinesis.Options)) (*kinesis.PutRecordsOutput, error)
PutResourcePolicy(context.Context, *kinesis.PutResourcePolicyInput, ...func(*kinesis.Options)) (*kinesis.PutResourcePolicyOutput, error)
RegisterStreamConsumer(context.Context, *kinesis.RegisterStreamConsumerInput, ...func(*kinesis.Options)) (*kinesis.RegisterStreamConsumerOutput, error)
RemoveTagsFromStream(context.Context, *kinesis.RemoveTagsFromStreamInput, ...func(*kinesis.Options)) (*kinesis.RemoveTagsFromStreamOutput, error)
SplitShard(context.Context, *kinesis.SplitShardInput, ...func(*kinesis.Options)) (*kinesis.SplitShardOutput, error)
StartStreamEncryption(context.Context, *kinesis.StartStreamEncryptionInput, ...func(*kinesis.Options)) (*kinesis.StartStreamEncryptionOutput, error)
StopStreamEncryption(context.Context, *kinesis.StopStreamEncryptionInput, ...func(*kinesis.Options)) (*kinesis.StopStreamEncryptionOutput, error)
SubscribeToShard(context.Context, *kinesis.SubscribeToShardInput, ...func(*kinesis.Options)) (*kinesis.SubscribeToShardOutput, error)
UpdateShardCount(context.Context, *kinesis.UpdateShardCountInput, ...func(*kinesis.Options)) (*kinesis.UpdateShardCountOutput, error)
UpdateStreamMode(context.Context, *kinesis.UpdateStreamModeInput, ...func(*kinesis.Options)) (*kinesis.UpdateStreamModeOutput, error)
}
func main() {
t := reflect.TypeOf((*KinesisClient)(nil)).Elem()
data := make([]map[string]string, 0)
for i := 0; i < t.NumMethod(); i++ {
// Parsing the method signature
var (
method = t.Method(i)
params []string
callArgs []string
functionCall string
inputType string
innerFunctionCall = fmt.Sprintf("%s(", method.Name)
)
for j := 0; j < method.Type.NumIn(); j++ {
isTheLastArgument := j == method.Type.NumIn()-1
p := method.Type.In(j)
paramName := fmt.Sprintf("param%d", j)
params = append(params, fmt.Sprintf("%s %s", paramName, p))
if j > 0 { // skip receiver
callArgs = append(callArgs, paramName)
}
switch {
// Is context.Context
case p.Implements(reflect.TypeOf((*context.Context)(nil)).Elem()):
innerFunctionCall += "context.Background(), "
// Variadic argument
case method.Type.IsVariadic() && isTheLastArgument:
// explicitly skip variadic parameters
// Pointer to
case p.Kind() == reflect.Ptr:
functionCall += "obj *sobek.Object,"
inputType = strings.ReplaceAll(p.String(), "*", "")
innerFunctionCall += "in, "
}
}
innerFunctionCall += ")" // close the function call
results := []string{}
for j := 0; j < method.Type.NumOut(); j++ {
r := method.Type.Out(j)
results = append(results, r.String())
}
data = append(data, map[string]string{
"Name": method.Name,
"Params": fmt.Sprintf("%s", strings.Join(params, ", ")),
"Results": fmt.Sprintf("%s", strings.Join(results, ", ")),
"CallArgs": fmt.Sprintf("%s", strings.Join(callArgs, ", ")),
"FunctionCall": functionCall,
"InnerFunctionCall": innerFunctionCall,
"InputType": inputType,
})
}
tmplParsed, err := template.New("wrapper").Parse(tmpl)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing template: %v\n", err)
return
}
file, err := os.Create("kinesis_gen.go")
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating file: %v\n", err)
return
}
defer file.Close()
if err := tmplParsed.Execute(file, data); err != nil {
fmt.Fprintf(os.Stderr, "Error executing template: %v\n", err)
}
}