bolt 0.23.0 → 0.24.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bolt might be problematic. Click here for more details.

Files changed (192) hide show
  1. checksums.yaml +4 -4
  2. data/bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb +5 -2
  3. data/bolt-modules/boltlib/lib/puppet/functions/puppetdb_query.rb +5 -1
  4. data/bolt-modules/boltlib/lib/puppet/functions/run_task.rb +5 -8
  5. data/lib/bolt/applicator.rb +11 -8
  6. data/lib/bolt/boltdir.rb +13 -5
  7. data/lib/bolt/catalog.rb +22 -47
  8. data/lib/bolt/config.rb +1 -26
  9. data/lib/bolt/executor.rb +1 -1
  10. data/lib/bolt/outputter.rb +0 -9
  11. data/lib/bolt/outputter/human.rb +29 -14
  12. data/lib/bolt/outputter/json.rb +12 -1
  13. data/lib/bolt/pal.rb +12 -10
  14. data/lib/bolt/target.rb +0 -6
  15. data/lib/bolt/task.rb +53 -10
  16. data/lib/bolt/transport/base.rb +1 -6
  17. data/lib/bolt/transport/local.rb +11 -13
  18. data/lib/bolt/transport/local/shell.rb +2 -2
  19. data/lib/bolt/transport/ssh.rb +16 -11
  20. data/lib/bolt/transport/winrm.rb +8 -11
  21. data/lib/bolt/version.rb +1 -1
  22. data/lib/bolt_ext/schemas/task.json +12 -5
  23. data/libexec/apply_catalog.rb +3 -1
  24. data/libexec/bolt_catalog +4 -0
  25. data/vendored/puppet/lib/puppet.rb +2 -1
  26. data/vendored/puppet/lib/puppet/application/agent.rb +2 -6
  27. data/vendored/puppet/lib/puppet/application/apply.rb +100 -60
  28. data/vendored/puppet/lib/puppet/application/cert.rb +26 -291
  29. data/vendored/puppet/lib/puppet/application/device.rb +0 -5
  30. data/vendored/puppet/lib/puppet/application/lookup.rb +1 -1
  31. data/vendored/puppet/lib/puppet/application/ssl.rb +133 -0
  32. data/vendored/puppet/lib/puppet/application_support.rb +1 -2
  33. data/vendored/puppet/lib/puppet/configurer.rb +34 -50
  34. data/vendored/puppet/lib/puppet/configurer/downloader.rb +1 -1
  35. data/vendored/puppet/lib/puppet/configurer/plugin_handler.rb +1 -1
  36. data/vendored/puppet/lib/puppet/daemon.rb +1 -1
  37. data/vendored/puppet/lib/puppet/defaults.rb +40 -117
  38. data/vendored/puppet/lib/puppet/face/epp.rb +2 -2
  39. data/vendored/puppet/lib/puppet/face/help.rb +21 -7
  40. data/vendored/puppet/lib/puppet/face/node/clean.rb +14 -10
  41. data/vendored/puppet/lib/puppet/feature/base.rb +7 -23
  42. data/vendored/puppet/lib/puppet/feature/eventlog.rb +1 -1
  43. data/vendored/puppet/lib/puppet/file_serving/base.rb +2 -2
  44. data/vendored/puppet/lib/puppet/file_serving/fileset.rb +1 -1
  45. data/vendored/puppet/lib/puppet/file_serving/metadata.rb +2 -2
  46. data/vendored/puppet/lib/puppet/functions.rb +133 -0
  47. data/vendored/puppet/lib/puppet/functions/eyaml_lookup_key.rb +4 -5
  48. data/vendored/puppet/lib/puppet/functions/filter.rb +7 -6
  49. data/vendored/puppet/lib/puppet/functions/new.rb +37 -53
  50. data/vendored/puppet/lib/puppet/functions/warning.rb +1 -1
  51. data/vendored/puppet/lib/puppet/functions/yaml_data.rb +4 -5
  52. data/vendored/puppet/lib/puppet/gettext/config.rb +1 -1
  53. data/vendored/puppet/lib/puppet/graph.rb +0 -2
  54. data/vendored/puppet/lib/puppet/indirector/catalog/json.rb +14 -3
  55. data/vendored/puppet/lib/puppet/indirector/catalog/yaml.rb +0 -16
  56. data/vendored/puppet/lib/puppet/indirector/certificate/file.rb +0 -1
  57. data/vendored/puppet/lib/puppet/indirector/facts/yaml.rb +4 -2
  58. data/vendored/puppet/lib/puppet/indirector/key/file.rb +1 -6
  59. data/vendored/puppet/lib/puppet/indirector/node/exec.rb +1 -3
  60. data/vendored/puppet/lib/puppet/indirector/node/yaml.rb +0 -6
  61. data/vendored/puppet/lib/puppet/indirector/request.rb +1 -1
  62. data/vendored/puppet/lib/puppet/indirector/ssl_file.rb +3 -44
  63. data/vendored/puppet/lib/puppet/indirector/yaml.rb +4 -4
  64. data/vendored/puppet/lib/puppet/info_service/task_information_service.rb +7 -3
  65. data/vendored/puppet/lib/puppet/loaders.rb +1 -0
  66. data/vendored/puppet/lib/puppet/module/task.rb +198 -29
  67. data/vendored/puppet/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  68. data/vendored/puppet/lib/puppet/network/format_support.rb +13 -8
  69. data/vendored/puppet/lib/puppet/network/formats.rb +93 -2
  70. data/vendored/puppet/lib/puppet/network/http/api/indirected_routes.rb +10 -3
  71. data/vendored/puppet/lib/puppet/node/facts.rb +11 -1
  72. data/vendored/puppet/lib/puppet/parser/catalog_compiler.rb +56 -0
  73. data/vendored/puppet/lib/puppet/parser/compiler.rb +3 -1
  74. data/vendored/puppet/lib/puppet/parser/functions.rb +3 -1
  75. data/vendored/puppet/lib/puppet/parser/functions/filter.rb +1 -1
  76. data/vendored/puppet/lib/puppet/parser/functions/generate.rb +1 -1
  77. data/vendored/puppet/lib/puppet/parser/functions/sprintf.rb +12 -1
  78. data/vendored/puppet/lib/puppet/parser/functions/tagged.rb +1 -4
  79. data/vendored/puppet/lib/puppet/parser/scope.rb +1 -1
  80. data/vendored/puppet/lib/puppet/parser/script_compiler.rb +7 -2
  81. data/vendored/puppet/lib/puppet/pops/evaluator/deferred_resolver.rb +5 -3
  82. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_converter.rb +23 -4
  83. data/vendored/puppet/lib/puppet/pops/evaluator/runtime3_support.rb +3 -4
  84. data/vendored/puppet/lib/puppet/pops/functions/dispatch.rb +4 -0
  85. data/vendored/puppet/lib/puppet/pops/issues.rb +8 -0
  86. data/vendored/puppet/lib/puppet/pops/loader/loader.rb +2 -2
  87. data/vendored/puppet/lib/puppet/pops/loader/loader_paths.rb +3 -1
  88. data/vendored/puppet/lib/puppet/pops/loader/module_loaders.rb +30 -9
  89. data/vendored/puppet/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +62 -0
  90. data/vendored/puppet/lib/puppet/pops/loader/static_loader.rb +0 -1
  91. data/vendored/puppet/lib/puppet/pops/loader/task_instantiator.rb +13 -70
  92. data/vendored/puppet/lib/puppet/pops/loaders.rb +19 -29
  93. data/vendored/puppet/lib/puppet/pops/lookup/hiera_config.rb +1 -1
  94. data/vendored/puppet/lib/puppet/pops/model/model_label_provider.rb +4 -1
  95. data/vendored/puppet/lib/puppet/pops/pcore.rb +10 -33
  96. data/vendored/puppet/lib/puppet/pops/serialization.rb +2 -0
  97. data/vendored/puppet/lib/puppet/pops/serialization/from_data_converter.rb +2 -1
  98. data/vendored/puppet/lib/puppet/pops/serialization/to_data_converter.rb +11 -3
  99. data/vendored/puppet/lib/puppet/pops/serialization/to_stringified_converter.rb +226 -0
  100. data/vendored/puppet/lib/puppet/pops/types/p_object_type.rb +3 -0
  101. data/vendored/puppet/lib/puppet/pops/validation/checker4_0.rb +97 -47
  102. data/vendored/puppet/lib/puppet/pops/validation/validator_factory_4_0.rb +7 -8
  103. data/vendored/puppet/lib/puppet/property/keyvalue.rb +70 -8
  104. data/vendored/puppet/lib/puppet/provider/aix_object.rb +483 -0
  105. data/vendored/puppet/lib/puppet/provider/file/windows.rb +1 -1
  106. data/vendored/puppet/lib/puppet/provider/group/aix.rb +51 -112
  107. data/vendored/puppet/lib/puppet/provider/package/gem.rb +1 -1
  108. data/vendored/puppet/lib/puppet/provider/package/pip.rb +1 -1
  109. data/vendored/puppet/lib/puppet/provider/package/puppet_gem.rb +1 -1
  110. data/vendored/puppet/lib/puppet/provider/package/rpm.rb +1 -1
  111. data/vendored/puppet/lib/puppet/provider/package/windows/package.rb +1 -1
  112. data/vendored/puppet/lib/puppet/provider/package/zypper.rb +1 -1
  113. data/vendored/puppet/lib/puppet/provider/service/systemd.rb +1 -1
  114. data/vendored/puppet/lib/puppet/provider/service/windows.rb +37 -40
  115. data/vendored/puppet/lib/puppet/provider/user/aix.rb +142 -254
  116. data/vendored/puppet/lib/puppet/resource.rb +20 -3
  117. data/vendored/puppet/lib/puppet/resource/catalog.rb +2 -12
  118. data/vendored/puppet/lib/puppet/rest/routes.rb +97 -34
  119. data/vendored/puppet/lib/puppet/settings.rb +1 -1
  120. data/vendored/puppet/lib/puppet/settings/file_setting.rb +1 -1
  121. data/vendored/puppet/lib/puppet/ssl/base.rb +1 -9
  122. data/vendored/puppet/lib/puppet/ssl/certificate_request.rb +1 -13
  123. data/vendored/puppet/lib/puppet/ssl/certificate_request_attributes.rb +1 -1
  124. data/vendored/puppet/lib/puppet/ssl/host.rb +114 -232
  125. data/vendored/puppet/lib/puppet/ssl/key.rb +1 -5
  126. data/vendored/puppet/lib/puppet/ssl/oids.rb +1 -1
  127. data/vendored/puppet/lib/puppet/test/test_helper.rb +0 -4
  128. data/vendored/puppet/lib/puppet/transaction/event.rb +3 -7
  129. data/vendored/puppet/lib/puppet/transaction/persistence.rb +1 -1
  130. data/vendored/puppet/lib/puppet/type/exec.rb +18 -16
  131. data/vendored/puppet/lib/puppet/type/file.rb +3 -3
  132. data/vendored/puppet/lib/puppet/type/file/source.rb +20 -7
  133. data/vendored/puppet/lib/puppet/type/group.rb +3 -5
  134. data/vendored/puppet/lib/puppet/type/notify.rb +1 -1
  135. data/vendored/puppet/lib/puppet/type/package.rb +2 -5
  136. data/vendored/puppet/lib/puppet/type/schedule.rb +1 -1
  137. data/vendored/puppet/lib/puppet/type/service.rb +3 -6
  138. data/vendored/puppet/lib/puppet/type/tidy.rb +1 -1
  139. data/vendored/puppet/lib/puppet/type/user.rb +13 -20
  140. data/vendored/puppet/lib/puppet/util.rb +8 -9
  141. data/vendored/puppet/lib/puppet/util/execution.rb +3 -3
  142. data/vendored/puppet/lib/puppet/util/feature.rb +61 -39
  143. data/vendored/puppet/lib/puppet/util/log/destinations.rb +1 -1
  144. data/vendored/puppet/lib/puppet/util/rdoc.rb +1 -1
  145. data/vendored/puppet/lib/puppet/util/run_mode.rb +1 -1
  146. data/vendored/puppet/lib/puppet/util/storage.rb +1 -1
  147. data/vendored/puppet/lib/puppet/util/suidmanager.rb +7 -5
  148. data/vendored/puppet/lib/puppet/util/tag_set.rb +1 -1
  149. data/vendored/puppet/lib/puppet/util/tagging.rb +1 -1
  150. data/vendored/puppet/lib/puppet/util/windows.rb +18 -2
  151. data/vendored/puppet/lib/puppet/util/windows/adsi.rb +154 -205
  152. data/vendored/puppet/lib/puppet/util/windows/service.rb +770 -0
  153. data/vendored/puppet/lib/puppet/util/yaml.rb +41 -5
  154. data/vendored/puppet/lib/puppet/version.rb +1 -1
  155. data/vendored/puppet/lib/puppet_pal.rb +280 -24
  156. metadata +8 -38
  157. data/lib/bolt/catalog/compiler.rb +0 -48
  158. data/lib/bolt/catalog/loaders.rb +0 -19
  159. data/vendored/puppet/lib/puppet/application/ca.rb +0 -11
  160. data/vendored/puppet/lib/puppet/application/certificate.rb +0 -17
  161. data/vendored/puppet/lib/puppet/application/certificate_request.rb +0 -7
  162. data/vendored/puppet/lib/puppet/application/certificate_revocation_list.rb +0 -7
  163. data/vendored/puppet/lib/puppet/face/ca.rb +0 -266
  164. data/vendored/puppet/lib/puppet/face/certificate.rb +0 -167
  165. data/vendored/puppet/lib/puppet/face/certificate_request.rb +0 -56
  166. data/vendored/puppet/lib/puppet/face/certificate_revocation_list.rb +0 -56
  167. data/vendored/puppet/lib/puppet/graph/random_prioritizer.rb +0 -16
  168. data/vendored/puppet/lib/puppet/graph/title_hash_prioritizer.rb +0 -16
  169. data/vendored/puppet/lib/puppet/indirector/certificate/ca.rb +0 -9
  170. data/vendored/puppet/lib/puppet/indirector/certificate/disabled_ca.rb +0 -22
  171. data/vendored/puppet/lib/puppet/indirector/certificate_request/ca.rb +0 -22
  172. data/vendored/puppet/lib/puppet/indirector/certificate_request/disabled_ca.rb +0 -22
  173. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/ca.rb +0 -8
  174. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/disabled_ca.rb +0 -22
  175. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/file.rb +0 -8
  176. data/vendored/puppet/lib/puppet/indirector/certificate_revocation_list/rest.rb +0 -11
  177. data/vendored/puppet/lib/puppet/indirector/certificate_status.rb +0 -4
  178. data/vendored/puppet/lib/puppet/indirector/certificate_status/file.rb +0 -91
  179. data/vendored/puppet/lib/puppet/indirector/certificate_status/rest.rb +0 -11
  180. data/vendored/puppet/lib/puppet/indirector/key/ca.rb +0 -16
  181. data/vendored/puppet/lib/puppet/indirector/key/disabled_ca.rb +0 -22
  182. data/vendored/puppet/lib/puppet/indirector/ldap.rb +0 -86
  183. data/vendored/puppet/lib/puppet/indirector/node/ldap.rb +0 -275
  184. data/vendored/puppet/lib/puppet/provider/aixobject.rb +0 -392
  185. data/vendored/puppet/lib/puppet/provider/cron/crontab.rb +0 -297
  186. data/vendored/puppet/lib/puppet/ssl/certificate_authority.rb +0 -475
  187. data/vendored/puppet/lib/puppet/ssl/certificate_authority/autosign_command.rb +0 -45
  188. data/vendored/puppet/lib/puppet/ssl/certificate_authority/interface.rb +0 -324
  189. data/vendored/puppet/lib/puppet/ssl/certificate_factory.rb +0 -219
  190. data/vendored/puppet/lib/puppet/ssl/certificate_revocation_list.rb +0 -111
  191. data/vendored/puppet/lib/puppet/ssl/inventory.rb +0 -55
  192. data/vendored/puppet/lib/puppet/type/cron.rb +0 -480
