-
Notifications
You must be signed in to change notification settings - Fork 21
FM-2298 and FM-2299 update Login and User to take hash of permissions #79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# === Defined Parser Function: sqlserver_validate_hash_uniq_values | ||
# | ||
# [args*] A hash, that contains string or string[] for values | ||
# | ||
# @raise [Puppet::ParserError] When duplicates are found | ||
# | ||
module Puppet::Parser::Functions | ||
newfunction(:sqlserver_validate_hash_uniq_values) do |arguments| | ||
|
||
raise(Puppet::ParseError, 'Expect a Hash as an argument') unless arguments[0].is_a?(Hash) | ||
|
||
value = arguments[0].each_value.collect { |v| v }.flatten | ||
|
||
total_count = value.count | ||
uniq_count = value.uniq.count | ||
msg = arguments[1] ? arguments[1] : "Duplicate values passed to hash #{value}" | ||
if uniq_count != total_count | ||
raise(Puppet::ParseError, msg) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ | |
# @see http://technet.microsoft.com/en-us/library/ms189751(v=sql.110).aspx Create Login | ||
# @see http://technet.microsoft.com/en-us/library/ms189828(v=sql.110).aspx Alter Login | ||
# | ||
# [permissions] | ||
# A hash of permissions that should be managed for the login. Valid keys are 'GRANT', 'GRANT_WITH_OPTION', 'DENY' or 'REVOKE'. Valid values must be an array of Strings i.e. {'GRANT' => ['CONNECT SQL', 'CREATE ANY DATABASE'] } | ||
# | ||
## | ||
define sqlserver::login ( | ||
$login = $title, | ||
$instance = 'MSSQLSERVER', | ||
|
@@ -57,6 +61,7 @@ | |
$check_expiration = false, | ||
$check_policy = true, | ||
$disabled = false, | ||
$permissions = { }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parameter not added to in-file docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
) { | ||
|
||
sqlserver_validate_instance_name($instance) | ||
|
@@ -67,15 +72,52 @@ | |
fail ('Can not have check expiration enabled when check_policy is disabled') | ||
} | ||
|
||
$create_delete = $ensure ? { | ||
$_create_delete = $ensure ? { | ||
present => 'create', | ||
absent => 'delete', | ||
} | ||
|
||
sqlserver_tsql{ "login-${instance}-${login}": | ||
instance => $instance, | ||
command => template("sqlserver/${create_delete}/login.sql.erb"), | ||
command => template("sqlserver/${_create_delete}/login.sql.erb"), | ||
onlyif => template('sqlserver/query/login_exists.sql.erb'), | ||
require => Sqlserver::Config[$instance] | ||
} | ||
|
||
if $ensure == present { | ||
validate_hash($permissions) | ||
$_upermissions = sqlserver_upcase($permissions) | ||
sqlserver_validate_hash_uniq_values($_upermissions, "Duplicate permissions found for sqlserver::login[${title}]") | ||
|
||
Sqlserver::Login::Permissions{ | ||
login => $login, | ||
instance => $instance, | ||
require => Sqlserver_tsql["login-${instance}-${login}"] | ||
} | ||
if has_key($_upermissions, 'GRANT') and is_array($_upermissions['GRANT']) { | ||
sqlserver::login::permissions{ "Sqlserver::Login[${title}]-GRANT-${login}": | ||
state => 'GRANT', | ||
permissions => $_upermissions['GRANT'], | ||
} | ||
} | ||
if has_key($_upermissions, 'DENY') and is_array($_upermissions['DENY']) { | ||
sqlserver::login::permissions{ "Sqlserver::Login[${title}]-DENY-${login}": | ||
state => 'DENY', | ||
permissions => $_upermissions['DENY'], | ||
} | ||
} | ||
if has_key($_upermissions, 'REVOKE') and is_array($_upermissions['REVOKE']) { | ||
sqlserver::login::permissions{ "Sqlserver::Login[${title}]-REVOKE-${login}": | ||
state => 'REVOKE', | ||
permissions => $_upermissions['REVOKE'], | ||
} | ||
} | ||
if has_key($_upermissions, 'GRANT_WITH_OPTION') and is_array($_upermissions['GRANT_WITH_OPTION']) { | ||
sqlserver::login::permissions{ "Sqlserver::Login[${title}]-GRANT-WITH_GRANT_OPTION-${login}": | ||
state => 'GRANT', | ||
with_grant_option => true, | ||
permissions => $_upermissions['GRANT_WITH_OPTION'], | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## | ||
# == Define Resource Type: sqlserver::login::permission# | ||
# == Define Resource Type: sqlserver::login::permissions# | ||
# | ||
# === Requirement/Dependencies: | ||
# | ||
|
@@ -20,7 +20,7 @@ | |
# The name of the instance where the user and database exists. Defaults to 'MSSQLSERVER' | ||
# | ||
## | ||
define sqlserver::login::permission ( | ||
define sqlserver::login::permissions ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this intentionally backwards incompatible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, unreleased, and b/c it takes arrays now and roles::permissions as well, wanted to ensure same pattern. |
||
$login, | ||
$permissions, | ||
$state = 'GRANT', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,9 @@ | |
# [password] | ||
# The password for the user, can only be used when the database is a contained database. | ||
# | ||
# [permissions] | ||
# A hash of permissions that should be managed for the user. Valid keys are 'GRANT', 'GRANT_WITH_OPTION', 'DENY' or 'REVOKE'. Valid values must be an array of Strings i.e. {'GRANT' => ['SELECT', 'INSERT'] } | ||
# | ||
## | ||
define sqlserver::user ( | ||
$database, | ||
|
@@ -43,6 +46,7 @@ | |
$instance = 'MSSQLSERVER', | ||
$login = undef, | ||
$password = undef, | ||
$permissions = { }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. parameter not added to in-file docs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
) | ||
{ | ||
sqlserver_validate_instance_name($instance) | ||
|
@@ -69,4 +73,41 @@ | |
require => Sqlserver::Config[$instance] | ||
} | ||
|
||
if $ensure == present { | ||
validate_hash($permissions) | ||
$_upermissions = sqlserver_upcase($permissions) | ||
sqlserver_validate_hash_uniq_values($_upermissions, "Duplicate permissions found for sqlserver::user[${title}]") | ||
|
||
Sqlserver::User::Permissions{ | ||
user => $user, | ||
database => $database, | ||
instance => $instance, | ||
require => Sqlserver_tsql["user-${instance}-${database}-${user}"] | ||
} | ||
if has_key($_upermissions, 'GRANT') and is_array($_upermissions['GRANT']) { | ||
sqlserver::user::permissions{ "Sqlserver::User[${title}]-GRANT-${user}": | ||
state => 'GRANT', | ||
permissions => $_upermissions['GRANT'], | ||
} | ||
} | ||
if has_key($_upermissions, 'DENY') and is_array($_upermissions['DENY']) { | ||
sqlserver::user::permissions{ "Sqlserver::User[${title}]-DENY-${user}": | ||
state => 'DENY', | ||
permissions => $_upermissions['DENY'], | ||
} | ||
} | ||
if has_key($_upermissions, 'REVOKE') and is_array($_upermissions['REVOKE']) { | ||
sqlserver::user::permissions{ "Sqlserver::User[${title}]-REVOKE-${user}": | ||
state => 'REVOKE', | ||
permissions => $_upermissions['REVOKE'], | ||
} | ||
} | ||
if has_key($_upermissions, 'GRANT_WITH_OPTION') and is_array($_upermissions['GRANT_WITH_OPTION']) { | ||
sqlserver::user::permissions{ "Sqlserver::User[${title}]-GRANT-WITH_GRANT_OPTION-${user}": | ||
state => 'GRANT', | ||
with_grant_option => true, | ||
permissions => $_upermissions['GRANT_WITH_OPTION'], | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
## | ||
# == Define Resource Type: sqlserver::user::permission# | ||
# == Define Resource Type: sqlserver::user::permissions | ||
# | ||
# === Requirement/Dependencies: | ||
# | ||
|
@@ -26,7 +26,7 @@ | |
# The name of the instance where the user and database exists. Defaults to 'MSSQLSERVER' | ||
# | ||
## | ||
define sqlserver::user::permission ( | ||
define sqlserver::user::permissions ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, backwards incompat There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unreleased pattern matching to sqlserver::role::permissions |
||
$user, | ||
$database, | ||
$permissions, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing in-code docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking something more like the standard for functions: https://github.com/puppetlabs/puppetlabs-stdlib/blob/master/lib/puppet/parser/functions/abs.rb#L6-L9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is the same pattern we have in all the other functions for sqlserver however. At that point we would either to redo all of them or have inconsistency. This one also works with Yardocs to generate documentation with puppet-strings.