-
Notifications
You must be signed in to change notification settings - Fork 5
/
casc.pp
67 lines (62 loc) · 1.86 KB
/
casc.pp
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
60
61
62
63
64
65
66
67
# deep merge w/ merge_hash_arrays is incapable of properly merging multiple
# `- credentails` array of hash elements under:
#
# credentials:
# system:
# domainCredentials:
# [- credentials:]
#
# as it converts `basicSSHUserPrivateKey` array elements to encapsulated in a
# hash IF they are not in the base hash but lower down in the hierachy. Yes,
# this seems crazy, having nested hashes does not appear to be the triggering
# condition nor not having a similar value to shadow from lower in the
# hierachy.
$casc = lookup({
name => 'jenkinsx::casc',
value_type => Hash[String, Any],
merge => {
strategy => 'deep',
merge_hash_arrays => false,
},
})
# helm jenkins chart values
$master = lookup({
name => 'jenkinsx::master',
value_type => Hash[String, Any],
merge => {
strategy => 'deep',
merge_hash_arrays => false,
},
})
if $casc {
if $casc['credentials'] and
$casc['credentials']['system'] and
$casc['credentials']['system']['domainCredentials'] {
$dom_creds = $casc['credentials']['system']['domainCredentials']
$merged_creds = $dom_creds.reduce([]) |Array $result, Hash $value| {
$result + $value['credentials']
}
$real_casc = $casc + {
credentials => {
system => {
domainCredentials => [ credentials => $merged_creds ],
},
}
}
} else {
$real_casc = $casc
}
$real_master = deep_merge($master, {
'master' => {
'JCasC' => {
'configScripts' => { '01-casc' => inline_template("<%- require 'yaml'-%><%= YAML.dump(@real_casc) %>") }
}
}
})
# debug -- WILL PRINT SECRETS
notice('merged config:')
notice(inline_template("<%- require 'yaml'-%><%= YAML.dump(@real_master) %>"))
file { "${::pwd}/jenkins.yaml":
content => inline_template("<%- require 'yaml'-%><%= YAML.dump(@real_master) %>"),
}
}