Module: OsCtld::SendReceive
- Extended by:
- OsCtl::Lib::Utils::File
- Defined in:
- lib/osctld/send_receive.rb
Defined Under Namespace
Modules: Commands
Classes: Command, KeyChain, Log, Server, Tokens
Constant Summary
collapse
- PROTOCOL_VERSION =
2
- USER =
'osctl-ct-receive'.freeze
- UID =
Etc.getpwnam(USER).uid
- SOCKET =
File.join(RunState::SEND_RECEIVE_DIR, 'control.sock')
- AUTHORIZED_KEYS =
File.join(RunState::SEND_RECEIVE_DIR, 'authorized_keys')
- HOOK =
File.join(RunState::SEND_RECEIVE_DIR, 'run')
- MUTEX =
Mutex.new
Class Method Summary
collapse
Class Method Details
.assets(add) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/osctld/send_receive.rb', line 50
def self.assets(add)
add.symlink(
HOOK,
desc: 'Command run by remote node'
)
add.file(
AUTHORIZED_KEYS,
desc: 'Keys that are authorized to send containers to this node',
user: UID,
group: 0,
mode: 0o400,
optional: true
)
Server.assets(add)
end
|
.deploy ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/osctld/send_receive.rb', line 30
def self.deploy
sync do
regenerate_file(AUTHORIZED_KEYS, 0o400) do |new, _old|
DB::Pools.get.each { |pool| pool.send_receive_key_chain.deploy(new) }
end
File.chown(UID, 0, AUTHORIZED_KEYS)
end
end
|
.protocol_error(version) ⇒ Object
83
84
85
86
87
88
89
|
# File 'lib/osctld/send_receive.rb', line 83
def self.protocol_error(version)
if version.nil?
"send/receive protocol version missing, expected #{PROTOCOL_VERSION}"
else
"unsupported send/receive protocol version #{version}, expected #{PROTOCOL_VERSION}"
end
end
|
.protocol_version ⇒ Object
75
76
77
|
# File 'lib/osctld/send_receive.rb', line 75
def self.protocol_version
PROTOCOL_VERSION
end
|
.setup ⇒ Object
20
21
22
23
24
|
# File 'lib/osctld/send_receive.rb', line 20
def self.setup
Server.start
replace_symlink(HOOK, OsCtld.hook_src('send-receive'))
end
|
.started_using_key(pool, name) ⇒ Object
40
41
42
|
# File 'lib/osctld/send_receive.rb', line 40
def self.started_using_key(pool, name)
pool.send_receive_key_chain.started_using_key(name)
end
|
.stop ⇒ Object
26
27
28
|
# File 'lib/osctld/send_receive.rb', line 26
def self.stop
Server.stop
end
|
.stopped_using_key(pool, name) ⇒ Object
44
45
46
47
48
|
# File 'lib/osctld/send_receive.rb', line 44
def self.stopped_using_key(pool, name)
sync do
deploy if pool.send_receive_key_chain.stopped_using_key(name)
end
end
|
.supported_protocol_version?(version) ⇒ Boolean
79
80
81
|
# File 'lib/osctld/send_receive.rb', line 79
def self.supported_protocol_version?(version)
version == PROTOCOL_VERSION
end
|
.sync ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/osctld/send_receive.rb', line 67
def self.sync(&)
if MUTEX.owned?
yield
else
MUTEX.synchronize(&)
end
end
|