This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
344c005
commit 2562ea2
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) |