sqs-list-queues 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/sqs-list-queues +62 -0
- data/lib/sqs-list-queues.rb +5 -0
- data/lib/sqs-list-queues/client.rb +25 -0
- data/lib/sqs-list-queues/config.rb +30 -0
- data/lib/sqs-list-queues/lister.rb +66 -0
- data/lib/sqs-list-queues/runner.rb +128 -0
- data/lib/sqs-list-queues/version.rb +3 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7cc3bebdbdeef157d7ca36c992ee9cf342bef893
|
4
|
+
data.tar.gz: 90072d014b7cc86f65d8b323c1c98af5ecdc5204
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd425cb7fc9d7b22d5ea1644d67f33d5ece7a9ecc2f3c0fec7fb88c96b3811f7754ab32160a6f3d7c8fd4048eee535e84ba4ae00612507fc017d3a517a28be6d
|
7
|
+
data.tar.gz: 718cd925493432caee9cb1addafc9112f3190685cbf5ecfd9613305165f32e357197e22f099962530182dc2893f65c6cb95ac861742140af9705ded5912f5a55
|
data/bin/sqs-list-queues
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
require 'sqs-list-queues'
|
6
|
+
|
7
|
+
config = SqsListQueues::Config.new
|
8
|
+
|
9
|
+
opts_parser = OptionParser.new do |opts|
|
10
|
+
opts.banner = "Usage: sqs-list-queues [OPTIONS] [PATTERN ...]"
|
11
|
+
opts.separator ""
|
12
|
+
opts.on("-c", "--counts", "Show message counts") do
|
13
|
+
config.show_counts = true
|
14
|
+
end
|
15
|
+
opts.on("-a", "--arn", "Show queue ARN") do
|
16
|
+
config.show_arn = true
|
17
|
+
end
|
18
|
+
opts.on("-u", "--url", "Show queue URL") do
|
19
|
+
config.show_url = true
|
20
|
+
end
|
21
|
+
opts.on("-j", "--json", "Show output in json format") do
|
22
|
+
config.json_format = true
|
23
|
+
end
|
24
|
+
opts.separator ""
|
25
|
+
opts.separator <<-EOF
|
26
|
+
|
27
|
+
Lists SQS queues (either all queues, or if at least one PATTERN is given,
|
28
|
+
those queues whose names match at least one PATTERN, implicitly prefixed by
|
29
|
+
"^"). One line is printed to standard output for each queue.
|
30
|
+
|
31
|
+
If --counts is shown, prefix by the message counts (visible, not visible, and
|
32
|
+
delayed, in that order); then show the queue name, or ARN, or URL. If JSON
|
33
|
+
format is selected, the queue name is always shown, and the ARN and URL can
|
34
|
+
both be selected if desired.
|
35
|
+
|
36
|
+
Examples:
|
37
|
+
|
38
|
+
# List all queue names
|
39
|
+
sqs-list-queues
|
40
|
+
|
41
|
+
# List queues whose names start with either "Foo" or "Bar", showing queue
|
42
|
+
# URLs not names:
|
43
|
+
sqs-list-queues --url Foo Bar
|
44
|
+
|
45
|
+
# List queues whose names start with "MyQueues", showing message counts:
|
46
|
+
sqs-list-queues --counts MyQueues
|
47
|
+
|
48
|
+
EOF
|
49
|
+
end
|
50
|
+
|
51
|
+
opts_parser.parse!
|
52
|
+
|
53
|
+
unless ARGV.empty?
|
54
|
+
config.patterns = ARGV
|
55
|
+
end
|
56
|
+
|
57
|
+
config.validate
|
58
|
+
|
59
|
+
rc = SqsListQueues::Runner.new(config).run
|
60
|
+
exit rc
|
61
|
+
|
62
|
+
# eof sqs-list-queues
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SqsListQueues
|
2
|
+
|
3
|
+
class Client
|
4
|
+
|
5
|
+
def self.configure
|
6
|
+
Aws.config.merge! core_v2_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.core_v2_options
|
10
|
+
{
|
11
|
+
http_proxy: get_proxy,
|
12
|
+
user_agent_suffix: "sqs-list-queues #{VERSION}",
|
13
|
+
# http_wire_trace: true,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get_proxy
|
18
|
+
e = ENV['https_proxy']
|
19
|
+
e = "https://#{e}" if e && !e.empty? && !e.start_with?('http')
|
20
|
+
return e
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SqsListQueues
|
2
|
+
|
3
|
+
class Config
|
4
|
+
# Stronger builder pattern would be nice
|
5
|
+
attr_accessor :client_options, :sqs_client,
|
6
|
+
:patterns,
|
7
|
+
:show_counts,
|
8
|
+
:show_arn,
|
9
|
+
:show_url,
|
10
|
+
:json_format
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@client_options = {}
|
14
|
+
@patterns = nil
|
15
|
+
@show_counts = false
|
16
|
+
@show_arn = false
|
17
|
+
@show_url = false
|
18
|
+
@json_format = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate
|
22
|
+
unless @json_format
|
23
|
+
if @show_arn and @show_url
|
24
|
+
raise "Can't show both ARN and URL unless JSON format is selected"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module SqsListQueues
|
2
|
+
|
3
|
+
class Lister
|
4
|
+
|
5
|
+
# ListQueues /seems/ to return the queues in ASCII order (case sensitive).
|
6
|
+
# The following algorithm depends on this assumption.
|
7
|
+
|
8
|
+
# Allowed characters in SQS queue names, in that order (see above).
|
9
|
+
ALPHABET = ("0".."9").to_a \
|
10
|
+
+ ["-"] \
|
11
|
+
+ ("A".."Z").to_a \
|
12
|
+
+ ["_"] \
|
13
|
+
+ ("a".."z").to_a
|
14
|
+
|
15
|
+
# Ceiling of ListQueues results
|
16
|
+
MAX_RESULTS = 1000
|
17
|
+
|
18
|
+
def initialize(sqs_client)
|
19
|
+
@sqs_client = sqs_client
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_possibly_truncated_list(prefix)
|
23
|
+
# $stderr.puts "Querying with prefix = #{prefix.inspect}"
|
24
|
+
@sqs_client.list_queues(queue_name_prefix: prefix).queue_urls
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_full_list(prefix = "")
|
28
|
+
urls = get_possibly_truncated_list prefix
|
29
|
+
|
30
|
+
if urls.count < MAX_RESULTS
|
31
|
+
return urls
|
32
|
+
end
|
33
|
+
|
34
|
+
last_result = urls.last
|
35
|
+
last_name = File.basename last_result
|
36
|
+
|
37
|
+
# If prefix = "foo"
|
38
|
+
# and the last result we have is "foolish"
|
39
|
+
# then to discover things later than this, we have to use a longer prefix
|
40
|
+
# then "foo":
|
41
|
+
# - "foom", "foon" (etc, for all possible character after "l"), each of
|
42
|
+
# which must be iterated independently
|
43
|
+
# - but for "fool"... we can try "fool" (which will certainly return some
|
44
|
+
# results we already have), and _may_ return additional results
|
45
|
+
|
46
|
+
problematic_letter = last_name[prefix.length]
|
47
|
+
|
48
|
+
# The fool case
|
49
|
+
fool_names = get_full_list(prefix + problematic_letter)
|
50
|
+
index_of_last_result = fool_names.index last_result
|
51
|
+
fool_names = fool_names[index_of_last_result+1 .. -1]
|
52
|
+
|
53
|
+
# The foom, foon... case
|
54
|
+
problematic_index = ALPHABET.index problematic_letter
|
55
|
+
remaining_letters = ALPHABET[problematic_index+1 .. -1]
|
56
|
+
|
57
|
+
remaining_names = remaining_letters.map do |letter|
|
58
|
+
get_full_list(prefix + letter)
|
59
|
+
end
|
60
|
+
|
61
|
+
(urls + fool_names + remaining_names).flatten
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require 'json'
|
3
|
+
require 'rosarium'
|
4
|
+
|
5
|
+
module SqsListQueues
|
6
|
+
|
7
|
+
class Runner
|
8
|
+
|
9
|
+
def initialize(config)
|
10
|
+
@config = config
|
11
|
+
|
12
|
+
@config.sqs_client ||= begin
|
13
|
+
effective_options = SqsListQueues::Client.core_v2_options.merge(config.client_options)
|
14
|
+
Aws::SQS::Client.new(effective_options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def promise
|
19
|
+
promise_queue_urls.then do |queue_urls|
|
20
|
+
Rosarium::Promise.all(queue_urls.map {|queue_url| promise_queue queue_url}.reject &:nil?)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def promise_queue_urls
|
25
|
+
prefixes = get_pattern_prefixes
|
26
|
+
|
27
|
+
if prefixes.empty? or prefixes.any? {|prefix| prefix == ""}
|
28
|
+
Rosarium::Promise.execute do
|
29
|
+
SqsListQueues::Lister.new(@config.sqs_client).get_full_list
|
30
|
+
end
|
31
|
+
else
|
32
|
+
Rosarium::Promise.all(
|
33
|
+
prefixes.map do |prefix|
|
34
|
+
Rosarium::Promise.execute do
|
35
|
+
SqsListQueues::Lister.new(@config.sqs_client).get_full_list(prefix)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
).then do |v|
|
39
|
+
v.flatten.uniq
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_pattern_prefixes
|
45
|
+
if @config.patterns.nil?
|
46
|
+
[]
|
47
|
+
else
|
48
|
+
@config.patterns.map do |pattern|
|
49
|
+
pattern.match(/^([0-9A-Za-z_-]*)/)[1]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def pattern_to_string_prefix(pattern)
|
55
|
+
m = pattern.match /^/
|
56
|
+
end
|
57
|
+
|
58
|
+
def promise_queue(queue_url)
|
59
|
+
queue_name = File.basename queue_url
|
60
|
+
return nil unless name_matches_patterns?(queue_name)
|
61
|
+
|
62
|
+
Rosarium::Promise.execute do
|
63
|
+
r = {
|
64
|
+
name: queue_name,
|
65
|
+
url: queue_url,
|
66
|
+
}
|
67
|
+
|
68
|
+
required_attributes = []
|
69
|
+
|
70
|
+
if @config.show_arn
|
71
|
+
required_attributes << 'QueueArn'
|
72
|
+
end
|
73
|
+
|
74
|
+
if @config.show_counts
|
75
|
+
required_attributes << 'ApproximateNumberOfMessages'
|
76
|
+
required_attributes << 'ApproximateNumberOfMessagesNotVisible'
|
77
|
+
required_attributes << 'ApproximateNumberOfMessagesDelayed'
|
78
|
+
end
|
79
|
+
|
80
|
+
unless required_attributes.empty?
|
81
|
+
r[:attributes] = @config.sqs_client.get_queue_attributes(
|
82
|
+
queue_url: queue_url,
|
83
|
+
attribute_names: required_attributes,
|
84
|
+
).attributes
|
85
|
+
end
|
86
|
+
|
87
|
+
r
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def name_matches_patterns?(queue_name)
|
92
|
+
return true if @config.patterns.nil?
|
93
|
+
|
94
|
+
@config.patterns.any? do |pattern|
|
95
|
+
queue_name.match("^" + pattern)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def run
|
100
|
+
promise.then do |queues|
|
101
|
+
queues.each do |queue|
|
102
|
+
if @config.json_format
|
103
|
+
puts JSON.generate(queue)
|
104
|
+
else
|
105
|
+
if @config.show_counts
|
106
|
+
msg = queue[:attributes]["ApproximateNumberOfMessages"]
|
107
|
+
invis = queue[:attributes]["ApproximateNumberOfMessagesNotVisible"]
|
108
|
+
delayed = queue[:attributes]["ApproximateNumberOfMessagesDelayed"]
|
109
|
+
print "#{msg}\t#{invis}\t#{delayed}\t"
|
110
|
+
end
|
111
|
+
|
112
|
+
if @config.show_arn
|
113
|
+
puts queue[:attributes]["QueueArn"]
|
114
|
+
elsif @config.show_url
|
115
|
+
puts queue[:url]
|
116
|
+
else
|
117
|
+
puts queue[:name]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end.value!
|
122
|
+
|
123
|
+
return 0
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sqs-list-queues
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rachel Evans
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rosarium
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
description: "\n sqs-list-queues lists your SQS queues (working around the 1000
|
42
|
+
queue limit\n in the ListQueues API).\n\n Options are available to filter
|
43
|
+
by queue name, show message counts, show\n queue ARNs and/or names, and output
|
44
|
+
as json.\n\n Respects $https_proxy.\n "
|
45
|
+
email: sqs-list-queues-git@rve.org.uk
|
46
|
+
executables:
|
47
|
+
- sqs-list-queues
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- bin/sqs-list-queues
|
52
|
+
- lib/sqs-list-queues.rb
|
53
|
+
- lib/sqs-list-queues/client.rb
|
54
|
+
- lib/sqs-list-queues/config.rb
|
55
|
+
- lib/sqs-list-queues/lister.rb
|
56
|
+
- lib/sqs-list-queues/runner.rb
|
57
|
+
- lib/sqs-list-queues/version.rb
|
58
|
+
homepage: https://github.com/rvedotrc/sqs-list-queues
|
59
|
+
licenses:
|
60
|
+
- Apache-2.0
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.5.1
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: List SQS queues, optionally with message counts and more
|
82
|
+
test_files: []
|