Esempio n. 1
0
    def __generate_fence_objects_from_policy(policy):
        fences = list()
        for fence in policy["fences"]:
            if fence["type"] == "GEO_CIRCLE":
                fences.append(
                    GeoCircleFence(
                        latitude=fence["latitude"],
                        longitude=fence["longitude"],
                        radius=fence["radius"],
                        name=fence["name"]
                    )
                )
            elif fence["type"] == "TERRITORY":
                fences.append(
                    TerritoryFence(
                        country=fence["country"],
                        administrative_area=fence["administrative_area"],
                        postal_code=fence["postal_code"],
                        name=fence["name"]
                    )
                )
            else:
                raise InvalidFenceType(
                    "Fence type \"{0}\" was not a valid Fence type".format(
                        fence["type"]
                    )
                )

        return fences
Esempio n. 2
0
 def __geofence_to_geo_circle(geofence):
     return GeoCircleFence(
         geofence.latitude,
         geofence.longitude,
         geofence.radius,
         name=geofence.name
     )
Esempio n. 3
0
def step_impl(context):
    policy = context.entity_manager.get_current_auth_policy()
    for row in context.table:
        new_fence = GeoCircleFence(latitude=row["latitude"],
                                   longitude=row["longitude"],
                                   radius=row["radius"],
                                   name=row["name"])

        policy.fences.append(new_fence)
    context.entity_manager.set_current_auth_policy(policy)
Esempio n. 4
0
    def __generate_fence_from_policy_dict(fence):
        if not fence.get("type"):
            # Denotes a legacy geofence that can become a GeoCircleFence
            return GeoCircleFence(fence["latitude"],
                                  fence["longitude"],
                                  fence["radius"],
                                  name=fence.get("name"))

        if fence["type"] == "TERRITORY":
            return TerritoryFence(
                fence["country"],
                administrative_area=fence.get("administrative_area"),
                postal_code=fence.get("postal_code"),
                name=fence.get("name"))

        if fence["type"] == "GEO_CIRCLE":
            return GeoCircleFence(fence["latitude"],
                                  fence["longitude"],
                                  fence["radius"],
                                  name=fence.get("name"))

        raise ValueError("Invalid fence type received in Auth Response")
Esempio n. 5
0
def step_impl(context):

    default_nested_policy = FactorsPolicy(
        knowledge_required=True,
        deny_emulator_simulator=None,
        deny_rooted_jailbroken=None,
        fences=None
    )

    default_cond_geo_policy = ConditionalGeoFencePolicy(
        inside=default_nested_policy,
        outside=default_nested_policy,
        fences=[GeoCircleFence(latitude=30, longitude=30, radius=3000,
                               name="cool geofence")]
    )

    context.entity_manager.set_current_directory_service_policy(
        default_cond_geo_policy)
    context.entity_manager.set_current_auth_policy(default_cond_geo_policy)