diff --git a/heroku3/models/__init__.py b/heroku3/models/__init__.py index 218bf4f..a480b01 100644 --- a/heroku3/models/__init__.py +++ b/heroku3/models/__init__.py @@ -154,6 +154,16 @@ def __init__(self): def __repr__(self): return "".format(self.name) +class SNI(BaseResource): + """Heroku SNI.""" + + _strs = ["id", "name", "certificate_chain", "cname"] + _pks = ["name", "id"] + _dates = ["created_at", "updated_at"] + + def __repr__(self): + return "".format(self.name) + class User(BaseResource): """Heroku User.""" diff --git a/heroku3/models/app.py b/heroku3/models/app.py index 1740624..154712a 100644 --- a/heroku3/models/app.py +++ b/heroku3/models/app.py @@ -3,6 +3,8 @@ # Third party libraries from heroku3.models.slug import Slug +from requests.exceptions import HTTPError +from requests import codes as http_codes # Project libraries from .dyno import Dyno @@ -11,7 +13,7 @@ from .buildpack_installation import BuildpackInstallation from .domain import Domain from .region import Region -from ..models import User, Stack, BaseResource, Organization +from ..models import User, Stack, BaseResource, Organization, SNI from .release import Release from .logdrain import LogDrain from .formation import Formation @@ -134,6 +136,33 @@ def remove_addon(self, id): item = self._h._resource_deserialize(r.content.decode("utf-8")) return Addon.new_from_dict(item, h=self._h, app=self) + + def add_sni(self, certificate_chain, private_key): + payload = { 'certificate_chain': certificate_chain, 'private_key': private_key } + + r = self._h._http_resource(method="POST", resource=("apps", self.name, "sni-endpoints"), data=self._h._resource_serialize(payload)) + + r.raise_for_status() + item = self._h._resource_deserialize(r.content.decode("utf-8")) + return SNI.new_from_dict(item, h=self._h, app=self) + + + def remove_sni(self, sni_id_or_name): + r = self._h._http_resource(method="DELETE", resource=("apps", self.name, "sni-endpoints", sni_id_or_name)) + + r.raise_for_status() + item = self._h._resource_deserialize(r.content.decode("utf-8")) + return SNI.new_from_dict(item, h=self._h, app=self) + + + def get_sni(self, sni_id_or_name): + r = self._h._http_resource(method="GET", resource=("apps", self.id, "sni-endpoint", sni_id_or_name)) + + r.raise_for_status() + item = self._h._resource_deserialize(r.content.decode("utf-8")) + return SNI.new_from_dict(item, h=self._h, app=self) + + def collaborators(self, **kwargs): """The collaborators for this app.""" return self._h._get_resources( @@ -305,6 +334,39 @@ def resize_formation_process(self, formation_id_or_name, size): r.raise_for_status() return self._h._process_items(self._h._resource_deserialize(r.content.decode("utf-8")), Formation) + def get_boot_timeout(self): + try: + r = self._h._http_resource( + method="GET", + resource=("apps", self.id, "limits", "boot_timeout") + ) + except HTTPError as e: + if e.response.status_code == http_codes.not_found: + return None + else: + r.raise_for_status() + + obj = r.json() + assert obj["name"] == "boot_timeout" + return obj["value"] + + def set_boot_timeout(self, value): + r = self._h._http_resource( + method="PUT", + resource=("apps", self.id, "limits", "boot_timeout"), + data=self._h._resource_serialize({"value": value}) + ) + r.raise_for_status() + return r.ok + + def remove_boot_timeout(self): + r = self._h._http_resource( + method="DELETE", + resource=("apps", self.id, "limits", "boot_timeout") + ) + r.raise_for_status() + return r.ok + @property def info(self): """Returns current info for this app."""