boxgrinder-core 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.3.9
2
+
3
+ * [BGBUILD-312] Discover which user to switch to after root dependent sections have been executed
4
+
1
5
  v0.3.8
2
6
 
3
7
  * [BGBUILD-305] Incorrect version information in 0.9.6 schema causing validation errors
data/Manifest CHANGED
@@ -0,0 +1,44 @@
1
+ CHANGELOG
2
+ LICENSE
3
+ Manifest
4
+ README
5
+ Rakefile
6
+ boxgrinder-core.gemspec
7
+ lib/boxgrinder-core.rb
8
+ lib/boxgrinder-core/appliance-parser.rb
9
+ lib/boxgrinder-core/appliance-validator.rb
10
+ lib/boxgrinder-core/errors.rb
11
+ lib/boxgrinder-core/helpers/appliance-config-helper.rb
12
+ lib/boxgrinder-core/helpers/appliance-definition-helper.rb
13
+ lib/boxgrinder-core/helpers/appliance-transformation-helper.rb
14
+ lib/boxgrinder-core/helpers/exec-helper.rb
15
+ lib/boxgrinder-core/helpers/log-helper.rb
16
+ lib/boxgrinder-core/models/appliance-config.rb
17
+ lib/boxgrinder-core/models/config.rb
18
+ lib/boxgrinder-core/models/task.rb
19
+ lib/boxgrinder-core/schemas/appliance_schema_0.8.0.yaml
20
+ lib/boxgrinder-core/schemas/appliance_schema_0.9.0.yaml
21
+ lib/boxgrinder-core/schemas/appliance_schema_0.9.6.yaml
22
+ rubygem-boxgrinder-core.spec
23
+ spec/appliance-parser-spec.rb
24
+ spec/appliance-validator-spec.rb
25
+ spec/helpers/appliance-config-helper-spec.rb
26
+ spec/helpers/appliance-definition-helper-spec.rb
27
+ spec/helpers/appliance-transformation-helper-spec.rb
28
+ spec/helpers/exec-helper-spec.rb
29
+ spec/helpers/log-helper-spec.rb
30
+ spec/models/appliance-config-spec.rb
31
+ spec/models/config-spec.rb
32
+ spec/rspec/ls/one
33
+ spec/rspec/ls/two
34
+ spec/rspec/src/appliances/0.8.x.appl
35
+ spec/rspec/src/appliances/0.9.x-invalid.appl
36
+ spec/rspec/src/appliances/0.9.x.appl
37
+ spec/rspec/src/appliances/comments.appl
38
+ spec/rspec/src/appliances/ephemeral-repo.appl
39
+ spec/rspec/src/appliances/full.appl
40
+ spec/rspec/src/appliances/invalid-yaml.appl
41
+ spec/rspec/src/appliances/legacy.appl
42
+ spec/rspec/src/appliances/repo.appl
43
+ spec/rspec/src/config/empty
44
+ spec/rspec/src/config/valid
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{boxgrinder-core}
5
- s.version = "0.3.8"
5
+ s.version = "0.3.9"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Marek Goldmann"]
9
- s.date = %q{2011-09-10}
9
+ s.date = %q{2011-11-15}
10
10
  s.description = %q{Core library for BoxGrinder}
11
11
  s.email = %q{info@boxgrinder.org}
12
12
  s.extra_rdoc_files = ["CHANGELOG", "LICENSE", "README", "lib/boxgrinder-core.rb", "lib/boxgrinder-core/appliance-parser.rb", "lib/boxgrinder-core/appliance-validator.rb", "lib/boxgrinder-core/errors.rb", "lib/boxgrinder-core/helpers/appliance-config-helper.rb", "lib/boxgrinder-core/helpers/appliance-definition-helper.rb", "lib/boxgrinder-core/helpers/appliance-transformation-helper.rb", "lib/boxgrinder-core/helpers/exec-helper.rb", "lib/boxgrinder-core/helpers/log-helper.rb", "lib/boxgrinder-core/models/appliance-config.rb", "lib/boxgrinder-core/models/config.rb", "lib/boxgrinder-core/models/task.rb", "lib/boxgrinder-core/schemas/appliance_schema_0.8.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.0.yaml", "lib/boxgrinder-core/schemas/appliance_schema_0.9.6.yaml"]
