Skip to content

Commit 275c5ae

Browse files
committed
Usernames and databases have to be quoted.
It's legal for databases and users to have odd characters (like '-') that require quoting. This is done in some parts of the code but not others. This fixes that.
1 parent b708621 commit 275c5ae

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

lib/influxdb/query/cluster.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ module InfluxDB
22
module Query
33
module Cluster # :nodoc:
44
def create_cluster_admin(username, password)
5-
execute("CREATE USER #{username} WITH PASSWORD '#{password}' WITH ALL PRIVILEGES")
5+
execute("CREATE USER \"#{username}\" WITH PASSWORD '#{password}' WITH ALL PRIVILEGES")
66
end
77

88
def list_cluster_admins
99
list_users.select { |u| u["admin".freeze] }.map { |u| u["username".freeze] }
1010
end
1111

1212
def revoke_cluster_admin_privileges(username)
13-
execute("REVOKE ALL PRIVILEGES FROM #{username}")
13+
execute("REVOKE ALL PRIVILEGES FROM \"#{username}\"")
1414
end
1515
end
1616
end

lib/influxdb/query/continuous_query.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def create_continuous_query(name, database, query, resample_every: nil, resample
2424
end
2525

2626
def delete_continuous_query(name, database)
27-
execute("DROP CONTINUOUS QUERY #{name} ON #{database}")
27+
execute("DROP CONTINUOUS QUERY \"#{name}\" ON \"#{database}\"")
2828
end
2929
end
3030
end

lib/influxdb/query/database.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ module InfluxDB
22
module Query
33
module Database # :nodoc:
44
def create_database(name = nil)
5-
execute("CREATE DATABASE #{name || config.database}")
5+
execute("CREATE DATABASE \"#{name || config.database}\"")
66
end
77

88
def delete_database(name = nil)
9-
execute("DROP DATABASE #{name || config.database}")
9+
execute("DROP DATABASE \"#{name || config.database}\"")
1010
end
1111

1212
def list_databases

lib/influxdb/query/user.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ module User # :nodoc:
66
def create_database_user(database, username, password, options = {})
77
permissions = options.fetch(:permissions, :all)
88
execute(
9-
"CREATE user #{username} WITH PASSWORD '#{password}'; "\
10-
"GRANT #{permissions.to_s.upcase} ON #{database} TO #{username}"
9+
"CREATE user \"#{username}\" WITH PASSWORD '#{password}'; "\
10+
"GRANT #{permissions.to_s.upcase} ON \"#{database}\" TO \"#{username}\""
1111
)
1212
end
1313

1414
def update_user_password(username, password)
15-
execute("SET PASSWORD FOR #{username} = '#{password}'")
15+
execute("SET PASSWORD FOR \"#{username}\" = '#{password}'")
1616
end
1717

1818
# permission => [:all]
1919
def grant_user_admin_privileges(username)
20-
execute("GRANT ALL PRIVILEGES TO #{username}")
20+
execute("GRANT ALL PRIVILEGES TO \"#{username}\"")
2121
end
2222

2323
# permission => [:read|:write|:all]
2424
def grant_user_privileges(username, database, permission)
25-
execute("GRANT #{permission.to_s.upcase} ON #{database} TO #{username}")
25+
execute("GRANT #{permission.to_s.upcase} ON \"#{database}\" TO \"#{username}\"")
2626
end
2727

2828
def list_user_grants(username)
29-
execute("SHOW GRANTS FOR #{username}")
29+
execute("SHOW GRANTS FOR \"#{username}\"")
3030
end
3131

3232
# permission => [:read|:write|:all]
3333
def revoke_user_privileges(username, database, permission)
34-
execute("REVOKE #{permission.to_s.upcase} ON #{database} FROM #{username}")
34+
execute("REVOKE #{permission.to_s.upcase} ON \"#{database}\" FROM \"#{username}\"")
3535
end
3636

3737
def delete_user(username)
38-
execute("DROP USER #{username}")
38+
execute("DROP USER \"#{username}\"")
3939
end
4040

4141
# => [{"username"=>"usr", "admin"=>true}, {"username"=>"justauser", "admin"=>false}]

0 commit comments

Comments
 (0)