summaryrefslogtreecommitdiff
path: root/lib/puppet/type
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/type')
-rw-r--r--lib/puppet/type/mysql_database.rb11
-rw-r--r--lib/puppet/type/mysql_grant.rb77
-rw-r--r--lib/puppet/type/mysql_user.rb22
3 files changed, 110 insertions, 0 deletions
diff --git a/lib/puppet/type/mysql_database.rb b/lib/puppet/type/mysql_database.rb
new file mode 100644
index 0000000..bb25ffa
--- /dev/null
+++ b/lib/puppet/type/mysql_database.rb
@@ -0,0 +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."
+
+ # TODO: only [[:alnum:]_] allowed
+ end
+end
+
diff --git a/lib/puppet/type/mysql_grant.rb b/lib/puppet/type/mysql_grant.rb
new file mode 100644
index 0000000..415f5aa
--- /dev/null
+++ b/lib/puppet/type/mysql_grant.rb
@@ -0,0 +1,77 @@
+# This has to be a separate type to enable collecting
+Puppet::Type.newtype(:mysql_grant) do
+ @doc = "Manage a database user's rights."
+ #ensurable
+
+ autorequire :mysql_db do
+ # puts "Starting db autoreq for %s" % self[:name]
+ reqs = []
+ matches = self[:name].match(/^([^@]+)@([^\/]+)\/(.+)$/)
+ unless matches.nil?
+ reqs << matches[3]
+ end
+ # puts "Autoreq: '%s'" % reqs.join(" ")
+ reqs
+ end
+
+ autorequire :mysql_user do
+ # puts "Starting user autoreq for %s" % self[:name]
+ reqs = []
+ matches = self[:name].match(/^([^@]+)@([^\/]+).*$/)
+ unless matches.nil?
+ reqs << "%s@%s" % [ matches[1], matches[2] ]
+ end
+ # puts "Autoreq: '%s'" % reqs.join(" ")
+ reqs
+ end
+
+ newparam(:name) do
+ desc "The primary key: either user@host for global privilges or user@host/database for database specific privileges"
+ end
+ newproperty(:privileges, :array_matching => :all) do
+ desc "The privileges the user should have. The possible values are implementation dependent."
+ munge do |v|
+ symbolize(v)
+ end
+
+ def should_to_s(newvalue = @should)
+ if newvalue
+ unless newvalue.is_a?(Array)
+ newvalue = [ newvalue ]
+ end
+ newvalue.collect do |v| v.to_s end.sort.join ", "
+ else
+ nil
+ end
+ end
+
+ def is_to_s(currentvalue = @is)
+ if currentvalue
+ unless currentvalue.is_a?(Array)
+ currentvalue = [ currentvalue ]
+ end
+ currentvalue.collect do |v| v.to_s end.sort.join ", "
+ else
+ nil
+ end
+ end
+
+ # use the sorted outputs for comparison
+ def insync?(is)
+ if defined? @should and @should
+ case self.should_to_s
+ when "all"
+ self.provider.all_privs_set?
+ when self.is_to_s(is)
+ true
+ else
+ false
+ end
+ else
+ true
+ end
+ end
+
+ end
+end
+
diff --git a/lib/puppet/type/mysql_user.rb b/lib/puppet/type/mysql_user.rb
new file mode 100644
index 0000000..55d97b6
--- /dev/null
+++ b/lib/puppet/type/mysql_user.rb
@@ -0,0 +1,22 @@
+# This has to be a separate type to enable collecting
+Puppet::Type.newtype(:mysql_user) do
+ @doc = "Manage a database user."
+ ensurable
+ newparam(:name) do
+ desc "The name of the user. This uses the 'username@hostname' form."
+
+ validate do |value|
+ if value.split('@').first.size > 16
+ raise ArgumentError,
+ "MySQL usernames are limited to a maximum of 16 characters"
+ else
+ super
+ end
+ end
+ end
+
+ newproperty(:password_hash) do
+ desc "The password hash of the user. Use mysql_password() for creating such a hash."
+ end
+end
+