@@ -19,6 +19,7 @@
19
19
  require 'rubygems'
20
20
  require 'hashery/opencascade'
21
21
  require 'yaml'
22
+ require 'etc'
22
23
 
23
24
  module BoxGrinder
24
25
  class Config < OpenCascade
@@ -54,6 +55,8 @@ module BoxGrinder
54
55
  merge_with_symbols!(values)
55
56
 
56
57
  self.backtrace = true if [:debug, :trace].include?(self.log_level)
58
+
59
+ populate_user_ids!
57
60
  end
58
61
 
59
62
  def merge_with_symbols!(values)
@@ -73,5 +76,18 @@ module BoxGrinder
73
76
  end
74
77
  end if second
75
78
  end
79
+
80
+ def populate_user_ids!
81
+ self.uid = Process.uid
82
+ self.gid = Process.gid
83
+ begin
84
+ if env = ENV['SUDO_USER'] || ENV['LOGNAME']
85
+ user = Etc.getpwnam(env)
86
+ self.uid = user.uid
87
+ self.gid = user.gid
88
+ end
89
+ rescue ArgumentError #No such name, just use initial defaults.
90
+ end
91
+ end
76
92
  end
77
- end
93
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Summary: Core library for BoxGrinder
7
7
  Name: rubygem-%{gemname}
8
- Version: 0.3.8
8
+ Version: 0.3.9
9
9
  Release: 1%{?dist}
10
10
  Group: Development/Languages
11
11
  License: LGPLv3+
@@ -76,6 +76,10 @@ popd
76
76
  %{gemdir}/doc/%{gemname}-%{version}
77
77
 
78
78
  %changelog
79
+ * Fri Oct 14 2011 Marc Savy <msavy@redhat.com> - 0.3.9-1
80
+ - Upstream release: 0.3.9
81
+ - [BGBUILD-312] Discover which user to switch to after root dependent sections have been executed
82
+
79
83
  * Wed Sep 7 2011 Marek Goldmann <mgoldman@redhat.com> - 0.3.8-1
80
84
  - [BGBUILD-305] Incorrect version information in 0.9.6 schema causing validation errors
81
85
 
@@ -22,18 +22,25 @@ require 'boxgrinder-core/models/config'
22
22
 
23
23
  module BoxGrinder
24
24
  describe Config do
25
+
26
+ def get_config
27
+ # Some extra challenges due to calls being in initialize
28
+ Config.any_instance.stub(:populate_user_ids!)
29
+ config = Config.new
30
+ config
31
+ end
32
+
25
33
  it "should not load options from file if it doesn't exist" do
26
34
  ENV['BG_CONFIG_FILE'] = ""
27
35
 
