consul-migrate 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +54 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/consul-migrate.gemspec +28 -0
- data/lib/consul/migrate.rb +14 -0
- data/lib/consul/migrate/client.rb +70 -0
- data/lib/consul/migrate/version.rb +5 -0
- metadata +141 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzA5ODIyY2UzNmNmNjk1M2EzMTZhMzI1ZmFiNDVjYWM5YzEzMDYwMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWU4YTM4YmZiMjkzNWQ0MDI4MmJiMDM4M2UwNWQyY2U2MTRlZGVhZA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDQ1ZjcyOTA5MTk0MjAzNDE2YzYyMDhhZDFlNTk1YTBkOWRhMWVjYmYyZWIx
|
10
|
+
M2ZmZDE1OTI2YzgzYzU4NDM1N2E4ZTczY2UwZDIyMDk3NzM2ODk2MTdiY2Vi
|
11
|
+
ZTE2YzYwODc2OTYxNTU0NzZmNDEzOWZjYzZjMzdmMGY5NjdmODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWI3MjNhMTBhOTUzNmQ4MzA4OWRkMGRiN2NiNGY0YTIyZjZlMzFjOWE3ZDU3
|
14
|
+
OGMzMTVmYjgxODQxYTNhMzE1MmQ1YmY3MGIzMTM3NzE3MTA0OWU3ODdmMmUz
|
15
|
+
ZmY3N2MxODZhZDljZDZiMWRlMzRhZDI4MGY1ZjhlNGYxODk0ZmI=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.0.0
|
4
|
+
deploy:
|
5
|
+
provider: rubygems
|
6
|
+
api_key:
|
7
|
+
secure: tZYTVOUWGEXpTVz4yjsGrMj4+QQ8DHbCbW+O0wKe+ohXttxG7T6xFOhuqAFjgvfEWRc93+/XVSQTXNNFbXO1NV1jNnSwHNoFe6aAZi825D6WeoeqiJHtsGGEoA8AH34B7sfCi20d5FOwrHkHTf9iG9KxZNdmUPHOEIbqaSA9shhtOqV2xp2a2IO24XmUBVT83slqm8w8zlJ0RziF+neSQJ/Tz+Ce4Z7QwaD0XV3sBS1kC4labwGUuWcfTxlpwNf1qs3IqcZIKg+WpTJG8JHGuV4CGpE6rb6VeqAz68L+Jx704f+jDJneKr8GzzFOmCZxUVg+bBMcbM1bjQXKDcCSdepKTNV2JGkzZF3ziAhhAAZfEAtZBPeGc4S5pNsW6gLboGPM3NiofekrcPwMw4HAghf9I3qbokvJd0nxQPzMyriKW0AamZEkw62lxA3ccB9yUJlIYEJqvn40J1T+y6KRD6Td/QRuVKS3N3I6zd+GnO4kjwOAkc6QGWEhLQWNUZ8R0ZZw9h8BfJVR2n6JJb4b4KflTIAooP53VURaQnLqVD2nKlNoTEuieOW2uiKrgvy8Pf+X+pf9GaxSY0N4jgYXrjeLXO2U4qfHXGa0OaZnKtxFK2OzX15g8TaRwuFcKGrfbgWHL5kTFF2qqPUaPsLQhR8LUDferXs7xeqTKR9p+rw=
|
8
|
+
gem: consul-migrate
|
9
|
+
on:
|
10
|
+
tags: true
|
11
|
+
repo: Cimpress-MCP/consul-migrate
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015 Cimpress
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# consul-migrate
|
2
|
+
|
3
|
+
consul-migrate is a Ruby gem for migrating Consul's ACL datacenter. Consul does not natively support such migration mechanism, but does provide an API for accessing ACLs. consul-migrate uses this API to export ACL tokens from the current authoritative ACL datacenter and import them to another datacenter.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'consul-migrate'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install consul-migrate
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
From the current authoritative ACL datacenter:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require consul-migrate
|
26
|
+
|
27
|
+
client = Consul::Migrate::Client.new(acl_token: 'you-acl-master-token')
|
28
|
+
client.export_acls('/path/to/file')
|
29
|
+
```
|
30
|
+
|
31
|
+
From the desired new ACL datacenter:
|
32
|
+
```ruby
|
33
|
+
require consul-migrate
|
34
|
+
client = Consul::Migrate::Client.new(acl_token: 'you-acl-master-token')
|
35
|
+
client.import_acls('/path/to/file')
|
36
|
+
```
|
37
|
+
|
38
|
+
## Caveats
|
39
|
+
|
40
|
+
consul-migrate currently is only set up to work with the default `-client` (127.0.0.1) and default http port (8500). Future versions of consul-migrate should have parameters for inputing these values.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/[my-github-username]/consul-migrate/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
49
|
+
|
50
|
+
## TODO
|
51
|
+
|
52
|
+
1. Have it work as a cli so that scripting is not necessary
|
53
|
+
2. Include port and address as options instead of hardcoded values.
|
54
|
+
3. Spec test should also test for default policy allow case
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "consul/migrate"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'consul/migrate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'consul-migrate'
|
8
|
+
spec.version = Consul::Migrate::VERSION
|
9
|
+
spec.authors = ['Calvin Leung Huang']
|
10
|
+
spec.email = ['cleung2010@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Gem to import and export Consul ACL tokens'
|
13
|
+
spec.description = 'Gem that can be used to import and export Consul ACL tokens'
|
14
|
+
spec.homepage = 'https://github.com/Cimpress-MCP/consul-migrate'
|
15
|
+
spec.license = 'Apache 2.0'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
26
|
+
spec.add_development_dependency 'sinatra', '~> 1.4'
|
27
|
+
spec.add_development_dependency 'fakefs', '~> 0.6'
|
28
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
|
4
|
+
module Consul
|
5
|
+
module Migrate
|
6
|
+
class Client
|
7
|
+
attr_reader :options
|
8
|
+
|
9
|
+
def bind_client; options[:bind_client]; end
|
10
|
+
def port; options[:port]; end
|
11
|
+
def acl_token; options[:acl_token]; end
|
12
|
+
def base_url; "http://#{bind_client}:#{port}"; end
|
13
|
+
|
14
|
+
def initialize(options = {})
|
15
|
+
@options = {
|
16
|
+
:bind_client => 'localhost',
|
17
|
+
:port => 8500
|
18
|
+
}.merge(options)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Get all ACLs
|
22
|
+
def get_acl_list
|
23
|
+
url = "#{base_url}/v1/acl/list?token=#{acl_token}"
|
24
|
+
response = Net::HTTP.get_response(URI.parse(url))
|
25
|
+
|
26
|
+
return response
|
27
|
+
end
|
28
|
+
|
29
|
+
# PUT single ACL
|
30
|
+
def put_acl(acl_hash)
|
31
|
+
uri = URI("#{base_url}/v1/acl/create?token=#{acl_token}")
|
32
|
+
req = Net::HTTP::Put.new(uri)
|
33
|
+
req.body = acl_hash.to_json
|
34
|
+
|
35
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
36
|
+
http.request(req)
|
37
|
+
end
|
38
|
+
|
39
|
+
return response
|
40
|
+
end
|
41
|
+
|
42
|
+
# Export ACLs into a file
|
43
|
+
def export_acls(dest)
|
44
|
+
json = get_acl_list.body
|
45
|
+
|
46
|
+
File.open(dest, 'w') { |file|
|
47
|
+
file.write(json)
|
48
|
+
}
|
49
|
+
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
# Import ACLs from a file
|
54
|
+
# Returns array of IDs that were inserted into consul's ACL
|
55
|
+
def import_acls(file)
|
56
|
+
f = File.read(file)
|
57
|
+
data_hash = JSON.parse(f)
|
58
|
+
|
59
|
+
result = []
|
60
|
+
data_hash.each do |k, v|
|
61
|
+
h = JSON.parse(put_acl(k).body)
|
62
|
+
result.push(h)
|
63
|
+
end
|
64
|
+
|
65
|
+
return result
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
metadata
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: consul-migrate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Calvin Leung Huang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.21.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.21.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.1.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: fakefs
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.6'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.6'
|
97
|
+
description: Gem that can be used to import and export Consul ACL tokens
|
98
|
+
email:
|
99
|
+
- cleung2010@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- consul-migrate.gemspec
|
114
|
+
- lib/consul/migrate.rb
|
115
|
+
- lib/consul/migrate/client.rb
|
116
|
+
- lib/consul/migrate/version.rb
|
117
|
+
homepage: https://github.com/Cimpress-MCP/consul-migrate
|
118
|
+
licenses:
|
119
|
+
- Apache 2.0
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ! '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ! '>='
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubyforge_project:
|
137
|
+
rubygems_version: 2.4.5
|
138
|
+
signing_key:
|
139
|
+
specification_version: 4
|
140
|
+
summary: Gem to import and export Consul ACL tokens
|
141
|
+
test_files: []
|