def listen_to_token_requests()

in src/influxDBTokenPublisher.py [0:0]


def listen_to_token_requests(args, influxdb_rw_token) -> None:
    """
    Setup a new IPC subscription over local pub/sub to listen to token requests and vend tokens.

    Parameters
    ----------
        args(Namespace): Parsed arguments
        influxdb_rw_token(str): InfluxDB RW token

    Returns
    -------
        None
    """

    try:
        influxDB_data = {}
        influxDB_data['InfluxDBContainerName'] = args.influxdb_container_name
        influxDB_data['InfluxDBOrg'] = args.influxdb_org
        influxDB_data['InfluxDBBucket'] = args.influxdb_bucket
        influxDB_data['InfluxDBPort'] = args.influxdb_port
        influxDB_data['InfluxDBInterface'] = args.influxdb_interface
        influxDB_data['InfluxDBRWToken'] = influxdb_rw_token
        influxDB_data['InfluxDBServerProtocol'] = args.server_protocol
        influxDB_data['InfluxDBSkipTLSVerify'] = args.skip_tls_verify
        influxDB_json = json.dumps(influxDB_data)

        logging.info('Successfully retrieved InfluxDB parameters!')

        ipc_client = awsiot.greengrasscoreipc.connect()
        request = SubscribeToTopicRequest()
        request.topic = args.subscribe_topic
        handler = InfluxDBTokenStreamHandler(influxDB_json, args.publish_topic)
        operation = ipc_client.new_subscribe_to_topic(handler)
        operation.activate(request)
        logging.info('Successfully subscribed to topic: {}'.format(args.subscribe_topic))
        logging.info("InfluxDB has been successfully set up; now listening to token requests...")
    except concurrent.futures.TimeoutError as e:
        logging.error('Timeout occurred while subscribing to topic: {}'.format(args.subscribe_topic), exc_info=True)
        raise e
    except UnauthorizedError as e:
        logging.error('Unauthorized error while subscribing to topic: {}'.format(args.subscribe_topic), exc_info=True)
        raise e
    except Exception as e:
        logging.error('Exception while subscribing to topic: {}'.format(args.subscribe_topic), exc_info=True)
        raise e