def testConfigEndPoint_DefaultSetting(self):
        httpClient = self.TestRequestClient()

        cloudRequestEngine = CloudRequestEngine({
            "resource_key":
            TestCloudRequestEngine.testResourceKey,
            "http_client":
            httpClient
        })
        self.assertEqual(Constants.BASE_URL_DEFAULT,
                         cloudRequestEngine.baseURL)
    def testConfigEndPoint_EnvironmentVariableSetting(self):
        httpClient = self.TestRequestClient()

        os.environ[
            Constants.
            FOD_CLOUD_API_URL] = TestCloudRequestEngine.testEnvVarEndPoint
        cloudRequestEngine = CloudRequestEngine({
            "resource_key":
            TestCloudRequestEngine.testResourceKey,
            "http_client":
            httpClient
        })
        self.assertEqual(TestCloudRequestEngine.testEnvVarEndPoint,
                         cloudRequestEngine.baseURL)
Exemplo n.º 3
0
    def __init__(self, settings):

        super(LocationPipelineBuilder, self).__init__(settings)

        # Add specific engines

        self.add(CloudRequestEngine(settings))

        location = LocationCloud(settings)

        if "cache" in settings:
            location.set_cache(settings["cache"])

        self.add(location)
    def __init__(self,
                 resource_key,
                 location_provider="fiftyonedegrees",
                 settings={}):

        super(LocationPipelineBuilder, self).__init__(settings)

        # Add specific engines

        settings["resource_key"] = resource_key

        self.add(CloudRequestEngine(settings))

        location = LocationCloud(location_provider=location_provider)

        if "cache" in settings:
            location.set_cache(settings["cache"])

        self.add(location)
    def __init__(self, settings=None, usage_sharing=True, **kwargs):
        """!

        Constructor for Device Detection Pipeline Builder
        Depending on parameters passed through, builds a pipeline
        with either the cloud or on premise device detection engines

        General pipeline settings:

        @type javascript_builder_settings: dict
        @param javascript_builder_settings: parameters for the pipeline's JavaScript builder to populate additional evidence from the clientside.
            - obj_name: the name of the client side object 
            with the JavaScript properties in it ('fod' by default)
            - protocol: The protocol ("http" or "https") used by 
            the client side callback url. This can be overridden 
            with header.protocol evidence
            - host The host of the client side callback url. 
            This can be overridden with header.host evidence.
            - endpoint The endpoint of the client side callback url
            * enable_cookies - whether cookies should be enabled
            * minify: Whether to minify the JavaScript
        @type cache: Cache
        @param cache: An instance of the fiftyone.pipeline.engines.cache
        class

        Cloud Engine Settings:

        @type resource_key: string
        @param resource_key: the 51Degrees cloud resource key
        @type cloud_request_origin: string
        @param cloud_request_origin: The value to set the Origin header to when making requests to the cloud service

        On Premise Engine Settings

        @type usage_sharing : bool
        @param usage_sharing : Whether to enable usage sharing if using the on premise engine
        @type data_file_path: string
        @param data_file_path: path to the data file
        @type auto_update: bool
        @param auto_update: whether to automatically update the datafile when required
        @type restricted_properties: list
        @param restricted_properties: List of property keys to limit the engine to
        @type license_keys: string
        @param licence_keys: licencekeys to use for the data file update service
        @type download: bool
        @param download: whether to download the datafile or keep it in memory when it is returned from the datafile update service
        @type max_matched_useragents_length : int
        @param Number of characters to consider in the matched User-Agent. Ignored if update_matched_useragent is false
        @type update_matched_useragent: 
        @param: update_matched_useragent: True if the detection should record the matched characters from the target User-Agent
        @type drift: int
        @param drift: Set maximum drift in hash position to allow when processing HTTP headers
        @type difference: int
        @param difference: set the maximum difference to allow when processing HTTP headers. The difference is the difference in hash value between the hash that was found, and the hash that is being searched for. By default this is 0.
        @type allow_unmatched : bool
        @param allow_unmatched:  True if there should be at least one matched node in order for the results to be considered valid. By default, this is false
        @type performance_profile: string
        @param performance_profile: options are: LowMemory, MaxPerformance, Balanced, BalancedTemp, HighPerformance
        @type reuse_temp_file: bool
        @param reuse_temp_file: Indicates that an existing temp file may be used. This should be selected if multiple instances wish to use the same file to prevent high disk usage.
        @type concurrency: int
        @param concurrency: defaults to the number of cpus in the machine
        @type update_on_start : bool
        @param update_on_start : When this is set to true the datafile is updated / downloaded immediately on initialisation. This is useful if no initial datafile is present.
        @type file_system_watcher: bool
        @param file_system_watcher: whether to check the datafile's path for changes and update the connected FlowElement's data 
        @type polling_interval: int
        @param polling_interval: How often to poll for updates to the datafile (minutes)
        @type update_time_maximum_randomisation : int
        @param update_time_maximum_randomisation :
        Maximum randomisation offset in seconds to polling time interval
        @type verify_md5 : bool
        @type create_temp_copy: bool
        @param create_temp_copy: whether to copy datafile to temporary location when updating
        @type data_file_update_base_url: string
        @param data_file_update_base_url: base url for the datafile update service

        """
        if settings is None:
            settings = {}

        settings = merge_two_dicts(dict(**kwargs), locals())

        settings = merge_two_dicts(settings, settings["settings"])

        del settings["self"]

        super(DeviceDetectionCloudPipelineBuilder, self).__init__(settings)

        # Add specific engines

        self.add(CloudRequestEngine(settings))
        device = DeviceDetectionCloud()

        if "cache" in settings:
            device.set_cache(settings["cache"])

        self.add(device)
