|
1 |
| -module Puppet |
2 |
| - newtype(:java_ks) do |
3 |
| - @doc = 'Manages the entries in a java keystore, and uses composite namevars to |
4 |
| - accomplish the same alias spread across multiple target keystores.' |
| 1 | +Puppet::Type.newtype(:java_ks) do |
| 2 | + @doc = 'Manages the entries in a java keystore, and uses composite namevars to |
| 3 | + accomplish the same alias spread across multiple target keystores.' |
5 | 4 |
|
6 |
| - ensurable do |
| 5 | + ensurable do |
7 | 6 |
|
8 |
| - desc 'Has three states: present, absent, and latest. Latest |
9 |
| - will compare the on disk MD5 fingerprint of the certificate and to that |
10 |
| - in keytool to determine if insync? returns true or false. We redefine |
11 |
| - insync? for this paramerter to accomplish this.' |
| 7 | + desc 'Has three states: present, absent, and latest. Latest |
| 8 | + will compare the on disk MD5 fingerprint of the certificate and to that |
| 9 | + in keytool to determine if insync? returns true or false. We redefine |
| 10 | + insync? for this paramerter to accomplish this.' |
12 | 11 |
|
13 |
| - newvalue(:present) do |
14 |
| - provider.create |
15 |
| - end |
| 12 | + newvalue(:present) do |
| 13 | + provider.create |
| 14 | + end |
16 | 15 |
|
17 |
| - newvalue(:absent) do |
18 |
| - provider.destroy |
19 |
| - end |
| 16 | + newvalue(:absent) do |
| 17 | + provider.destroy |
| 18 | + end |
20 | 19 |
|
21 |
| - newvalue(:latest) do |
22 |
| - if provider.exists? |
23 |
| - provider.update |
24 |
| - else |
25 |
| - provider.create |
26 |
| - end |
| 20 | + newvalue(:latest) do |
| 21 | + if provider.exists? |
| 22 | + provider.update |
| 23 | + else |
| 24 | + provider.create |
27 | 25 | end
|
| 26 | + end |
28 | 27 |
|
29 |
| - def insync?(is) |
30 |
| - |
31 |
| - @should.each do |should| |
32 |
| - case should |
33 |
| - when :present |
34 |
| - return true if is == :present |
35 |
| - when :absent |
36 |
| - return true if is == :absent |
37 |
| - when :latest |
38 |
| - unless is == :absent |
39 |
| - return true if provider.latest == provider.current |
40 |
| - end |
| 28 | + def insync?(is) |
| 29 | + |
| 30 | + @should.each do |should| |
| 31 | + case should |
| 32 | + when :present |
| 33 | + return true if is == :present |
| 34 | + when :absent |
| 35 | + return true if is == :absent |
| 36 | + when :latest |
| 37 | + unless is == :absent |
| 38 | + return true if provider.latest == provider.current |
41 | 39 | end
|
42 | 40 | end
|
43 |
| - |
44 |
| - return false |
45 | 41 | end
|
46 | 42 |
|
47 |
| - defaultto :present |
| 43 | + return false |
48 | 44 | end
|
49 | 45 |
|
50 |
| - newparam(:name) do |
51 |
| - desc 'The alias that is used to identify the entry in the keystore. This will be |
52 |
| - converted to lowercase.' |
| 46 | + defaultto :present |
| 47 | + end |
| 48 | + |
| 49 | + newparam(:name) do |
| 50 | + desc 'The alias that is used to identify the entry in the keystore. This will be |
| 51 | + converted to lowercase.' |
53 | 52 |
|
54 |
| - isnamevar |
| 53 | + isnamevar |
55 | 54 |
|
56 |
| - munge do |value| |
57 |
| - value.downcase |
58 |
| - end |
| 55 | + munge do |value| |
| 56 | + value.downcase |
59 | 57 | end
|
| 58 | + end |
60 | 59 |
|
61 |
| - newparam(:target) do |
62 |
| - desc 'Destination file for the keystore. This will autorequire the parent directory of the file.' |
| 60 | + newparam(:target) do |
| 61 | + desc 'Destination file for the keystore. This will autorequire the parent directory of the file.' |
63 | 62 |
|
64 |
| - isnamevar |
65 |
| - end |
| 63 | + isnamevar |
| 64 | + end |
66 | 65 |
|
67 |
| - newparam(:certificate) do |
68 |
| - desc 'An already signed certificate that we can place in the keystore. This will autorequire the specified file.' |
| 66 | + newparam(:certificate) do |
| 67 | + desc 'An already signed certificate that we can place in the keystore. This will autorequire the specified file.' |
69 | 68 |
|
70 |
| - isrequired |
71 |
| - end |
| 69 | + isrequired |
| 70 | + end |
72 | 71 |
|
73 |
| - newparam(:private_key) do |
74 |
| - desc 'If you want an application to be a server and encrypt traffic, |
75 |
| - you will need a private key. Private key entries in a keystore must be |
76 |
| - accompanied by a signed certificate for the keytool provider. This will autorequire the specified file.' |
77 |
| - end |
| 72 | + newparam(:private_key) do |
| 73 | + desc 'If you want an application to be a server and encrypt traffic, |
| 74 | + you will need a private key. Private key entries in a keystore must be |
| 75 | + accompanied by a signed certificate for the keytool provider. This will autorequire the specified file.' |
| 76 | + end |
78 | 77 |
|
79 |
| - newparam(:chain) do |
80 |
| - desc 'Some java applications do not properly send |
81 |
| - intermediary certificate authorities, in this case you can bundle them |
82 |
| - with the server certificate using chain. This will autorequire the specified file.' |
83 |
| - end |
| 78 | + newparam(:chain) do |
| 79 | + desc 'Some java applications do not properly send |
| 80 | + intermediary certificate authorities, in this case you can bundle them |
| 81 | + with the server certificate using chain. This will autorequire the specified file.' |
| 82 | + end |
84 | 83 |
|
85 |
| - newparam(:password) do |
86 |
| - desc 'The password used to protect the keystore. If private keys are |
87 |
| - subsequently also protected this password will be used to attempt |
88 |
| - unlocking. Must be six or more characters in length. Cannot be used |
89 |
| - together with :password_file, but you must pass at least one of these parameters.' |
| 84 | + newparam(:password) do |
| 85 | + desc 'The password used to protect the keystore. If private keys are |
| 86 | + subsequently also protected this password will be used to attempt |
| 87 | + unlocking. Must be six or more characters in length. Cannot be used |
| 88 | + together with :password_file, but you must pass at least one of these parameters.' |
90 | 89 |
|
91 |
| - validate do |value| |
92 |
| - raise Puppet::Error, "password is #{value.length} characters long; must be 6 characters or greater in length" if value.length < 6 |
93 |
| - end |
| 90 | + validate do |value| |
| 91 | + raise Puppet::Error, "password is #{value.length} characters long; must be 6 characters or greater in length" if value.length < 6 |
94 | 92 | end
|
| 93 | + end |
95 | 94 |
|
96 |
| - newparam(:password_file) do |
97 |
| - desc 'The path to a file containing the password used to protect the |
98 |
| - keystore. This cannot be used together with :password, but you must pass at least one of these parameters.' |
99 |
| - end |
| 95 | + newparam(:password_file) do |
| 96 | + desc 'The path to a file containing the password used to protect the |
| 97 | + keystore. This cannot be used together with :password, but you must pass at least one of these parameters.' |
| 98 | + end |
100 | 99 |
|
101 |
| - newparam(:trustcacerts) do |
102 |
| - desc "Certificate authorities aren't by default trusted so if you are adding a CA you need to set this to true. |
103 |
| - Defaults to :false." |
| 100 | + newparam(:trustcacerts) do |
| 101 | + desc "Certificate authorities aren't by default trusted so if you are adding a CA you need to set this to true. |
| 102 | + Defaults to :false." |
104 | 103 |
|
105 |
| - newvalues(:true, :false) |
| 104 | + newvalues(:true, :false) |
106 | 105 |
|
107 |
| - defaultto :false |
108 |
| - end |
| 106 | + defaultto :false |
| 107 | + end |
109 | 108 |
|
110 |
| - newparam(:path) do |
111 |
| - desc "The search path used for command (keytool, openssl) execution. |
112 |
| - Paths can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list." |
| 109 | + newparam(:path) do |
| 110 | + desc "The search path used for command (keytool, openssl) execution. |
| 111 | + Paths can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list." |
113 | 112 |
|
114 |
| - # Support both arrays and colon-separated fields. |
115 |
| - def value=(*values) |
116 |
| - @value = values.flatten.collect { |val| |
117 |
| - val.split(File::PATH_SEPARATOR) |
118 |
| - }.flatten |
119 |
| - end |
| 113 | + # Support both arrays and colon-separated fields. |
| 114 | + def value=(*values) |
| 115 | + @value = values.flatten.collect { |val| |
| 116 | + val.split(File::PATH_SEPARATOR) |
| 117 | + }.flatten |
120 | 118 | end
|
| 119 | + end |
121 | 120 |
|
122 |
| - # Where we setup autorequires. |
123 |
| - autorequire(:file) do |
124 |
| - auto_requires = [] |
125 |
| - [:private_key, :certificate, :chain].each do |param| |
126 |
| - if @parameters.include?(param) |
127 |
| - auto_requires << @parameters[param].value |
128 |
| - end |
| 121 | + # Where we setup autorequires. |
| 122 | + autorequire(:file) do |
| 123 | + auto_requires = [] |
| 124 | + [:private_key, :certificate, :chain].each do |param| |
| 125 | + if @parameters.include?(param) |
| 126 | + auto_requires << @parameters[param].value |
129 | 127 | end
|
130 |
| - if @parameters.include?(:target) |
131 |
| - auto_requires << ::File.dirname(@parameters[:target].value) |
132 |
| - end |
133 |
| - auto_requires |
134 | 128 | end
|
| 129 | + if @parameters.include?(:target) |
| 130 | + auto_requires << ::File.dirname(@parameters[:target].value) |
| 131 | + end |
| 132 | + auto_requires |
| 133 | + end |
135 | 134 |
|
136 |
| - # Our title_patterns method for mapping titles to namevars for supporting |
137 |
| - # composite namevars. |
138 |
| - def self.title_patterns |
139 |
| - identity = lambda {|x| x} |
| 135 | + # Our title_patterns method for mapping titles to namevars for supporting |
| 136 | + # composite namevars. |
| 137 | + def self.title_patterns |
| 138 | + identity = lambda {|x| x} |
| 139 | + [ |
140 | 140 | [
|
| 141 | + /^([^:]+)$/, |
141 | 142 | [
|
142 |
| - /^([^:]+)$/, |
143 |
| - [ |
144 |
| - [ :name, identity ] |
145 |
| - ] |
146 |
| - ], |
| 143 | + [ :name, identity ] |
| 144 | + ] |
| 145 | + ], |
| 146 | + [ |
| 147 | + /^(.*):(.*)$/, |
147 | 148 | [
|
148 |
| - /^(.*):(.*)$/, |
149 |
| - [ |
150 |
| - [ :name, identity ], |
151 |
| - [ :target, identity ] |
152 |
| - ] |
| 149 | + [ :name, identity ], |
| 150 | + [ :target, identity ] |
153 | 151 | ]
|
154 | 152 | ]
|
155 |
| - end |
| 153 | + ] |
| 154 | + end |
156 | 155 |
|
157 |
| - validate do |
158 |
| - if value(:password) and value(:password_file) |
159 |
| - self.fail "You must pass either 'password' or 'password_file', not both." |
160 |
| - end |
| 156 | + validate do |
| 157 | + if value(:password) and value(:password_file) |
| 158 | + self.fail "You must pass either 'password' or 'password_file', not both." |
| 159 | + end |
161 | 160 |
|
162 |
| - unless value(:password) or value(:password_file) |
163 |
| - self.fail "You must pass one of 'password' or 'password_file'." |
164 |
| - end |
| 161 | + unless value(:password) or value(:password_file) |
| 162 | + self.fail "You must pass one of 'password' or 'password_file'." |
165 | 163 | end
|
166 | 164 | end
|
167 | 165 | end
|
0 commit comments