Beispiel #1
0
def demo(user_api_key):
    """ Perform the txpachube.client.Client tests """

    user_api_key_id = None
    user_api_key_found = False
    required_permissions = [u'get', u'put', u'post', u'delete']
    required_permissions_available = True

    client = txpachube.client.Client()

    ################################################################################
    # Api Keys
    ################################################################################

    # check that supplied key has appropriate permissions for the test.
    try:
        logging.info("Requesting details of the supplied API key")
        apikey = yield client.read_api_key(api_key=user_api_key,
                                           key_id=user_api_key)
        logging.info("Received API key:\n%s\n" % apikey)

        # Multiple access_methods declarations can exist within a permissions dict.
        # Create a consolidated list that can be checked once.
        consolidated_access_methods = []
        for permission in apikey.permissions:
            for method in permission.access_methods:
                if method not in consolidated_access_methods:
                    consolidated_access_methods.append(method)

        for required_permission in required_permissions:
            if required_permission not in consolidated_access_methods:
                logging.error(
                    "The supplied key does not have the %s permission which is required"
                    % required_permission)
                defer.returnValue(False)

        logging.info(
            "The supplied API key supports the required permissions for this test"
        )

    except Exception, ex:
        logging.error("Error reading key details: %s" % str(ex))
        defer.returnValue(False)
Beispiel #2
0
def demo(user_api_key):
    """ Perform the txpachube.client.Client tests """
    
    user_api_key_id = None
    user_api_key_found = False
    required_permissions = [u'get', u'put', u'post', u'delete']
    required_permissions_available = True
    
    client = txpachube.client.Client()
    
    
    ################################################################################
    # Api Keys 
    ################################################################################
    
    
    # check that supplied key has appropriate permissions for the test. 
    try:
        logging.info("Requesting details of the supplied API key")
        apikey = yield client.read_api_key(api_key=user_api_key, key_id=user_api_key)
        logging.info("Received API key:\n%s\n" % apikey)
        
        # Multiple access_methods declarations can exist within a permissions dict.
        # Create a consolidated list that can be checked once.
        consolidated_access_methods = []
        for permission in apikey.permissions:
            for method in permission.access_methods:
                if method not in consolidated_access_methods:
                    consolidated_access_methods.append(method)        
        
        for required_permission in required_permissions:
            if required_permission not in consolidated_access_methods:
                logging.error("The supplied key does not have the %s permission which is required" % required_permission)
                defer.returnValue(False)
                
        logging.info("The supplied API key supports the required permissions for this test")
        
    except Exception, ex:
        logging.error("Error reading key details: %s" % str(ex))
        defer.returnValue(False)    
Beispiel #3
0
        logging.error("Error listing keys: %s" % str(ex))   


    # create a new api key
    try:
        candidate_key = txpachube.Key(label='temp key', permissions=[{'access_methods' : [u'get']}])
        logging.info("Requesting a new key be created")
        created_key_id = yield client.create_api_key(api_key=user_api_key, data=candidate_key.encode())
        logging.info("Received new API key: %s" % created_key_id)
        
        if created_key_id:
            
            # read the newly created key
            try:
                logging.info("Requesting details for new key using key_id: %s" % created_key_id)
                read_key = yield client.read_api_key(api_key=user_api_key, key_id=created_key_id)
                logging.info("Received API key:\n%s\n" % read_key)
            except Exception, ex:
                logging.error("Error reading new key details: %s" % str(ex))
            
            # delete the newly created key
            try:
                logging.info("Deleting the created key with key_id: %s" % created_key_id)
                delete_success = yield client.delete_api_key(api_key=user_api_key, key_id=created_key_id)
                logging.info("Received delete key result: %s" % delete_success)
            except Exception, ex:
                logging.error("Error deleting new key: %s" % str(ex))
                            
        else:
            logging.info("Can't read or delete new key as no key id was returned for the new key")
            
Beispiel #4
0
                                      permissions=[{
                                          'access_methods': [u'get']
                                      }])
        logging.info("Requesting a new key be created")
        created_key_id = yield client.create_api_key(
            api_key=user_api_key, data=candidate_key.encode())
        logging.info("Received new API key: %s" % created_key_id)

        if created_key_id:

            # read the newly created key
            try:
                logging.info(
                    "Requesting details for new key using key_id: %s" %
                    created_key_id)
                read_key = yield client.read_api_key(api_key=user_api_key,
                                                     key_id=created_key_id)
                logging.info("Received API key:\n%s\n" % read_key)
            except Exception, ex:
                logging.error("Error reading new key details: %s" % str(ex))

            # delete the newly created key
            try:
                logging.info("Deleting the created key with key_id: %s" %
                             created_key_id)
                delete_success = yield client.delete_api_key(
                    api_key=user_api_key, key_id=created_key_id)
                logging.info("Received delete key result: %s" % delete_success)
            except Exception, ex:
                logging.error("Error deleting new key: %s" % str(ex))

        else: