Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Re2o
Re2o API client
Compare Revisions
7bcd0924b823cc11a5714b96cc96fe26638ac9c7...5b4523c797bffb90c998d5b424548756baa0c1d2
Commits (4)
Update URLs
· be662c58
moamoak
authored
Jun 23, 2018
be662c58
Refactor exceptions
· d37d4743
moamoak
authored
Jun 23, 2018
d37d4743
Add comments
· baa6de4f
moamoak
authored
Jun 23, 2018
baa6de4f
Handle permission denied and relogin cases
· 5b4523c7
moamoak
authored
Jun 23, 2018
5b4523c7
Expand all
Hide whitespace changes
Inline
Side-by-side
re2oapi/client.py
View file @
5b4523c7
This diff is collapsed.
Click to expand it.
re2oapi/endpoints.py
View file @
5b4523c7
from
.
import
exceptions
urls
=
{
'root'
:
'/api/'
,
'articles-list'
:
'/api/cotisations/articles/'
,
'articles-details'
:
'/api/cotisations/articles/{pk}/'
,
'banques-list'
:
'/api/cotisations/banques/'
,
'banques-details'
:
'/api/cotisations/banques/{pk}/'
,
'cotisations-list'
:
'/api/cotisations/cotisations/'
,
'cotisations-details'
:
'/api/cotisations/cotisations/{pk}/'
,
'factures-list'
:
'/api/cotisations/factures/'
,
'factures-details'
:
'/api/cotisations/factures/{pk}/'
,
'paiments-list'
:
'/api/cotisations/paiements/'
,
'paiements-details'
:
'/api/cotisations/paiements/{pk}/'
,
'ventes-list'
:
'/api/cotisations/ventes/'
,
'ventes-details'
:
'/api/cotisations/ventes/{pk}/'
,
'domains-list'
:
'/api/machines/domains/'
,
'domains-details'
:
'/api/machines/domains/{pk}/'
,
'extensions-list'
:
'/api/machines/extensions/'
,
'extensions-details'
:
'/api/machines/extensions/{pk}/'
,
'interfaces-list'
:
'/api/machines/interfaces/'
,
'interfaces-details'
:
'/api/machines/interfaces/{pk}/'
,
'iplists-list'
:
'/api/machines/iplists/'
,
'iplists-details'
:
'/api/machines/iplists/{pk}/'
,
'iptypes-list'
:
'/api/machines/iptypes/'
,
'iptypes-details'
:
'/api/machines/iptypes/{pk}/'
,
'ipv6lists-list'
:
'/api/machines/ipv6lists/'
,
'ipv6lists-details'
:
'/api/machines/ipv6lists/{pk}/'
,
'machines-list'
:
'/api/machines/machines/'
,
'machines-details'
:
'/api/machines/machines/{pk}/'
,
'machinetypes-list'
:
'/api/machines/machinetypes/'
,
'machinetypes-details'
:
'/api/machines/machinetypes/{pk}/'
,
'mx-list'
:
'/api/machines/mx/'
,
'mx-details'
:
'/api/machines/mx/{pk}/'
,
'nas-list'
:
'/api/machines/nas/'
,
'nas-details'
:
'/api/machines/nas/{pk}/'
,
'ns-list'
:
'/api/machines/ns/'
,
'ns-details'
:
'/api/machines/ns/{pk}/'
,
'ouvertureportlists-list'
:
'/api/machines/ouvertureportlists/'
,
'ouvertureportlists-details'
:
'/api/machines/ouvertureportlists/{pk}/'
,
'ouvertureports-list'
:
'/api/machines/ouvertureports/'
,
'ouvertureports-details'
:
'/api/machines/ouvertureports/{pk}/'
,
'servicelinks-list'
:
'/api/machines/servicelinks/'
,
'servicelinks-details'
:
'/api/machines/servicelinks/{pk}/'
,
'services-list'
:
'/api/machines/services/'
,
'services-details'
:
'/api/machines/services/{pk}/'
,
'soa-list'
:
'/api/machines/soa/'
,
'soa-details'
:
'/api/machines/soa/{pk}/'
,
'srv-list'
:
'/api/machines/srv/'
,
'srv-details'
:
'/api/machines/srv/{pk}/'
,
'txt-list'
:
'/api/machines/txt/'
,
'txt-details'
:
'/api/machines/txt/{pk}/'
,
'vlans-list'
:
'/api/machines/vlans/'
,
'vlans-details'
:
'/api/machines/vlans/{pk}'
,
'accesspoint-list'
:
'/api/topologie/acesspoint/'
,
'accesspoint-details'
:
'/api/topologie/acesspoint/{pk}/'
,
'building-list'
:
'/api/topologie/building/'
,
'building-details'
:
'/api/topologie/building/{pk}/'
,
'constructorswitch-list'
:
'/api/topologie/constructorswitch/'
,
'contructorswitch-details'
:
'/api/topologie/constructorswitch/{pk}/'
,
'modelswitch-list'
:
'/api/topologie/modelswitch/'
,
'modelswitch-details'
:
'/api/topologie/modelswitch/{pk}/'
,
'room-list'
:
'/api/topologie/room/'
,
'room-details'
:
'/api/topologie/room/{pk}/'
,
'stack-list'
:
'/api/topologie/stack/'
,
'stack-details'
:
'/api/topologie/stack/{pk}/'
,
'switch-list'
:
'/api/topologie/switch/'
,
'switch-details'
:
'/api/topologie/switch/{pk}/'
,
'switchbay-list'
:
'/api/topologie/switchbay/'
,
'switchbay-details'
:
'/api/topologie/switchbay/{pk}/'
,
'switchport-list'
:
'/api/topologie/switchport/'
,
'switchport-details'
:
'/api/topologie/switchport/{pk}/'
,
'adherents-list'
:
'/api/users/adherents/'
,
'adherents-details'
:
'/api/users/adherents/{pk}/'
,
'bans-list'
:
'/api/users/bans/'
,
'bans-details'
:
'/api/users/bans/{pk}/'
,
'clubs-list'
:
'/api/users/clubs/'
,
'clubs-details'
:
'/api/users/clubs/{pk}/'
,
'listrights-list'
:
'/api/users/listrights/'
,
'listrights-details'
:
'/api/users/listrights/{pk}/'
,
'schools-list'
:
'/api/users/schools/'
,
'schools-details'
:
'/api/users/schools/{pk}/'
,
'serviceusers-list'
:
'/api/users/serviceusers/'
,
'serviceusers-details'
:
'/api/users/serviceusers/{pk}/'
,
'shells-list'
:
'/api/users/shells/'
,
'shells-details'
:
'/api/users/shells/{pk}/'
,
'users-list'
:
'/api/users/users/'
,
'users-details'
:
'/api/users/users/{pk}/'
,
'whitelists-list'
:
'/api/users/whitelists/'
,
'whitelists-details'
:
'/api/users/whitelists/{pk}/'
,
'hostmacip-list'
:
'/api/dhcp/hostmacip/'
,
'servicesregen-list'
:
'/api/services/regen/'
,
'token'
:
'/api/token-auth/'
,
'root'
:
'/api/'
,
'article-list'
:
'/api/cotisations/article/'
,
'article-detail'
:
'/api/cotisations/article/{pk}/'
,
'banque-list'
:
'/api/cotisations/banque/'
,
'banque-detail'
:
'/api/cotisations/banque/{pk}/'
,
'cotisation-list'
:
'/api/cotisations/cotisation/'
,
'cotisation-detail'
:
'/api/cotisations/cotisation/{pk}/'
,
'facture-list'
:
'/api/cotisations/facture/'
,
'facture-detail'
:
'/api/cotisations/facture/{pk}/'
,
'paiment-list'
:
'/api/cotisations/paiement/'
,
'paiement-detail'
:
'/api/cotisations/paiement/{pk}/'
,
'vente-list'
:
'/api/cotisations/vente/'
,
'vente-detail'
:
'/api/cotisations/vente/{pk}/'
,
'domain-list'
:
'/api/machines/domain/'
,
'domain-detail'
:
'/api/machines/domain/{pk}/'
,
'extension-list'
:
'/api/machines/extension/'
,
'extension-detail'
:
'/api/machines/extension/{pk}/'
,
'interface-list'
:
'/api/machines/interface/'
,
'interface-detail'
:
'/api/machines/interface/{pk}/'
,
'iplist-list'
:
'/api/machines/iplist/'
,
'iplist-detail'
:
'/api/machines/iplist/{pk}/'
,
'iptype-list'
:
'/api/machines/iptype/'
,
'iptype-detail'
:
'/api/machines/iptype/{pk}/'
,
'ipv6list-list'
:
'/api/machines/ipv6list/'
,
'ipv6list-detail'
:
'/api/machines/ipv6list/{pk}/'
,
'machine-list'
:
'/api/machines/machine/'
,
'machine-detail'
:
'/api/machines/machine/{pk}/'
,
'machinetype-list'
:
'/api/machines/machinetype/'
,
'machinetype-detail'
:
'/api/machines/machinetype/{pk}/'
,
'mx-list'
:
'/api/machines/mx/'
,
'mx-detail'
:
'/api/machines/mx/{pk}/'
,
'nas-list'
:
'/api/machines/nas/'
,
'nas-detail'
:
'/api/machines/nas/{pk}/'
,
'ns-list'
:
'/api/machines/ns/'
,
'ns-detail'
:
'/api/machines/ns/{pk}/'
,
'ouvertureportlist-list'
:
'/api/machines/ouvertureportlist/'
,
'ouvertureportlist-detail'
:
'/api/machines/ouvertureportlist/{pk}/'
,
'ouvertureport-list'
:
'/api/machines/ouvertureport/'
,
'ouvertureport-detail'
:
'/api/machines/ouvertureport/{pk}/'
,
'servicelink-list'
:
'/api/machines/servicelink/'
,
'servicelink-detail'
:
'/api/machines/servicelink/{pk}/'
,
'service-list'
:
'/api/machines/service/'
,
'service-detail'
:
'/api/machines/service/{pk}/'
,
'soa-list'
:
'/api/machines/soa/'
,
'soa-detail'
:
'/api/machines/soa/{pk}/'
,
'srv-list'
:
'/api/machines/srv/'
,
'srv-detail'
:
'/api/machines/srv/{pk}/'
,
'txt-list'
:
'/api/machines/txt/'
,
'txt-detail'
:
'/api/machines/txt/{pk}/'
,
'vlan-list'
:
'/api/machines/vlan/'
,
'vlan-detail'
:
'/api/machines/vlan/{pk}/'
,
'optionaluser-detail'
:
'/api/preferences/optionaluser/'
,
'optionalmachine-detail'
:
'/api/preferences/optionalmachine/'
,
'optionaltopologie-detail'
:
'/api/preferences/optionaltopologie/'
,
'generaloption-detail'
:
'/api/preferences/generaloption/'
,
'homeservice-list'
:
'/api/preferences/service/'
,
'homeservice-detail'
:
'/api/preferences/service/{pk}/'
,
'assooption-detail'
:
'/api/preferences/assooption/'
,
'homeoption-detail'
:
'/api/preferences/homeoption/'
,
'mailmessageoption-detail'
:
'/api/preferences/mailmessageoption/'
,
'accesspoint-list'
:
'/api/topologie/acesspoint/'
,
'accesspoint-detail'
:
'/api/topologie/acesspoint/{pk}/'
,
'building-list'
:
'/api/topologie/building/'
,
'building-detail'
:
'/api/topologie/building/{pk}/'
,
'constructorswitch-list'
:
'/api/topologie/constructorswitch/'
,
'constructorswitch-detail'
:
'/api/topologie/constructorswitch/{pk}/'
,
'modelswitch-list'
:
'/api/topologie/modelswitch/'
,
'modelswitch-detail'
:
'/api/topologie/modelswitch/{pk}/'
,
'room-list'
:
'/api/topologie/room/'
,
'room-detail'
:
'/api/topologie/room/{pk}/'
,
'server-list'
:
'/api/topologie/server/'
,
'server-detail'
:
'/api/topologie/server/{pk}/'
,
'stack-list'
:
'/api/topologie/stack/'
,
'stack-detail'
:
'/api/topologie/stack/{pk}/'
,
'switch-list'
:
'/api/topologie/switch/'
,
'switch-detail'
:
'/api/topologie/switch/{pk}/'
,
'switchbay-list'
:
'/api/topologie/switchbay/'
,
'switchbay-detail'
:
'/api/topologie/switchbay/{pk}/'
,
'switchport-list'
:
'/api/topologie/switchport/'
,
'switchport-detail'
:
'/api/topologie/switchport/{pk}/'
,
'adherent-list'
:
'/api/users/adherent/'
,
'adherent-detail'
:
'/api/users/adherent/{pk}/'
,
'ban-list'
:
'/api/users/ban/'
,
'ban-detail'
:
'/api/users/ban/{pk}/'
,
'club-list'
:
'/api/users/club/'
,
'club-detail'
:
'/api/users/club/{pk}/'
,
'listright-list'
:
'/api/users/listright/'
,
'listright-detail'
:
'/api/users/listright/{pk}/'
,
'school-list'
:
'/api/users/school/'
,
'school-detail'
:
'/api/users/school/{pk}/'
,
'serviceuser-list'
:
'/api/users/serviceuser/'
,
'serviceuser-detail'
:
'/api/users/serviceuser/{pk}/'
,
'shell-list'
:
'/api/users/shell/'
,
'shell-detail'
:
'/api/users/shell/{pk}/'
,
'user-list'
:
'/api/users/user/'
,
'user-detail'
:
'/api/users/user/{pk}/'
,
'whitelist-list'
:
'/api/users/whitelist/'
,
'whitelist-detail'
:
'/api/users/whitelist/{pk}/'
,
'dnszones-list'
:
'/api/dns/zones/'
,
'hostmacip-list'
:
'/api/dhcp/hostmacip/'
,
'mailingstandard-list'
:
'/api/mailing/standard/'
,
'mailingclub-list'
:
'/api/mailing/club/'
,
'servicesregen-list'
:
'/api/services/regen/'
,
'servicesregen-detail'
:
'/api/services/regen/{pk}/'
,
'token'
:
'/api/token-auth/'
,
}
...
...
@@ -102,7 +117,7 @@ def get_endpoint_for(name, **kwargs):
try
:
url
=
urls
[
name
]
except
KeyError
as
e
:
raise
exceptions
.
URLNameNotExists
(
name
)
raise
exceptions
.
URLName
Does
NotExists
(
name
)
else
:
try
:
return
url
.
format_map
(
kwargs
)
...
...
re2oapi/exceptions.py
View file @
5b4523c7
class
URLNameNotExists
(
ValueError
):
pass
class
APIClientGenericError
(
ValueError
):
template
=
"{}"
class
URLParameterMissing
(
ValueError
):
pass
def
__init__
(
self
,
*
data
):
self
.
data
=
data
self
.
message
=
self
.
template
.
format
(
*
data
)
super
(
APIClientGenericError
,
self
).
__init__
(
self
.
message
)
class
InvalidCredentials
(
ValueError
):
pass
class
TokenFileNotFound
(
Value
Error
):
pass
class
URLNameDoesNotExists
(
APIClientGeneric
Error
):
template
=
"The name '{}' was not foud among the possible endpoints."
class
TokenNotInTokenFile
(
ValueError
):
pass
class
URLParameterMissing
(
APIClientGenericError
):
template
=
"The url named '{}' require the parameter '{}' to be built."
class
InvalidCredentials
(
APIClientGenericError
):
template
=
"The credentials for {}@{} are not valid."
class
PermissionDenied
(
APIClientGenericError
):
template
=
"The {} request to '{}' was denied for {}."
class
TokenFileNotFound
(
APIClientGenericError
):
template
=
"Token file at {} not found."
class
TokenNotInTokenFile
(
APIClientGenericError
):
template
=
"Token for {}@{} not found in token file ({})."