Exemplo n.º 1
0
    def post(self, *args, **kwargs):
        """Add entry in ACL.

        Args:

            [0], the project id (mandatory)

        Example URLs:

            POST /api/v1/projects/52313ecb-9d00-4b7d-b873-b55d3d9ada26/
                wifi_acl

            {
                "addr": "60:57:18:B1:A4:B8",
                "desc": "Dell Laptop"
            }
        """

        project_id = uuid.UUID(args[0])
        project = self.service.projects[project_id]

        desc = "Generic Station" if 'desc' not in kwargs else kwargs['desc']
        addr = EtherAddress(kwargs['addr'])

        allowed = project.wifi_props.allowed
        acl = ACL(addr=addr, desc=desc)

        allowed[str(acl.addr)] = acl

        project.save()

        url = "/api/v1/projects/%s/wifi_acl/%s" % (project_id, addr)

        self.set_header("Location", url)
Exemplo n.º 2
0
    def __load_acl(self):
        """ Load ACL list. """

        for allow in Session().query(TblAllow).all():

            if allow.addr in self.allowed:
                raise ValueError(allow.addr_str)

            acl = ACL(allow.addr, allow.label)
            self.allowed[allow.addr] = acl

        for deny in Session().query(TblDeny).all():
            if deny.addr in self.denied:
                raise ValueError(deny.addr_str)

            acl = ACL(deny.addr, deny.label)
            self.denied[deny.addr] = acl
Exemplo n.º 3
0
    def upsert_acl(self, addr, desc):
        """Upsert ACL."""

        acl = ACL(addr=addr, desc=desc)

        self.wifi_props.allowed[str(acl.addr)] = acl

        self.save()

        return acl
Exemplo n.º 4
0
    def add_denied(self, sta_addr, label):
        """ Add entry to ACL. """

        deny = Session().query(TblDeny) \
                        .filter(TblDeny.addr == sta_addr) \
                        .first()
        if deny:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblDeny(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.denied[sta_addr] = acl

        return acl
Exemplo n.º 5
0
    def add_allowed(self, sta_addr, label):
        """ Add entry to ACL. """

        allow = Session().query(TblAllow) \
                         .filter(TblAllow.addr == sta_addr) \
                         .first()
        if allow:
            raise ValueError(sta_addr)

        session = Session()
        session.add(TblAllow(addr=sta_addr, label=label))
        session.commit()

        acl = ACL(sta_addr, label)
        self.allowed[sta_addr] = acl

        return acl
Exemplo n.º 6
0
    def to_python(self, value):

        try:

            out = {}

            for acl in value.values():

                if not isinstance(acl, ACL):
                    acl = ACL(**acl)

                out[str(acl.addr)] = acl

            return out

        except ValueError as ex:
            raise ValidationError(ex)