-
Notifications
You must be signed in to change notification settings - Fork 0
/
kafka.go
100 lines (91 loc) · 2.03 KB
/
kafka.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
package lib
import (
"context"
"github.com/savaki/aiven"
"github.com/savaki/aiven/kafka"
"gopkg.in/urfave/cli.v1"
)
var Kafka = cli.Command{
Name: "kafka",
Usage: "kafka related commands",
Subcommands: cli.Commands{
{
Name: "list-topics",
Usage: "list kafka topics",
Flags: []cli.Flag{
flagEmail,
flagPassword,
flagOTP,
flagProject,
flagService,
},
Action: Do(listTopics),
},
{
Name: "create-topic",
Usage: "create kafka topic",
Flags: []cli.Flag{
flagEmail,
flagPassword,
flagOTP,
flagProject,
flagService,
flagName,
flagCleanupPolicy,
flagPartitions,
flagReplication,
flagRetentionHours,
},
Action: Do(createTopic),
},
{
Name: "delete-topic",
Usage: "delete kafka topic",
Flags: []cli.Flag{
flagEmail,
flagPassword,
flagOTP,
flagProject,
flagService,
flagName,
},
Action: Do(deleteTopic),
},
},
}
func listTopics(ctx context.Context) (interface{}, error) {
client, err := aiven.NewOTP(opts.Email, opts.Password, opts.OTP)
if err != nil {
return nil, err
}
return kafka.New(client).ListTopics(ctx, kafka.ListTopicsIn{
Project: opts.Project,
Service: opts.Service,
})
}
func createTopic(ctx context.Context) (interface{}, error) {
client, err := aiven.NewOTP(opts.Email, opts.Password, opts.OTP)
if err != nil {
return nil, err
}
return nil, kafka.New(client).CreateTopic(ctx, kafka.CreateTopicIn{
Project: opts.Project,
Service: opts.Service,
CleanupPolicy: opts.Topic.CleanupPolicy,
Partitions: opts.Topic.Partitions,
Replication: opts.Topic.Replication,
RetentionHours: opts.Topic.RetentionHours,
TopicName: opts.Topic.Name,
})
}
func deleteTopic(ctx context.Context) (interface{}, error) {
client, err := aiven.NewOTP(opts.Email, opts.Password, opts.OTP)
if err != nil {
return nil, err
}
return nil, kafka.New(client).DeleteTopic(ctx, kafka.DeleteTopicIn{
Project: opts.Project,
Service: opts.Service,
TopicName: opts.Topic.Name,
})
}