def test_set_channel_nodes(self, patched_env, patched_resource,
                            patched_client):
     """
     Test the set_channel_nodes function
     """
     from chalicelib import channels
     channels.set_channel_nodes(CHANNEL_NAME, NODE_IDS)
Ejemplo n.º 2
0
def update_tiles():
    """
    scan for data with tags with MSAM-Tile name and include in those named tiles
    """
    try:
        ddb_table_name = CONTENT_TABLE_NAME
        ddb_resource = boto3.resource('dynamodb')
        ddb_table = ddb_resource.Table(ddb_table_name)
        # very broad textual scan
        response = ddb_table.scan(
            FilterExpression="contains(#data, :tagname)",
            ExpressionAttributeNames={"#data": "data"},
            ExpressionAttributeValues={":tagname": "MSAM-Tile"})
        items = response["Items"]
        # check for paging
        while "LastEvaluatedKey" in response:
            # scan again with start key
            response = ddb_table.scan(
                FilterExpression="contains(#data, :tagname)",
                ExpressionAttributeNames={"#data": "data"},
                ExpressionAttributeValues={":tagname": "MSAM-Tile"},
                ExclusiveStartKey=response['LastEvaluatedKey'])
            items = items + response["Items"]
        # filter down the results
        for record in items:
            cloud_resource = json.loads(record["data"])
            if "Tags" in cloud_resource:
                if "MSAM-Tile" in cloud_resource["Tags"]:
                    arn = record["arn"]
                    tile_name = cloud_resource["Tags"]["MSAM-Tile"]
                    print("arn {} needed on tile {}".format(arn, tile_name))
                    nodes = channels.get_channel_nodes(tile_name)
                    ids = [item["id"] for item in nodes]
                    print("existing tile contents: {}".format(json.dumps(ids)))
                    if arn not in ids:
                        print("adding {} to tile {}".format(arn, tile_name))
                        ids.append(arn)
                        print("updated tile contents: {}".format(
                            json.dumps(ids)))
                        channels.set_channel_nodes(tile_name, ids)
                    else:
                        print("already present on tile")
    except ClientError as error:
        print(error)
def set_channel_nodes(name):
    """
     API entry point to set the nodes for a given channel name.
    """
    return channel_tiles.set_channel_nodes(name, app.current_request.json_body)
def set_channel_nodes(name):
    """
     API entry point to set the nodes for a given channel name.
    """
    return channel_tiles.set_channel_nodes(app.current_request, name)