Add protocol field to domain allowing https domain
Change-Id: Id827780fb64f0d32d944e5062bcab6e2b2e2909a
This commit is contained in:
parent
e4af5f9d83
commit
1b987b3579
@ -13,14 +13,28 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
AVAILABLE_PROTOCOLS = [
|
||||
u'http',
|
||||
u'https']
|
||||
|
||||
from poppy.model import common
|
||||
|
||||
|
||||
class Domain(common.DictSerializableModel):
|
||||
|
||||
def __init__(self, domain):
|
||||
def __init__(self, domain, protocol='http'):
|
||||
self._domain = domain
|
||||
|
||||
if (protocol in AVAILABLE_PROTOCOLS):
|
||||
self._protocol = protocol
|
||||
else:
|
||||
raise ValueError(
|
||||
u'Protocol: {0} not in currently available'
|
||||
' protocols: {1}'.format(
|
||||
protocol,
|
||||
AVAILABLE_PROTOCOLS)
|
||||
)
|
||||
|
||||
@property
|
||||
def domain(self):
|
||||
"""domain.
|
||||
@ -34,6 +48,22 @@ class Domain(common.DictSerializableModel):
|
||||
"""domain setter."""
|
||||
self._domain = value
|
||||
|
||||
@property
|
||||
def protocol(self):
|
||||
return self._protocol
|
||||
|
||||
@protocol.setter
|
||||
def protocol(self, value):
|
||||
if (value in AVAILABLE_PROTOCOLS):
|
||||
self._protocol = value
|
||||
else:
|
||||
raise ValueError(
|
||||
u'Protocol: {0} not in currently available'
|
||||
' protocols: {1}'.format(
|
||||
value,
|
||||
AVAILABLE_PROTOCOLS)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def init_from_dict(cls, dict_obj):
|
||||
"""Construct a model instance from a dictionary.
|
||||
@ -45,4 +75,5 @@ class Domain(common.DictSerializableModel):
|
||||
"""
|
||||
o = cls("unnamed")
|
||||
o.domain = dict_obj.get("domain", "unnamed")
|
||||
o.protocol = dict_obj.get("protocol", "http")
|
||||
return o
|
||||
|
@ -88,6 +88,9 @@ class ServiceController(base.ServiceBase):
|
||||
# of each group
|
||||
dp = self._process_new_domain(classified_domain,
|
||||
post_data['rules'])
|
||||
# TODO(tonytan4ever): also classify domains based on their
|
||||
# protocols. http and https domains needs to be created
|
||||
# with separate base urls.
|
||||
resp = self.policy_api_client.put(
|
||||
self.policy_api_base_url.format(
|
||||
policy_name=dp),
|
||||
@ -329,6 +332,9 @@ class ServiceController(base.ServiceBase):
|
||||
# in this case we should update existing policy
|
||||
# instead of create a new policy
|
||||
LOG.info('Start to update policy %s' % dp)
|
||||
# TODO(tonytan4ever): also classify domains based on
|
||||
# their protocols. http and https domains needs to be
|
||||
# created with separate base urls.
|
||||
resp = self.policy_api_client.put(
|
||||
self.policy_api_base_url.format(
|
||||
policy_name=dp),
|
||||
@ -448,6 +454,9 @@ class ServiceController(base.ServiceBase):
|
||||
try:
|
||||
for policy in policies:
|
||||
LOG.info('Starting to delete policy %s' % policy)
|
||||
# TODO(tonytan4ever): needs to look at if service
|
||||
# domain is an https domain, if it is then a different
|
||||
# base url is needed
|
||||
resp = self.policy_api_client.delete(
|
||||
self.policy_api_base_url.format(policy_name=policy))
|
||||
LOG.info('akamai response code: %s' % resp.status_code)
|
||||
|
@ -18,4 +18,5 @@ from poppy.model.helpers import domain
|
||||
|
||||
def load_from_json(json_data):
|
||||
domain_name = json_data.get("domain")
|
||||
return domain.Domain(domain_name)
|
||||
protocol = json_data.get("protocol", 'http')
|
||||
return domain.Domain(domain_name, protocol)
|
||||
|
@ -26,3 +26,4 @@ class Model(collections.OrderedDict):
|
||||
def __init__(self, domain):
|
||||
super(Model, self).__init__()
|
||||
self['domain'] = domain.domain
|
||||
self['protocol'] = domain.protocol
|
||||
|
@ -49,6 +49,9 @@ class ServiceSchema(schema_base.SchemaBase):
|
||||
'(#(.*))?$',
|
||||
re.UNICODE
|
||||
)
|
||||
},
|
||||
'protocol': {
|
||||
'type': 'string'
|
||||
}}},
|
||||
'required': True,
|
||||
'minItems': 1},
|
||||
@ -256,7 +259,10 @@ class ServiceSchema(schema_base.SchemaBase):
|
||||
re.UNICODE
|
||||
),
|
||||
'required': True
|
||||
}}},
|
||||
},
|
||||
'protocol': {
|
||||
'type': 'string'
|
||||
}}}
|
||||
},
|
||||
'origins': {
|
||||
'type': 'array',
|
||||
|
@ -44,7 +44,7 @@ class TestServiceModel(base.TestCase):
|
||||
self.myorigins.append(origin.Origin('yoursite.io', port=80, ssl=True))
|
||||
|
||||
self.mydomains.append(domain.Domain('oursite.org'))
|
||||
self.mydomains.append(domain.Domain('wiki.cc'))
|
||||
self.mydomains.append(domain.Domain('wiki.cc', 'https'))
|
||||
|
||||
# test a rule with referrer restriction
|
||||
r1 = restriction.Restriction('referrer_site')
|
||||
@ -74,6 +74,8 @@ class TestServiceModel(base.TestCase):
|
||||
|
||||
# domains
|
||||
self.assertEqual(myservice.domains, self.mydomains)
|
||||
self.assertEqual(myservice.domains[0].protocol, 'http')
|
||||
self.assertEqual(myservice.domains[1].protocol, 'https')
|
||||
myservice.domains = []
|
||||
self.assertEqual(myservice.domains, [])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user