Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usernames and database names have to be quoted. #248

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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