@@ -6,7 +6,7 @@ Puppet::Type.type(:file).provide :windows do
6
6
 
7
7
  include Puppet::Util::Warnings
8
8
 
9
- if Puppet.features.microsoft_windows?
9
+ if Puppet::Util::Platform.windows?
10
10
  require 'puppet/util/windows'
11
11
  include Puppet::Util::Windows::Security
12
12
  end
@@ -1,10 +1,6 @@
1
- #
2
1
  # Group Puppet provider for AIX. It uses standard commands to manage groups:
3
2
  # mkgroup, rmgroup, lsgroup, chgroup
4
- #
5
- # Author:: Hector Rivas Gandara <keymon@gmail.com>
6
- #
7
- require 'puppet/provider/aixobject'
3
+ require 'puppet/provider/aix_object'
8
4
 
9
5
  Puppet::Type.type(:group).provide :aix, :parent => Puppet::Provider::AixObject do
10
6
  desc "Group management for AIX."
@@ -13,131 +9,74 @@ Puppet::Type.type(:group).provide :aix, :parent => Puppet::Provider::AixObject d
13
9
  defaultfor :operatingsystem => :aix
14
10
  confine :operatingsystem => :aix
15
11
 
16
- # Provider features
17
- has_features :manages_aix_lam
18
- has_features :manages_members
19
-
20
12
  # Commands that manage the element
