nub 0.0.128 → 0.0.132
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 +4 -4
- data/lib/nub/config.rb +24 -18
- data/lib/nub/user.rb +5 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6716e8061fc1229e2f09ee178f5de3a7f393fc4813293eacb47212a51e6fc066
|
4
|
+
data.tar.gz: 41b6d8ade5c092f30bfac71f476d8391dfaad58c1e738519eff525fc6fcc9362
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d699b969b580355a1ca0c6a5000a311d6aebe25e99ec42f7fb775cfeed48f335db762e7e13d57f1800b2e5c85f69b7d3a6d265fc7f5f3b1c9c1dded884b26d53
|
7
|
+
data.tar.gz: 77f0c05ccf459386ff39a6d274a4d11ae212a1ff88483ee601d4ecf731da10bebd0c7f10f6f7672f3244795e9a3bfbb2586599d282e9102279a362ebe0deccfe
|
data/lib/nub/config.rb
CHANGED
@@ -22,19 +22,19 @@
|
|
22
22
|
require 'yaml'
|
23
23
|
require 'colorize'
|
24
24
|
|
25
|
-
require_relative 'user'
|
26
25
|
require_relative 'log'
|
26
|
+
require_relative 'user'
|
27
|
+
require_relative 'module'
|
27
28
|
|
28
29
|
# Simple YAML configuration for an application.
|
29
30
|
# Uses singleton pattern for single source of truth
|
30
31
|
module Config
|
31
32
|
extend self
|
32
|
-
|
33
|
+
mattr_accessor(:path, :yml)
|
33
34
|
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
end
|
35
|
+
# Defaults
|
36
|
+
@@yml = {}
|
37
|
+
@@path = ""
|
38
38
|
|
39
39
|
# Singleton new alternate
|
40
40
|
# @param config [String] name or path of the config file
|
@@ -42,46 +42,52 @@ module Config
|
|
42
42
|
|
43
43
|
# Determine caller's file path to look for sidecar config
|
44
44
|
caller_path = caller_locations(1, 1).first.path
|
45
|
-
|
46
|
-
if !File.exists?(
|
47
|
-
|
45
|
+
@@path = File.expand_path(File.join(File.dirname(caller_path), config))
|
46
|
+
if !File.exists?(@@path)
|
47
|
+
@@path = "/home/#{User.name}/.config/#{config.split('/').first}"
|
48
48
|
end
|
49
49
|
|
50
50
|
# Open the config file or create in memory yml
|
51
51
|
begin
|
52
|
-
@@
|
52
|
+
@@yml = File.exists?(@@path) ? YAML.load_file(@@path) : {}
|
53
53
|
rescue Exception => e
|
54
54
|
Log.die(e)
|
55
55
|
end
|
56
56
|
|
57
|
-
return
|
57
|
+
return Config
|
58
|
+
end
|
59
|
+
|
60
|
+
# Set back to defaults read for init again
|
61
|
+
def reset
|
62
|
+
self.yml = {}
|
63
|
+
self.path = ""
|
58
64
|
end
|
59
65
|
|
60
66
|
# Simple bool whether the config exists or not on disk
|
61
67
|
def exists?
|
62
|
-
return File.exists?(
|
68
|
+
return File.exists?(@@path)
|
63
69
|
end
|
64
70
|
|
65
71
|
# Hash like getter
|
66
72
|
def [](key)
|
67
|
-
return @@
|
73
|
+
return @@yml[key]
|
68
74
|
end
|
69
75
|
|
70
76
|
# Hash like setter
|
71
77
|
def []=(key, val)
|
72
|
-
return @@
|
78
|
+
return @@yml[key] = val
|
73
79
|
end
|
74
80
|
|
75
81
|
# Get the given key and raise an error if it doesn't exist
|
76
82
|
def get!(key)
|
77
|
-
Log.die("couldn't find '#{key}' in config") if !@@
|
78
|
-
return @@
|
83
|
+
Log.die("couldn't find '#{key}' in config") if !@@yml.key?(key)
|
84
|
+
return @@yml[key]
|
79
85
|
end
|
80
86
|
|
81
87
|
# Save the config file
|
82
88
|
def save
|
83
|
-
return unless @@
|
84
|
-
File.open(
|
89
|
+
return unless @@yml
|
90
|
+
File.open(@@path, 'w', 0600){|f| f.write(@@yml.to_yaml)}
|
85
91
|
end
|
86
92
|
end
|
87
93
|
|
data/lib/nub/user.rb
CHANGED
@@ -28,16 +28,15 @@ module User
|
|
28
28
|
|
29
29
|
# Drop root privileges to original user
|
30
30
|
# Only affects ruby commands not system commands
|
31
|
-
#
|
32
|
-
# +returns+:: uid, gid of prior user
|
31
|
+
# @returns [uid, gid] of root user
|
33
32
|
def drop_privileges()
|
34
33
|
uid = gid = nil
|
35
34
|
|
36
35
|
if Process.uid.zero?
|
37
36
|
uid, gid = Process.uid, Process.gid
|
38
37
|
sudo_uid, sudo_gid = ENV['SUDO_UID'].to_i, ENV['SUDO_GID'].to_i
|
39
|
-
Process::Sys.
|
40
|
-
Process::Sys.
|
38
|
+
Process::Sys.seteuid(sudo_uid)
|
39
|
+
Process::Sys.setegid(sudo_gid)
|
41
40
|
end
|
42
41
|
|
43
42
|
return uid, gid
|
@@ -45,9 +44,8 @@ module User
|
|
45
44
|
|
46
45
|
# Raise privileges if dropped earlier
|
47
46
|
# Only affects ruby commands not system commands
|
48
|
-
#
|
49
|
-
#
|
50
|
-
# +gid+:: gid of user to assume
|
47
|
+
# @param uid [String] uid of user to assume
|
48
|
+
# @param gid [String] gid of user to assume
|
51
49
|
def raise_privileges(uid, gid)
|
52
50
|
if uid and gid
|
53
51
|
Process::Sys.seteuid(uid)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.132
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Crummett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|