Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@classmethod
def find(cls, conn, **kwargs):
resp, data = cls.query(conn, cls.INSTANCE_PATTERN, 'GET', **kwargs)
obj = cls.construct_instance(data)
obj.conn = conn
return obj
@classmethod
def construct_instance(cls, data):
obj = cls()
obj._original_attrs = data
obj.attrs = copy(data)
return obj
class Service(Model):
COLLECTION_PATTERN = '/service'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
def purge_key(self, key):
self._query('POST', '/purge/%s' % key)
def purge_all(self):
self._query('POST', '/purge_all')
def version(self):
""" Create a new version under this service. """
ver = Version()
ver.conn = self.conn
ver.attrs = {
# Parent params
return vcl
class Domain(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/domain'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def check_cname(self):
resp, data = self._query('GET', '/check')
return (data[1], data[2])
class Backend(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/backend'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Director(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/director'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Origin(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/origin'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Healthcheck(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/backend'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Director(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/director'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Origin(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/origin'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Healthcheck(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = '/user/$id'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
class Settings(Model):
INSTANCE_PATTERN = Version.COLLECTION_PATTERN + '/$version/settings'
COLLECTION_PATTERN = INSTANCE_PATTERN
class Condition(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/condition'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Header(Model):
return data
def item(self, item_key, item_value=None):
if item_value is not None:
return DictionaryItem.upsert(self.conn, {
'service_id': self.attrs['service_id'],
'dictionary_id': self.attrs['id'],
'item_key': item_key,
'item_value': item_value,
})
return DictionaryItem.find(self.conn, service_id=self.attrs['service_id'], dictionary_id=self.attrs['id'], item_key=item_key)
def items(self):
return DictionaryItem.list(self.conn, service_id=self.attrs['service_id'], dictionary_id=self.attrs['id'])
class DictionaryItem(Model):
COLLECTION_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/items'
INSTANCE_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/item/$item_key'
INSTANCE_CREATE_PATTERN = Service.COLLECTION_PATTERN + '/$service_id/dictionary/$dictionary_id/item'
@classmethod
def upsert(cls, conn, data):
# https://docs.fastly.com/api/config#dictionary_item_34c884a7cdce84dfcfd38dac7a0b5bb0
instance = cls.construct_instance(data)
instance.conn = conn
params_str = urlencode(instance.attrs)
resp, data = instance._query('PUT', body=params_str)
instance._original_attrs = data
instance.attrs = data
return instance
def _collection_query(self, method, suffix='', body=None):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = '/user/$id'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
class Settings(Model):
INSTANCE_PATTERN = Version.COLLECTION_PATTERN + '/$version/settings'
COLLECTION_PATTERN = INSTANCE_PATTERN
class Condition(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/condition'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Header(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/header'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class VCL(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/vcl'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def download(self):
resp, data = self._query('GET', '/download')
return data
def main(self):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/origin'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Healthcheck(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = '/user/$id'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
class Settings(Model):
INSTANCE_PATTERN = Version.COLLECTION_PATTERN + '/$version/settings'
COLLECTION_PATTERN = INSTANCE_PATTERN
class Condition(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/condition'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Header(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/header'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class VCL(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/vcl'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def download(self):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/header'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class VCL(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/vcl'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def download(self):
resp, data = self._query('GET', '/download')
return data
def main(self):
resp, data = self._query('PUT', '/main')
return data
class Dictionary(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/dictionary'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def info(self):
resp, data = self._collection_query('GET', suffix='/$id/info')
return data
def item(self, item_key, item_value=None):
if item_value is not None:
return DictionaryItem.upsert(self.conn, {
'service_id': self.attrs['service_id'],
'dictionary_id': self.attrs['id'],
'item_key': item_key,
'item_value': item_value,
})
return DictionaryItem.find(self.conn, service_id=self.attrs['service_id'], dictionary_id=self.attrs['id'], item_key=item_key)
vcl.attrs = {
# Parent params
'service_id': self.attrs['service_id'],
'version': self.attrs['number'],
# New instance params
'name': name,
'content': content,
}
vcl.save()
return vcl
class Domain(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/domain'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
def check_cname(self):
resp, data = self._query('GET', '/check')
return (data[1], data[2])
class Backend(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/backend'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Director(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/director'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Origin(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/director'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Origin(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/origin'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Healthcheck(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = '/user/$id'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
class Settings(Model):
INSTANCE_PATTERN = Version.COLLECTION_PATTERN + '/$version/settings'
COLLECTION_PATTERN = INSTANCE_PATTERN
class Condition(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/condition'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Header(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/header'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class VCL(Model):
resp, data = self._query('GET', '/check')
return (data[1], data[2])
class Backend(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/backend'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Director(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/director'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Origin(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/origin'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Healthcheck(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/healthcheck'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class Syslog(Model):
COLLECTION_PATTERN = Version.COLLECTION_PATTERN + '/$version/syslog'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$name'
class User(Model):
COLLECTION_PATTERN = '/user/$id'
INSTANCE_PATTERN = COLLECTION_PATTERN + '/$id'
class Settings(Model):
INSTANCE_PATTERN = Version.COLLECTION_PATTERN + '/$version/settings'
COLLECTION_PATTERN = INSTANCE_PATTERN
class Condition(Model):