Skip to content

Commit

Permalink
Merge pull request #248 from estheruary/quote-all-the-things
Browse files Browse the repository at this point in the history
Usernames and database names have to be quoted.
  • Loading branch information
hennevogel authored Feb 6, 2021
2 parents 15515ac + 275c5ae commit 409f1e1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lib/influxdb/query/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ module InfluxDB
module Query
module Cluster # :nodoc:
def create_cluster_admin(username, password)
execute("CREATE USER #{username} WITH PASSWORD '#{password}' WITH ALL PRIVILEGES")
execute("CREATE USER \"#{username}\" WITH PASSWORD '#{password}' WITH ALL PRIVILEGES")
end

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

def revoke_cluster_admin_privileges(username)
execute("REVOKE ALL PRIVILEGES FROM #{username}")
execute("REVOKE ALL PRIVILEGES FROM \"#{username}\"")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/influxdb/query/continuous_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def create_continuous_query(name, database, query, resample_every: nil, resample
end

def delete_continuous_query(name, database)
execute("DROP CONTINUOUS QUERY #{name} ON #{database}")
execute("DROP CONTINUOUS QUERY \"#{name}\" ON \"#{database}\"")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/influxdb/query/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ module InfluxDB
module Query
module Database # :nodoc:
def create_database(name = nil)
execute("CREATE DATABASE #{name || config.database}")
execute("CREATE DATABASE \"#{name || config.database}\"")
end

def delete_database(name = nil)
execute("DROP DATABASE #{name || config.database}")
execute("DROP DATABASE \"#{name || config.database}\"")
end

def list_databases
Expand Down
16 changes: 8 additions & 8 deletions lib/influxdb/query/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,36 @@ module User # :nodoc:
def create_database_user(database, username, password, options = {})
permissions = options.fetch(:permissions, :all)
execute(
"CREATE user #{username} WITH PASSWORD '#{password}'; "\
"GRANT #{permissions.to_s.upcase} ON #{database} TO #{username}"
"CREATE user \"#{username}\" WITH PASSWORD '#{password}'; "\
"GRANT #{permissions.to_s.upcase} ON \"#{database}\" TO \"#{username}\""
)
end

def update_user_password(username, password)
execute("SET PASSWORD FOR #{username} = '#{password}'")
execute("SET PASSWORD FOR \"#{username}\" = '#{password}'")
end

# permission => [:all]
def grant_user_admin_privileges(username)
execute("GRANT ALL PRIVILEGES TO #{username}")
execute("GRANT ALL PRIVILEGES TO \"#{username}\"")
end

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

def list_user_grants(username)
execute("SHOW GRANTS FOR #{username}")
execute("SHOW GRANTS FOR \"#{username}\"")
end

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

def delete_user(username)
execute("DROP USER #{username}")
execute("DROP USER \"#{username}\"")
end

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

0 comments on commit 409f1e1

Please sign in to comment.