Class: OsCtld::User
Instance Attribute Summary collapse
Instance Method Summary
collapse
#define_assets
#acquire_manipulation_lock, #init_manipulable, #is_being_manipulated?, #manipulate, #manipulated_by, #release_manipulation_lock
Methods included from Lockable
#exclusively, included, #inclusively, #init_lock, #lock, #unlock
Constructor Details
#initialize(pool, name, load: true, config: nil) ⇒ User
Returns a new instance of User.
17
18
19
20
21
22
23
24
|
# File 'lib/osctld/user.rb', line 17
def initialize(pool, name, load: true, config: nil)
init_lock
init_manipulable
@pool = pool
@name = name
@attrs = Attributes.new
load_config(config) if load
end
|
Instance Attribute Details
#attrs ⇒ Object
Returns the value of attribute attrs
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def attrs
@attrs
end
|
#gid_map ⇒ Object
Returns the value of attribute gid_map
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def gid_map
@gid_map
end
|
#name ⇒ Object
Returns the value of attribute name
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def name
@name
end
|
#pool ⇒ Object
Returns the value of attribute pool
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def pool
@pool
end
|
#registered=(value) ⇒ Object
Sets the attribute registered
15
16
17
|
# File 'lib/osctld/user.rb', line 15
def registered=(value)
@registered = value
end
|
#standalone ⇒ Object
Returns the value of attribute standalone
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def standalone
@standalone
end
|
#ugid ⇒ Object
Returns the value of attribute ugid
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def ugid
@ugid
end
|
#uid_map ⇒ Object
Returns the value of attribute uid_map
14
15
16
|
# File 'lib/osctld/user.rb', line 14
def uid_map
@uid_map
end
|
Instance Method Details
#assets ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/osctld/user.rb', line 49
def assets
define_assets do |add|
add.directory(
userdir,
desc: 'User directory',
user: 0,
group: ugid,
mode: 0o751
)
add.directory(
homedir,
desc: 'Home directory',
user: ugid,
group: ugid,
mode: 0o751
)
add.file(
config_path,
desc: "osctld's user config",
user: 0,
group: 0,
mode: 0o400
)
add.entry('/etc/passwd', desc: 'System user') do |asset|
asset.validate_block do
if /^#{Regexp.escape(sysusername)}:x:#{ugid}:#{ugid}:/ !~ File.read(asset.path)
asset.add_error('entry missing or invalid')
end
end
end
add.entry('/etc/group', desc: 'System group') do |asset|
asset.validate_block do
if /^#{Regexp.escape(sysgroupname)}:x:#{ugid}:$/ !~ File.read(asset.path)
asset.add_error('entry missing or invalid')
end
end
end
end
end
|
#config_path ⇒ Object
157
158
159
|
# File 'lib/osctld/user.rb', line 157
def config_path
inclusively { File.join(pool.conf_path, 'user', "#{name}.yml") }
end
|
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/osctld/user.rb', line 38
def configure(uid_map, gid_map, ugid: nil, standalone: true)
exclusively do
@ugid = ugid || UGidRegistry.get
@uid_map = uid_map
@gid_map = gid_map
@standalone = standalone
end
save_config
end
|
#containers ⇒ Object
168
169
170
171
172
|
# File 'lib/osctld/user.rb', line 168
def containers
DB::Containers.get do |cts|
cts.select { |ct| ct.user == self && ct.pool.name == pool.name }
end
end
|
#has_containers? ⇒ Boolean
161
162
163
164
165
166
|
# File 'lib/osctld/user.rb', line 161
def has_containers?
any_ct = DB::Containers.get.detect do |ct|
ct.user.name == name && ct.pool.name == pool.name
end
any_ct ? true : false
end
|
#homedir ⇒ Object
153
154
155
|
# File 'lib/osctld/user.rb', line 153
def homedir
File.join(userdir, '.home')
end
|
#id ⇒ Object
26
27
28
|
# File 'lib/osctld/user.rb', line 26
def id
name
end
|
#id_range_allocation_owner ⇒ Object
174
175
176
|
# File 'lib/osctld/user.rb', line 174
def id_range_allocation_owner
"user:#{name}"
end
|
#ident ⇒ Object
30
31
32
|
# File 'lib/osctld/user.rb', line 30
def ident
inclusively { "#{pool.name}:#{name}" }
end
|
#log_type ⇒ Object
178
179
180
|
# File 'lib/osctld/user.rb', line 178
def log_type
"user=#{ident}"
end
|
#manipulation_resource ⇒ Object
182
183
184
|
# File 'lib/osctld/user.rb', line 182
def manipulation_resource
['user', ident]
end
|
#registered? ⇒ Boolean
94
95
96
97
98
99
|
# File 'lib/osctld/user.rb', line 94
def registered?
inclusively { return registered unless registered.nil? }
v = SystemUsers.include?(sysusername)
exclusively { self.registered = v }
v
end
|
#set(opts) ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/osctld/user.rb', line 104
def set(opts)
opts.each do |k, v|
case k
when :standalone
exclusively { @standalone = true }
when :attrs
attrs.update(v)
else
raise "unsupported option '#{k}'"
end
end
save_config
end
|
#sysgroupname ⇒ Object
145
146
147
|
# File 'lib/osctld/user.rb', line 145
def sysgroupname
sysusername
end
|
#sysusername ⇒ Object
141
142
143
|
# File 'lib/osctld/user.rb', line 141
def sysusername
"#{pool.name}-#{name}"
end
|
#unset(opts) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/osctld/user.rb', line 124
def unset(opts)
opts.each do |k, v|
case k
when :standalone
exclusively { @standalone = false }
when :attrs
v.each { |attr| attrs.unset(attr) }
else
raise "unsupported option '#{k}'"
end
end
save_config
end
|
#userdir ⇒ Object
149
150
151
|
# File 'lib/osctld/user.rb', line 149
def userdir
inclusively { File.join(pool.user_dir, name) }
end
|