rabbitmq-definition 0.1.2 → 0.1.3
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 +4 -4
- data/README.md +4 -4
- data/lib/rabbitmq_definition/command.rb +9 -1
- data/lib/rabbitmq_definition/create.rb +1 -11
- data/lib/rabbitmq_definition/load.rb +9 -0
- data/lib/rabbitmq_definition/rabbitmq-definition.rake +8 -4
- data/lib/rabbitmq_definition/version.rb +1 -1
- data/spec/rabbitmq_definition/load_spec.rb +18 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e5b2d64905691e862ce14c01418eff57785970f
|
4
|
+
data.tar.gz: 14c2cc91b17fc496429f7bb6f1b6f155bf5a9377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72d3c1ba953f095709d5de11c3a9d4b293efe89d484bcab92c03545debf4c381ee099b4c608bed0d8b724f408771432a67c5aa0389c5548565aa5258ee22a84a
|
7
|
+
data.tar.gz: 8b0e9a1183745a7cc6843dca0626de824f58c4b68ac478217ac5b9ff787dc39d668325f3ad145b1d7d4994f45c00d3bd9fcd5155132a8bcac5180480c027002d
|
data/README.md
CHANGED
@@ -21,9 +21,9 @@ RABBITMQ_MANAGEMENT_URL=http://guest:guest@localhost:15672
|
|
21
21
|
|
22
22
|
Create a new vhost and definition for your application. It will create the vhosts of your choice and add permissions to the user in the environment variable to those vhosts.
|
23
23
|
```ruby
|
24
|
-
bundle exec rake rabbitmq:create
|
24
|
+
bundle exec rake rabbitmq:create # It will ask you what vhosts to create the definition with
|
25
25
|
# or
|
26
|
-
bundle exec rake rabbitmq:create
|
26
|
+
bundle exec rake rabbitmq:create VHOSTS=hats # It will directly create a vhost named '/hats'
|
27
27
|
```
|
28
28
|
|
29
29
|
### Drop definition
|
@@ -36,9 +36,9 @@ Drop the vhosts in from your RabbitMQ instance and remove the file:
|
|
36
36
|
### Dump definition
|
37
37
|
Dump the definition of the vhosts in your RabbitMQ instance into definition file:
|
38
38
|
```ruby
|
39
|
-
bundle exec rake rabbitmq:dump
|
39
|
+
bundle exec rake rabbitmq:dump # It will dump the vhosts specificed in the existing definition file
|
40
40
|
# or
|
41
|
-
bundle exec rake rabbitmq:dump
|
41
|
+
bundle exec rake rabbitmq:dump VHOSTS=hats # It will dump the specified vhost in a new definition few
|
42
42
|
```
|
43
43
|
|
44
44
|
### Load definition
|
@@ -22,7 +22,15 @@ module RabbitMQ::Definition
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def user
|
25
|
-
|
25
|
+
uri_endpoint.user
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_permissions_for_vhost(vhost)
|
29
|
+
client.update_permissions_of(vhost, user, {
|
30
|
+
:configure => ".*",
|
31
|
+
:write => ".*",
|
32
|
+
:read => ".*"
|
33
|
+
})
|
26
34
|
end
|
27
35
|
end
|
28
36
|
end
|
@@ -16,20 +16,10 @@ module RabbitMQ::Definition
|
|
16
16
|
Logger.progress "Creating vhost '#{vhost}'" if verbose
|
17
17
|
client.create_vhost(vhost)
|
18
18
|
Logger.progress "Adding permissions for '#{user}' to vhost '#{vhost}'" if verbose
|
19
|
-
|
19
|
+
add_permissions_for_vhost(vhost)
|
20
20
|
end
|
21
21
|
Dump.run(client, false, @vhosts)
|
22
22
|
end
|
23
23
|
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def all_permissions
|
28
|
-
{
|
29
|
-
:configure => ".*",
|
30
|
-
:write => ".*",
|
31
|
-
:read => ".*"
|
32
|
-
}
|
33
|
-
end
|
34
24
|
end
|
35
25
|
end
|
@@ -7,8 +7,17 @@ module RabbitMQ::Definition
|
|
7
7
|
definition = FileDefinition.read
|
8
8
|
Logger.progress "Uploading definition..."
|
9
9
|
client.upload_definitions(definition.to_json)
|
10
|
+
ensure_permissions(definition)
|
10
11
|
Logger.success "Done"
|
11
12
|
end
|
12
13
|
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def ensure_permissions(definition)
|
18
|
+
definition.vhosts.each do |vhost|
|
19
|
+
add_permissions_for_vhost(vhost['name'])
|
20
|
+
end
|
21
|
+
end
|
13
22
|
end
|
14
23
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
namespace :rabbitmq do
|
2
|
+
def retrieve_vhosts
|
3
|
+
ENV["VHOSTS"] ? ENV["VHOSTS"].split(",") : nil
|
4
|
+
end
|
5
|
+
|
2
6
|
desc "Create a RabbitMQ schema for a vhost (comma separated vhosts)"
|
3
|
-
task :create
|
4
|
-
RabbitMQ::Definition.create(
|
7
|
+
task :create do |t, args|
|
8
|
+
RabbitMQ::Definition.create(retrieve_vhosts)
|
5
9
|
end
|
6
10
|
|
7
11
|
desc "Drop all RabbitMQ queues/exchanges/bindings"
|
@@ -10,8 +14,8 @@ namespace :rabbitmq do
|
|
10
14
|
end
|
11
15
|
|
12
16
|
desc "Dump RabbitMQ JSON structure (from defined vhosts or supplied comma separated vhosts) "
|
13
|
-
task :dump
|
14
|
-
RabbitMQ::Definition.dump(
|
17
|
+
task :dump do |t, args|
|
18
|
+
RabbitMQ::Definition.dump(retrieve_vhosts)
|
15
19
|
end
|
16
20
|
|
17
21
|
desc "Load RabbitMQ JSON structure"
|
@@ -3,10 +3,19 @@ describe RabbitMQ::Definition::Load do
|
|
3
3
|
double(
|
4
4
|
"client",
|
5
5
|
:upload_definitions => nil,
|
6
|
+
:endpoint => ENV['RABBITMQ_MANAGEMENT_URL'],
|
7
|
+
:update_permissions_of => nil
|
6
8
|
)
|
7
9
|
end
|
10
|
+
let(:all_permissions) do
|
11
|
+
{
|
12
|
+
:configure => ".*",
|
13
|
+
:write => ".*",
|
14
|
+
:read => ".*"
|
15
|
+
}
|
16
|
+
end
|
8
17
|
|
9
|
-
|
18
|
+
context "when a definition file does NOT exist" do
|
10
19
|
before { allow(RabbitMQ::Definition::FileDefinition).to receive(:exists?).and_return(false) }
|
11
20
|
|
12
21
|
it "notifies about error" do
|
@@ -18,8 +27,9 @@ describe RabbitMQ::Definition::Load do
|
|
18
27
|
context "when a definition file does NOT exist" do
|
19
28
|
let(:json) { '{"definitions": "json"}' }
|
20
29
|
before do
|
21
|
-
|
22
|
-
|
30
|
+
definition = double(:to_json => json, :vhosts => [{'name' => '/'}])
|
31
|
+
allow(RabbitMQ::Definition::FileDefinition).to receive(:exists?).and_return(true)
|
32
|
+
expect(RabbitMQ::Definition::FileDefinition).to receive(:read).and_return(definition)
|
23
33
|
end
|
24
34
|
|
25
35
|
it "notifies progress" do
|
@@ -32,6 +42,11 @@ describe RabbitMQ::Definition::Load do
|
|
32
42
|
described_class.run(client, true)
|
33
43
|
end
|
34
44
|
|
45
|
+
it "ensures the user has granted permissions for the definition vhosts" do
|
46
|
+
expect(client).to receive(:update_permissions_of).with('/', 'guest', all_permissions).once
|
47
|
+
described_class.run(client, false)
|
48
|
+
end
|
49
|
+
|
35
50
|
it "uploads the json definition to the client " do
|
36
51
|
expect(client).to receive(:upload_definitions).with(json).once
|
37
52
|
described_class.run(client, false)
|