api

package
v0.0.0-...-7025c6a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package api manages the api controllers

Index

Constants

View Source
const ERROR_BASE_URL = "http://readium.org/license-status-document/error/"

Error types defined by the License Status Document specification

View Source
const REGISTER_ERROR = ERROR_BASE_URL + "registration"
View Source
const RENEW_DATE = ERROR_BASE_URL + "renew/date" // unused
View Source
const RENEW_ERROR = ERROR_BASE_URL + "renew"
View Source
const RETURN_ALREADY = ERROR_BASE_URL + "return/already" // unused
View Source
const RETURN_ERROR = ERROR_BASE_URL + "return"
View Source
const RETURN_EXPIRED = ERROR_BASE_URL + "return/expired" // unused
View Source
const REVOKE_ERROR = ERROR_BASE_URL + "revoke"

Error types defined for this server

View Source
const SERVER_ERROR = ERROR_BASE_URL + "server"

Variables

View Source
var (
	ErrMissingLicenseId  = errors.New("missing required license identifier")
	ErrMissingDeviceInfo = errors.New("missing required device information")
)
View Source
var ErrNotFound = &ErrResponse{
	HTTPStatusCode: 404,
	Type:           "about:blank",
	Title:          "Resource not found.",
}

Functions

func ErrInvalidRequest

func ErrInvalidRequest(err error) render.Renderer

func ErrRegister

func ErrRegister(err error) render.Renderer

func ErrRender

func ErrRender(err error) render.Renderer

func ErrRenew

func ErrRenew(err error) render.Renderer

func ErrReturn

func ErrReturn(err error) render.Renderer

func ErrRevoke

func ErrRevoke(err error) render.Renderer

func ErrServer

func ErrServer(err error) render.Renderer

func NewLicenseInfoListResponse

func NewLicenseInfoListResponse(licenses *[]stor.LicenseInfo) []render.Renderer

NewLicenseInfoListResponse creates a rendered list of licenses

func NewPublicationListResponse

func NewPublicationListResponse(publications *[]stor.Publication) []render.Renderer

NewPublicationListResponse creates a rendered list of publications

Types

type APICtrl

type APICtrl struct {
	*conf.Config // TODO: change for an interface (dependency)
	stor.Store
	Cert *tls.Certificate
}

APICtrl contains the context required by http handlers.

func NewAPICtrl

func NewAPICtrl(cf *conf.Config, st stor.Store, cr *tls.Certificate) *APICtrl

NewAPICtrl returns a new API controller

func (*APICtrl) CreateLicense

func (a *APICtrl) CreateLicense(w http.ResponseWriter, r *http.Request)

CreateLicense adds a new license to the database.

func (*APICtrl) CreatePublication

func (a *APICtrl) CreatePublication(w http.ResponseWriter, r *http.Request)

CreatePublication adds a new Publication to the database.

func (*APICtrl) DeleteLicense

func (a *APICtrl) DeleteLicense(w http.ResponseWriter, r *http.Request)

DeleteLicense removes an existing license from the database.

func (*APICtrl) DeletePublication

func (a *APICtrl) DeletePublication(w http.ResponseWriter, r *http.Request)

DeletePublication removes an existing Publication from the database.

func (*APICtrl) FreshLicense

func (a *APICtrl) FreshLicense(w http.ResponseWriter, r *http.Request)

FreshLicense returns a fresh license

func (*APICtrl) GenerateLicense

func (a *APICtrl) GenerateLicense(w http.ResponseWriter, r *http.Request)

GenerateLicense creates a license in the db and returns a fresh license

func (*APICtrl) GetLicense

func (a *APICtrl) GetLicense(w http.ResponseWriter, r *http.Request)

GetLicense returns a specific license

func (*APICtrl) GetPublication

func (a *APICtrl) GetPublication(w http.ResponseWriter, r *http.Request)

GetPublication returns a specific publication

func (*APICtrl) ListLicenses

func (a *APICtrl) ListLicenses(w http.ResponseWriter, r *http.Request)

ListLicenses lists all licenses present in the database.

func (*APICtrl) ListPublications

func (a *APICtrl) ListPublications(w http.ResponseWriter, r *http.Request)

ListPublications lists all publications present in the database.

func (*APICtrl) Register

func (a *APICtrl) Register(w http.ResponseWriter, r *http.Request)

Register records a new device using the license and returns a status document.

func (*APICtrl) Renew

func (a *APICtrl) Renew(w http.ResponseWriter, r *http.Request)

Renew extends the lifetime of a license and returns a status document.

func (*APICtrl) Return

func (a *APICtrl) Return(w http.ResponseWriter, r *http.Request)

Return forces the expiration of a license and returns a status document.

func (*APICtrl) Revoke

func (a *APICtrl) Revoke(w http.ResponseWriter, r *http.Request)

Revoke forces the expiration of a license and returns a status document.

func (*APICtrl) SearchLicenses

func (a *APICtrl) SearchLicenses(w http.ResponseWriter, r *http.Request)

SearchLicenses searches licenses corresponding to a specific criteria.

func (*APICtrl) SearchPublications

func (a *APICtrl) SearchPublications(w http.ResponseWriter, r *http.Request)

SearchPublications searches publications corresponding to a specific criteria.

func (*APICtrl) StatusDoc

func (a *APICtrl) StatusDoc(w http.ResponseWriter, r *http.Request)

Status returns a status document for the input license.

func (*APICtrl) UpdateLicense

func (a *APICtrl) UpdateLicense(w http.ResponseWriter, r *http.Request)

UpdateLicense updates an existing License in the database.

func (*APICtrl) UpdatePublication

func (a *APICtrl) UpdatePublication(w http.ResponseWriter, r *http.Request)

UpdatePublication updates an existing Publication in the database.

type ErrResponse

type ErrResponse struct {
	//not serialized
	Err            error `json:"-"` // low-level runtime error
	HTTPStatusCode int   `json:"-"` // http response status code
	//mandatory
	Type  string `json:"type"`
	Title string `json:"title"`
	//optional
	Detail   string `json:"detail,omitempty"` // application-level error message
	Instance string `json:"instance,omitempty"`
}

ErrResponse renderer type for handling all sorts of errors.

In the best case scenario, the excellent github.com/pkg/errors package helps reveal information on the error, setting it on Err, and in the Render() method, using it to set the application-specific error code in AppCode.

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

type LicenseInfoRequest

type LicenseInfoRequest struct {
	*stor.LicenseInfo
}

LicenseInfoRequest is the request payload for licenses.

func (*LicenseInfoRequest) Bind

func (l *LicenseInfoRequest) Bind(r *http.Request) error

Bind post-processes requests after unmarshalling.

type LicenseInfoResponse

type LicenseInfoResponse struct {
	*stor.LicenseInfo
	// do not serialize the following properties
	//ID omit `json:"ID,omitempty"`
	//CreatedAt   omit `json:"CreatedAt,omitempty"`
	//UpdatedAt   omit `json:"UpdatedAt,omitempty"`
	//DeletedAt   omit `json:"DeletedAt,omitempty"`
	Publication omit `json:"Publication,omitempty"`
}

LicenseInfoResponse is the response payload for licenses.

func NewLicenseInfoResponse

func NewLicenseInfoResponse(license *stor.LicenseInfo) *LicenseInfoResponse

NewLicenseInfoResponse creates a rendered license

func (*LicenseInfoResponse) Render

Render processes responses before marshalling.

type LicenseRequest

type LicenseRequest struct {
	PublicationID string     `json:"publication_id" validate:"required,uuid"`
	UserID        string     `json:"user_id,omitempty" validate:"required"`
	UserName      string     `json:"user_name,omitempty"`
	UserEmail     string     `json:"user_email,omitempty"`
	UserEncrypted []string   `json:"user_encrypted,omitempty"`
	Start         *time.Time `json:"start,omitempty"`
	End           *time.Time `json:"end,omitempty"`
	Copy          *int32     `json:"copy,omitempty"`
	Print         *int32     `json:"print,omitempty"`
	Profile       string     `json:"profile,omitempty"`
	TextHint      string     `json:"text_hint" validate:"required"`
	PassHash      string     `json:"pass_hash" validate:"required"`
}

LicenseRequest is the request payload for licenses. TODO: add an extension point for custom user properties, that have to be returned in the license, optionally encrypted.

func (*LicenseRequest) Bind

func (l *LicenseRequest) Bind(r *http.Request) error

Bind post-processes requests after unmarshalling.

type LicenseResponse

type LicenseResponse struct {
	*lic.License
}

LicenseResponse is the response payload for licenses.

func NewLicenseResponse

func NewLicenseResponse(license *lic.License) *LicenseResponse

NewLicenseResponse creates a rendered license

func (*LicenseResponse) Render

Render processes responses before marshalling.

type PublicationRequest

type PublicationRequest struct {
	*stor.Publication
}

PublicationRequest is the request publication payload.

func (*PublicationRequest) Bind

func (p *PublicationRequest) Bind(r *http.Request) error

Bind post-processes requests after unmarshalling.

type PublicationResponse

type PublicationResponse struct {
	*stor.Publication
}

PublicationResponse is the response publication payload.

func NewPublicationResponse

func NewPublicationResponse(pub *stor.Publication) *PublicationResponse

NewPublicationResponse creates a rendered publication.

func (*PublicationResponse) Render

Render processes responses before marshalling.

type StatusDocResponse

type StatusDocResponse struct {
	*lic.StatusDoc
}

LicenseResponse is the response payload for licenses.

func NewStatusDocResponse

func NewStatusDocResponse(statusDoc *lic.StatusDoc) *StatusDocResponse

NewLicenseResponse creates a rendered license

func (*StatusDocResponse) Render

Render processes responses before marshalling.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL