HEX
Server: Apache
System: Linux server.enlacediseno.com 4.18.0-553.62.1.el8_10.x86_64 #1 SMP Wed Jul 16 04:08:25 EDT 2025 x86_64
User: maor (1069)
PHP: 7.3.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //var/lib/puppet/lib/puppet/type/hdssh_authorized_key.rb
module Puppet
	newtype(:hdssh_authorized_key) do
		@doc = "Manages SSH authorized keys. Currently only type 2 keys are
		supported.
		
		**Autorequires:** If Puppet is managing the user account in which this 
		SSH key should be installed, the `hdssh_authorized_key` resource will autorequire
		that user."

		#Abuse ensurable. It 'doesn't exist' if it is incorrect, and it is 'created' if we need to make a change
		ensurable

		newparam(:name) do
			desc "The SSH key comment. This attribute is currently used as a
			system-wide primary key and therefore has to be unique."

			isnamevar

			validate do |value|
				raise Puppet::Error, "Resourcename must not contain whitespace: #{value}" if value =~ /\s/
			end
		end

		newparam(:user) do
			desc "The user account in which the SSH key should be installed.
			The resource will automatically depend on this user."
		end

		newproperty(:target) do
			desc "The absolute filename in which to store the SSH key. This
			property is optional and should only be used in cases where keys
			are stored in a non-standard location (i.e.` not in
			`~user/.ssh/authorized_keys`)."

			defaultto :absent

			def should
				return super if defined?(@should) and @should[0] != :absent

				return nil unless user = resource[:user]

				begin
					return File.expand_path("~#{user}/.ssh/authorized_keys")
				rescue
					Puppet.debug "The required user is not yet present on the system"
					return nil
				end
			end

			def insync?(is)
#				is == should
				true
			end
		end

		newparam(:present, :array_matching => :all) do
                        desc "Key options, see sshd(8) for possible values. Multiple values should be specified as an array."

			validate do |value|
				raise Puppet::Error, "Options must be provided as an array, not a comma separated list" if value != :absent and value.include?(',')
			end
			def should_to_s(value)
				return value.join("\n")
			end
		end

		#We need to have a property that changes (or at least can return false from insync), and absent seems as good as any
		newproperty(:absent, :array_matching => :all) do
                        desc "Key options, see sshd(8) for possible values. Multiple values should be specified as an array."

			defaultto []

			validate do |value|
				raise Puppet::Error, "Options must be provided as an array, not a comma separated list" if value != :absent and value.include?(',')
			end
			def should_to_s(value)
				#This gets reallllly long in the logs, and is pretty useless to us. We just need to know that the blank key list got added
				return "ABSENT KEY LIST"
			end
			def insync?(is)
				true
			end
		end

		newparam(:purge) do
                        desc "Key options, see sshd(8) for possible values. Multiple values should be specified as an array."

			defaultto :false 
			newvalues(:false, :true)
		end

		autorequire(:user) do
			should(:user) if should(:user)
		end

		validate do
			# Go ahead if target attribute is defined
			return if @parameters[:target].shouldorig[0] != :absent

			# Go ahead if user attribute is defined
			return if @parameters.include?(:user)

			# If neither target nor user is defined, this is an error
			raise Puppet::Error, "Attribute 'user' or 'target' is mandatory"
		end
	end
end