Defined Type: cassandra::schema::user
- Defined in:
- manifests/schema/user.pp
Overview
Create or drop users.
To use this class, a suitable authenticator
(e.g. PasswordAuthenticator)
must be set in the Cassandra class.
19 20 21 22 23 24 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'manifests/schema/user.pp', line 19
define cassandra::schema::user (
$ensure = present,
$login = true,
$password = undef,
$superuser = false,
$user_name = $title,
){
include 'cassandra::schema'
if $::cassandrarelease != undef {
if versioncmp($::cassandrarelease, '2.2') < 0 {
$operate_with_roles = false
} else {
$operate_with_roles = true
}
} else {
$operate_with_roles = false
}
if $operate_with_roles {
$read_script = 'LIST ROLES'
} else {
$read_script = 'LIST USERS'
}
$read_command = "${::cassandra::schema::cqlsh_opts} -e \"${read_script}\" ${::cassandra::schema::cqlsh_conn} | grep '\s*${user_name} |'"
if $ensure == present {
if $operate_with_roles {
# we are running cassandra > 2.2
$create_script1 = "CREATE ROLE IF NOT EXISTS ${user_name}"
if $password != undef {
$create_script2 = "${create_script1} WITH PASSWORD = '${password}'"
} else {
$create_script2 = $create_script1
}
if $superuser {
if $password != undef {
$create_script3 = "${create_script2} AND SUPERUSER = true"
} else {
$create_script3 = "${create_script2} WITH SUPERUSER = true"
}
} else {
$create_script3 = $create_script2
}
if $login {
if $superuser or $password != undef {
$create_script = "${create_script3} AND LOGIN = true"
}
else {
$create_script = "${create_script3} WITH LOGIN = true"
}
} else {
$create_script = $create_script3
}
} else {
$create_script1 = "CREATE USER IF NOT EXISTS ${user_name}"
if $password != undef {
$create_script2 = "${create_script1} WITH PASSWORD '${password}'"
} else {
$create_script2 = $create_script1
}
if $superuser {
$create_script = "${create_script2} SUPERUSER"
} else {
$create_script = "${create_script2} NOSUPERUSER"
}
}
$create_command = "${::cassandra::schema::cqlsh_opts} -e \"${create_script}\" ${::cassandra::schema::cqlsh_conn}"
exec { "Create user (${user_name})":
command => $create_command,
unless => $read_command,
require => Exec['::cassandra::schema connection test'],
}
} elsif $ensure == absent {
if $operate_with_roles {
$delete_script = "DROP ROLE ${user_name}"
} else {
$delete_script = "DROP USER ${user_name}"
}
$delete_command = "${::cassandra::schema::cqlsh_opts} -e \"${delete_script}\" ${::cassandra::schema::cqlsh_conn}"
exec { "Delete user (${user_name})":
command => $delete_command,
onlyif => $read_command,
require => Exec['::cassandra::schema connection test'],
}
} else {
fail("Unknown action (${ensure}) for ensure attribute.")
}
}
|