From 8084063b0db10061ef89e22628ec2bd090639ac7 Mon Sep 17 00:00:00 2001 From: David Swan Date: Wed, 9 Jan 2019 09:50:02 +0000 Subject: [PATCH 1/2] (MODULES-8193) - Wrapper methods created for inbuilt 4.x functions These were created to bridge the gap between the 4.x and 3.x functions and account for the difference in their naming. --- REFERENCE.md | 160 ++++++++++++++---- lib/puppet/functions/mysql/password.rb | 3 +- lib/puppet/functions/mysql/strip_hash.rb | 3 + lib/puppet/functions/mysql_password.rb | 21 +++ lib/puppet/functions/mysql_strip_hash.rb | 21 +++ spec/functions/mysql_password_wrapper_spec.rb | 28 +++ .../mysql_strip_hash_wrapper_spec.rb | 28 +++ 7 files changed, 229 insertions(+), 35 deletions(-) create mode 100644 lib/puppet/functions/mysql_password.rb create mode 100644 lib/puppet/functions/mysql_strip_hash.rb create mode 100644 spec/functions/mysql_password_wrapper_spec.rb create mode 100644 spec/functions/mysql_strip_hash_wrapper_spec.rb diff --git a/REFERENCE.md b/REFERENCE.md index fe4c2c3ac..4a3e3dc54 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1,9 +1,11 @@ # Reference -## Classes +## Table of Contents + +**Classes** -### Public Classes +_Public Classes_ * [`mysql::bindings`](#mysqlbindings): Parent class for MySQL bindings. * [`mysql::client`](#mysqlclient): Installs and configures the MySQL client. @@ -12,7 +14,7 @@ * [`mysql::server::monitor`](#mysqlservermonitor): This is a helper class to add a monitoring user to the database * [`mysql::server::mysqltuner`](#mysqlservermysqltuner): Manage the MySQLTuner package. -### Private Classes +_Private Classes_ * `mysql::backup::mysqlbackup`: Manage the mysqlbackup client. * `mysql::backup::mysqldump`: "Provider" for mysqldump @@ -35,31 +37,35 @@ * `mysql::server::root_password`: Private class for managing the root password * `mysql::server::service`: Private class for managing the MySQL service -## Defined types +**Defined types** * [`mysql::db`](#mysqldb): Create and configure a MySQL database. -## Resource types +**Resource types** -### Public Resource types +_Public Resource types_ * [`mysql_plugin`](#mysql_plugin): Manage MySQL plugins. -### Private Resource types +_Private Resource types_ * `mysql_database`: Manage a MySQL database. * `mysql_datadir`: Manage MySQL datadirs with mysql_install_db OR mysqld (5.7.6 and above). * `mysql_grant`: Manage a MySQL user's rights. * `mysql_user`: Manage a MySQL user. This includes management of users password as well as privileges. -## Functions +**Functions** -* [`mysql_deepmerge`](#mysql_deepmerge): Recursively merges two or more hashes together and returns the resulting hash. -* [`mysql_dirname`](#mysql_dirname): Returns the dirname of a path +* [`mysql::password`](#mysqlpassword): Hash a string as mysql's "PASSWORD()" function would do it +* [`mysql::strip_hash`](#mysqlstrip_hash): When given a hash this function strips out all blank entries. +* [`mysql_password`](#mysql_password): A wrapper for the 4.x function 'mysql::password' to bridge the gap between + it and the 3.x function 'mysql_password'. * [`mysql_password`](#mysql_password): Hash a string as mysql's "PASSWORD()" function would do it +* [`mysql_strip_hash`](#mysql_strip_hash): A wrapper for the 4.x function 'mysql::strip_hash' to bridge the gap between + it and the 3.x function 'mysql_strip_hash'. * [`mysql_strip_hash`](#mysql_strip_hash): TEMPORARY FUNCTION: EXPIRES 2014-03-10 When given a hash this function strips out all blank entries. -## Tasks +**Tasks** * [`export`](#export): Allows you to backup your database to local file. * [`sql`](#sql): Allows you to execute arbitary SQL @@ -616,6 +622,22 @@ This parameter no longer does anything. It exists only for backwards compatibili Default value: `undef` +##### `create_root_login_file` + +Data type: `Any` + + + +Default value: $mysql::params::create_root_login_file + +##### `login_file` + +Data type: `Any` + + + +Default value: $mysql::params::login_file + ### mysql::server::backup Create and manage a MySQL backup. @@ -811,7 +833,7 @@ Default value: '1M' Data type: `Any` -Specifies an array of optional arguments which should be passed through to the backup tool. (Currently only supported by the xtrabackup provider.) +Specifies an array of optional arguments which should be passed through to the backup tool. (Supported by the xtrabackup and mysqldump providers.) Default value: [] @@ -879,13 +901,13 @@ Source path for the mysqltuner package. Default value: `undef` -##### `environment` +##### `tuner_location` Data type: `Any` -Environment variables active during download, e.g. to download via proxies: environment => 'https_proxy=http://proxy.example.com:80' +Destination for the mysqltuner package. -Default value: `undef` +Default value: '/usr/local/bin/mysqltuner' ## Defined types @@ -922,6 +944,14 @@ Data type: `Any` The password for $user for the database you're creating. +##### `tls_options` + +Data type: `Any` + +The tls_options for $user for the database you're creating. + +Default value: `undef` + ##### `dbname` Data type: `Any` @@ -962,6 +992,14 @@ The privileges to be granted for user@host on the database. Default value: 'ALL' +##### `grant_options` + +Data type: `Any` + +The grant_options for the grant for user@host on the database. + +Default value: `undef` + ##### `sql` Data type: `Optional[Variant[Array, Hash, String]]` @@ -1002,6 +1040,14 @@ Command to read the sqlfile for importing the database. Useful for compressed sq Default value: 'cat' +##### `mysql_exec_path` + +Data type: `Any` + + + +Default value: $mysql::params::exec_path + ## Resource types ### mysql_plugin @@ -1048,39 +1094,63 @@ The name of the MySQL plugin to manage. ## Functions -### mysql_deepmerge +### mysql::password -Type: Ruby 3.x API +Type: Ruby 4.x API -- When there is a duplicate key that is a hash, they are recursively merged. -- When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." -- When there are conficting uses of dashes and underscores in two keys (which mysql would otherwise equate), - the rightmost style will win. +Hash a string as mysql's "PASSWORD()" function would do it -#### `mysql_deepmerge()` +#### `mysql::password(String $password)` -- When there is a duplicate key that is a hash, they are recursively merged. -- When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." -- When there are conficting uses of dashes and underscores in two keys (which mysql would otherwise equate), - the rightmost style will win. +The mysql::password function. -Returns: `Hash` +Returns: `String` hash +The mysql password hash from the clear text password. -### mysql_dirname +##### `password` -Type: Ruby 3.x API +Data type: `String` + +Plain text password. + +### mysql::strip_hash + +Type: Ruby 4.x API + +When given a hash this function strips out all blank entries. + +#### `mysql::strip_hash(Hash $hash)` + +The mysql::strip_hash function. + +Returns: `Hash` hash +The given hash with all blank entries removed + +##### `hash` + +Data type: `Hash` + +Hash to be stripped -Returns the dirname of a path +### mysql_password + +Type: Ruby 4.x API -#### `mysql_dirname(String $path)` +A wrapper for the 4.x function 'mysql::password' to bridge the gap between + it and the 3.x function 'mysql_password'. -Returns: `String` Directory name of path. +#### `mysql_password(String $password)` -##### `path` +The mysql_password function. + +Returns: `String` hash +The mysql password hash from the 4.x function mysql::password. + +##### `password` Data type: `String` -Path to find the dirname for. +Plain text password. ### mysql_password @@ -1090,6 +1160,8 @@ Hash a string as mysql's "PASSWORD()" function would do it #### `mysql_password(String $password)` +The mysql_password function. + Returns: `String` the mysql password hash from the clear text password. ##### `password` @@ -1100,6 +1172,26 @@ Plain text password. ### mysql_strip_hash +Type: Ruby 4.x API + +A wrapper for the 4.x function 'mysql::strip_hash' to bridge the gap between + it and the 3.x function 'mysql_strip_hash'. + +#### `mysql_strip_hash(Hash $hash)` + +The mysql_strip_hash function. + +Returns: `Hash` hash +The given hash with all blank entries removed + +##### `hash` + +Data type: `Hash` + +Hash to be stripped + +### mysql_strip_hash + Type: Ruby 3.x API TEMPORARY FUNCTION: EXPIRES 2014-03-10 diff --git a/lib/puppet/functions/mysql/password.rb b/lib/puppet/functions/mysql/password.rb index 24d1cc5b1..4a8db82cf 100644 --- a/lib/puppet/functions/mysql/password.rb +++ b/lib/puppet/functions/mysql/password.rb @@ -6,7 +6,8 @@ # @param password # Plain text password. # - # @return the mysql password hash from the clear text password. + # @return hash + # The mysql password hash from the clear text password. # dispatch :password do required_param 'String', :password diff --git a/lib/puppet/functions/mysql/strip_hash.rb b/lib/puppet/functions/mysql/strip_hash.rb index 90a74e686..2efe26301 100644 --- a/lib/puppet/functions/mysql/strip_hash.rb +++ b/lib/puppet/functions/mysql/strip_hash.rb @@ -5,6 +5,9 @@ # @param hash # Hash to be stripped # + # @return hash + # The given hash with all blank entries removed + # dispatch :strip_hash do required_param 'Hash', :hash return_type 'Hash' diff --git a/lib/puppet/functions/mysql_password.rb b/lib/puppet/functions/mysql_password.rb new file mode 100644 index 000000000..dc2916261 --- /dev/null +++ b/lib/puppet/functions/mysql_password.rb @@ -0,0 +1,21 @@ +# @summary +# A wrapper for the 4.x function 'mysql::password' to bridge the gap between +# it and the 3.x function 'mysql_password'. +# +Puppet::Functions.create_function(:mysql_password) do + # @param password + # Plain text password. + # + # @return + # The mysql password hash from the 4.x function mysql::password. + # + dispatch :mysql_password do + required_param 'String', :password + return_type 'String' + end + + def mysql_password(password) + call_function('deprecation', 'mysql_password', "This method has been deprecated, please use the namespaced version 'mysql::password' instead.") + call_function('mysql::password', password) + end +end diff --git a/lib/puppet/functions/mysql_strip_hash.rb b/lib/puppet/functions/mysql_strip_hash.rb new file mode 100644 index 000000000..dfef4c6fa --- /dev/null +++ b/lib/puppet/functions/mysql_strip_hash.rb @@ -0,0 +1,21 @@ +# @summary +# A wrapper for the 4.x function 'mysql::strip_hash' to bridge the gap between +# it and the 3.x function 'mysql_strip_hash'. +# +Puppet::Functions.create_function(:mysql_strip_hash) do + # @param hash + # Hash to be stripped + # + # @return hash + # The given hash with all blank entries removed + # + dispatch :mysql_strip_hash do + required_param 'Hash', :hash + return_type 'Hash' + end + + def mysql_strip_hash(hash) + call_function('deprecation', 'mysql_strip_hash', "This method has been deprecated, please use the namespaced version 'mysql::strip_hash' instead.") + call_function('mysql::strip_hash', hash) + end +end diff --git a/spec/functions/mysql_password_wrapper_spec.rb b/spec/functions/mysql_password_wrapper_spec.rb new file mode 100644 index 000000000..5b68dd972 --- /dev/null +++ b/spec/functions/mysql_password_wrapper_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe 'mysql_password' do + it 'exists' do + is_expected.not_to eq(nil) + end + + it 'raises a ArgumentError if there is less than 1 arguments' do + is_expected.to run.with_params.and_raise_error(ArgumentError) + end + + it 'raises a ArgumentError if there is more than 1 arguments' do + is_expected.to run.with_params('foo', 'bar').and_raise_error(ArgumentError) + end + + # Please note that the below test's fail if run via rspec rather than rake + it 'converts password into a hash' do + is_expected.to run.with_params('password').and_return('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19') + end + + it 'converts an empty password into a empty string' do + is_expected.to run.with_params('').and_return('') + end + + it 'does not convert a password that is already a hash' do + is_expected.to run.with_params('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19').and_return('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19') + end +end diff --git a/spec/functions/mysql_strip_hash_wrapper_spec.rb b/spec/functions/mysql_strip_hash_wrapper_spec.rb new file mode 100644 index 000000000..be11d835f --- /dev/null +++ b/spec/functions/mysql_strip_hash_wrapper_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe 'mysql_strip_hash' do + it 'exists' do + is_expected.not_to eq(nil) + end + + it 'raises a ArgumentError if there is less than 1 arguments' do + is_expected.to run.with_params.and_raise_error(ArgumentError) + end + + it 'raises a ArgumentError if there is more than 1 arguments' do + is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(ArgumentError) + end + + # Please note that the below test's fail if run via rspec rather than rake + it 'raises a ArgumentError if argument is not a hash' do + is_expected.to run.with_params('foo').and_raise_error(ArgumentError) + end + + it 'passes a hash without blanks through' do + is_expected.to run.with_params('one' => 1, 'two' => 2, 'three' => 3).and_return('one' => 1, 'two' => 2, 'three' => 3) + end + + it 'removes blank hash elements' do + is_expected.to run.with_params('one' => 1, 'two' => '', 'three' => nil, 'four' => 4).and_return('one' => 1, 'three' => nil, 'four' => 4) + end +end From df9b4be3331c71ecc3acf341a5bc38c62c24ad5e Mon Sep 17 00:00:00 2001 From: David Swan Date: Wed, 9 Jan 2019 09:53:00 +0000 Subject: [PATCH 2/2] (MODULES-8193) - Puppet Strings ran and reference.md updated --- REFERENCE.md | 3 +-- lib/puppet/functions/mysql/strip_hash.rb | 2 +- lib/puppet/functions/mysql_strip_hash.rb | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 4a3e3dc54..da211fb53 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1143,8 +1143,7 @@ A wrapper for the 4.x function 'mysql::password' to bridge the gap between The mysql_password function. -Returns: `String` hash -The mysql password hash from the 4.x function mysql::password. +Returns: `String` The mysql password hash from the 4.x function mysql::password. ##### `password` diff --git a/lib/puppet/functions/mysql/strip_hash.rb b/lib/puppet/functions/mysql/strip_hash.rb index 2efe26301..a978ae89d 100644 --- a/lib/puppet/functions/mysql/strip_hash.rb +++ b/lib/puppet/functions/mysql/strip_hash.rb @@ -5,7 +5,7 @@ # @param hash # Hash to be stripped # - # @return hash + # @return hash # The given hash with all blank entries removed # dispatch :strip_hash do diff --git a/lib/puppet/functions/mysql_strip_hash.rb b/lib/puppet/functions/mysql_strip_hash.rb index dfef4c6fa..263a9b747 100644 --- a/lib/puppet/functions/mysql_strip_hash.rb +++ b/lib/puppet/functions/mysql_strip_hash.rb @@ -6,7 +6,7 @@ # @param hash # Hash to be stripped # - # @return hash + # @return hash # The given hash with all blank entries removed # dispatch :mysql_strip_hash do