21
13
  commands :list => "/usr/sbin/lsgroup"
22
14
  commands :add => "/usr/bin/mkgroup"
23
15
  commands :delete => "/usr/sbin/rmgroup"
24
16
  commands :modify => "/usr/bin/chgroup"
25
17
 
26
- # Group attributes to ignore
27
- def self.attribute_ignore
28
- []
29
- end
30
-
31
- # AIX attributes to properties mapping.
32
- #
33
- # Valid attributes to be managed by this provider.
34
- # It is a list with of hash
35
- # :aix_attr AIX command attribute name
36
- # :puppet_prop Puppet property name
37
- # :to Method to adapt puppet property to aix command value. Optional.
38
- # :from Method to adapt aix command value to puppet property. Optional
39
- self.attribute_mapping = [
40
- #:name => :name,
41
- {:aix_attr => :id, :puppet_prop => :gid },
42
- {:aix_attr => :users, :puppet_prop => :members,
43
- :from => :users_from_attr},
44
- {:aix_attr => :attributes, :puppet_prop => :attributes},
45
- ]
46
-
47
- #--------------
48
- # Command definition
49
-
50
- # Return the IA module arguments based on the resource param ia_load_module
51
- def get_ia_module_args
52
- if @resource[:ia_load_module]
53
- ["-R", @resource[:ia_load_module].to_s]
54
- else
55
- []
56
- end
57
- end
58
-
59
- def lscmd(value=@resource[:name])
60
- [self.class.command(:list)] +
61
- self.get_ia_module_args +
62
- [ value]
63
- end
64
-
65
- def lsallcmd()
66
- lscmd("ALL")
67
- end
18
+ # Provider features
19
+ has_features :manages_aix_lam
20
+ has_features :manages_members
68
21
 
69
- def addcmd(extra_attrs = [])
70
- # Here we use the @resource.to_hash to get the list of provided parameters
71
- # Puppet does not call to self.<parameter>= method if it does not exists.
22
+ class << self
23
+ # Used by the AIX user provider. Returns a hash of:
24
+ # {
25
+ # :name => <group_name>,
26
+ # :gid => <gid>
27
+ # }
72
28
  #
73
- # It gets an extra list of arguments to add to the user.
74
- [self.class.command(:add) ] +
75
- self.get_ia_module_args +
76
- self.hash2args(@resource.to_hash) +
77
- extra_attrs + [@resource[:name]]
78
- end
79
-
80
- def modifycmd(hash = property_hash)
81
- args = self.hash2args(hash)
82
- return nil if args.empty?
83
-
84
- [self.class.command(:modify)] +
85
- self.get_ia_module_args +
86
- args + [@resource[:name]]
87
- end
29
+ # that matches the group, which can either be the group name or
30
+ # the gid. Takes an optional set of ia_module_args
31
+ def find(group, ia_module_args = [])
32
+ groups = list_all(ia_module_args)
33
+
34
+ id_property = mappings[:puppet_property][:id]
35
+
36
+ if group.is_a?(String)
37
+ # Find by name
38
+ group_hash = groups.find { |cur_group| cur_group[:name] == group }
39
+ else
40
+ # Find by gid
41
+ group_hash = groups.find do |cur_group|
42
+ id_property.convert_attribute_value(cur_group[:id]) == group
43
+ end
44
+ end
88
45
 
