Change type of restriction to access
Change-Id: I7456f74f4cdeb2218d5cc56acb2cb177d47ca273
This commit is contained in:
parent
21d5cb572f
commit
87dc252635
|
@ -17,7 +17,7 @@ from poppy.model import common
|
|||
from poppy.model.helpers import rule
|
||||
|
||||
|
||||
VALID_RESTRICTION_TYPES = [
|
||||
VALID_RESTRICTION_ACCESSES = [
|
||||
u'whitelist',
|
||||
u'blacklist']
|
||||
|
||||
|
@ -29,9 +29,9 @@ class Restriction(common.DictSerializableModel):
|
|||
def __init__(self, name,
|
||||
# use r_type because type is
|
||||
# a python reserved word
|
||||
r_type='whitelist', rules=[]):
|
||||
access='whitelist', rules=[]):
|
||||
self._name = name
|
||||
self._type = r_type
|
||||
self._access = access
|
||||
self._rules = rules
|
||||
|
||||
@property
|
||||
|
@ -47,22 +47,22 @@ class Restriction(common.DictSerializableModel):
|
|||
self._name = value
|
||||
|
||||
@property
|
||||
def type(self):
|
||||
def access(self):
|
||||
"""name.
|
||||
|
||||
:returns name
|
||||
"""
|
||||
return self._type
|
||||
return self._access
|
||||
|
||||
@type.setter
|
||||
def type(self, value):
|
||||
if (value in VALID_RESTRICTION_TYPES):
|
||||
@access.setter
|
||||
def access(self, value):
|
||||
if (value in VALID_RESTRICTION_ACCESSES):
|
||||
self._status = value
|
||||
else:
|
||||
raise ValueError(
|
||||
u'Type {0} not in valid options: {1}'.format(
|
||||
value,
|
||||
VALID_RESTRICTION_TYPES)
|
||||
VALID_RESTRICTION_ACCESSES)
|
||||
)
|
||||
|
||||
@property
|
||||
|
@ -87,8 +87,8 @@ class Restriction(common.DictSerializableModel):
|
|||
:returns o
|
||||
"""
|
||||
|
||||
r_type = dict_obj.get("type", 'whitelist')
|
||||
o = cls("unnamed", r_type)
|
||||
access = dict_obj.get("access", 'whitelist')
|
||||
o = cls("unnamed", access)
|
||||
o.name = dict_obj.get("name", "unnamed")
|
||||
rules_dict_list = dict_obj.get("rules", [])
|
||||
o.rules = []
|
||||
|
|
|
@ -562,9 +562,9 @@ class ServiceController(base.ServiceBase):
|
|||
|
||||
for restriction_rule in restriction_rules:
|
||||
entity_rule_mapping = {}
|
||||
if restriction_rule.type == 'whitelist':
|
||||
if restriction_rule.access == 'whitelist':
|
||||
entity_rule_mapping = white_list_entities
|
||||
elif restriction_rule.type == 'blacklist':
|
||||
elif restriction_rule.access == 'blacklist':
|
||||
entity_rule_mapping = black_list_entities
|
||||
for rule_entry in restriction_rule.rules:
|
||||
# classify rules based on their entities, then request_urls
|
||||
|
@ -635,16 +635,16 @@ class ServiceController(base.ServiceBase):
|
|||
# end loop - request url
|
||||
# end loop - entity
|
||||
|
||||
def _get_behavior_name(self, entity, entity_restriction_type):
|
||||
def _get_behavior_name(self, entity, entity_restriction_access):
|
||||
prefix = suffix = None
|
||||
if entity == 'referrer':
|
||||
prefix = 'referer'
|
||||
elif entity == 'client_ip':
|
||||
prefix = 'ip'
|
||||
|
||||
if entity_restriction_type == 'whitelist':
|
||||
if entity_restriction_access == 'whitelist':
|
||||
suffix = 'whitelist'
|
||||
elif entity_restriction_type == 'blacklist':
|
||||
elif entity_restriction_access == 'blacklist':
|
||||
suffix = 'blacklist'
|
||||
|
||||
return '-'.join([prefix, suffix])
|
||||
|
|
|
@ -639,7 +639,7 @@ class ServicesController(base.ServicesController):
|
|||
|
||||
restrictions = [restriction.Restriction(
|
||||
r.get('name'),
|
||||
r.get('type'),
|
||||
r.get('access'),
|
||||
|
||||
[rule.Rule(r_rule.get('name'),
|
||||
referrer=r_rule.get('referrer'),
|
||||
|
|
|
@ -19,8 +19,8 @@ from poppy.transport.pecan.models.request import rule
|
|||
|
||||
def load_from_json(json_data):
|
||||
name = json_data.get('name')
|
||||
r_type = json_data.get('type', 'whitelist')
|
||||
res = restriction.Restriction(name, r_type)
|
||||
access = json_data.get('access', 'whitelist')
|
||||
res = restriction.Restriction(name, access)
|
||||
rules = json_data.get('rules', [])
|
||||
rules = [rule.load_from_json(r) for r in rules]
|
||||
res.rules = rules
|
||||
|
|
|
@ -29,5 +29,5 @@ class Model(collections.OrderedDict):
|
|||
def __init__(self, restriction):
|
||||
super(Model, self).__init__()
|
||||
self['name'] = util.help_escape(restriction.name)
|
||||
self['type'] = restriction.type
|
||||
self['access'] = restriction.access
|
||||
self['rules'] = [rule.Model(r) for r in restriction.rules]
|
||||
|
|
|
@ -423,7 +423,7 @@ class ServiceSchema(schema_base.SchemaBase):
|
|||
'required': True,
|
||||
'minLength': 1,
|
||||
'maxLength': 256},
|
||||
'type': {
|
||||
'access': {
|
||||
'type': 'string',
|
||||
'enum': [
|
||||
"whitelist",
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"restrictions_list": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -482,7 +482,7 @@
|
|||
"restrictions_list": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only 1234",
|
||||
|
@ -531,7 +531,7 @@
|
|||
"restrictions_list": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only 1234",
|
||||
|
|
|
@ -121,7 +121,7 @@
|
|||
"request_url" : "/index.htm"}]}],
|
||||
"restrictions_list": [
|
||||
{"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "only me",
|
||||
"referrer": "www.mywebsite.com"}]}
|
||||
]
|
||||
|
@ -388,7 +388,7 @@
|
|||
"request_url" : "/index.htm"}]}],
|
||||
"restrictions_list": [
|
||||
{"name": "test",
|
||||
"type": "nonsense",
|
||||
"access": "nonsense",
|
||||
"rules": [{"name": "only me",
|
||||
"referrer": "www.mywebsite.com"}]}
|
||||
]
|
||||
|
@ -518,7 +518,7 @@
|
|||
"request_url" : "/index.htm"}]}],
|
||||
"restrictions_list": [{"name":"default",
|
||||
"rules": [{"client_ip": "1.2.3.4"}]},{
|
||||
"name":"default-blacklist", "type": "blacklist",
|
||||
"name":"default-blacklist", "access": "blacklist",
|
||||
"rules": [{"client_ip": "5.6.7.8"}]}]
|
||||
},
|
||||
"origin_invalid_port": {
|
||||
|
@ -904,4 +904,4 @@
|
|||
"request_url" : "/index.htm"}]}],
|
||||
"restrictions_list": []
|
||||
}
|
||||
}
|
||||
}
|
|
@ -185,7 +185,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -223,7 +223,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -270,7 +270,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -354,7 +354,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -439,7 +439,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -525,7 +525,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "test",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only me",
|
||||
|
@ -537,4 +537,4 @@
|
|||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -206,13 +206,13 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images2/*"}]
|
||||
}},
|
||||
{"op": "replace",
|
||||
"path": "/restrictions/0",
|
||||
"value": {"name": "new_restricted",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/*"}]
|
||||
}}
|
||||
],
|
||||
|
@ -236,7 +236,7 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "r",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images/*"}]
|
||||
}
|
||||
}
|
||||
|
@ -245,7 +245,7 @@
|
|||
{"op": "replace",
|
||||
"path": "/restrictions/0",
|
||||
"value": {"name": "new_restricted",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images2/*"}]
|
||||
}}
|
||||
],
|
||||
|
@ -253,13 +253,13 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images3/*"}]
|
||||
}},
|
||||
{"op": "replace",
|
||||
"path": "/restrictions/1",
|
||||
"value": {"name": "new_restricted",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images3/*"}]
|
||||
}}
|
||||
],
|
||||
|
@ -267,7 +267,7 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [{"name": "rule1", "referrer": "www.thesite.com", "request_url": "/images3/*"}]
|
||||
}},
|
||||
{"op": "replace",
|
||||
|
@ -280,7 +280,7 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "r", "referrer": "www.thesite.com", "request_url": "/images/*"}]
|
||||
}
|
||||
}
|
||||
|
@ -289,7 +289,7 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "referrer": "a.co", "request_url":"/images/*"}]
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +320,7 @@
|
|||
{"op": "replace",
|
||||
"path": "/restrictions/0",
|
||||
"value": {"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com",
|
||||
"request_url": "/*"
|
||||
|
@ -337,7 +337,7 @@
|
|||
{"op": "replace",
|
||||
"path": "/restrictions/0",
|
||||
"value": {"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com",
|
||||
"request_url": "/*"
|
||||
|
@ -347,7 +347,7 @@
|
|||
{"op": "replace",
|
||||
"path": "/restrictions/0",
|
||||
"value": {"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "mywebsite.com",
|
||||
"referrer": "www.mywebsite.com",
|
||||
"request_url": "/*"
|
||||
|
|
|
@ -216,7 +216,7 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted-blacklist",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [{"name": "rule1", "referrer": "myblacklist.com"}]
|
||||
}
|
||||
}
|
||||
|
@ -225,14 +225,14 @@
|
|||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted-whitelist",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [{"name": "rule1", "client_ip": "1.2.3.4"}]
|
||||
}
|
||||
},
|
||||
{"op": "add",
|
||||
"path": "/restrictions/-",
|
||||
"value": {"name": "restricted-blacklist",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [{"name": "rule1", "client_ip": "5.6.7.8"}]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,7 +336,7 @@ class TestServiceActions(base.TestBase):
|
|||
self.restrictions_list = [
|
||||
{
|
||||
u"name": u"website only",
|
||||
u"type": u"whitelist",
|
||||
u"access": u"whitelist",
|
||||
u"rules": [
|
||||
{
|
||||
u"name": domain,
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
@ -59,7 +59,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
@ -97,7 +97,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
@ -71,7 +71,7 @@
|
|||
},
|
||||
{
|
||||
"name": "graphic and US only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mockgraphicsite.com",
|
||||
|
@ -192,7 +192,7 @@
|
|||
},
|
||||
{
|
||||
"name": "no graphic",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mockgraphicsite.com",
|
||||
|
@ -202,7 +202,7 @@
|
|||
},
|
||||
{
|
||||
"name": "no logo",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mockgraphicsite.com",
|
||||
|
@ -241,7 +241,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "only from ip 1234",
|
||||
"type": "blacklist",
|
||||
"access": "blacklist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "only ip",
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
"restrictions": [
|
||||
{
|
||||
"name": "website only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mocksite.com",
|
||||
|
@ -54,7 +54,7 @@
|
|||
},
|
||||
{
|
||||
"name": "graphic and US only",
|
||||
"type": "whitelist",
|
||||
"access": "whitelist",
|
||||
"rules": [
|
||||
{
|
||||
"name": "mockgraphicsite.com",
|
||||
|
|
Loading…
Reference in New Issue