on_container 0.0.7 → 0.0.8
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 +5 -5
- data/lib/on_container/version.rb +1 -1
- data/on_container.gemspec +1 -1
- metadata +6 -14
- data/lib/on_container/step_down_from_root.rb +0 -55
- data/spec/on_container_spec.rb +0 -5
- data/spec/spec_helper.rb +0 -14
- data/spec/step_down_from_root_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9b925ace8fb6fd6a98bf34a8ece37b21e18d25db9d348c7473dc68c8941b6769
|
4
|
+
data.tar.gz: 60a7a5747314918c66233d9e0847869e67c16887f46aae0a5de9aebaaa228a60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 878956892f1cdf7f9ae0509b76b3262ec5d6b4d2bfb606ac315e15ed69be6a7bb57259f994a13cfb3ffa55756a2b7612b40d4c6b3c8023bbe81f8c065166da9c
|
7
|
+
data.tar.gz: 33dd25d152e4fb8631c814ef17c7582c63ff9c3cf50d57f384b7f73c8b21eed800a1b73e0f2782066d7f73c963c4b2f0b9b0096215c7a199de2b96e17af990b8
|
data/lib/on_container/version.rb
CHANGED
data/on_container.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: on_container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
19
|
+
version: '2.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1
|
26
|
+
version: '2.1'
|
27
27
|
description: A small collection of scripts and routines to help ruby development within
|
28
28
|
containers
|
29
29
|
email:
|
@@ -47,12 +47,8 @@ files:
|
|
47
47
|
- lib/on_container/dev/setup_ops.rb
|
48
48
|
- lib/on_container/load_env_secrets.rb
|
49
49
|
- lib/on_container/ops/service_connection_checks.rb
|
50
|
-
- lib/on_container/step_down_from_root.rb
|
51
50
|
- lib/on_container/version.rb
|
52
51
|
- on_container.gemspec
|
53
|
-
- spec/on_container_spec.rb
|
54
|
-
- spec/spec_helper.rb
|
55
|
-
- spec/step_down_from_root_spec.rb
|
56
52
|
homepage: https://github.com/IcaliaLabs/on-container-for-ruby
|
57
53
|
licenses:
|
58
54
|
- MIT
|
@@ -76,13 +72,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
72
|
- !ruby/object:Gem::Version
|
77
73
|
version: '0'
|
78
74
|
requirements: []
|
79
|
-
|
80
|
-
rubygems_version: 2.5.2.3
|
75
|
+
rubygems_version: 3.1.4
|
81
76
|
signing_key:
|
82
77
|
specification_version: 4
|
83
78
|
summary: A small collection of scripts and routines to help ruby development within
|
84
79
|
containers
|
85
|
-
test_files:
|
86
|
-
- spec/on_container_spec.rb
|
87
|
-
- spec/spec_helper.rb
|
88
|
-
- spec/step_down_from_root_spec.rb
|
80
|
+
test_files: []
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'etc'
|
4
|
-
|
5
|
-
module OnContainer
|
6
|
-
class StepDownFromRoot
|
7
|
-
attr_reader :curent_user, :target_user
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@curent_user = Etc.getpwuid
|
11
|
-
end
|
12
|
-
|
13
|
-
def target_user
|
14
|
-
@target_user ||= Etc.getpwuid(developer_uid)
|
15
|
-
end
|
16
|
-
|
17
|
-
def perform
|
18
|
-
return unless root_user?
|
19
|
-
return warn_no_developer_uid unless developer_uid?
|
20
|
-
|
21
|
-
switch_to_developer_user
|
22
|
-
end
|
23
|
-
|
24
|
-
def root_user?
|
25
|
-
curent_user.name == 'root'
|
26
|
-
end
|
27
|
-
|
28
|
-
def developer_uid?
|
29
|
-
developer_uid > 0
|
30
|
-
end
|
31
|
-
|
32
|
-
def developer_uid
|
33
|
-
@developer_uid ||= ENV.fetch('DEVELOPER_UID', '').to_i
|
34
|
-
end
|
35
|
-
|
36
|
-
protected
|
37
|
-
|
38
|
-
def switch_to_developer_user
|
39
|
-
target_user_name = target_user.name
|
40
|
-
puts "Switching from 'root' user to '#{target_user_name}'..."
|
41
|
-
Kernel.exec 'su-exec', target_user_name, $0, *$*
|
42
|
-
end
|
43
|
-
|
44
|
-
def warn_no_developer_uid
|
45
|
-
puts "The 'DEVELOPER_UID' environment variable is not set... " \
|
46
|
-
'still running as root!'
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.perform
|
50
|
-
new.perform
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
OnContainer::StepDownFromRoot.perform
|
data/spec/on_container_spec.rb
DELETED
data/spec/spec_helper.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
require "on_container"
|
3
|
-
|
4
|
-
RSpec.configure do |config|
|
5
|
-
# Enable flags like --only-failures and --next-failure
|
6
|
-
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
-
|
8
|
-
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
-
config.disable_monkey_patching!
|
10
|
-
|
11
|
-
config.expect_with :rspec do |c|
|
12
|
-
c.syntax = :expect
|
13
|
-
end
|
14
|
-
end
|
@@ -1,63 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'on_container/step_down_from_root'
|
4
|
-
|
5
|
-
RSpec.describe OnContainer::StepDownFromRoot do
|
6
|
-
let(:root_user) do
|
7
|
-
instance_double "struct Etc::Passwd",
|
8
|
-
name: 'root',
|
9
|
-
passwd: 'x',
|
10
|
-
uid: 0,
|
11
|
-
gid: 0,
|
12
|
-
gecos: 'root',
|
13
|
-
dir: '/root',
|
14
|
-
shell: '/bin/bash'
|
15
|
-
end
|
16
|
-
|
17
|
-
let(:developer_user) do
|
18
|
-
instance_double "struct Etc::Passwd",
|
19
|
-
name: 'developer',
|
20
|
-
passwd: 'x',
|
21
|
-
uid: 1000,
|
22
|
-
gid: 1000,
|
23
|
-
gecos: 'Developer User,,,',
|
24
|
-
dir: '/usr/src',
|
25
|
-
shell: '/bin/bash'
|
26
|
-
end
|
27
|
-
|
28
|
-
let(:example_current_user) { root_user }
|
29
|
-
let(:example_target_user) { developer_user }
|
30
|
-
let(:example_developer_uid) { '1000' }
|
31
|
-
|
32
|
-
before do
|
33
|
-
allow(ENV).to receive(:fetch).with('DEVELOPER_UID', '') { example_developer_uid }
|
34
|
-
allow(Etc).to receive(:getpwuid) { example_current_user }
|
35
|
-
allow(Etc).to receive(:getpwuid).with(example_target_user.uid) { example_target_user }
|
36
|
-
allow(Kernel).to receive(:exec).with('su-exec', example_target_user.name, any_args)
|
37
|
-
end
|
38
|
-
|
39
|
-
describe '#perform' do
|
40
|
-
it 'changes to the target user' do
|
41
|
-
subject.perform
|
42
|
-
expect(Kernel).to have_received(:exec).with 'su-exec', example_target_user.name, any_args
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'without a developer uid' do
|
46
|
-
let(:example_developer_uid) { '' }
|
47
|
-
|
48
|
-
example 'does not change the current user' do
|
49
|
-
subject.perform
|
50
|
-
expect(Kernel).not_to have_received(:exec)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when not as root' do
|
55
|
-
let(:example_current_user) { developer_user }
|
56
|
-
|
57
|
-
example 'does not change the current user' do
|
58
|
-
subject.perform
|
59
|
-
expect(Kernel).not_to have_received(:exec)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|