Beispiel #1
0
def main():
    if len(sys.argv) < 2:
        data = bytearray(
            'I, the server, hereby agree that I will pay $100 to this student.'
            .encode('ascii'))
        data = data[:32]
    else:
        data_file = open(sys.argv[1])
        data = data_file.read()
        data_file.close()

    try:
        oracle = Oracle()
        oracle.connect()

        tag = oracle.mac(data, len(data))

        ret = oracle.vrfy(data, len(data), tag)
        print(ret)
        if ret == 1:
            print("Message verified successfully!")
        else:
            print("Message verification failed.")

    finally:
        oracle.disconnect()
Beispiel #2
0
class Account:
    """
    Houses queries to the Eupath account db.
    """
    def __init__(self, connection_string):
        """
        Oracle underlies the account db
        :param connection_string: account db connection string
        """
        self.db = Oracle(connection_string)

    def get_users_by_user_ids(self, user_ids):
        """
        Query to obtain user information (full name and email) for a  given list of user wdk ids.
        :param user_ids: list of user wdk ids
        :return: id, full name and email data for each user
        """
        # TODO: Becomes inefficient with too many users.  Will need a better strategy.  Also can't use
        # bind variables with an IN clause.
        self.db.connect()
        sql = """
                   SELECT user_id, first_name | | ' ' | | last_name AS full_name, email
                   FROM (
                     SELECT
                       a.user_id, first_name, last_name, email
                     FROM userAccounts.accounts a
                     LEFT JOIN (
                       SELECT
                         user_id,
                         MAX(CASE WHEN key = 'first_name' THEN value END) AS first_name,
                         MAX(CASE WHEN key = 'last_name' THEN value END) AS last_name
                       FROM UserAccounts.Account_Properties
                       GROUP BY user_id) ap
                       ON a.user_id = ap.user_id
                     )
                   WHERE user_id IN (""" + ",".join(user_ids) + ")"
        try:
            self.db.execute(sql)
            results = self.db.cursor.fetchall()
            return results
        finally:
            self.db.disconnect()
Beispiel #3
0
def main():
    if len(sys.argv) < 2:
        data = bytearray('I, the server, hereby agree that I will pay $100 to this student.'.encode('ascii'))
        data = data[:32]
    else:
        data_file = open(sys.argv[1])
        data = data_file.read()
        data_file.close()

    try:
        oracle = Oracle()
        oracle.connect()

        tag = oracle.mac(data, len(data))

        ret = oracle.vrfy(data, len(data), tag)
        print(ret)
        if ret == 1:
            print("Message verified successfully!")
        else:
            print("Message verification failed.")

    finally:
        oracle.disconnect()
Beispiel #4
0
class AppDB:
    """
    Houses queries to the Eupath app db.
    """
    def __init__(self, connection_string):
        """
        Oracle underlies the app db
        :param connection_string: app db connection string
        """
        self.db = Oracle(connection_string)

    def get_installation_status(self, dataset_id):
        """
        An installed dataset will appear in the installeduserdataset table.
        :param dataset_id: the id of the dataset to check for installation.
        :return: one or no results
        """
        self.db.connect()
        sql = """
              SELECT * FROM apidbuserdatasets.installeduserdataset WHERE user_dataset_id = :dataset_id
              """
        bindvars = {"dataset_id": dataset_id}
        try:
            self.db.execute(sql, bindvars)
            result = self.db.cursor.fetchone()
            return result
        finally:
            self.db.disconnect()

    def get_handled_status(self, event_id):
        """
        A handled dataset's install event will appear in the userdatasetevent table.  The presence of a date for
        the completed column indicates whether a user dataset was successfully handled or not.  An unsuccessfully
        handled datasets halts queue processing until cleared.  A successfully handled dataset may still not be
        installed.
        :param event_id: the dataset's install event id against which to lookup whether the dataset was handled.
        :return: one or no results
        """
        self.db.connect()
        sql = """
              SELECT * FROM apidbuserdatasets.userdatasetevent WHERE event_id = :event_id
              """
        bindvars = {"event_id": event_id}
        try:
            self.db.execute(sql, bindvars)
            result = self.db.cursor.fetchone()
            return result
        finally:
            self.db.disconnect()

    def get_owner(self, dataset_id):
        """
        A handled dataset's owner as found in the database should match the owner as determined via the dataset's
        dataset.json file.  The owner is immutable.
        :param dataset_id: the id of the dataset for which the user is checked
        :return: should be one row
        """
        self.db.connect()
        sql = """
              SELECT * FROM apidbuserdatasets.userdatasetowner WHERE user_dataset_id = :dataset_id
              """
        bindvars = {"dataset_id": dataset_id}
        try:
            self.db.execute(sql, bindvars)
            result = self.db.cursor.fetchone()
            return result
        finally:
            self.db.disconnect()

    def get_shares(self, dataset_id):
        self.db.connect()
        sql = """
              SELECT * FROM apidbuserdatasets.userdatasetsharedwith WHERE user_dataset_id = :dataset_id
              """
        bindvars = {"dataset_id": dataset_id}
        try:
            self.db.execute(sql, bindvars)
            results = self.db.cursor.fetchall()
            return results
        finally:
            self.db.disconnect()