89
- def deletecmd
90
- [self.class.command(:delete)] +
91
- self.get_ia_module_args +
92
- [@resource[:name]]
93
- end
46
+ unless group_hash
47
+ raise ArgumentError, _("No AIX group exists with a group name or gid of %{group}!") % { group: group }
48
+ end
94
49
 
50
+ # Convert :id => :gid
51
+ id = group_hash.delete(:id)
52
+ group_hash[:gid] = id_property.convert_attribute_value(id)
95
53
 
96
- #--------------
97
- # Overwrite get_arguments to add the attributes' arguments
98
- def get_arguments(key, value, mapping, objectinfo)
99
- # In the case of attributes, return a list of key=value
100
- if key == :attributes
101
- unless value and value.is_a? Hash
102
- raise Puppet::Error, _("Attributes must be a list of pairs key=value on %{resource}[%{name}]") %
103
- { resource: @resource.class.name, name: @resource.name }
104
- end
105
- return value.select { |k,v| true }.map { |pair| pair.join("=") }
54
+ group_hash
106
55
  end
107
- super(key, value, mapping, objectinfo)
108
- end
109
56
 
110
- def filter_attributes(hash)
111
- # Return only not managed attributes.
112
- hash.select {
113
- |k,v| !self.class.attribute_mapping_from.include?(k) and
114
- !self.class.attribute_ignore.include?(k)
115
- }.inject({}) {
116
- |h, array| h[array[0]] = array[1]; h
117
- }
118
- end
57
+ # Define some Puppet Property => AIX Attribute (and vice versa)
58
+ # conversion functions here. This is so we can unit test them.
119
59
 
120
- def attributes
121
- filter_attributes(getosinfo(false))
122
- end
60
+ def members_to_users(members)
61
+ return members unless members.is_a?(Array)
62
+ members.join(',')
63
+ end
123
64
 
124
- def attributes=(attr_hash)
125
- #self.class.validate(param, value)
126
- param = :attributes
127
- cmd = modifycmd({param => filter_attributes(attr_hash)})
128
- if cmd
129
- begin
130
- execute(cmd)
131
- rescue Puppet::ExecutionFailure => detail
132
- raise Puppet::Error, _("Could not set %{param} on %{resource}[%{name}]: %{detail}") % { param: param, resource: @resource.class.name, name: @resource.name, detail: detail }, detail.backtrace
133
- end
65
+ def users_to_members(users)
66
+ users.split(',')
134
67
  end
135
68
  end
136
69
 
137
- # Force convert users it a list.
138
- def users_from_attr(value)
139
- (value.is_a? String) ? value.split(',') : value
140
- end
70
+ mapping puppet_property: :members,
71
+ aix_attribute: :users,
72
+ property_to_attribute: method(:members_to_users),
73
+ attribute_to_property: method(:users_to_members)
141
74
 
75
+ numeric_mapping puppet_property: :gid,
76
+ aix_attribute: :id
142
77
 
78
+ # Now that we have all of our mappings, let's go ahead and make
79
+ # the resource methods (property getters + setters for our mapped
80
+ # properties + a getter for the attributes property).
81
+ mk_resource_methods
143
82
  end
@@ -95,7 +95,7 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d
95
95
  def install(useversion = true)
96
96
  command = [command(:gemcmd), "install"]
97
97
  command += install_options if resource[:install_options]
98
- if Puppet.features.microsoft_windows?
98
+ if Puppet::Util::Platform.windows?
99
99
  version = resource[:ensure]
100
100
  command << "-v" << %Q["#{version}"] if (! resource[:ensure].is_a? Symbol) and useversion
101
101
  else
@@ -53,7 +53,7 @@ Puppet::Type.type(:package).provide :pip,
53
53
  end
54
54
 
55
55
  def self.cmd
56
- if Puppet.features.microsoft_windows?
56
+ if Puppet::Util::Platform.windows?
57
57
  ["pip.exe"]
58
58
  else
59
59
  ["pip", "pip-python"]
@@ -6,7 +6,7 @@ Puppet::Type.type(:package).provide :puppet_gem, :parent => :gem do
6
6
 
7
7
  has_feature :versionable, :install_options, :uninstall_options
8
8
 
9
- if Puppet.features.microsoft_windows?
9
+ if Puppet::Util::Platform.windows?
10
10
  # On windows, we put our ruby ahead of anything that already
11
11
  # existed on the system PATH. This means that we do not need to
12
12
  # sort out the absolute path.
@@ -325,7 +325,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
325
325
  r = s[ri+1,s.length]
326
326
  if arch = r.scan(ARCH_REGEX)[0]
327
327
  a = arch.gsub(/\./, '')
328
- r.gsub!(ARCH_REGEX, '')
328
+ r.gsub!(ARCH_REGEX, '')
329
329
  end
330
330
  else
331
331
  v = s
@@ -71,7 +71,7 @@ class Puppet::Provider::Package::Windows
71
71
 
72
72
  def self.replace_forward_slashes(value)
73
73
  if value.include?('/')
74
- value.gsub!('/', "\\")
74
+ value = value.gsub('/', "\\")
75
75
  Puppet.debug('Package source parameter contained /s - replaced with \\s')
76
76
  end
77
77
  value
@@ -1,4 +1,4 @@
1
- Puppet::Type.type(:package).provide :zypper, :parent => :rpm do
1
+ Puppet::Type.type(:package).provide :zypper, :parent => :rpm, :source => :rpm do
2
2
  desc "Support for SuSE `zypper` package manager. Found in SLES10sp2+ and SLES11.
3
3
 
4
4
  This provider supports the `install_options` attribute, which allows command-line flags to be passed to zypper.
@@ -19,7 +19,7 @@ Puppet::Type.type(:service).provide :systemd, :parent => :base do
19
19
  end
20
20
 
21
21
  defaultfor :osfamily => [:archlinux]
22
- defaultfor :osfamily => :redhat, :operatingsystemmajrelease => "7"
22
+ defaultfor :osfamily => :redhat, :operatingsystemmajrelease => ["7", "8"]
23
23
  defaultfor :osfamily => :redhat, :operatingsystem => :fedora
24
24
  defaultfor :osfamily => :suse
25
25
  defaultfor :osfamily => :coreos
@@ -16,54 +16,48 @@ Puppet::Type.type(:service).provide :windows, :parent => :service do
16
16
 
17
17
  has_feature :refreshable
18
18
 
19
- commands :net => 'net.exe'
20
-
21
19
  def enable
