Beispiel #1
0
 def flush(self):
     query = """
     DELETE FROM cache;
     """
     # Since called outside request (e.g. tests), force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL cache tables')
Beispiel #2
0
 def flush(self):
     query = """
     DELETE FROM cache;
     """
     # Since called outside request (e.g. tests), force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL cache tables')
Beispiel #3
0
 def flush(self):
     query = """
     DELETE FROM user_principals;
     DELETE FROM access_control_entries;
     """
     # Since called outside request (e.g. tests), force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL permission tables')
Beispiel #4
0
 def flush(self):
     query = """
     DELETE FROM user_principals;
     DELETE FROM access_control_entries;
     """
     # Since called outside request (e.g. tests), force commit.
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL permission tables')
Beispiel #5
0
    def _verify_token(self, access_token):
        uri = self.oid_config["userinfo_endpoint"]
        # Opaque access token string. Fetch user info from profile.
        try:
            resp = requests.get(uri, headers={"Authorization": "Bearer " + access_token})
            resp.raise_for_status()
            userprofile = resp.json()
            return userprofile

        except (requests.exceptions.HTTPError, ValueError, KeyError) as e:
            logger.debug("Unable to fetch user profile from %s (%s)" % (uri, e))
            return None
Beispiel #6
0
    def _verify_token(self, access_token):
        uri = self.oid_config['userinfo_endpoint']
        # Opaque access token string. Fetch user info from profile.
        try:
            resp = requests.get(uri, headers={'Authorization': 'Bearer ' + access_token})
            resp.raise_for_status()
            userprofile = resp.json()
            return userprofile

        except (requests.exceptions.HTTPError, ValueError, KeyError) as e:
            logger.debug('Unable to fetch user profile from %s (%s)' % (uri, e))
            return None
Beispiel #7
0
 def flush(self, auth=None):
     """Delete records from tables without destroying schema. Mainly used
     in tests suites.
     """
     query = """
     DELETE FROM deleted;
     DELETE FROM records;
     DELETE FROM timestamps;
     DELETE FROM metadata;
     """
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL storage tables')
Beispiel #8
0
 def flush(self, auth=None):
     """Delete records from tables without destroying schema. Mainly used
     in tests suites.
     """
     query = """
     DELETE FROM deleted;
     DELETE FROM records;
     DELETE FROM timestamps;
     DELETE FROM metadata;
     """
     with self.client.connect(force_commit=True) as conn:
         conn.execute(query)
     logger.debug('Flushed PostgreSQL storage tables')
Beispiel #9
0
    def initialize_schema(self):
        """Create PostgreSQL tables, and run necessary schema migrations.

        .. note::

            Relies on JSONB fields, available in recent versions of PostgreSQL.
        """
        version = self._get_installed_version()
        if not version:
            # Create full schema.
            self._check_database_encoding()
            self._check_database_timezone()
            # Create full schema.
            self._execute_sql_file('schema.sql')
            logger.info('Created PostgreSQL storage tables '
                        '(version %s).' % self.schema_version)
            return

        logger.debug('Detected PostgreSQL schema version %s.' % version)
        migrations = [(v, v + 1) for v in range(version, self.schema_version)]
        if not migrations:
            logger.info('Schema is up-to-date.')

        for migration in migrations:
            # Check order of migrations.
            expected = migration[0]
            current = self._get_installed_version()
            error_msg = "Expected version %s. Found version %s."
            if expected != current:
                raise AssertionError(error_msg % (expected, current))

            logger.info('Migrate schema from version %s to %s.' % migration)
            filepath = 'migration_%03d_%03d.sql' % migration
            self._execute_sql_file(os.path.join('migrations', filepath))

        logger.info('Schema migration done.')