Skip to content

added support for <app>/limits/boot_timeout #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions heroku3/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,16 @@ def __init__(self):
def __repr__(self):
return "<stack '{0}'>".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 "<SNI '{0}'>".format(self.name)


class User(BaseResource):
"""Heroku User."""
Expand Down
64 changes: 63 additions & 1 deletion heroku3/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand Down