Example #1
0
 def ReadApprovalRequest(self, requestor_username, approval_id):
     """Reads an approval request object with a given id."""
     try:
         return self.approvals_by_username[requestor_username][approval_id]
     except KeyError:
         raise db.UnknownApprovalRequestError(
             "Can't find approval with id: %s" % approval_id)
Example #2
0
File: mem.py Project: hanul93/grr
 def GrantApproval(self, requestor_username, approval_id, grantor_username):
     try:
         approval = self.approvals_by_username[requestor_username][
             approval_id]
         approval.grants.append(
             objects.ApprovalGrant(grantor_username=grantor_username,
                                   timestamp=rdfvalue.RDFDatetime.Now()))
     except KeyError:
         raise db.UnknownApprovalRequestError(
             "Can't find approval with id: %s" % approval_id)
Example #3
0
    def ReadApprovalRequest(self,
                            requestor_username,
                            approval_id,
                            cursor=None):
        """Reads an approval request object with a given id."""

        query = (
            "SELECT approval_request.approval_id, approval_request.timestamp, "
            "approval_request.approval_request, "
            "approval_grant.grantor_username, approval_grant.timestamp "
            "FROM approval_request "
            "LEFT JOIN approval_grant USING (username, approval_id) "
            "WHERE approval_request.approval_id=%s "
            "AND approval_request.username=%s")

        cursor.execute(query,
                       [_ApprovalIDToInt(approval_id), requestor_username])
        res = cursor.fetchall()
        if not res:
            raise db_module.UnknownApprovalRequestError(
                "Approval '%s' not found." % approval_id)

        approval_id_int, timestamp, approval_request_bytes, _, _ = res[0]

        approval_request = _StringToRDFProto(objects.ApprovalRequest,
                                             approval_request_bytes)
        approval_request.approval_id = _IntToApprovalID(approval_id_int)
        approval_request.timestamp = _MysqlToRDFDatetime(timestamp)

        for _, _, _, grantor_username, timestamp in res:
            if not grantor_username:
                continue

            # Note: serialized approval_request objects are guaranteed to not
            # have any grants.
            approval_request.grants.append(
                objects.ApprovalGrant(
                    grantor_username=grantor_username,
                    timestamp=_MysqlToRDFDatetime(timestamp)))

        return approval_request