Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
cdn scopes and configurations (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandromodarelli authored Nov 18, 2019
1 parent 344c005 commit 2562ea2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pystackpath/stacks/cdnsites/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pystackpath.util import BaseSite
from pystackpath.stacks.cdnsites.scopes import Scopes


class CdnSites(BaseSite):
Expand Down Expand Up @@ -57,3 +58,6 @@ def enable(self):
response = self._client.post(f"{self._base_api}/sites/{self.id}/enable")
response.raise_for_status()
return self

def scopes(self):
return Scopes(self._client, f"{self._base_api}/sites/{self.id}")
48 changes: 48 additions & 0 deletions pystackpath/stacks/cdnsites/scopes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from pystackpath.util import BaseObject, pagination_query, PageInfo
from pystackpath.stacks.cdnsites.scopes.configuration import Configuration


class Scopes(BaseObject):
def index(self, first="", after="", filter="", sort_by="", disable_transparent_mode=None):
"""
Retrieve a CDN site's scopes
:return: a list of site scopes
"""
pagination = pagination_query(first=first, after=after, filter=filter, sort_by=sort_by)
params = {
"disable_transparent_mode": disable_transparent_mode
}
response = self._client.get(f"{self._base_api}/scopes",
params={**pagination, **params})
response.raise_for_status()
items = [self.loaddict(item) for item in response.json()["results"]]
pageinfo = PageInfo(**response.json()["pageInfo"])

return {"results": items, "pageinfo": pageinfo}

def create(self, **payload):
"""
Create a new CDN site scope
:param payload: dict according to https://stackpath.dev/reference/configuration#createscope
:return: dict with created site
String id A CDN site scope's unique identifier.
String platform A CDN site scope's platform.
Scope platforms are used internally by StackPath for metrics collection and billing purposes.
Typically, most site scope platforms have the value "CDS"
String path The HTTP request path that is handled by a scope.
"""
response = self._client.post(f"{self._base_api}/scopes", json=payload)
response.raise_for_status()
return self.loaddict(response.json()["scope"])

def delete(self):
"""
Delete a CDN site scope
:return: delivery domains configured on a site
"""
response = self._client.delete(f"{self._base_api}/scopes/{self.id}")
response.raise_for_status()
return self

def configuration(self):
return Configuration(self._client, f"{self._base_api}/scopes/{self.id}")
22 changes: 22 additions & 0 deletions pystackpath/stacks/cdnsites/scopes/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pystackpath.util import BaseObject, pagination_query, PageInfo


class Configuration(BaseObject):
def get(self):
"""
Retrieve a CDN site's scope configuration
:return: site's scope configuration
"""
response = self._client.get(f"{self._base_api}/configuration")
response.raise_for_status()
return self.loaddict(response.json()["configuration"])

def update(self, **payload):
"""
Update a CDN site's scope configuration
:param payload: dict according to https://stackpath.dev/reference/configuration#updatescopeconfiguration
:return: dict with new configuration
"""
response = self._client.post(f"{self._base_api}/configuration", json=payload)
response.raise_for_status()
return self.loaddict(response.json()["configuration"])

0 comments on commit 2562ea2

Please sign in to comment.