Puppet Function: cd4peadm::parse_license
- Defined in:
-
lib/puppet/functions/cd4peadm/parse_license.rb
- Function type:
- Ruby 4.x API
Overview
cd4peadm::parse_license(String[1] $license_text) ⇒ Hash
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
|
# File 'lib/puppet/functions/cd4peadm/parse_license.rb', line 4
Puppet::Functions.create_function(:'cd4peadm::parse_license') do
dispatch('validate_license') do
param 'String[1]', :license_text
return_type 'Hash'
end
LICENSE_REGEX = /\A-----BEGIN LICENSE FILE-----(.*)-----END LICENSE FILE-----\Z/m
def validate_license(license_text)
match = LICENSE_REGEX.match(license_text)
if match
begin
no_newlines = match[1].gsub(/\n/, '')
decoded_contents = Base64.strict_decode64(no_newlines)
outer_json = JSON.parse(decoded_contents)
encoded_license_data = outer_json['enc']
if encoded_license_data.nil?
raise 'Invalid license: encoded license data missing'
end
decoded_license_data = Base64.strict_decode64(encoded_license_data)
license_data = JSON.parse(decoded_license_data)
rescue Exception => e
raise "Invalid license: #{e.message}"
end
else
raise 'License is not in the correct format'
end
end
end
|