consul-migrate 0.1.1 → 0.1.2
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 +8 -8
- data/.travis.yml +1 -0
- data/README.md +4 -4
- data/bin/consul-migrate +4 -0
- data/consul-migrate.gemspec +6 -4
- data/lib/consul/migrate.rb +1 -0
- data/lib/consul/migrate/cli.rb +71 -0
- data/lib/consul/migrate/client.rb +35 -18
- data/lib/consul/migrate/defaults.rb +10 -0
- data/lib/consul/migrate/error.rb +8 -0
- data/lib/consul/migrate/version.rb +1 -1
- metadata +27 -10
- data/bin/console +0 -14
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MWY0MGEzNDA0ZjFkYjQwNDI5ZmNhYTE5MzNkYzZjZmNhYjQ2NWJkOQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWNjYTE0ZGZjNWFiZDczOTdjMTI2MWQyNTg4ZDIwYjA4NjRlNTEyNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGFiN2VjM2VlNTA4OTZhN2E4ODkzMzgxZDlkYzQ4YzljYjc2ZTI4ZWY4ZjZh
|
10
|
+
NzdlZTUxMDA1NjUxOWJmZWI4YWNlYTRhNGNhYTZlM2E0OGMxMWQ3OWM1YmNj
|
11
|
+
NzIwNDJmNWVmMTcwMTI4YjYxNWZkZWM1MGIwMzMxZTZjYTc0MTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODIzNWMyNjVmMjgyNzExZWY0MmQ2ZWVmNjk5ZDcwMTUyMTdjNDk2MjJjMDhl
|
14
|
+
NmZhMzliNTNiYWNhMDNiYWE5MGJhYjViZWE3MWI0MzM2MDkyNGM4MzI0Njk4
|
15
|
+
OTcwOGM5Y2NhYWViNGEyMmQ2Y2U2YWIyZTViOWU0YTllYmU2NDY=
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -22,16 +22,16 @@ Or install it yourself as:
|
|
22
22
|
From the current authoritative ACL datacenter:
|
23
23
|
|
24
24
|
```ruby
|
25
|
-
require consul
|
25
|
+
require 'consul/migrate'
|
26
26
|
|
27
|
-
client = Consul::Migrate::Client.new(acl_token: '
|
27
|
+
client = Consul::Migrate::Client.new(acl_token: 'your-acl-master-token')
|
28
28
|
client.export_acls('/path/to/file')
|
29
29
|
```
|
30
30
|
|
31
31
|
From the desired new ACL datacenter:
|
32
32
|
```ruby
|
33
|
-
require consul
|
34
|
-
client = Consul::Migrate::Client.new(acl_token: '
|
33
|
+
require 'consul/migrate'
|
34
|
+
client = Consul::Migrate::Client.new(acl_token: 'your-acl-master-token')
|
35
35
|
client.import_acls('/path/to/file')
|
36
36
|
```
|
37
37
|
|
data/bin/consul-migrate
ADDED
data/consul-migrate.gemspec
CHANGED
@@ -15,14 +15,16 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.license = 'Apache 2.0'
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
-
spec.bindir = '
|
19
|
-
spec.executables = spec.files.grep(%r{^
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'webmock', '~> 1.21
|
25
|
-
spec.add_development_dependency 'rspec', '~> 3.1
|
24
|
+
spec.add_development_dependency 'webmock', '~> 1.21'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.1'
|
26
26
|
spec.add_development_dependency 'sinatra', '~> 1.4'
|
27
27
|
spec.add_development_dependency 'fakefs', '~> 0.6'
|
28
|
+
|
29
|
+
spec.add_runtime_dependency 'thor', '~> 0.19'
|
28
30
|
end
|
data/lib/consul/migrate.rb
CHANGED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'consul/migrate/version'
|
2
|
+
require 'consul/migrate/client'
|
3
|
+
require 'consul/migrate/defaults'
|
4
|
+
require 'thor'
|
5
|
+
require 'yaml'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
module Consul
|
9
|
+
module Migrate
|
10
|
+
class Cli < Thor
|
11
|
+
|
12
|
+
attr_accessor :client
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
read_config
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'version', 'Display consul-migrate version'
|
20
|
+
def version
|
21
|
+
say VERSION
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'init', 'Initialize consul-migrate instance'
|
25
|
+
method_option :bind_client, type: :string, aliases: :c,
|
26
|
+
desc: 'HTTPS client to bind to'
|
27
|
+
method_option :port, type: :numeric, aliases: :p,
|
28
|
+
desc: 'Port to bind to'
|
29
|
+
method_option :acl_token, type: :string, aliases: :t,
|
30
|
+
desc: 'ACL token that is used to access API'
|
31
|
+
def init
|
32
|
+
write_config(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
desc 'export', 'Export ACLs from Consul via agent running in this system'
|
36
|
+
method_option :file, type: :string, default: 'output.json', aliases: :f,
|
37
|
+
desc: 'Target file to write to'
|
38
|
+
def export
|
39
|
+
@client.export_acls(options[:file])
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'import', 'Import ACLs into Consul cluster via agent running in this system'
|
43
|
+
method_option :file, type: :string, default: 'output.json', aliases: :f,
|
44
|
+
desc: 'Target file to read from'
|
45
|
+
def import
|
46
|
+
@client.import_acls(options[:file])
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def write_config(options)
|
52
|
+
parent_dir = File.dirname(CONFIG_FILE)
|
53
|
+
FileUtils.mkdir_p parent_dir
|
54
|
+
|
55
|
+
client = Consul::Migrate::Client.new(options)
|
56
|
+
|
57
|
+
File.open(CONFIG_FILE, 'w') do |f|
|
58
|
+
# Convert keys from symbols to string and turn hash into YAML
|
59
|
+
f.write client.options.to_yaml
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def read_config
|
64
|
+
return unless File.exists?(CONFIG_FILE)
|
65
|
+
|
66
|
+
config = YAML.load_file(CONFIG_FILE)
|
67
|
+
@client = Consul::Migrate::Client.new(config)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -1,47 +1,59 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'net/http'
|
3
|
+
require 'consul/migrate/defaults'
|
4
|
+
require 'consul/migrate/error'
|
3
5
|
|
4
6
|
module Consul
|
5
7
|
module Migrate
|
6
8
|
class Client
|
9
|
+
# Make options readable to CLI
|
7
10
|
attr_reader :options
|
8
11
|
|
9
|
-
def bind_client; options[:bind_client]; end
|
10
|
-
def port; options[:port]; end
|
11
|
-
|
12
|
-
def base_url
|
12
|
+
def bind_client; @options[:bind_client]; end
|
13
|
+
def port; @options[:port]; end
|
14
|
+
|
15
|
+
def base_url
|
16
|
+
"http://#{bind_client}:#{port}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def http_params
|
20
|
+
{ :token => @options[:acl_token] }
|
21
|
+
end
|
13
22
|
|
14
23
|
def initialize(options = {})
|
15
|
-
@options =
|
16
|
-
:bind_client => 'localhost',
|
17
|
-
:port => 8500
|
18
|
-
}.merge(options)
|
24
|
+
@options = CLIENT_DEFAULTS.merge(symbolize_keys(options))
|
19
25
|
end
|
20
26
|
|
21
|
-
#
|
27
|
+
# GET /v1/acl/list
|
22
28
|
def get_acl_list
|
23
|
-
|
24
|
-
|
29
|
+
uri = URI("#{base_url}/v1/acl/list")
|
30
|
+
uri.query = URI.encode_www_form(http_params)
|
31
|
+
response = Net::HTTP.get_response(uri)
|
25
32
|
|
26
|
-
|
33
|
+
fail(Error, response.body) unless response.kind_of? Net::HTTPSuccess
|
34
|
+
|
35
|
+
response.body
|
27
36
|
end
|
28
37
|
|
29
|
-
# PUT
|
38
|
+
# PUT /v1/acl/create
|
30
39
|
def put_acl(acl_hash)
|
31
|
-
uri = URI("#{base_url}/v1/acl/create
|
32
|
-
|
40
|
+
uri = URI("#{base_url}/v1/acl/create")
|
41
|
+
uri.query = URI.encode_www_form(http_params)
|
42
|
+
req = Net::HTTP::Put.new(uri.request_uri)
|
33
43
|
req.body = acl_hash.to_json
|
34
44
|
|
35
45
|
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
36
46
|
http.request(req)
|
37
47
|
end
|
38
48
|
|
39
|
-
|
49
|
+
fail(Error, response.body) unless response.kind_of? Net::HTTPSuccess
|
50
|
+
|
51
|
+
response.body
|
40
52
|
end
|
41
53
|
|
42
54
|
# Export ACLs into a file
|
43
55
|
def export_acls(dest)
|
44
|
-
json = get_acl_list
|
56
|
+
json = get_acl_list
|
45
57
|
|
46
58
|
File.open(dest, 'w') { |file|
|
47
59
|
file.write(json)
|
@@ -58,13 +70,18 @@ module Consul
|
|
58
70
|
|
59
71
|
result = []
|
60
72
|
data_hash.each do |k, v|
|
61
|
-
h = JSON.parse(put_acl(k)
|
73
|
+
h = JSON.parse(put_acl(k))
|
62
74
|
result.push(h)
|
63
75
|
end
|
64
76
|
|
65
77
|
return result
|
66
78
|
end
|
67
79
|
|
80
|
+
private
|
81
|
+
|
82
|
+
def symbolize_keys(hash)
|
83
|
+
Hash[hash.map{|k,v| v.is_a?(Hash) ? [k.to_sym, symbolize_keys(v)] : [k.to_sym, v] }]
|
84
|
+
end
|
68
85
|
end
|
69
86
|
end
|
70
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consul-migrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Calvin Leung Huang
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,28 +44,28 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.21
|
47
|
+
version: '1.21'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.21
|
54
|
+
version: '1.21'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 3.1
|
61
|
+
version: '3.1'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 3.1
|
68
|
+
version: '3.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sinatra
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,10 +94,25 @@ dependencies:
|
|
94
94
|
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.6'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: thor
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.19'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.19'
|
97
111
|
description: Gem that can be used to import and export Consul ACL tokens
|
98
112
|
email:
|
99
113
|
- cleung2010@gmail.com
|
100
|
-
executables:
|
114
|
+
executables:
|
115
|
+
- consul-migrate
|
101
116
|
extensions: []
|
102
117
|
extra_rdoc_files: []
|
103
118
|
files:
|
@@ -108,11 +123,13 @@ files:
|
|
108
123
|
- LICENSE.txt
|
109
124
|
- README.md
|
110
125
|
- Rakefile
|
111
|
-
- bin/
|
112
|
-
- bin/setup
|
126
|
+
- bin/consul-migrate
|
113
127
|
- consul-migrate.gemspec
|
114
128
|
- lib/consul/migrate.rb
|
129
|
+
- lib/consul/migrate/cli.rb
|
115
130
|
- lib/consul/migrate/client.rb
|
131
|
+
- lib/consul/migrate/defaults.rb
|
132
|
+
- lib/consul/migrate/error.rb
|
116
133
|
- lib/consul/migrate/version.rb
|
117
134
|
homepage: https://github.com/Cimpress-MCP/consul-migrate
|
118
135
|
licenses:
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
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
|