From 60e098f4c63e0ae7fc0d660b631bbde2c516e9f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Daher?= Date: Fri, 28 Jun 2019 18:26:03 -0300 Subject: [PATCH] Add support to Team resource --- tsuru/__init__.py | 2 ++ tsuru/models/__init__.py | 2 ++ tsuru/models/team.py | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tsuru/models/team.py diff --git a/tsuru/__init__.py b/tsuru/__init__.py index f840a91..dbddffc 100644 --- a/tsuru/__init__.py +++ b/tsuru/__init__.py @@ -6,6 +6,7 @@ Log, Plan, Platform, + Team, ) from tsuru.exceptions import ( DoesNotExist, @@ -25,6 +26,7 @@ 'Log', 'Plan', 'Platform', + 'Team', 'DoesNotExist', 'UnexpectedDataFormat', 'UnsupportedModelException', diff --git a/tsuru/models/__init__.py b/tsuru/models/__init__.py index 534c25c..01ce0e2 100644 --- a/tsuru/models/__init__.py +++ b/tsuru/models/__init__.py @@ -5,6 +5,7 @@ from tsuru.models.log import Log from tsuru.models.plan import Plan from tsuru.models.platform import Platform +from tsuru.models.team import Team __all__ = ( 'App', 'Deploy', @@ -13,4 +14,5 @@ 'Log', 'Plan', 'Platform', + 'Team', ) diff --git a/tsuru/models/team.py b/tsuru/models/team.py new file mode 100644 index 0000000..d2b1143 --- /dev/null +++ b/tsuru/models/team.py @@ -0,0 +1,25 @@ +from tsuru import exceptions +from tsuru.models.base import BaseModel + + +class Team(BaseModel): + _RESOURCE_NAME = 'teams' + _PK_FIELD = 'name' + + @classmethod + def get(cls, pk): + # Since /teams endpoint does not support detail, + # we fetch-all-and-match + all_teams = cls.list() + for team in all_teams: + if team.pk == pk: + return team + raise exceptions.DoesNotExist() + + @property + def name(self): + return self._get('name') + + @property + def permissions(self): + return self._get('permissions')