ohai 7.2.0.rc.1 → 7.2.0.rc.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ohai/mixin/ec2_metadata.rb +1 -0
- data/lib/ohai/plugins/ec2.rb +9 -2
- data/lib/ohai/plugins/eucalyptus.rb +12 -2
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/ec2_spec.rb +76 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d1436bcd73ef60c3c794bdf276c0b572e757455
|
4
|
+
data.tar.gz: b767aa0d9791d62f002005b904c2115585ce4139
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aced95949e6cb8df985e11c345dfba4a73f30a222fd06be5d250bcb36d69fa96c9566394a2bf3b4d6379ff765d307888d5765a61aaf648864af593f181ef7ef8
|
7
|
+
data.tar.gz: 82b6fa1453d0352261468a31e23af6a5a047ef681da5db209c4b49bbf87dcf3f5e17a352d9bf5308d67e1e207797bb60b8b3e8be386db482b2bef592e3373fd3
|
data/lib/ohai/plugins/ec2.rb
CHANGED
@@ -40,7 +40,7 @@ Ohai.plugin(:EC2) do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def looks_like_ec2?
|
43
|
-
# Try non-blocking connect so we don't "block" if
|
43
|
+
# Try non-blocking connect so we don't "block" if
|
44
44
|
# the Xen environment is *not* EC2
|
45
45
|
hint?('ec2') || has_ec2_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
|
46
46
|
end
|
@@ -49,7 +49,14 @@ Ohai.plugin(:EC2) do
|
|
49
49
|
if looks_like_ec2?
|
50
50
|
Ohai::Log.debug("looks_like_ec2? == true")
|
51
51
|
ec2 Mash.new
|
52
|
-
fetch_metadata.each
|
52
|
+
fetch_metadata.each do |k, v|
|
53
|
+
# fetch_metadata returns IAM security credentials, including the IAM user's
|
54
|
+
# secret access key. We'd rather not have ohai send this information
|
55
|
+
# to the server.
|
56
|
+
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
|
57
|
+
next if k == 'iam' && !hint?('iam')
|
58
|
+
ec2[k] = v
|
59
|
+
end
|
53
60
|
ec2[:userdata] = self.fetch_userdata
|
54
61
|
else
|
55
62
|
Ohai::Log.debug("looks_like_ec2? == false")
|
@@ -47,7 +47,7 @@ Ohai.plugin(:Eucalyptus) do
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def looks_like_euca?
|
50
|
-
# Try non-blocking connect so we don't "block" if
|
50
|
+
# Try non-blocking connect so we don't "block" if
|
51
51
|
# the Xen environment is *not* EC2
|
52
52
|
hint?('eucalyptus') || has_euca_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR,80)
|
53
53
|
end
|
@@ -56,7 +56,17 @@ Ohai.plugin(:Eucalyptus) do
|
|
56
56
|
if looks_like_euca?
|
57
57
|
Ohai::Log.debug("looks_like_euca? == true")
|
58
58
|
eucalyptus Mash.new
|
59
|
-
self.fetch_metadata.each
|
59
|
+
self.fetch_metadata.each do |k, v|
|
60
|
+
# Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS
|
61
|
+
# https://www.eucalyptus.com/blog/2013/10/15/iam-roles-and-instance-profiles-eucalyptus-34
|
62
|
+
#
|
63
|
+
# fetch_metadata returns IAM security credentials, including the IAM user's
|
64
|
+
# secret access key. We'd rather not have ohai send this information
|
65
|
+
# to the server.
|
66
|
+
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html#instancedata-data-categories
|
67
|
+
next if k == 'iam' && !hint?('iam')
|
68
|
+
eucalyptus[k] = v
|
69
|
+
end
|
60
70
|
eucalyptus[:userdata] = self.fetch_userdata
|
61
71
|
else
|
62
72
|
Ohai::Log.debug("looks_like_euca? == false")
|
data/lib/ohai/version.rb
CHANGED
@@ -44,6 +44,7 @@ describe Ohai::System, "plugin ec2" do
|
|
44
44
|
@http_client.should_receive(:get).
|
45
45
|
with("/").twice.
|
46
46
|
and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
|
47
|
+
File.stub(:exist?).and_return(false)
|
47
48
|
end
|
48
49
|
|
49
50
|
it "should recursively fetch all the ec2 metadata" do
|
@@ -64,6 +65,7 @@ describe Ohai::System, "plugin ec2" do
|
|
64
65
|
and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
65
66
|
|
66
67
|
@plugin.run
|
68
|
+
|
67
69
|
@plugin[:ec2].should_not be_nil
|
68
70
|
@plugin[:ec2]['instance_type'].should == "c1.medium"
|
69
71
|
@plugin[:ec2]['ami_id'].should == "ami-5d2dc934"
|
@@ -92,33 +94,80 @@ describe Ohai::System, "plugin ec2" do
|
|
92
94
|
@http_client.should_receive(:get).
|
93
95
|
with("/2012-01-12/user-data/").
|
94
96
|
and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
97
|
+
|
95
98
|
@plugin.run
|
96
99
|
|
97
100
|
@plugin[:ec2].should_not be_nil
|
98
101
|
@plugin[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com')
|
99
102
|
end
|
100
103
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
@http_client.should_receive(:get).
|
112
|
-
with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
|
113
|
-
and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
|
114
|
-
@http_client.should_receive(:get).
|
115
|
-
with("/2012-01-12/user-data/").
|
116
|
-
and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
117
|
-
@plugin.run
|
104
|
+
context "with ec2_iam cloud file" do
|
105
|
+
before do
|
106
|
+
if windows?
|
107
|
+
File.stub(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(true)
|
108
|
+
File.stub(:read).with('C:\chef\ohai\hints/iam.json').and_return('')
|
109
|
+
else
|
110
|
+
File.stub(:exist?).with('/etc/chef/ohai/hints/iam.json').and_return(true)
|
111
|
+
File.stub(:read).with('/etc/chef/ohai/hints/iam.json').and_return('')
|
112
|
+
end
|
113
|
+
end
|
118
114
|
|
119
|
-
|
120
|
-
|
121
|
-
|
115
|
+
it "should parse ec2 iam/ directory and collect iam/security-credentials/" do
|
116
|
+
@http_client.should_receive(:get).
|
117
|
+
with("/2012-01-12/meta-data/").
|
118
|
+
and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
|
119
|
+
@http_client.should_receive(:get).
|
120
|
+
with("/2012-01-12/meta-data/iam/").
|
121
|
+
and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
|
122
|
+
@http_client.should_receive(:get).
|
123
|
+
with("/2012-01-12/meta-data/iam/security-credentials/").
|
124
|
+
and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
|
125
|
+
@http_client.should_receive(:get).
|
126
|
+
with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
|
127
|
+
and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
|
128
|
+
@http_client.should_receive(:get).
|
129
|
+
with("/2012-01-12/user-data/").
|
130
|
+
and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
131
|
+
|
132
|
+
@plugin.run
|
133
|
+
|
134
|
+
@plugin[:ec2].should_not be_nil
|
135
|
+
@plugin[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
|
136
|
+
@plugin[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "without ec2_iam cloud file" do
|
141
|
+
before do
|
142
|
+
if windows?
|
143
|
+
File.stub(:exist?).with('C:\chef\ohai\hints/iam.json').and_return(false)
|
144
|
+
else
|
145
|
+
File.stub(:exist?).with('/etc/chef/ohai/hints/iam.json').and_return(false)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should parse ec2 iam/ directory and NOT collect iam/security-credentials/" do
|
150
|
+
@http_client.should_receive(:get).
|
151
|
+
with("/2012-01-12/meta-data/").
|
152
|
+
and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
|
153
|
+
@http_client.should_receive(:get).
|
154
|
+
with("/2012-01-12/meta-data/iam/").
|
155
|
+
and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
|
156
|
+
@http_client.should_receive(:get).
|
157
|
+
with("/2012-01-12/meta-data/iam/security-credentials/").
|
158
|
+
and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
|
159
|
+
@http_client.should_receive(:get).
|
160
|
+
with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
|
161
|
+
and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
|
162
|
+
@http_client.should_receive(:get).
|
163
|
+
with("/2012-01-12/user-data/").
|
164
|
+
and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
|
165
|
+
|
166
|
+
@plugin.run
|
167
|
+
|
168
|
+
@plugin[:ec2].should_not be_nil
|
169
|
+
@plugin[:ec2]['iam'].should be_nil
|
170
|
+
end
|
122
171
|
end
|
123
172
|
|
124
173
|
it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
|
@@ -201,10 +250,13 @@ describe Ohai::System, "plugin ec2" do
|
|
201
250
|
it_should_behave_like "ec2"
|
202
251
|
|
203
252
|
before(:each) do
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
253
|
+
if windows?
|
254
|
+
File.should_receive(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
|
255
|
+
File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
|
256
|
+
else
|
257
|
+
File.should_receive(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
|
258
|
+
File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
|
259
|
+
end
|
208
260
|
end
|
209
261
|
end
|
210
262
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.2.0.rc.
|
4
|
+
version: 7.2.0.rc.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|