-
Notifications
You must be signed in to change notification settings - Fork 657
/
Copy pathnats_auth_config.rb
59 lines (55 loc) · 1.63 KB
/
nats_auth_config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module NATSSync
class NatsAuthConfig
def initialize(vms, director_subject, hm_subject)
@vms = vms
@hm_subject = hm_subject
@director_subject = director_subject
@config = { 'authorization' =>
{ 'users' => [] } }
end
def director_user
{
'user' => @director_subject,
'permissions' => {
'publish' => %w[agent.* hm.director.alert],
'subscribe' => ['director.>'],
},
}
end
def hm_user
{
'user' => @hm_subject,
'permissions' => {
'publish' => [],
'subscribe' => %w[hm.agent.heartbeat.* hm.agent.alert.* hm.agent.shutdown.* hm.director.alert],
},
}
end
def agent_user(agent_id, cn)
{
'user' => "C=USA, O=Cloud Foundry, CN=#{cn}.agent.bosh-internal",
'permissions' => {
'publish' => [
"hm.agent.heartbeat.#{agent_id}",
"hm.agent.alert.#{agent_id}",
"hm.agent.shutdown.#{agent_id}",
"director.*.#{agent_id}.*",
],
"subscribe": ["agent.#{agent_id}"],
},
}
end
def create_config
@config['authorization']['users'] << director_user unless @director_subject.nil?
@config['authorization']['users'] << hm_user unless @hm_subject.nil?
@vms.each do |vm|
agent_id = vm['agent_id']
if !vm['permanent_nats_credentials']
@config['authorization']['users'] << agent_user(agent_id, agent_id + '.bootstrap')
end
@config['authorization']['users'] << agent_user(agent_id, agent_id)
end
@config
end
end
end