kafka_cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +18 -0
- data/exe/kafkacli +120 -0
- data/lib/kafka_cli/cluster_service.rb +17 -0
- data/lib/kafka_cli/kafka_client.rb +91 -0
- data/lib/kafka_cli/service.rb +28 -0
- data/lib/kafka_cli/service_conf.rb +84 -0
- data/lib/kafka_cli/service_conf_element.rb +21 -0
- data/lib/kafka_cli/topic_service.rb +33 -0
- data/lib/kafka_cli/version.rb +5 -0
- data/lib/kafka_cli.rb +7 -0
- data/sig/kafka_cli.rbs +4 -0
- metadata +267 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: bf442f4795e5f3c802b0c2885d46b90e73a3d288a9f110b370184e574d71c9fd
|
|
4
|
+
data.tar.gz: e00a0507e2da345338ee436b7857b78e16d4c45cd8fee51fcc8b2fe780e29293
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a0329e3b66376206bce12de89795c6851496d5f0bbc56a367bdbe56f4c73adb535e8a5d9452dab267a98eea0b9d796e400d0388e72a4fd0886be0568c6aa82a2
|
|
7
|
+
data.tar.gz: 53f8485f4dc68e4ed207d0bc94e929fc7540bc473e5d9d8a71e9d482af4c914838d6e5169379c96745466a61f00f147e5c6338eaa8f7f335e437ffcab97dc0a2
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Thomas Tych
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# KafkaCli
|
|
2
|
+
|
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
|
4
|
+
|
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kafka_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
+
|
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
TODO: Write usage instructions here
|
|
26
|
+
|
|
27
|
+
## Development
|
|
28
|
+
|
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
+
|
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
+
|
|
33
|
+
## Contributing
|
|
34
|
+
|
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kafka_cli.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'minitest/test_task'
|
|
5
|
+
|
|
6
|
+
Minitest::TestTask.create(:test) do |t|
|
|
7
|
+
t.libs << 'test'
|
|
8
|
+
t.warning = false
|
|
9
|
+
t.test_globs = ['test/**/*_test.rb', 'test/**/test_*.rb']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'rubocop/rake_task'
|
|
13
|
+
|
|
14
|
+
RuboCop::RakeTask.new
|
|
15
|
+
|
|
16
|
+
require 'bump/tasks'
|
|
17
|
+
|
|
18
|
+
task default: %i[test rubocop]
|
data/exe/kafkacli
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require 'gli'
|
|
5
|
+
|
|
6
|
+
require 'kafka_cli'
|
|
7
|
+
|
|
8
|
+
class App
|
|
9
|
+
extend GLI::App
|
|
10
|
+
|
|
11
|
+
program_desc 'Describe your application here'
|
|
12
|
+
|
|
13
|
+
version KafkaCli::VERSION
|
|
14
|
+
|
|
15
|
+
subcommand_option_handling :normal
|
|
16
|
+
arguments :strict
|
|
17
|
+
|
|
18
|
+
desc 'Enable debug output with full stack traces'
|
|
19
|
+
switch %i[d debug], default_value: false
|
|
20
|
+
|
|
21
|
+
KafkaCli::ServiceConf::ATTRIBUTES.each_value do |attribute|
|
|
22
|
+
flag attribute.keys, **attribute.gli_options
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc 'Topic Operations'
|
|
26
|
+
command [:topic] do |topic|
|
|
27
|
+
topic.desc 'List topics'
|
|
28
|
+
topic.arg_name 'topic_pattern', %i[optional multiple]
|
|
29
|
+
topic.command [:list, :ls] do |list|
|
|
30
|
+
list.switch :verbose, :v,
|
|
31
|
+
desc: 'Enable verbose output',
|
|
32
|
+
default: false,
|
|
33
|
+
negatable: false
|
|
34
|
+
|
|
35
|
+
list.action do |_global, options, args|
|
|
36
|
+
@kafka_cli.topic.list(patterns: args, options: options)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
topic.desc 'Create topic'
|
|
41
|
+
topic.arg_name 'topic_name'
|
|
42
|
+
topic.command [:create, :new] do |create|
|
|
43
|
+
create.flag :partitions, :p,
|
|
44
|
+
desc: 'Partition count',
|
|
45
|
+
type: Integer,
|
|
46
|
+
default_value: -1
|
|
47
|
+
create.flag :replicas, :r,
|
|
48
|
+
desc: 'Replication count',
|
|
49
|
+
type: Integer,
|
|
50
|
+
default_value: -1
|
|
51
|
+
|
|
52
|
+
create.action do |_global, options, args|
|
|
53
|
+
exit_now!('When Creating topics, please specify topic_name') if args.empty?
|
|
54
|
+
@kafka_cli.topic.create(topic_names: args, options: options)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
topic.desc 'Delete topic'
|
|
59
|
+
topic.arg_name 'topic_name'
|
|
60
|
+
topic.command [:delete, :new] do |delete|
|
|
61
|
+
delete.action do |_global, options, args|
|
|
62
|
+
exit_now!('When Deleting topics, please specify topic_name') if args.empty?
|
|
63
|
+
@kafka_cli.topic.delete(topic_names: args, options: options)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc 'Broker Operations'
|
|
69
|
+
command [:broker] do |broker|
|
|
70
|
+
broker.desc 'List brokers'
|
|
71
|
+
broker.command [:list, :ls] do |list|
|
|
72
|
+
list.switch :verbose, :v,
|
|
73
|
+
desc: 'Enable verbose output',
|
|
74
|
+
default: false,
|
|
75
|
+
negatable: false
|
|
76
|
+
|
|
77
|
+
list.action do |_global, options, _args|
|
|
78
|
+
@kafka_cli.cluster.list_brokers(options: options)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
pre do |global, _command, _options, _args|
|
|
84
|
+
@debug = global[:debug]
|
|
85
|
+
|
|
86
|
+
@conf = KafkaCli::ServiceConf.new(**global)
|
|
87
|
+
@kafka_cli = KafkaCli::Service.new(conf: @conf)
|
|
88
|
+
|
|
89
|
+
true
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
post do |_global, _command, _options, _args|
|
|
93
|
+
true
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
on_error do |exception|
|
|
97
|
+
warn "❌ Error: #{exception.message}"
|
|
98
|
+
|
|
99
|
+
if @debug
|
|
100
|
+
warn " Exception: #{exception.class}"
|
|
101
|
+
warn ' Backtrace:'
|
|
102
|
+
# exception.backtrace.first(10).each do |line|
|
|
103
|
+
exception.backtrace.each do |line|
|
|
104
|
+
warn " #{line}"
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
warn 'Run with --debug for more information'
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
false
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.error_with_help(message)
|
|
114
|
+
puts "Error: #{message}"
|
|
115
|
+
puts
|
|
116
|
+
exit_now!(message)
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
exit App.run(ARGV)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module KafkaCli
|
|
4
|
+
class ClusterService
|
|
5
|
+
attr_reader :kafka_client
|
|
6
|
+
|
|
7
|
+
def initialize(kafka_client:)
|
|
8
|
+
@kafka_client = kafka_client
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def list_brokers(options: {})
|
|
12
|
+
kafka_client.brokers do |broker|
|
|
13
|
+
puts broker
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rdkafka'
|
|
4
|
+
|
|
5
|
+
module KafkaCli
|
|
6
|
+
class KafkaClient
|
|
7
|
+
DEFAULT_RESULT_WAIT = 30
|
|
8
|
+
|
|
9
|
+
attr_reader :conf
|
|
10
|
+
|
|
11
|
+
def initialize(conf:)
|
|
12
|
+
@conf = conf
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new_admin
|
|
16
|
+
client.admin
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def admin
|
|
20
|
+
@admin ||= new_admin
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def client
|
|
24
|
+
@client ||= Rdkafka::Config.new(client_config)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def client_config
|
|
28
|
+
@client_config ||= {
|
|
29
|
+
'client.id' => conf.client_id,
|
|
30
|
+
'bootstrap.servers' => conf.brokers,
|
|
31
|
+
'security.protocol' => conf.brokers_auth_mode,
|
|
32
|
+
'ssl.certificate.location' => conf.ssl_certificate,
|
|
33
|
+
'ssl.key.location' => conf.ssl_key,
|
|
34
|
+
'ssl.key.password' => conf.ssl_key_password,
|
|
35
|
+
'ssl.ca.location' => conf.ssl_ca,
|
|
36
|
+
'enable.ssl.certificate.verification' => conf.ssl_verify,
|
|
37
|
+
'socket.timeout.ms' => conf.socket_timeout,
|
|
38
|
+
'request.timeout.ms' => conf.request_timeout
|
|
39
|
+
}.compact
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def topics(&)
|
|
43
|
+
return enum_for(:topics) unless block_given?
|
|
44
|
+
|
|
45
|
+
metadata = admin.metadata
|
|
46
|
+
metadata.topics.each(&)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def brokers(&)
|
|
50
|
+
return enum_for(:topics) unless block_given?
|
|
51
|
+
|
|
52
|
+
metadata = admin.metadata
|
|
53
|
+
metadata.brokers.each(&)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_topic(topic_name:, partitions: -1, replicas: -1, max_wait: DEFAULT_RESULT_WAIT)
|
|
57
|
+
result = admin.create_topic(topic_name, partitions, replicas)
|
|
58
|
+
result.wait(max_wait_timeout: max_wait)
|
|
59
|
+
rescue Rdkafka::RdkafkaError => e
|
|
60
|
+
if e.code == :topic_already_exists
|
|
61
|
+
puts "Topic '#{topic_name}' already exists."
|
|
62
|
+
else
|
|
63
|
+
puts "Failed to create topic '#{topic_name}'; error is #{e}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def create_topics(topic_names:, partitions: -1, replicas: -1, max_wait: DEFAULT_RESULT_WAIT)
|
|
68
|
+
topic_names.each do |topic_name|
|
|
69
|
+
create_topic(topic_name: topic_name, partitions: partitions, replicas: replicas,
|
|
70
|
+
max_wait: max_wait)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def delete_topic(topic_name:, max_wait: DEFAULT_RESULT_WAIT)
|
|
75
|
+
result = admin.delete_topic(topic_name)
|
|
76
|
+
result.wait(max_wait_timeout: max_wait)
|
|
77
|
+
rescue Rdkafka::RdkafkaError => e
|
|
78
|
+
if e.code == :unknown_topic_or_part
|
|
79
|
+
puts "Topic '#{topic_name}' does not exist or was already deleted."
|
|
80
|
+
else
|
|
81
|
+
puts "Failed to delete topic '#{topic_name}'; error is #{e}"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def delete_topics(topic_names:, max_wait: DEFAULT_RESULT_WAIT)
|
|
86
|
+
topic_names.each do |topic_name|
|
|
87
|
+
delete_topic(topic_name: topic_name, max_wait: max_wait)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'service_conf'
|
|
4
|
+
require_relative 'kafka_client'
|
|
5
|
+
require_relative 'cluster_service'
|
|
6
|
+
require_relative 'topic_service'
|
|
7
|
+
|
|
8
|
+
module KafkaCli
|
|
9
|
+
class Service
|
|
10
|
+
attr_reader :conf
|
|
11
|
+
|
|
12
|
+
def initialize(conf:)
|
|
13
|
+
@conf = conf
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def cluster
|
|
17
|
+
@cluster ||= ClusterService.new(kafka_client: kafka_client)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def topic
|
|
21
|
+
@topic ||= TopicService.new(kafka_client: kafka_client)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def kafka_client
|
|
25
|
+
@kafka_client = KafkaClient.new(conf: conf)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'service_conf_element'
|
|
4
|
+
|
|
5
|
+
module KafkaCli
|
|
6
|
+
class ServiceConf
|
|
7
|
+
attr_reader :options
|
|
8
|
+
|
|
9
|
+
DEFAULT_CLIENT_ID = 'kafkacli'
|
|
10
|
+
DEFAULT_BROKER = 'localhost:9092'
|
|
11
|
+
|
|
12
|
+
ATTRIBUTES = [
|
|
13
|
+
ServiceConfElement.new(
|
|
14
|
+
label: :client_id,
|
|
15
|
+
keys: [:'client-id'],
|
|
16
|
+
default_value: DEFAULT_CLIENT_ID,
|
|
17
|
+
desc: 'Kafka client id'
|
|
18
|
+
),
|
|
19
|
+
ServiceConfElement.new(
|
|
20
|
+
label: :brokers,
|
|
21
|
+
keys: %i[brokers b],
|
|
22
|
+
default_value: DEFAULT_BROKER,
|
|
23
|
+
desc: 'Boostrap servers'
|
|
24
|
+
),
|
|
25
|
+
ServiceConfElement.new(
|
|
26
|
+
label: :ssl_certificate,
|
|
27
|
+
keys: %i[certificate cert],
|
|
28
|
+
desc: 'SSL certificate for AUTH (PEM)'
|
|
29
|
+
),
|
|
30
|
+
ServiceConfElement.new(
|
|
31
|
+
label: :ssl_key,
|
|
32
|
+
keys: [:key],
|
|
33
|
+
desc: 'SSL private key for AUTH (PEM)'
|
|
34
|
+
),
|
|
35
|
+
ServiceConfElement.new(
|
|
36
|
+
label: :ssl_key_password,
|
|
37
|
+
keys: [:'key-password'],
|
|
38
|
+
desc: 'SSL private key password (if encrypted)'
|
|
39
|
+
),
|
|
40
|
+
ServiceConfElement.new(
|
|
41
|
+
label: :ssl_ca,
|
|
42
|
+
keys: [:'ca-cert'],
|
|
43
|
+
desc: 'SSL CA certificate (PEM)'
|
|
44
|
+
),
|
|
45
|
+
ServiceConfElement.new(
|
|
46
|
+
label: :ssl_verify,
|
|
47
|
+
keys: [:'ssl-verify'],
|
|
48
|
+
default_value: true,
|
|
49
|
+
desc: 'SSL hostname verification'
|
|
50
|
+
),
|
|
51
|
+
ServiceConfElement.new(
|
|
52
|
+
label: :socket_timeout,
|
|
53
|
+
keys: [:'socket-timeout'],
|
|
54
|
+
default_value: 30_000,
|
|
55
|
+
desc: 'Socket Timeout'
|
|
56
|
+
),
|
|
57
|
+
ServiceConfElement.new(
|
|
58
|
+
label: :request_timeout,
|
|
59
|
+
desc: 'Request Timeout',
|
|
60
|
+
keys: [:'request-timeout'],
|
|
61
|
+
default_value: 30_000
|
|
62
|
+
)
|
|
63
|
+
].to_h { |attribute| [attribute.label, attribute] }
|
|
64
|
+
|
|
65
|
+
def initialize(**options)
|
|
66
|
+
@options = options
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def method_missing(method_name, *args, **kwargs, &)
|
|
70
|
+
return super unless ATTRIBUTES.key?(method_name.to_sym)
|
|
71
|
+
|
|
72
|
+
options_name = ATTRIBUTES[method_name.to_sym].keys.first
|
|
73
|
+
options.fetch(options_name, nil)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def respond_to_missing?(method_name, include_private = false)
|
|
77
|
+
ATTRIBUTES.key?(method_name.to_sym) || super
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def brokers_auth_mode
|
|
81
|
+
'ssl' if ssl_certificate
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module KafkaCli
|
|
4
|
+
class ServiceConfElement
|
|
5
|
+
attr_reader :label, :keys, :desc, :default_value
|
|
6
|
+
|
|
7
|
+
def initialize(label:, keys:, desc: nil, default_value: nil)
|
|
8
|
+
@label = label
|
|
9
|
+
@keys = keys
|
|
10
|
+
@desc = desc
|
|
11
|
+
@default_value = default_value
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def gli_options
|
|
15
|
+
{
|
|
16
|
+
desc: desc,
|
|
17
|
+
default_value: default_value
|
|
18
|
+
}.compact
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module KafkaCli
|
|
4
|
+
class TopicService
|
|
5
|
+
attr_reader :kafka_client
|
|
6
|
+
|
|
7
|
+
def initialize(kafka_client:)
|
|
8
|
+
@kafka_client = kafka_client
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def list(patterns: [], options: {})
|
|
12
|
+
patterns = patterns.map { |pattern| Regexp.new(pattern) }
|
|
13
|
+
|
|
14
|
+
kafka_client.topics do |topic|
|
|
15
|
+
next if patterns.size.positive? && patterns.none? do |pattern|
|
|
16
|
+
pattern.match?(topic[:topic_name])
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
puts topic
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def create(topic_names: [], options: {})
|
|
24
|
+
kafka_client.create_topics(topic_names: topic_names,
|
|
25
|
+
partitions: options[:partitions],
|
|
26
|
+
replicas: options[:replicas])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def delete(topic_names: [], options: {})
|
|
30
|
+
kafka_client.delete_topics(topic_names: topic_names)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/kafka_cli.rb
ADDED
data/sig/kafka_cli.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: kafka_cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Thomas Tych
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: bump
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.10.0
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.10.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: byebug
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '12.0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '12.0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: irb
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - "~>"
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '1.15'
|
|
47
|
+
- - ">="
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: 1.15.2
|
|
50
|
+
type: :development
|
|
51
|
+
prerelease: false
|
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - "~>"
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '1.15'
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: 1.15.2
|
|
60
|
+
- !ruby/object:Gem::Dependency
|
|
61
|
+
name: minitest
|
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
|
63
|
+
requirements:
|
|
64
|
+
- - "~>"
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: '5.25'
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: 5.25.5
|
|
70
|
+
type: :development
|
|
71
|
+
prerelease: false
|
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - "~>"
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '5.25'
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: 5.25.5
|
|
80
|
+
- !ruby/object:Gem::Dependency
|
|
81
|
+
name: minitest-focus
|
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
|
83
|
+
requirements:
|
|
84
|
+
- - "~>"
|
|
85
|
+
- !ruby/object:Gem::Version
|
|
86
|
+
version: '1.4'
|
|
87
|
+
type: :development
|
|
88
|
+
prerelease: false
|
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - "~>"
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '1.4'
|
|
94
|
+
- !ruby/object:Gem::Dependency
|
|
95
|
+
name: rake
|
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - "~>"
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '13.3'
|
|
101
|
+
type: :development
|
|
102
|
+
prerelease: false
|
|
103
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - "~>"
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '13.3'
|
|
108
|
+
- !ruby/object:Gem::Dependency
|
|
109
|
+
name: rubocop
|
|
110
|
+
requirement: !ruby/object:Gem::Requirement
|
|
111
|
+
requirements:
|
|
112
|
+
- - "~>"
|
|
113
|
+
- !ruby/object:Gem::Version
|
|
114
|
+
version: '1.81'
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 1.81.1
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '1.81'
|
|
125
|
+
- - ">="
|
|
126
|
+
- !ruby/object:Gem::Version
|
|
127
|
+
version: 1.81.1
|
|
128
|
+
- !ruby/object:Gem::Dependency
|
|
129
|
+
name: rubocop-minitest
|
|
130
|
+
requirement: !ruby/object:Gem::Requirement
|
|
131
|
+
requirements:
|
|
132
|
+
- - "~>"
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: '0.38'
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: 0.38.2
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - "~>"
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0.38'
|
|
145
|
+
- - ">="
|
|
146
|
+
- !ruby/object:Gem::Version
|
|
147
|
+
version: 0.38.2
|
|
148
|
+
- !ruby/object:Gem::Dependency
|
|
149
|
+
name: rubocop-rake
|
|
150
|
+
requirement: !ruby/object:Gem::Requirement
|
|
151
|
+
requirements:
|
|
152
|
+
- - "~>"
|
|
153
|
+
- !ruby/object:Gem::Version
|
|
154
|
+
version: '0.7'
|
|
155
|
+
- - ">="
|
|
156
|
+
- !ruby/object:Gem::Version
|
|
157
|
+
version: 0.7.1
|
|
158
|
+
type: :development
|
|
159
|
+
prerelease: false
|
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - "~>"
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '0.7'
|
|
165
|
+
- - ">="
|
|
166
|
+
- !ruby/object:Gem::Version
|
|
167
|
+
version: 0.7.1
|
|
168
|
+
- !ruby/object:Gem::Dependency
|
|
169
|
+
name: simplecov
|
|
170
|
+
requirement: !ruby/object:Gem::Requirement
|
|
171
|
+
requirements:
|
|
172
|
+
- - "~>"
|
|
173
|
+
- !ruby/object:Gem::Version
|
|
174
|
+
version: '0.22'
|
|
175
|
+
type: :development
|
|
176
|
+
prerelease: false
|
|
177
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
178
|
+
requirements:
|
|
179
|
+
- - "~>"
|
|
180
|
+
- !ruby/object:Gem::Version
|
|
181
|
+
version: '0.22'
|
|
182
|
+
- !ruby/object:Gem::Dependency
|
|
183
|
+
name: gli
|
|
184
|
+
requirement: !ruby/object:Gem::Requirement
|
|
185
|
+
requirements:
|
|
186
|
+
- - "~>"
|
|
187
|
+
- !ruby/object:Gem::Version
|
|
188
|
+
version: '2.22'
|
|
189
|
+
- - ">="
|
|
190
|
+
- !ruby/object:Gem::Version
|
|
191
|
+
version: 2.22.2
|
|
192
|
+
type: :runtime
|
|
193
|
+
prerelease: false
|
|
194
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
195
|
+
requirements:
|
|
196
|
+
- - "~>"
|
|
197
|
+
- !ruby/object:Gem::Version
|
|
198
|
+
version: '2.22'
|
|
199
|
+
- - ">="
|
|
200
|
+
- !ruby/object:Gem::Version
|
|
201
|
+
version: 2.22.2
|
|
202
|
+
- !ruby/object:Gem::Dependency
|
|
203
|
+
name: rdkafka
|
|
204
|
+
requirement: !ruby/object:Gem::Requirement
|
|
205
|
+
requirements:
|
|
206
|
+
- - "~>"
|
|
207
|
+
- !ruby/object:Gem::Version
|
|
208
|
+
version: '0.24'
|
|
209
|
+
- - ">="
|
|
210
|
+
- !ruby/object:Gem::Version
|
|
211
|
+
version: 0.24.2
|
|
212
|
+
type: :runtime
|
|
213
|
+
prerelease: false
|
|
214
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
215
|
+
requirements:
|
|
216
|
+
- - "~>"
|
|
217
|
+
- !ruby/object:Gem::Version
|
|
218
|
+
version: '0.24'
|
|
219
|
+
- - ">="
|
|
220
|
+
- !ruby/object:Gem::Version
|
|
221
|
+
version: 0.24.2
|
|
222
|
+
description: Kafka CLI based on rdkafka
|
|
223
|
+
email:
|
|
224
|
+
- thomas.tych@gmail.com
|
|
225
|
+
executables:
|
|
226
|
+
- kafkacli
|
|
227
|
+
extensions: []
|
|
228
|
+
extra_rdoc_files: []
|
|
229
|
+
files:
|
|
230
|
+
- LICENSE.txt
|
|
231
|
+
- README.md
|
|
232
|
+
- Rakefile
|
|
233
|
+
- exe/kafkacli
|
|
234
|
+
- lib/kafka_cli.rb
|
|
235
|
+
- lib/kafka_cli/cluster_service.rb
|
|
236
|
+
- lib/kafka_cli/kafka_client.rb
|
|
237
|
+
- lib/kafka_cli/service.rb
|
|
238
|
+
- lib/kafka_cli/service_conf.rb
|
|
239
|
+
- lib/kafka_cli/service_conf_element.rb
|
|
240
|
+
- lib/kafka_cli/topic_service.rb
|
|
241
|
+
- lib/kafka_cli/version.rb
|
|
242
|
+
- sig/kafka_cli.rbs
|
|
243
|
+
homepage: https://gitlab.com/ttych/kafka_cli.rb
|
|
244
|
+
licenses:
|
|
245
|
+
- MIT
|
|
246
|
+
metadata:
|
|
247
|
+
homepage_uri: https://gitlab.com/ttych/kafka_cli.rb
|
|
248
|
+
source_code_uri: https://gitlab.com/ttych/kafka_cli.rb
|
|
249
|
+
rubygems_mfa_required: 'true'
|
|
250
|
+
rdoc_options: []
|
|
251
|
+
require_paths:
|
|
252
|
+
- lib
|
|
253
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
|
+
requirements:
|
|
255
|
+
- - ">="
|
|
256
|
+
- !ruby/object:Gem::Version
|
|
257
|
+
version: 3.2.0
|
|
258
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
|
+
requirements:
|
|
260
|
+
- - ">="
|
|
261
|
+
- !ruby/object:Gem::Version
|
|
262
|
+
version: '0'
|
|
263
|
+
requirements: []
|
|
264
|
+
rubygems_version: 3.7.2
|
|
265
|
+
specification_version: 4
|
|
266
|
+
summary: Kafka CLI
|
|
267
|
+
test_files: []
|