-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8c350a
commit 219562a
Showing
2 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require File.join(File.dirname(__FILE__), '../f5') | ||
require 'json' | ||
|
||
Puppet::Type.type(:f5_passwordpolicy).provide(:rest, parent: Puppet::Provider::F5) do | ||
mk_resource_methods | ||
|
||
def self.instances | ||
instances = [] | ||
instances << new(password_policy_properties) | ||
instances | ||
end | ||
|
||
def self.prefetch(resources) | ||
raise 'More than 1 f5_passwordpolicy resource in catalog' unless resources.size == 1 | ||
resource = resources.values[0] | ||
resource.provider = instances.first | ||
end | ||
|
||
def self.password_policy_properties | ||
properties = {} | ||
policy = Puppet::Provider::F5.call('/mgmt/tm/auth/password-policy') | ||
|
||
properties[:name] = '/Common/password-policy' | ||
%w[expirationWarning maxDuration maxLoginFailures minDuration minimumLength passwordMemory policyEnforcement requiredLowercase requiredNumeric requiredSpecial requiredUppercase].each do |property| | ||
properties[property.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase.to_sym] = policy[property] | ||
end | ||
properties[:provider] = :rest | ||
properties | ||
end | ||
|
||
def create_message(hash) | ||
# Create the message by stripping :ensure, :name and :provider. | ||
hash.reject do |k, _| | ||
[:ensure, :name, :provider, Puppet::Type.metaparams].flatten.include?(k) | ||
end | ||
end | ||
|
||
def message(object) | ||
# Allows us to pass in resources and get all the attributes out | ||
# in the form of a hash. | ||
message = object.to_hash | ||
|
||
# Map for conversion in the message. | ||
map = { | ||
} | ||
|
||
message = strip_nil_values(message) | ||
message = convert_underscores(message) | ||
message = rename_keys(map, message) | ||
message = create_message(message) | ||
message = string_to_integer(message) | ||
|
||
message.to_json | ||
end | ||
|
||
def flush | ||
begin | ||
Puppet::Provider::F5.put('/mgmt/tm/auth/password-policy/', | ||
message(@property_hash)) | ||
rescue StandardError => e | ||
# Something went wrong. | ||
@property_hash = self.class.password_policy_properties | ||
raise e | ||
end | ||
@property_hash = self.class.password_policy_properties | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
Puppet::Type.newtype(:f5_passwordpolicy) do | ||
@doc = 'Sets the password policy on the BIG-IP system.' | ||
|
||
apply_to_device if Facter.value(:url).nil? | ||
|
||
newparam(:name, namevar: true) do | ||
end | ||
|
||
newproperty(:expiration_warning) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:max_duration) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:max_login_failures) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:min_duration) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:minimum_length) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:password_memory) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:policy_enforcement) do | ||
munge do |value| | ||
value = value.downcase if value.respond_to? :downcase | ||
|
||
case value | ||
when true, 'true', 'enabled' | ||
'enabled' | ||
when false, 'false', 'disabled' | ||
'disabled' | ||
else | ||
raise ArgumentError, 'expected a boolean value, \'enabled\' or \'disabled\'' | ||
end | ||
end | ||
end | ||
|
||
newproperty(:required_lowercase) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:required_numeric) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:required_special) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
|
||
newproperty(:required_uppercase) do | ||
newvalues(/^\d+$/) | ||
munge { |value| Integer(value) } | ||
end | ||
end |