28
- lambda {
29
- config = Config.new
36
+ lambda { get_config
30
37
  }.should raise_error(RuntimeError, "You specified empty configuration file path. Please make sure you set correct path for BG_CONFIG_FILE environment variable.")
31
38
  end
32
39
 
33
40
  it "should load empty config file" do
34
41
  ENV['BG_CONFIG_FILE'] = "#{File.dirname(__FILE__)}/../rspec/src/config/empty"
35
42
 
36
- config = Config.new
43
+ config = get_config
37
44
  config.force.should == false
38
45
  config.log_level.should == :info
39
46
  end
@@ -41,7 +48,7 @@ module BoxGrinder
41
48
  it "should load config file" do
42
49
  ENV['BG_CONFIG_FILE'] = "#{File.dirname(__FILE__)}/../rspec/src/config/valid"
43
50
 
44
- config = Config.new
51
+ config = get_config
45
52
  config.force.should == true
46
53
  config.log_level.should == 'trace'
47
54
  config.dir.build.should == 'build'
@@ -50,22 +57,78 @@ module BoxGrinder
50
57
 
51
58
  it "should raise a file not found error if BG_CONFIG_FILE is set, but the path is invalid" do
52
59
  ENV['BG_CONFIG_FILE'] = "leo/tol/stoy"
53
- lambda { Config.new }.should raise_error(RuntimeError, "Configuration file 'leo/tol/stoy' couldn't be found. Please make sure you set correct path for BG_CONFIG_FILE environment variable.")
60
+ lambda { get_config }.should raise_error(RuntimeError, "Configuration file 'leo/tol/stoy' couldn't be found. Please make sure you set correct path for BG_CONFIG_FILE environment variable.")
54
61
  end
55
62
 
56
63
  it "should raise if the specified config file is whitespace" do
57
64
  ENV['BG_CONFIG_FILE'] = " "
58
65
 
59
66
  lambda {
60
- config = Config.new
67
+ config = get_config
61
68
  }.should raise_error(RuntimeError, "You specified empty configuration file path. Please make sure you set correct path for BG_CONFIG_FILE environment variable.")
62
69
  end
63
70
 
64
71
  it "should merge platform" do
65
72
  # Make sure we don't have the variable defined anymore
66
73
  ENV.delete('BG_CONFIG_FILE')
67
- config = Config.new.merge(:platform => :ec2)
74
+ config = get_config.merge(:platform => :ec2)
68
75
  config.platform.should == :ec2
69
76
  end
77
+
78
+ context ".populate_user_ids!" do
79
+ before(:each) do
80
+ # Work-around due to unstubbing not working properly.
81
+ ['LOGNAME', 'SUDO_USER'].each{|e| ENV.delete(e)}
82
+ @user = mock('gravy', :uid => 347, :gid => 547)
83
+ @root = mock('root', :uid => 0, :gid => 0)
84
+ Etc.stub!(:getpwnam).and_return(@user)
85
+ @config = Config.new
86
+ end
87
+
88
+
89
+ it "should discover a user and group when under su" do
90
+ ENV['LOGNAME'] = 'gravy1'
91
+ ['SUDO_USER', 'LOGNAME'].each{|v| puts "From config-spec.rb: #{ENV[v]}"}
92
+
93
+ Process.should_receive(:uid).and_return(99)
94
+ Process.should_receive(:gid).and_return(79)
95
+ Etc.should_receive(:getpwnam).with('gravy1').and_return(@user)
96
+
97
+ @config.populate_user_ids!
98
+ @config.uid.should == 347
99
+ @config.gid.should == 547
100
+ end
101
+
102
+ it "should discover a user and group when under sudo" do
103
+ ENV['SUDO_USER'] = 'gravy2'
104
+ Process.should_receive(:uid).and_return(99)
105
+ Process.should_receive(:gid).and_return(79)
106
+ Etc.should_receive(:getpwnam).with('gravy2').and_return(@user)
107
+
108
+ @config.populate_user_ids!
109
+ @config.uid.should == 347
110
+ @config.gid.should == 547
111
+ end
112
+
113
+ it "should set process uid/gid if variables are not set" do
114
+ Process.should_receive(:uid).and_return(23)
115
+ Process.should_receive(:gid).and_return(26)
116
+
117
+ @config.populate_user_ids!
118
+ @config.uid.should == 23
119
+ @config.gid.should == 26
120
+ end
121
+
122
+ it "should return process uid/gid if user does not exist" do
123
+ ENV['SUDO_USER'] = 'fakegravy'
124
+ Process.should_receive(:uid).and_return(23)
125
+ Process.should_receive(:gid).and_return(26)
126
+ Etc.should_receive(:getpwnam).with('fakegravy').and_raise(ArgumentError)
127
+
128
+ @config.populate_user_ids!
129
+ @config.uid.should == 23
130
+ @config.gid.should == 26
131
+ end
132
+ end
70
133
  end
71
134
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boxgrinder-core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 8
10
- version: 0.3.8
9
+ - 9
10
+ version: 0.3.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - Marek Goldmann
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-10 00:00:00 +02:00
18
+ date: 2011-11-15 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency