1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00
Files
peeringdb-peeringdb/docs/dev/modules/rest.py.md
Stefan Pratter a0f1970fec Support 202211 (#1304)
* Carrier object implementation #909

* API keys: disabling of user account by a PeeringDB admin does not disable access via a User API key. Also no disable mech, only revoke. #1140

* Ops: django needs lightweight healthcheck route that confirms database connectivity #1284

* Ops: various indexes are needed #1285

* API requests with invalid Authentication headers should notify users in some way. #1220

* Allow user to change account username #1130

* UX to remove carriers from facilities more inline the other similar UX

* more UX fixes for removing carriers from facilities

* Cache hints are needed for optimal CDN use #970

* fixes Commandline tool "Run command" button gone #1278

* RIR status gets deleted when changes are made to the network #1279

* Improve MTU field #658

* CSRF cookie not set error from email confirmation view #1296

* expose CSP_CONNECT_SRC

* fix confirm email path checking in session middleware

* Ops: Emails to OPERATIONS_EMAIL need to be rate-limited #1282

* add website field to carrier ux

* website field on carrier optional with org fallback

* linting

* add *.google-analytics.com to CSP_CONNECT_SRC

* poetry relock

* fix issues with confirm-email reverse during session creation validation

* fix tests

* fix tests

* pin django-peeringdb to support_202211

* linting

* django ratelimit to <4

* regen docs

* fix automated net stats to only include networks with status `ok` #1283

* linting

* poetry lock

Co-authored-by: Matt Griswold <grizz@20c.com>
2023-01-18 10:32:46 -06:00

8.4 KiB

Generated from rest.py on 2023-01-17 22:33:48.360745

peeringdb_server.rest

REST API view definitions.

REST API path routing.

REST API permission checking (facilitated through django-grainy).

REST API error handling.

REST API list filtering logic.

peeringdb-py client compatibility checking.

The peeringdb REST API is implemented through django-rest-framework.

Functions


model_view_set

def model_view_set(model, methods=None, mixins=None)

Shortcut for peeringdb models to generate viewset and register in the API urls.


Classes


ASSetViewSet

ASSetViewSet(peeringdb_server.rest.ReadOnlyMixin, rest_framework.viewsets.ModelViewSet)

AS-SET endpoint.

List all as sets mapped by asn.

Methods

get_queryset

def get_queryset(self)

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)


BasicAuthMFABlockWrite

BasicAuthMFABlockWrite(rest_framework.permissions.BasePermission)

When an account has MFA enabled and basic-auth is used to authenticate the account for a write operation on the API block the request.

Methods

has_permission

def has_permission(self, request, view)

Return True if permission is granted, False otherwise.


CarrierFacilityMixin

CarrierFacilityMixin(builtins.object)

Custom API endpoints for the carrier-facility object, exposed to api/carrierfac/{id}/{action}

Methods

approve

def approve(self, request, *args, **kwargs)

Allows the org to approve a carrier listing at their facility


reject

def reject(self, request, *args, **kwargs)

Allows the org to reject a carrier listing at their facility


CarrierFacilityViewSet

CarrierFacilityViewSet(peeringdb_server.rest.CarrierFacilityMixin, peeringdb_server.rest.ModelViewSet)

Custom API endpoints for the carrier-facility object, exposed to api/carrierfac/{id}/{action}

CarrierViewSet

CarrierViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

DataException

DataException(builtins.ValueError)

Inappropriate argument value (of correct type).

DataMissingException

DataMissingException(peeringdb_server.rest.DataException)

"" Raised when the json data sent with a POST, PUT or PATCH request is missing.

Methods

_init_

def __init__(self, method)

Initialize self. See help(type(self)) for accurate signature.


DataParseException

DataParseException(peeringdb_server.rest.DataException)

Raised when the json data sent with a POST, PUT or PATCH request could not be parsed.

Methods

_init_

def __init__(self, method, exc)

Initialize self. See help(type(self)) for accurate signature.


FacilityViewSet

FacilityViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

IXLanPrefixViewSet

IXLanPrefixViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

IXLanViewSet

IXLanViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

InactiveKeyBlock

InactiveKeyBlock(rest_framework.permissions.BasePermission)

When an OrganizationAPIKey or a UserAPIKey has status inactive requests made with such keys should be blocked

Methods

has_permission

def has_permission(self, request, view)

Return True if permission is granted, False otherwise.


InactiveKeyException

InactiveKeyException(rest_framework.exceptions.APIException)

Raised on api authentications with inactive api keys

InternetExchangeFacilityViewSet

InternetExchangeFacilityViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

InternetExchangeMixin

InternetExchangeMixin(builtins.object)

Custom API endpoints for the internet exchange object, exposed to api/ix/{id}/{action}

Methods

request_ixf_import

def request_ixf_import(self, request, *args, **kwargs)

Allows managers of an ix to request an ix-f import. (#779)


InternetExchangeViewSet

InternetExchangeViewSet(peeringdb_server.rest.InternetExchangeMixin, peeringdb_server.rest.ModelViewSet)

Custom API endpoints for the internet exchange object, exposed to api/ix/{id}/{action}

ModelViewSet

ModelViewSet(rest_framework.viewsets.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

Methods

get_queryset

def get_queryset(self)

Prepare the queryset.


partial_update

def partial_update(self, request, *args, **kwargs)

PATCH (partial update) is currently disabled.


require_data

def require_data(self, request)

Test that the request contains data in its body that can be parsed to the required format (json) and is not empty.

Will raise DataParseException error if request payload could not be parsed.

Will raise DataMissingException error if request payload is missing or was parsed to an empty object.


NetworkContactViewSet

NetworkContactViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

NetworkFacilityViewSet

NetworkFacilityViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

NetworkIXLanViewSet

NetworkIXLanViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

NetworkViewSet

NetworkViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

OrganizationViewSet

OrganizationViewSet(peeringdb_server.rest.ModelViewSet)

Generic ModelViewSet Base Class. This should probably be moved to a common lib ?

RestRouter

RestRouter(rest_framework.routers.DefaultRouter)

The default router extends the SimpleRouter, but also adds in a default API root view, and adds format suffix patterns to the URLs.

Methods

_init_

def __init__(self, trailing_slash=False)

Initialize self. See help(type(self)) for accurate signature.


client_check

client_check(builtins.object)

Decorator that can be attached to rest viewset responses and will generate an error response if the requesting peeringdb client is running a client or backend version that is incompatible with the server.

Compatibilty is controlled via facsimile during deploy and can be configured in env.misc.api.compat

Methods

_call_

def __call__(self, fn)

Call self as a function.


_init_

def __init__(self)

Initialize self. See help(type(self)) for accurate signature.


backend_max_version

def backend_max_version(self, backend)

Return the max supported version for the specified backend.


backend_min_version

def backend_min_version(self, backend)

Return the min supported version for the specified backend.


client_info

def client_info(self, request)

Parse the useragent in the request and return client version info if possible.

Any connecting client that is NOT the peeringdb client will currently return an empty dict and not compatibility checking will be done.


compat_check

def compat_check(self, request)

Check if the connecting client is compatible with the API.

This is currently only sensible when the request is made through the official peeringdb-py client, any other client will be passed through without checks.

On incompatibility a ValueError is raised.


version_pad

def version_pad(self, version)

Take a semantic version tuple and zero pad to dev version.


version_string

def version_string(self, version)

Take a semantic version tuple and turn into a "." delimited string.


version_tuple

def version_tuple(self, str_version)

Take a semantic version string and turn into a tuple.