Skip to content

Commit

Permalink
[#642] Log possible problems with the datastore permission checks ins…
Browse files Browse the repository at this point in the history
…tead of raising an exception.

If postgres is set to a language other than english, some strings might not occur in the error message returned from the database. This change makes the checks less strict but in almost all cases, this should not be a problem because the only error raised during executing of the permission check statements are (expected) permission errors.
  • Loading branch information
domoritz committed Mar 25, 2013
1 parent 818e605 commit 46e3fde
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions ckanext/datastore/plugin.py
Expand Up @@ -61,17 +61,20 @@ def configure(self, config):
if not ('debug' in config and config['debug']):
self._check_separate_db()
if self.legacy_mode:
log.warn('Legacy mode active. The sql search will not be available.')
log.warn("Legacy mode active."
"The sql search will not be available.")
else:
self._check_read_permissions()

self._create_alias_table()
else:
log.warn("We detected that CKAN is running on a read only database. "
"Permission checks and the creation of _table_metadata are skipped.")
log.warn("We detected that CKAN is running on a read"
"only database. Permission checks and the creation "
"of _table_metadata are skipped.")
else:
log.warn("We detected that you do not use a PostgreSQL database. "
"The DataStore will NOT work and datastore tests will be skipped.")
log.warn("We detected that you do not use a PostgreSQL"
"database. The DataStore will NOT work and datastore"
"tests will be skipped.")

## Do light wrapping around action function to add datastore_active
## to resource dict. Not using IAction extension as this prevents
Expand Down Expand Up @@ -118,7 +121,11 @@ def _is_read_only_database(self):
if 'permission denied' in str(e) or 'read-only transaction' in str(e):
pass
else:
raise
log.critical("Possibly unsafe datastore. If '{0}' "
"does not mean 'permission denied', or "
"'read-only transaction' you have to double "
"check the permissions for the datastore "
"table.".format(e.message))
else:
return False
finally:
Expand Down Expand Up @@ -166,7 +173,10 @@ def _check_read_permissions(self):
read_connection.execute(sql)
except ProgrammingError, e:
if 'permission denied' not in str(e):
raise
log.critical("Possibly unsafe datastore. If '{0}'"
"does not mean 'permission denied', "
"you have to double check the permissions "
"for the datastore table.".format(e.message))
else:
log.info("Connection url {0}".format(self.read_url))
if 'debug' in self.config and self.config['debug']:
Expand Down

0 comments on commit 46e3fde

Please sign in to comment.