Skip to content

Commit

Permalink
support purging for all types of resources
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Nov 1, 2024
1 parent 22705cc commit 471b9ea
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 30 deletions.
4 changes: 0 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1470,8 +1470,6 @@ Valid values: `%r{[01]}`

Backend or not.

Default value: `1`

##### `default_hostgroup`

Valid values: `%r{\d+}`
Expand Down Expand Up @@ -1504,8 +1502,6 @@ Valid values: `%r{[01]}`

Frontend or not.

Default value: `1`

##### `max_connections`

Valid values: `%r{\d+}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
backup_writer_hostgroup = @resource.value(:backup_writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
offline_hostgroup = @resource.value(:offline_hostgroup)
query = 'DELETE FROM `mysql_group_replication_hostgroups` ' \
"WHERE `writer_hostgroup` = #{writer_hostgroup} AND `backup_writer_hostgroup` = #{backup_writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup} AND `offline_hostgroup` = #{offline_hostgroup}"
writer_hostgroup = @property_hash[:writer_hostgroup]
backup_writer_hostgroup = @property_hash[:backup_writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
offline_hostgroup = @property_hash[:offline_hostgroup]
query = 'DELETE FROM `mysql_group_replication_hostgroups`'
query << " WHERE `writer_hostgroup` = #{writer_hostgroup} AND `backup_writer_hostgroup` = #{backup_writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup} AND `offline_hostgroup` = #{offline_hostgroup}"
mysql([defaults_file, '-e', query].compact)

@property_hash.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_query_rule/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def create
end

def destroy
rule_id = @resource.value(:rule_id)
rule_id = @property_hash[:rule_id]
mysql([defaults_file, '-e', "DELETE FROM `mysql_query_rules` WHERE `rule_id` = '#{rule_id}'"].compact)

@property_hash.clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def create
end

def destroy
writer_hostgroup = @resource.value(:writer_hostgroup)
reader_hostgroup = @resource.value(:reader_hostgroup)
writer_hostgroup = @property_hash[:writer_hostgroup]
reader_hostgroup = @property_hash[:reader_hostgroup]
query = 'DELETE FROM `mysql_replication_hostgroups` ' \
"WHERE `writer_hostgroup` = #{writer_hostgroup} AND `reader_hostgroup` = #{reader_hostgroup}"
mysql([defaults_file, '-e', query].compact)
Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/proxy_mysql_server/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostgroup_id = @resource.value(:hostgroup_id)
hostname = @property_hash[:hostname]
port = @property_hash[:port]
hostgroup_id = @property_hash[:hostgroup_id]
query = 'DELETE FROM `mysql_servers` ' \
"WHERE `hostname` = '#{hostname}' AND `port` = #{port} AND `hostgroup_id` = '#{hostgroup_id}'"
mysql([defaults_file, '-e', query].compact)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def create
end

def destroy
hostname = @resource.value(:hostname)
port = @resource.value(:port)
hostname = @property_hash[:hostname]
port = @property_hash[:port]

query = "DELETE FROM `mysql_servers` WHERE `hostname` = '#{hostname}' AND `port` = #{port}"
mysql([defaults_file, '-e', query].compact)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_mysql_user/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create
end

def destroy
name = @resource[:name]
name = @property_hash[:name]
mysql([defaults_file, '-e', "DELETE FROM mysql_users WHERE username = '#{name}'"].compact)

@property_hash.clear
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/proxy_scheduler/proxysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create
end

def destroy
scheduler_id = @resource.value(:scheduler_id)
scheduler_id = @property_hash[:scheduler_id]

mysql([defaults_file, '-e', "DELETE FROM `scheduler` WHERE `id` = #{scheduler_id}"].compact)

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_group_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
raise('backup_writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:backup_writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('offline_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:offline_hostgroup].nil?
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
raise('name must match writer_hostgroup-backup_writer_hostgroup-reader_hostgroup-offline_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:backup_writer_hostgroup]}-#{self[:reader_hostgroup]}-#{self[:offline_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_mysql_query_rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
autorequire(:service) { 'proxysql' }

validate do
raise('rule_id parameter is required.') if self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if self[:name] != "mysql_query_rule-#{self[:rule_id]}"
raise('rule_id parameter is required.') if (self[:ensure] == :present) && self[:rule_id].nil?
raise('name must match \'mysql_query_rule-\'<rule_id> format') if (self[:ensure] == :present) && self[:name] != "mysql_query_rule-#{self[:rule_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_replication_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
validate do
raise('writer_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:writer_hostgroup].nil?
raise('reader_hostgroup parameter is required.') if (self[:ensure] == :present) && self[:reader_hostgroup].nil?
raise('name must match writer_hostgroup-reader_hostgroup parameters') if self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
raise('name must match writer_hostgroup-reader_hostgroup parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:writer_hostgroup]}-#{self[:reader_hostgroup]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname, port and hostgroup_id parameters') if self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
raise('name must match hostname, port and hostgroup_id parameters') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}-#{self[:hostgroup_id]}"
end

newparam(:name, namevar: true) do
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/proxy_mysql_server_no_hostgroup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
raise('hostname parameter is required.') if (self[:ensure] == :present) && self[:hostname].nil?
raise('port parameter is required.') if (self[:ensure] == :present) && self[:port].nil?
raise('hostgroup_id parameter is required.') if (self[:ensure] == :present) && self[:hostgroup_id].nil?
raise('name must match hostname and port') if self[:name] != "#{self[:hostname]}:#{self[:port]}"
raise('name must match hostname and port') if (self[:ensure] == :present) && self[:name] != "#{self[:hostname]}:#{self[:port]}"
end

newparam(:name, namevar: true) do
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_mysql_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
def initialize(*args)
super

return if self[:ensure] != :present

self[:password] = "*#{Digest::SHA1.hexdigest(Digest::SHA1.digest(self[:password])).upcase}" unless self[:password].start_with?('*') || self[:encrypt_password] != :true
end

Expand Down Expand Up @@ -82,13 +84,11 @@ def initialize(*args)

newproperty(:backend) do
desc 'Backend or not.'
defaultto 1
newvalue(%r{[01]})
end

newproperty(:frontend) do
desc 'Frontend or not.'
defaultto 1
newvalue(%r{[01]})
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/type/proxy_scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
autorequire(:service) { 'proxysql' }

validate do
raise('scheduler_id parameter is required.') if self[:scheduler_id].nil?
raise('scheduler_id parameter is required.') if (self[:ensure] == :present) && self[:scheduler_id].nil?
raise('filename parameter is required.') if (self[:ensure] == :present) && self[:filename].nil?
raise('name must match \'scheduler-\'<scheduler_id> format') if self[:name] != "scheduler-#{self[:scheduler_id]}"
raise('name must match \'scheduler-\'<scheduler_id> format') if (self[:ensure] == :present) && self[:name] != "scheduler-#{self[:scheduler_id]}"
end

newparam(:name, namevar: true) do
Expand Down

0 comments on commit 471b9ea

Please sign in to comment.