22
- w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_AUTO_START )
23
- raise Puppet::Error.new("Win32 service enable of #{@resource[:name]} failed" ) if( w32ss.nil? )
20
+ Puppet::Util::Windows::Service.set_startup_mode( @resource[:name], :SERVICE_AUTO_START )
24
21
  rescue => detail
25
- raise Puppet::Error.new("Cannot enable #{@resource[:name]}, error was: #{detail}", detail )
22
+ raise Puppet::Error.new(_("Cannot enable %{resource_name}, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
26
23
  end
27
24
 
28
25
  def disable
29
- w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DISABLED )
30
- raise Puppet::Error.new("Win32 service disable of #{@resource[:name]} failed" ) if( w32ss.nil? )
26
+ Puppet::Util::Windows::Service.set_startup_mode( @resource[:name], :SERVICE_DISABLED )
31
27
  rescue => detail
32
- raise Puppet::Error.new("Cannot disable #{@resource[:name]}, error was: #{detail}", detail )
28
+ raise Puppet::Error.new(_("Cannot disable %{resource_name}, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
33
29
  end
34
30
 
35
31
  def manual_start
36
- w32ss = Win32::Service.configure( 'service_name' => @resource[:name], 'start_type' => Win32::Service::SERVICE_DEMAND_START )
37
- raise Puppet::Error.new("Win32 service manual enable of #{@resource[:name]} failed" ) if( w32ss.nil? )
32
+ Puppet::Util::Windows::Service.set_startup_mode( @resource[:name], :SERVICE_DEMAND_START )
38
33
  rescue => detail
39
- raise Puppet::Error.new("Cannot enable #{@resource[:name]} for manual start, error was: #{detail}", detail )
34
+ raise Puppet::Error.new(_("Cannot enable %{resource_name} for manual start, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
40
35
  end
41
36
 
42
37
  def enabled?
43
- w32ss = Win32::Service.config_info( @resource[:name] )
44
- raise Puppet::Error.new("Win32 service query of #{@resource[:name]} failed" ) unless( !w32ss.nil? && w32ss.instance_of?( Struct::ServiceConfigInfo ) )
45
- debug("Service #{@resource[:name]} start type is #{w32ss.start_type}")
46
- case w32ss.start_type
47
- when Win32::Service.get_start_type(Win32::Service::SERVICE_AUTO_START),
48
- Win32::Service.get_start_type(Win32::Service::SERVICE_BOOT_START),
49
- Win32::Service.get_start_type(Win32::Service::SERVICE_SYSTEM_START)
38
+ start_type = Puppet::Util::Windows::Service.service_start_type(@resource[:name])
39
+ debug("Service #{@resource[:name]} start type is #{start_type}")
40
+ case start_type
41
+ when :SERVICE_AUTO_START,
42
+ :SERVICE_BOOT_START,
43
+ :SERVICE_SYSTEM_START
50
44
  :true
51
- when Win32::Service.get_start_type(Win32::Service::SERVICE_DEMAND_START)
45
+ when :SERVICE_DEMAND_START
52
46
  :manual
53
- when Win32::Service.get_start_type(Win32::Service::SERVICE_DISABLED)
47
+ when :SERVICE_DISABLED
54
48
  :false
55
49
  else
56
- raise Puppet::Error.new("Unknown start type: #{w32ss.start_type}")
50
+ raise Puppet::Error.new(_("Unknown start type: %{start_type}") % { start_type: start_type })
57
51
  end
58
52
  rescue => detail
59
- raise Puppet::Error.new("Cannot get start type for #{@resource[:name]}, error was: #{detail}", detail )
53
+ raise Puppet::Error.new(_("Cannot get start type %{resource_name}, error was: %{detail}") % { resource_name: @resource[:name], detail: detail }, detail )
60
54
  end
61
55
 
62
56
  def start
63
57
  if enabled? == :false
64
58
  # If disabled and not managing enable, respect disabled and fail.
65
59
  if @resource[:enable].nil?
66
- raise Puppet::Error, "Will not start disabled service #{@resource[:name]} without managing enable. Specify 'enable => false' to override."
60
+ raise Puppet::Error.new(_("Will not start disabled service %{resource_name} without managing enable. Specify 'enable => false' to override.") % { resource_name: @resource[:name] })
67
61
  # Otherwise start. If enable => false, we will later sync enable and
68
62
  # disable the service again.
69
63
  elsif @resource[:enable] == :true
@@ -72,35 +66,38 @@ Puppet::Type.type(:service).provide :windows, :parent => :service do
72
66
  manual_start
73
67
  end
74
68
  end
75
-
76
- net(:start, @resource[:name])
77
- rescue Puppet::ExecutionFailure => detail
78
- raise Puppet::Error.new("Cannot start #{@resource[:name]}, error was: #{detail}", detail )
69
+ Puppet::Util::Windows::Service.start(@resource[:name])
79
70
  end
80
71
 
81
72
  def stop
82
- net(:stop, @resource[:name])
83
- rescue Puppet::ExecutionFailure => detail
84
- raise Puppet::Error.new("Cannot stop #{@resource[:name]}, error was: #{detail}", detail )
73
+ Puppet::Util::Windows::Service.stop(@resource[:name])
85
74
  end
86
75
 
87
76
  def status
88
- w32ss = Win32::Service.status( @resource[:name] )
89
- raise Puppet::Error.new("Win32 service query of #{@resource[:name]} failed" ) unless( !w32ss.nil? && w32ss.instance_of?( Struct::ServiceStatus ) )
90
- state = case w32ss.current_state
91
- when "stopped", "pause pending", "stop pending", "paused" then :stopped
92
- when "running", "continue pending", "start pending" then :running
77
+ current_state = Puppet::Util::Windows::Service.service_state(@resource[:name])
78
+ state = case current_state
79
+ when :SERVICE_STOPPED,
80
+ :SERVICE_PAUSED,
81
+ :SERVICE_STOP_PENDING,
82
+ :SERVICE_PAUSE_PENDING
83
+ :stopped
84
+ when :SERVICE_RUNNING,
85
+ :SERVICE_CONTINUE_PENDING,
86
+ :SERVICE_START_PENDING
87
+ :running
93
88
  else
94
- raise Puppet::Error.new("Unknown service state '#{w32ss.current_state}' for service '#{@resource[:name]}'")
89
+ raise Puppet::Error.new(_("Unknown service state '%{current_state}' for service '%{resource_name}'") % { current_state: current_state, resource_name: @resource[:name] })
95
90
  end
96
- debug("Service #{@resource[:name]} is #{w32ss.current_state}")
91
+ debug("Service #{@resource[:name]} is #{current_state}")
97
92
  return state
98
- rescue => detail
99
- raise Puppet::Error.new("Cannot get status of #{@resource[:name]}, error was: #{detail}", detail )
100
93
  end
101
94
 
102
95
  # returns all providers for all existing services and startup state
103
96
  def self.instances
104
- Win32::Service.services.collect { |s| new(:name => s.service_name) }
97
+ services = []
98
+ Puppet::Util::Windows::Service.services.each do |service_name, _|
99
+ services.push(new(:name => service_name))
100
+ end
101
+ services
105
102
  end
106
103
  end
@@ -1,25 +1,21 @@
1
- #
2
1
  # User Puppet provider for AIX. It uses standard commands to manage users:
3
2
  # mkuser, rmuser, lsuser, chuser
4
3
  #
5
4
  # Notes:
6
5
  # - AIX users can have expiry date defined with minute granularity,
7
- # but puppet does not allow it. There is a ticket open for that (#5431)
6
+ # but Puppet does not allow it. There is a ticket open for that (#5431)
7
+ #
8
8
  # - AIX maximum password age is in WEEKs, not days
9
9
  #
10
10
  # See https://puppet.com/docs/puppet/latest/provider_development.html
11
11
  # for more information
12
- #
13
- # Author:: Hector Rivas Gandara <keymon@gmail.com>
14
- #
15
- require 'puppet/provider/aixobject'
12
+ require 'puppet/provider/aix_object'
16
13
  require 'tempfile'
17
14
  require 'date'
18
15
 
19
16
  Puppet::Type.type(:user).provide :aix, :parent => Puppet::Provider::AixObject do
20
17
  desc "User management for AIX."
21
18
 
22
- # This will the default provider for this platform
23
19
  defaultfor :operatingsystem => :aix
24
20
  confine :operatingsystem => :aix
25
21
 
@@ -29,7 +25,6 @@ Puppet::Type.type(:user).provide :aix, :parent => Puppet::Provider::AixObject do
29
25
  commands :delete => "/usr/sbin/rmuser"
30
26
  commands :modify => "/usr/bin/chuser"
31
27
 
32
- commands :lsgroup => "/usr/sbin/lsgroup"
33
28
  commands :chpasswd => "/bin/chpasswd"
34
29
 
35
30
  # Provider features
@@ -37,296 +32,189 @@ Puppet::Type.type(:user).provide :aix, :parent => Puppet::Provider::AixObject do
37
32
  has_features :manages_homedir, :manages_passwords, :manages_shell
38
33
  has_features :manages_expiry, :manages_password_age
39
34
 
40
- # Attribute verification (TODO)
41
- #verify :gid, "GID must be a string or int of a valid group" do |value|
42
- # value.is_a? String || value.is_a? Integer
43
- #end
44
- #
45
- #verify :groups, "Groups must be comma-separated" do |value|
46
- # value !~ /\s/
47
- #end
48
-
49
- # User attributes to ignore from AIX output.
50
- def self.attribute_ignore
51
- ["name"]
52
- end
53
-
54
- # AIX attributes to properties mapping.
55
- #
56
- # Valid attributes to be managed by this provider.
57
- # It is a list with of hash
58
- # :aix_attr AIX command attribute name
59
- # :puppet_prop Puppet property name
60
- # :to Method to adapt puppet property to aix command value. Optional.
61
- # :from Method to adapt aix command value to puppet property. Optional
62
- self.attribute_mapping = [
63
- {:aix_attr => :pgrp, :puppet_prop => :gid,
64
- :to => :gid_to_attr,
65
- :from => :gid_from_attr },
66
- {:aix_attr => :id, :puppet_prop => :uid},
67
- {:aix_attr => :groups, :puppet_prop => :groups},
68
- {:aix_attr => :home, :puppet_prop => :home},
69
- {:aix_attr => :shell, :puppet_prop => :shell},
70
- {:aix_attr => :expires, :puppet_prop => :expiry,
71
- :to => :expiry_to_attr,
72
- :from => :expiry_from_attr },
73
- {:aix_attr => :maxage, :puppet_prop => :password_max_age},
74
- {:aix_attr => :minage, :puppet_prop => :password_min_age},
75
- {:aix_attr => :pwdwarntime, :puppet_prop => :password_warn_days},
76
- {:aix_attr => :attributes, :puppet_prop => :attributes},
77
- { :aix_attr => :gecos, :puppet_prop => :comment },
78
- ]
79
-
80
- #--------------
81
- # Command definition
82
-
83
- # Return the IA module arguments based on the resource param ia_load_module
84
- def get_ia_module_args
85
- if @resource[:ia_load_module]
86
- ["-R", @resource[:ia_load_module].to_s]
87
- else
88
- []
35
+ class << self
36
+ def group_provider
37
+ @group_provider ||= Puppet::Type.type(:group).provider(:aix)
89
38
  end
90
- end
91
-
92
- # List groups and Ids
93
- def lsgroupscmd(value=@resource[:name])
94
- [command(:lsgroup)] +
95
- self.get_ia_module_args +
96
- ["-a", "id", value]
97
- end
98
39
 
99
- def lscmd(value=@resource[:name])
100
- [self.class.command(:list), "-c"] + self.get_ia_module_args + [ value]
101
- end
40
+ # Define some Puppet Property => AIX Attribute (and vice versa)
41
+ # conversion functions here.
102
42
 
103
- def lsallcmd()
104
- lscmd("ALL")
105
- end
43
+ def gid_to_pgrp(provider, gid)
44
+ group = group_provider.find(gid, provider.ia_module_args)
106
45
 
107
- def addcmd(extra_attrs = [])
108
- # Here we use the @resource.to_hash to get the list of provided parameters
109
- # Puppet does not call to self.<parameter>= method if it does not exists.
110
- #
111
- # It gets an extra list of arguments to add to the user.
112
- [self.class.command(:add)] + self.get_ia_module_args +
113
- self.hash2args(@resource.to_hash) +
114
- extra_attrs + [@resource[:name]]
115
- end
116
-
117
- # Get modify command. Set translate=false if no mapping must be used.
118
- # Needed for special properties like "attributes"
119
- def modifycmd(hash = property_hash)
120
- args = self.hash2args(hash)
121
- return nil if args.empty?
122
-
123
- [self.class.command(:modify)] + self.get_ia_module_args +
124
- args + [@resource[:name]]
125
- end
46
+ group[:name]
47
+ end
126
48
 
127
- def deletecmd
128
- [self.class.command(:delete)] + self.get_ia_module_args + [@resource[:name]]
129
- end
130
-
131
- #--------------
132
- # We overwrite the create function to change the password after creation.
133
- def create
134
- super
135
- # Reset the password if needed
136
- self.password = @resource[:password] if @resource[:password]
137
- end
49
+ def pgrp_to_gid(provider, pgrp)
50
+ group = group_provider.find(pgrp, provider.ia_module_args)
138
51
 
52
+ group[:gid]
53
+ end
139
54
 
140
- def get_arguments(key, value, mapping, objectinfo)
141
- # In the case of attributes, return a list of key=vlaue
142
- if key == :attributes
143
- unless value and value.is_a? Hash
144
- raise Puppet::Error, _("Attributes must be a list of pairs key=value on %{class_name}[%{resource_name}]") %
145
- { class_name: @resource.class.name, resource_name: @resource.name }
146
- end
147
- return value.map { |k,v| k.to_s.strip + "=" + v.to_s.strip}
55
+ def expiry_to_expires(expiry)
56
+ return '0' if expiry == "0000-00-00" || expiry.to_sym == :absent
57
+
58
+ DateTime.parse(expiry, "%Y-%m-%d %H:%M")
59
+ .strftime("%m%d%H%M%y")
148
60
  end
149
61
 
150
- super(key, value, mapping, objectinfo)
151
- end
62
+ def expires_to_expiry(provider, expires)
63
+ return :absent if expires == '0'
152
64
 
153
- # Get the groupname from its id
154
- def groupname_by_id(gid)
155
- groupname=nil
156
- execute(lsgroupscmd("ALL")).each_line { |entry|
157
- attrs = self.parse_attr_list(entry, nil)
158
- if attrs and attrs.include? :id and gid == attrs[:id].to_i
159
- groupname = entry.split(" ")[0]
65
+ unless (match_obj = /\A(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)\z/.match(expires))
66
+ #TRANSLATORS 'AIX' is the name of an operating system and should not be translated
67
+ Puppet.warning(_("Could not convert AIX expires date '%{expires}' on %{class_name}[%{resource_name}]") % { expires: expires, class_name: provider.resource.class.name, resource_name: provider.resource.name })
68
+ return :absent
160
69
  end
161
- }
162
- groupname
163
- end
164
-
165
- # Get the groupname from its id
166
- def groupid_by_name(groupname)
167
- attrs = self.parse_attr_list(execute(lsgroupscmd(groupname)).split("\n")[0], nil)
168
- attrs ? attrs[:id].to_i : nil
169
- end
170
70
 
171
- # Check that a group exists and is valid
172
- def verify_group(value)
173
- if value.is_a? Integer
174
- groupname = groupname_by_id(value)
175
- #TRANSLATORS 'AIX' is the name of the operating system and should not be translated
176
- raise ArgumentError, _("AIX group must be a valid existing group") unless groupname
177
- else
178
- #TRANSLATORS 'AIX' is the name of the operating system and should not be translated
179
- raise ArgumentError, _("AIX group must be a valid existing group") unless groupid_by_name(value)
180
- groupname = value
71
+ month, day, year = match_obj[1], match_obj[2], match_obj[-1]
72
+ return "20#{year}-#{month}-#{day}"
181
73
  end
182
- groupname
183
- end
184
-
185
- # The user's primary group. Can be specified numerically or by name.
186
- def gid_to_attr(value)
187
- verify_group(value)
188
- end
189
74
 
190
- # Get the group gid from its name
191
- def gid_from_attr(value)
192
- groupid_by_name(value)
193
- end
75
+ # We do some validation before-hand to ensure the value's an Array,
76
+ # a String, etc. in the property. This routine does a final check to
77
+ # ensure our value doesn't have whitespace before we convert it to
78
+ # an attribute.
79
+ def groups_to_groups(groups)
80
+ if groups =~ /\s/
81
+ raise ArgumentError, _("Invalid value %{groups}: Groups must be comma separated!") % { groups: groups }
82
+ end
194
83
 
195
- # The expiry date for this user. Must be provided in
196
- # a zero padded YYYY-MM-DD HH:MM format
197
- def expiry_to_attr(value)
198
- # For chuser the expires parameter is a 10-character string in the MMDDhhmmyy format
199
- # that is,"%m%d%H%M%y"
200
- newdate = '0'
201
- if value.is_a? String and value!="0000-00-00"
202
- d = DateTime.parse(value, "%Y-%m-%d %H:%M")
203
- newdate = d.strftime("%m%d%H%M%y")
84
+ groups
204
85
  end
205
- newdate
206
86
  end
207
87
 
208
- def expiry_from_attr(value)
209
- if value =~ /(..)(..)(..)(..)(..)/
210
- #d= DateTime.parse("20#{$5}-#{$1}-#{$2} #{$3}:#{$4}")
211
- #expiry_date = d.strftime("%Y-%m-%d %H:%M")
212
- #expiry_date = d.strftime("%Y-%m-%d")
213
- expiry_date = "20#{$5}-#{$1}-#{$2}"
214
- else
215
- unless value == '0'
216
- #TRANSLATORS 'AIX' is the name of an operating system and should not be translated
217
- Puppet.warn(_("Could not convert AIX expires date '%{value}' on %{class_name}[%{resource_name}]") %
218
- { value: value, class_name: @resource.class.name, resource_name: @resource.name })
219
- end
220
- expiry_date = :absent
88
+ mapping puppet_property: :comment,
89
+ aix_attribute: :gecos
90
+
91
+ mapping puppet_property: :expiry,
92
+ aix_attribute: :expires,
93
+ property_to_attribute: method(:expiry_to_expires),
94
+ attribute_to_property: method(:expires_to_expiry)
95
+
96
+ mapping puppet_property: :gid,
97
+ aix_attribute: :pgrp,
98
+ property_to_attribute: method(:gid_to_pgrp),
99
+ attribute_to_property: method(:pgrp_to_gid)
100
+
101
+ mapping puppet_property: :groups,
102
+ property_to_attribute: method(:groups_to_groups)
103
+
104
+ mapping puppet_property: :home
105
+ mapping puppet_property: :shell
106
+
107
+ numeric_mapping puppet_property: :uid,
108
+ aix_attribute: :id
109
+
110
+ numeric_mapping puppet_property: :password_max_age,
111
+ aix_attribute: :maxage
112
+
113
+ numeric_mapping puppet_property: :password_min_age,
114
+ aix_attribute: :minage
115
+
116
+ numeric_mapping puppet_property: :password_warn_days,
117
+ aix_attribute: :pwdwarntime
118
+
119
+ # Now that we have all of our mappings, let's go ahead and make
120
+ # the resource methods (property getters + setters for our mapped
121
+ # properties + a getter for the attributes property).
122
+ mk_resource_methods
123
+
124
+ # Helper function that parses the password from the given
125
+ # password filehandle. This is here to make testing easier
126
+ # for #password since we cannot configure Mocha to mock out
127
+ # a method and have it return a block's value, meaning we
128
+ # cannot test #password directly (not in a simple and obvious
129
+ # way, at least).
130
+ # @api private
131
+ def parse_password(f)
132
+ # From the docs, a user stanza is formatted as (newlines are explicitly
133
+ # stated here for clarity):
134
+ # <user>:\n
135
+ # <attribute1>=<value1>\n
136
+ # <attribute2>=<value2>\n
137
+ #
138
+ # First, find our user stanza
139
+ stanza = f.each_line.find { |line| line =~ /\A#{@resource[:name]}:/ }
140
+ return :absent unless stanza
141
+
142
+ # Now find the password line, if it exists. Note our call to each_line here
143
+ # will pick up right where we left off.
144
+ match_obj = nil
145
+ f.each_line.find do |line|
146
+ # Break if we find another user stanza. This means our user
147
+ # does not have a password.
148
+ break if line =~ /^\S+:$/
149
+
150
+ match_obj = /password = (\S+)/.match(line)
221
151
  end
222
- expiry_date
223
- end
152
+ return :absent unless match_obj
224
153
 
225
- def open_security_passwd
226
- # helper method for tests
227
- # AIX reference indicates this file is ASCII
228
- # https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.files/passwd_security.htm
229
- Puppet::FileSystem.open("/etc/security/passwd", nil, "r:ASCII")
154
+ match_obj[1]
230
155
  end
231
156
 
232
- #--------------------------------
233
- # Getter and Setter
234
- # When the provider is initialized, create getter/setter methods for each
235
- # property our resource type supports.
236
- # If setter or getter already defined it will not be overwritten
237
-
238
157
  #- **password**
239
158
  # The user's password, in whatever encrypted format the local machine
240
159
  # requires. Be sure to enclose any value that includes a dollar sign ($)
241
160
  # in single quotes ('). Requires features manages_passwords.
242
161
  #
243
- # Retrieve the password parsing directly the /etc/security/passwd
162
+ # Retrieve the password parsing the /etc/security/passwd file.
244
163
  def password
245
- password = :absent
246
- user = @resource[:name]
247
- f = open_security_passwd
248
- # Skip to the user
249
- f.each_line { |l| break if l =~ /^#{user}:\s*$/ }
250
- if ! f.eof?
251
- f.each_line { |l|
252
- # If there is a new user stanza, stop
253
- break if l =~ /^\S*:\s*$/
254
- # If the password= entry is found, return it, stripping trailing space
255
- if l =~ /^\s*password\s*=\s*(\S*)\s*$/
256
- password = $1; break;
257
- end
258
- }
164
+ # AIX reference indicates this file is ASCII
165
+ # https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.files/passwd_security.htm
166
+ Puppet::FileSystem.open("/etc/security/passwd", nil, "r:ASCII") do |f|
167
+ parse_password(f)
259
168
  end
260
- f.close()
261
- return password
262
169
  end
263
170
 
264
171
  def password=(value)
265
172
  user = @resource[:name]
266
173
 
267
- # Puppet execute does not support strings as input, only files.
268
- # The password is expected to be in an encrypted format given -e is specified:
269
- # https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.cmds1/chpasswd.htm
270
- # /etc/security/passwd is specified as an ASCII file per the AIX documentation
271
- tmpfile = Tempfile.new("puppet_#{user}_pw", :encoding => Encoding::ASCII)
272
- tmpfile << "#{user}:#{value}\n"
273
- tmpfile.close()
274
-
275
- # Options '-e', '-c', use encrypted password and clear flags
276
- # Must receive "user:enc_password" as input
277
- # command, arguments = {:failonfail => true, :combine => true}
278
- # Fix for bugs #11200 and #10915
279
- cmd = [self.class.command(:chpasswd), get_ia_module_args, '-e', '-c'].flatten
280
174
  begin
281
- output = execute(cmd, {:failonfail => false, :combine => true, :stdinfile => tmpfile.path })
282
- # chpasswd can return 1, even on success (at least on AIX 6.1); empty output indicates success
175
+ # Puppet execute does not support strings as input, only files.
176
+ # The password is expected to be in an encrypted format given -e is specified:
177
+ # https://www.ibm.com/support/knowledgecenter/ssw_aix_71/com.ibm.aix.cmds1/chpasswd.htm
178
+ # /etc/security/passwd is specified as an ASCII file per the AIX documentation
179
+ tempfile = nil
180
+ tempfile = Tempfile.new("puppet_#{user}_pw", :encoding => Encoding::ASCII)
181
+ tempfile << "#{user}:#{value}\n"
182
+ tempfile.close()
183
+
184
+ # Options '-e', '-c', use encrypted password and clear flags
185
+ # Must receive "user:enc_password" as input
186
+ # command, arguments = {:failonfail => true, :combine => true}
187
+ # Fix for bugs #11200 and #10915
188
+ cmd = [self.class.command(:chpasswd), *ia_module_args, '-e', '-c']
189
+ execute_options = {
190
+ :failonfail => false,
191
+ :combine => true,
192
+ :stdinfile => tempfile.path
193
+ }
194
+ output = execute(cmd, execute_options)
195
+
196
+ # chpasswd can return 1, even on success (at least on AIX 6.1); empty output
197
+ # indicates success
283
198
  if output != ""
284
199
  raise Puppet::ExecutionFailure, "chpasswd said #{output}"
285
200
  end
286
201
  rescue Puppet::ExecutionFailure => detail
287
- raise Puppet::Error, "Could not set #{param} on #{@resource.class.name}[#{@resource.name}]: #{detail}", detail.backtrace
202
+ raise Puppet::Error, "Could not set password on #{@resource.class.name}[#{@resource.name}]: #{detail}", detail.backtrace
288
203
  ensure
289
- tmpfile.delete()
204
+ if tempfile
205
+ # Extra close will noop. This is in case the write to our tempfile
206
+ # fails.
207
+ tempfile.close()
208
+ tempfile.delete()
209
+ end
290
210
  end
291
211
  end
292
212
 
293
- def managed_attribute_keys(hash)
294
- managed_attributes ||= @resource.original_parameters[:attributes] || hash.keys.map{|k| k.to_s}
295
- managed_attributes = [managed_attributes] unless managed_attributes.is_a?(Array)
296
- managed_attributes.map {|attr| key, _ = attr.split("="); key.strip.to_sym}
297
- end
298
-
299
- def should_include?(key, managed_keys)
300
- !self.class.attribute_mapping_from.include?(key) and
301
- !self.class.attribute_ignore.include?(key) and
302
- managed_keys.include?(key)
303
- end
304
-
305
- def filter_attributes(hash)
306
- # Return only managed attributes.
307
- managed_keys = managed_attribute_keys(hash)
308
- results = hash.select {
309
- |k,v| should_include?(k, managed_keys)
310
- }.inject({}) {
311
- |h, array| h[array[0]] = array[1]; h
312
- }
313
- results
314
- end
315
-
316
- def attributes
317
- filter_attributes(getosinfo(false))
318
- end
213
+ def create
214
+ super
319
215
 
320
- def attributes=(attr_hash)
321
- #self.class.validate(param, value)
322
- param = :attributes
323
- cmd = modifycmd({param => filter_attributes(attr_hash)})
324
- if cmd
325
- begin
326
- execute(cmd)
327
- rescue Puppet::ExecutionFailure => detail
328
- raise Puppet::Error, "Could not set #{param} on #{@resource.class.name}[#{@resource.name}]: #{detail}", detail.backtrace
329
- end
216
+ if (password = @resource.should(:password))
217
+ self.password = password
330
218
  end
331
219
  end
332
220