summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-01-26 12:57:11 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-01-26 12:57:11 -0200
commite51113be291e2c30088d9b25e9e279d9f3a675e1 (patch)
treeccf72ae0f54a85764af22c183b6892f680ae4084
parent36df5326bf1cd3cccc52589390b0de1cc71ddd30 (diff)
downloadpuppet-mysql-e51113be291e2c30088d9b25e9e279d9f3a675e1.tar.gz
puppet-mysql-e51113be291e2c30088d9b25e9e279d9f3a675e1.tar.bz2
More coding style
-rw-r--r--lib/puppet/provider/mysql_database/mysql.rb100
-rw-r--r--lib/puppet/provider/mysql_user/mysql.rb118
-rw-r--r--lib/puppet/type/mysql_database.rb12
3 files changed, 115 insertions, 115 deletions
diff --git a/lib/puppet/provider/mysql_database/mysql.rb b/lib/puppet/provider/mysql_database/mysql.rb
index 2b70e04..18b0a5a 100644
--- a/lib/puppet/provider/mysql_database/mysql.rb
+++ b/lib/puppet/provider/mysql_database/mysql.rb
@@ -1,55 +1,55 @@
require 'puppet/provider/package'
Puppet::Type.type(:mysql_database).provide(:mysql,
- :parent => Puppet::Provider::Package) do
-
- desc "Use mysql as database."
- commands :mysqladmin => '/usr/bin/mysqladmin'
- commands :mysql => '/usr/bin/mysql'
-
- # retrieve the current set of mysql users
- def self.instances
- dbs = []
-
- cmd = "#{command(:mysql)} mysql -NBe 'show databases'"
- execpipe(cmd) do |process|
- process.each do |line|
- dbs << new( { :ensure => :present, :name => line.chomp } )
- end
- end
- return dbs
- end
-
- def query
- result = {
- :name => @resource[:name],
- :ensure => :absent
- }
-
- cmd = "#{command(:mysql)} mysql -NBe 'show databases'"
- execpipe(cmd) do |process|
- process.each do |line|
- if line.chomp.eql?(@resource[:name])
- result[:ensure] = :present
- end
- end
- end
- result
- end
-
- def create
- mysqladmin "create", @resource[:name]
- end
- def destroy
- mysqladmin "-f", "drop", @resource[:name]
- end
-
- def exists?
- if mysql("mysql", "-NBe", "show databases").match(/^#{@resource[:name]}$/)
- true
- else
- false
- end
- end
+ :parent => Puppet::Provider::Package) do
+
+ desc "Use mysql as database."
+ commands :mysqladmin => '/usr/bin/mysqladmin'
+ commands :mysql => '/usr/bin/mysql'
+
+ # retrieve the current set of mysql users
+ def self.instances
+ dbs = []
+
+ cmd = "#{command(:mysql)} mysql -NBe 'show databases'"
+ execpipe(cmd) do |process|
+ process.each do |line|
+ dbs << new( { :ensure => :present, :name => line.chomp } )
+ end
+ end
+ return dbs
+ end
+
+ def query
+ result = {
+ :name => @resource[:name],
+ :ensure => :absent
+ }
+
+ cmd = "#{command(:mysql)} mysql -NBe 'show databases'"
+ execpipe(cmd) do |process|
+ process.each do |line|
+ if line.chomp.eql?(@resource[:name])
+ result[:ensure] = :present
+ end
+ end
+ end
+ result
+ end
+
+ def create
+ mysqladmin "create", @resource[:name]
+ end
+ def destroy
+ mysqladmin "-f", "drop", @resource[:name]
+ end
+
+ def exists?
+ if mysql("mysql", "-NBe", "show databases").match(/^#{@resource[:name]}$/)
+ true
+ else
+ false
+ end
+ end
end
diff --git a/lib/puppet/provider/mysql_user/mysql.rb b/lib/puppet/provider/mysql_user/mysql.rb
index a19b353..e04d7e6 100644
--- a/lib/puppet/provider/mysql_user/mysql.rb
+++ b/lib/puppet/provider/mysql_user/mysql.rb
@@ -1,76 +1,76 @@
require 'puppet/provider/package'
Puppet::Type.type(:mysql_user).provide(:mysql,
- # T'is funny business, this code is quite generic
- :parent => Puppet::Provider::Package) do
+ # T'is funny business, this code is quite generic
+ :parent => Puppet::Provider::Package) do
- desc "Use mysql as database."
- commands :mysql => '/usr/bin/mysql'
- commands :mysqladmin => '/usr/bin/mysqladmin'
+ desc "Use mysql as database."
+ commands :mysql => '/usr/bin/mysql'
+ commands :mysqladmin => '/usr/bin/mysqladmin'
- # retrieve the current set of mysql users
- def self.instances
- users = []
+ # retrieve the current set of mysql users
+ def self.instances
+ users = []
- cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user'"
- execpipe(cmd) do |process|
- process.each do |line|
- users << new( query_line_to_hash(line) )
- end
- end
- return users
- end
+ cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user'"
+ execpipe(cmd) do |process|
+ process.each do |line|
+ users << new( query_line_to_hash(line) )
+ end
+ end
+ return users
+ end
- def self.query_line_to_hash(line)
- fields = line.chomp.split(/\t/)
- {
- :name => fields[0],
- :password_hash => fields[1],
- :ensure => :present
- }
- end
+ def self.query_line_to_hash(line)
+ fields = line.chomp.split(/\t/)
+ {
+ :name => fields[0],
+ :password_hash => fields[1],
+ :ensure => :present
+ }
+ end
- def mysql_flush
- mysqladmin "flush-privileges"
- end
+ def mysql_flush
+ mysqladmin "flush-privileges"
+ end
- def query
- result = {}
+ def query
+ result = {}
- cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user where concat(user, \"@\", host) = \"%s\"'" % @resource[:name]
- execpipe(cmd) do |process|
- process.each do |line|
- unless result.empty?
- raise Puppet::Error,
- "Got multiple results for user '%s'" % @resource[:name]
- end
- result = query_line_to_hash(line)
- end
- end
- result
- end
+ cmd = "#{command(:mysql)} mysql -NBe 'select concat(user, \"@\", host), password from user where concat(user, \"@\", host) = \"%s\"'" % @resource[:name]
+ execpipe(cmd) do |process|
+ process.each do |line|
+ unless result.empty?
+ raise Puppet::Error,
+ "Got multiple results for user '%s'" % @resource[:name]
+ end
+ result = query_line_to_hash(line)
+ end
+ end
+ result
+ end
- def create
- mysql "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.should(:password_hash) ]
- mysql_flush
- end
+ def create
+ mysql "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.should(:password_hash) ]
+ mysql_flush
+ end
- def destroy
- mysql "mysql", "-e", "drop user '%s'" % @resource[:name].sub("@", "'@'")
- mysql_flush
- end
+ def destroy
+ mysql "mysql", "-e", "drop user '%s'" % @resource[:name].sub("@", "'@'")
+ mysql_flush
+ end
- def exists?
- not mysql("mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty?
- end
+ def exists?
+ not mysql("mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource[:name]).empty?
+ end
- def password_hash
- @property_hash[:password_hash]
- end
+ def password_hash
+ @property_hash[:password_hash]
+ end
- def password_hash=(string)
- mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ]
- mysql_flush
- end
+ def password_hash=(string)
+ mysql "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ]
+ mysql_flush
+ end
end
diff --git a/lib/puppet/type/mysql_database.rb b/lib/puppet/type/mysql_database.rb
index bb25ffa..b01bb83 100644
--- a/lib/puppet/type/mysql_database.rb
+++ b/lib/puppet/type/mysql_database.rb
@@ -1,11 +1,11 @@
# This has to be a separate type to enable collecting
Puppet::Type.newtype(:mysql_database) do
- @doc = "Manage a database."
- ensurable
- newparam(:name) do
- desc "The name of the database."
+ @doc = "Manage a database."
+ ensurable
+ newparam(:name) do
+ desc "The name of the database."
- # TODO: only [[:alnum:]_] allowed
- end
+ # TODO: only [[:alnum:]_] allowed
+ end
end