murakumo 0.3.9 → 0.4.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.
- data/bin/murakumo-show-ec2-tags +31 -0
- data/bin/murakumo-show-ip-address +4 -1
- data/lib/cli/murakumo_initializer_context.rb +2 -0
- data/lib/cli/murakumo_options.rb +2 -0
- data/lib/misc/murakumo_const.rb +1 -1
- data/lib/util/murakumo_ec2_client.rb +69 -0
- data/lib/util/murakumo_ec2_tags.rb +43 -0
- data/lib/util/murakumo_self_ip_address.rb +13 -0
- metadata +21 -16
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'optparse'
|
4
|
+
require 'util/murakumo_ec2_tags'
|
5
|
+
|
6
|
+
access_key = nil
|
7
|
+
secret_key = nil
|
8
|
+
endpoint = nil
|
9
|
+
instance_id = nil
|
10
|
+
|
11
|
+
ARGV.options do |opt|
|
12
|
+
opt.on('-k', '--access-key ACCESS_KEY') {|v| access_key = v }
|
13
|
+
opt.on('-s', '--secret-key SECRET_KEY') {|v| secret_key = v }
|
14
|
+
opt.on('-r', '--region REGION') {|v| endpoint = v }
|
15
|
+
opt.on('-i', '--instance-id INSTANCE_ID') {|v| instance_id = v }
|
16
|
+
opt.parse!
|
17
|
+
|
18
|
+
access_key ||= ENV['AMAZON_ACCESS_KEY_ID']
|
19
|
+
secret_key ||= ENV['AMAZON_SECRET_ACCESS_KEY']
|
20
|
+
|
21
|
+
unless access_key and secret_key
|
22
|
+
puts opt.help
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
tags = Murakumo::Util::ec2_tags(access_key, secret_key, endpoint, instance_id)
|
28
|
+
|
29
|
+
tags.each do |k, v|
|
30
|
+
puts "#{k}\t#{v}"
|
31
|
+
end
|
data/lib/cli/murakumo_options.rb
CHANGED
data/lib/misc/murakumo_const.rb
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'base64'
|
3
|
+
require 'net/https'
|
4
|
+
require 'openssl'
|
5
|
+
|
6
|
+
Net::HTTP.version_1_2
|
7
|
+
|
8
|
+
module Murakumo
|
9
|
+
|
10
|
+
module Util
|
11
|
+
|
12
|
+
class EC2Client
|
13
|
+
|
14
|
+
API_VERSION = '2011-12-01'
|
15
|
+
SIGNATURE_VERSION = 2
|
16
|
+
|
17
|
+
def initialize(accessKeyId, secretAccessKey, endpoint = 'ec2.us-east-1.amazonaws.com', algorithm = :SHA256)
|
18
|
+
@accessKeyId = accessKeyId
|
19
|
+
@secretAccessKey = secretAccessKey
|
20
|
+
@endpoint = endpoint
|
21
|
+
@algorithm = algorithm
|
22
|
+
|
23
|
+
if /\A[^.]+\Z/ =~ @endpoint
|
24
|
+
@endpoint = "ec2.#{@endpoint}.amazonaws.com"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def query(action, params = {})
|
29
|
+
params = {
|
30
|
+
:Action => action,
|
31
|
+
:Version => API_VERSION,
|
32
|
+
:Timestamp => Time.now.getutc.strftime('%Y-%m-%dT%H:%M:%SZ'),
|
33
|
+
:SignatureVersion => SIGNATURE_VERSION,
|
34
|
+
:SignatureMethod => "Hmac#{@algorithm}",
|
35
|
+
:AWSAccessKeyId => @accessKeyId,
|
36
|
+
}.merge(params)
|
37
|
+
|
38
|
+
signature = aws_sign(params)
|
39
|
+
params[:Signature] = signature
|
40
|
+
|
41
|
+
https = Net::HTTP.new(@endpoint, 443)
|
42
|
+
https.use_ssl = true
|
43
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
44
|
+
|
45
|
+
https.start do |w|
|
46
|
+
req = Net::HTTP::Post.new('/',
|
47
|
+
'Host' => @endpoint,
|
48
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
49
|
+
)
|
50
|
+
|
51
|
+
req.set_form_data(params)
|
52
|
+
res = w.request(req)
|
53
|
+
|
54
|
+
res.body
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
def aws_sign(params)
|
60
|
+
params = params.sort_by {|a, b| a.to_s }.map {|k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('&')
|
61
|
+
string_to_sign = "POST\n#{@endpoint}\n/\n#{params}"
|
62
|
+
digest = OpenSSL::HMAC.digest(OpenSSL::Digest.const_get(@algorithm).new, @secretAccessKey, string_to_sign)
|
63
|
+
Base64.encode64(digest).gsub("\n", '')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end # Util
|
68
|
+
|
69
|
+
end # Murakumo
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'rexml/document'
|
3
|
+
|
4
|
+
require 'util/murakumo_ec2_client'
|
5
|
+
|
6
|
+
module Murakumo
|
7
|
+
|
8
|
+
module Util
|
9
|
+
|
10
|
+
def ec2_tags(access_key, secret_key, endpoint = nil, instance_id = nil)
|
11
|
+
unless endpoint
|
12
|
+
local_hostname = Net::HTTP.get('169.254.169.254', '/latest/meta-data/local-hostname')
|
13
|
+
|
14
|
+
if /\A[^.]+\.([^.]+)\.compute\.internal\Z/ =~ local_hostname
|
15
|
+
endpoint = $1
|
16
|
+
else
|
17
|
+
endpoint = 'us-east-1'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
unless instance_id
|
22
|
+
instance_id = Net::HTTP.get('169.254.169.254', '/latest/meta-data/instance-id')
|
23
|
+
end
|
24
|
+
|
25
|
+
ec2cli = Murakumo::Util::EC2Client.new(access_key, secret_key, endpoint)
|
26
|
+
source = ec2cli.query('DescribeTags', 'Filter.1.Name' => 'resource-id', 'Filter.1.Value' => instance_id)
|
27
|
+
|
28
|
+
tags = {}
|
29
|
+
|
30
|
+
REXML::Document.new(source).each_element('//tagSet/item') do |element|
|
31
|
+
key = element.text('key')
|
32
|
+
value = element.text('value')
|
33
|
+
tags[key] = value
|
34
|
+
end
|
35
|
+
|
36
|
+
return tags
|
37
|
+
end
|
38
|
+
|
39
|
+
module_function :ec2_tags
|
40
|
+
|
41
|
+
end # Util
|
42
|
+
|
43
|
+
end # Murakumo
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: murakumo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winebarrel
|
@@ -88,33 +88,38 @@ executables:
|
|
88
88
|
- mrkmctl
|
89
89
|
- murakumo-install-init-script
|
90
90
|
- murakumo-show-ip-address
|
91
|
+
- murakumo-show-ec2-tags
|
91
92
|
extensions: []
|
92
93
|
|
93
94
|
extra_rdoc_files: []
|
94
95
|
|
95
96
|
files:
|
96
97
|
- README
|
97
|
-
- bin/murakumo
|
98
|
+
- bin/murakumo
|
99
|
+
- bin/murakumo-show-ec2-tags
|
98
100
|
- bin/murakumo-show-ip-address
|
101
|
+
- bin/murakumo-install-init-script
|
99
102
|
- bin/mrkmctl
|
100
|
-
- bin/murakumo
|
101
|
-
- lib/cli/murakumo_options.rb
|
102
103
|
- lib/cli/mrkmctl.rb
|
103
|
-
- lib/cli/mrkmctl_options.rb
|
104
104
|
- lib/cli/murakumo.rb
|
105
|
+
- lib/cli/murakumo_options.rb
|
105
106
|
- lib/cli/murakumo_initializer_context.rb
|
106
|
-
- lib/
|
107
|
-
- lib/
|
107
|
+
- lib/cli/mrkmctl_options.rb
|
108
|
+
- lib/misc/murakumo_const.rb
|
109
|
+
- lib/util/murakumo_ec2_tags.rb
|
110
|
+
- lib/util/murakumo_self_ip_address.rb
|
111
|
+
- lib/util/murakumo_ec2_client.rb
|
112
|
+
- lib/srv/murakumo_health_check_context.rb
|
108
113
|
- lib/srv/murakumo_server.rb
|
114
|
+
- lib/srv/murakumo_health_check_notifier.rb
|
109
115
|
- lib/srv/murakumo_health_checker.rb
|
116
|
+
- lib/srv/murakumo_balancer.rb
|
110
117
|
- lib/srv/murakumo_cloud.rb
|
111
|
-
-
|
112
|
-
- lib/misc/murakumo_const.rb
|
113
|
-
- etc/murakumo-update-config-for-ec2
|
114
|
-
- etc/gai.conf.example
|
118
|
+
- etc/murakumo.server
|
115
119
|
- etc/murakumo.yml.example
|
120
|
+
- etc/gai.conf.example
|
121
|
+
- etc/murakumo-update-config-for-ec2
|
116
122
|
- etc/dhclient-script.patch
|
117
|
-
- etc/murakumo.server
|
118
123
|
homepage: https://bitbucket.org/winebarrel/murakumo
|
119
124
|
licenses: []
|
120
125
|
|
@@ -144,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
149
|
requirements: []
|
145
150
|
|
146
151
|
rubyforge_project:
|
147
|
-
rubygems_version: 1.8.
|
152
|
+
rubygems_version: 1.8.13
|
148
153
|
signing_key:
|
149
154
|
specification_version: 3
|
150
155
|
summary: Murakumo is the internal DNS server which manages name information using a gossip protocol.
|