else:
    resource_key = "!!YOUR_RESOURCE_KEY!!"

if resource_key == "!!YOUR_RESOURCE_KEY!!":
    print("""
    You need to create a resource key at
    https://configure.51degrees.com and paste it into the code,
    'replacing !!YOUR_RESOURCE_KEY!!
    make sure to include the HardwareName, HardwareProfile and HardwareVendor
    properties used by this example
    """)
else:

    # Create an instance of the cloud request engine with your resource key

    request_engine_instance = CloudRequestEngine(
        {"resource_key": resource_key})

    # Now create an instance of the hardwareprofile cloud engine

    hardware_profile_engine_instance = HardwareProfileCloud()

    # Now create a pipeline and add those two engines
    # the Cloud Request Engine needs to go first

    pipeline = PipelineBuilder().add(request_engine_instance).add(
        hardware_profile_engine_instance).build()

    # we get a tac to test
    tac = "35925406"

    # We create a FlowData object from the pipeline
Exemplo n.º 7
0
            "/11D167 Safari/9537.53")

# TODO remove setheader properties from this list once UACH datafile is released.
exclude_properties = ["setheaderbrowseraccept-ch", "setheaderplatformaccept-ch", "setheaderhardwareaccept-ch"]

if "resource_key" in os.environ:
    resource_key = os.environ["resource_key"]
else:
    raise Exception("To run the cloud tests, please set a valid 51Degrees "
                    "cloud resource key as the resource_key environment variable.")

# Get Properties list
properties_list = get_properties_from_header_file(header_file_path)

# Create a simple pipeline to access the engine with and process it with flow data
cloudRequestEngine = CloudRequestEngine({"resource_key": resource_key})
deviceDetectionCloudEngine = DeviceDetectionCloud()
pipeline = PipelineBuilder() \
        .add(cloudRequestEngine) \
        .add(deviceDetectionCloudEngine) \
        .build()
            
class PropertyTests(unittest.TestCase):

    def test_available_properties(self):

        """!
        Tests whether the all the properties present in the engine when initialised with a resource key are accessible.
        """

        flowData = pipeline.create_flowdata()