Defined Type: keycloak::partial_import

Defined in:
manifests/partial_import.pp

Summary

Perform partialImport using CLI

Overview

Examples:

Perform partial import

keycloak::partial_import { 'mysettings':
  realm              => 'test',
  if_resource_exists => 'SKIP',
  source             => 'puppet:///modules/profile/keycloak/mysettings.json',
}

Parameters:

  • realm (String[1])

    The Keycloak Realm

  • if_resource_exists (Enum['FAIL','SKIP','OVERWRITE'])

    Behavior for when resources exist

  • source (Optional[Variant[Stdlib::Filesource, Stdlib::HTTPSUrl]]) (defaults to: undef)

    The import JSON source

  • content (Optional[String[1]]) (defaults to: undef)

    The import JSON content

  • filename (String[1]) (defaults to: $name)

    The filename of the stored JSON

  • require_realm (Boolean) (defaults to: true)

    Determines whether to require the Keycloak_realm resource

  • create_realm (Boolean) (defaults to: false)

    Determines whether to define the Keycloak_realm resource



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}"],
    }
  }
}