25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'manifests/partial_import.pp', line 25
define keycloak::partial_import (
String[1] $realm,
Enum['FAIL','SKIP','OVERWRITE'] $if_resource_exists,
Optional[Variant[Stdlib::Filesource, Stdlib::HTTPSUrl]] $source = undef,
Optional[String[1]] $content = undef,
String[1] $filename = $name,
Boolean $require_realm = true,
Boolean $create_realm = false,
) {
include keycloak
if ! $source and ! $content {
fail("keycloak::partial_import[${name}] must specify either source or content")
}
if $source and $content {
fail("keycloak::partial_import[${name}] specify either source or content, not both")
}
$file_path = "${keycloak::conf_dir}/${filename}.json"
$command = join([
"${keycloak::wrapper_path} create partialImport",
"-r ${realm} -s ifResourceExists=${if_resource_exists} -o",
"-f ${file_path}",
], ' ')
file { $file_path:
ensure => 'file',
owner => $keycloak::user,
group => $keycloak::group,
mode => '0600',
source => $source,
content => $content,
require => Class['keycloak::install'],
notify => Exec["partial-import-${name}"],
}
exec { "partial-import-${name}":
path => '/usr/bin:/bin:/usr/sbin:/sbin',
command => "${command} || { rm -f ${file_path}; exit 1; }",
logoutput => true,
refreshonly => true,
require => Keycloak_conn_validator['keycloak'],
}
if $require_realm {
Keycloak_realm[$realm] -> Exec["partial-import-${name}"]
}
if $create_realm {
keycloak_realm { $realm:
ensure => 'present',
before => Exec["partial-import-${name}"],
}
}
}
|