7
7
commands mysql_raw : 'mysql'
8
8
9
9
def self . instances
10
- instances = [ ]
10
+ instance_configs = { }
11
11
users . map do |user |
12
12
user_string = cmd_user ( user )
13
13
query = "SHOW GRANTS FOR #{ user_string } ;"
@@ -54,16 +54,32 @@ def self.instances
54
54
# fix double backslash that MySQL prints, so resources match
55
55
table . gsub! ( '\\\\' , '\\' )
56
56
# We need to return an array of instances so capture these
57
- instances << new (
58
- name : "#{ user } @#{ host } /#{ table } " ,
59
- ensure : :present ,
60
- privileges : stripped_privileges . sort ,
61
- table : table ,
62
- user : "#{ user } @#{ host } " ,
63
- options : options ,
64
- )
57
+ name = "#{ user } @#{ host } /#{ table } "
58
+ if instance_configs . key? ( name )
59
+ instance_config = instance_configs [ name ]
60
+ stripped_privileges . concat instance_config . privileges
61
+ options . concat instance_config . options
62
+ end
63
+
64
+ instance_configs [ name ] = {
65
+ :privileges => stripped_privileges . uniq . sort ,
66
+ :table => table ,
67
+ :user => "#{ user } @#{ host } " ,
68
+ :options => options . uniq ,
69
+ }
65
70
end
66
71
end
72
+ instances = [ ]
73
+ instance_configs . map do |name , config |
74
+ instances << new (
75
+ name : name ,
76
+ ensure : :present ,
77
+ privileges : config [ :privileges ] ,
78
+ table : config [ :table ] ,
79
+ user : config [ :user ] ,
80
+ options : config [ :options ] ,
81
+ )
82
+ end
67
83
instances
68
84
end
69
85
@@ -90,10 +106,10 @@ def grant(user, table, privileges, options)
90
106
def create
91
107
grant ( @resource [ :user ] , @resource [ :table ] , @resource [ :privileges ] , @resource [ :options ] )
92
108
93
- @property_hash [ :ensure ] = :present
94
- @property_hash [ :table ] = @resource [ :table ]
95
- @property_hash [ :user ] = @resource [ :user ]
96
- @property_hash [ :options ] = @resource [ :options ] if @resource [ :options ]
109
+ @property_hash [ :ensure ] = :present
110
+ @property_hash [ :table ] = @resource [ :table ]
111
+ @property_hash [ :user ] = @resource [ :user ]
112
+ @property_hash [ :options ] = @resource [ :options ] if @resource [ :options ]
97
113
@property_hash [ :privileges ] = @resource [ :privileges ]
98
114
99
115
exists? ? ( return true ) : ( return false )
0 commit comments