api

package
v0.0.0-...-e486867 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth0Login

func Auth0Login(ctx context.Context, code string, state string) (string, int, error)

Auth0Login consumes the auth0 code and will use the microcosm API to fetch a microcosm access_token

func DoSearch

func DoSearch(ctx context.Context, q url.Values) (*models.SearchResults, int, error)

DoSearch will perform a search against the search API for a given query

func GetCommentAttachments

func GetCommentAttachments(ctx context.Context, commentID int64) (*models.Attachments, int, error)

GetCommentAttachments returns attachments for a given comment

func GetConversation

func GetConversation(ctx context.Context, conversationID int64, jumpTo string, query url.Values) (*models.Conversation, int, error)

GetConversation returns a conversation if this user (defined by context) has permission to view it

func GetHuddles

func GetHuddles(ctx context.Context, query url.Values) (*models.Huddles, int, error)

GetHuddles returns a list of huddles for a given search.

func GetMicrocosm

func GetMicrocosm(ctx context.Context, microcosmID int64) (*models.Microcosm, int, error)

GetMicrocosm returns a microcosm if this user (defined by context) has permission to view it

func GetProfile

func GetProfile(ctx context.Context, profileID int64) (*models.Profile, int, error)

GetProfile returns a single profile for a given search.

func GetProfiles

func GetProfiles(ctx context.Context, query url.Values) (*models.Profiles, int, error)

GetProfiles returns a list of profiles for a given search.

func GetUpdates

func GetUpdates(ctx context.Context, q url.Values) (*models.UpdatesResults, int, error)

GetUpdates returns the personalised list of items that have been updated for the given user (defined by context)

func NewCache

func NewCache(addr string)

NewCache will create an API cache for a given memcached server address

func ProfileFromAPIContext

func ProfileFromAPIContext(ctx context.Context) (*models.Profile, int, error)

ProfileFromAPIContext is used to return the current profile of the site based on the /whoami call determined by the apiroot that is within the context and the access token also in the context

func RootFromRequest

func RootFromRequest(req *http.Request) (string, int, error)

RootFromRequest returns the URL of the API for the site associated with the request, i.e. https://subdomain.apidomain.tld/api/v1

func SiteFromAPIContext

func SiteFromAPIContext(ctx context.Context) (*models.Site, int, error)

SiteFromAPIContext is used to return a Site given the apiRoot that is within the context.

Types

type CommentForm

type CommentForm struct {
	ID          int64  `json:"id"`
	ItemType    string `json:"itemType" validate:"required"`
	ItemID      int64  `json:"itemId" validate:"required"`
	InReplyTo   int64  `json:"inReplyTo"`
	Markdown    string `json:"markdown" validate:"required,max=50000"`
	Attachments int64  `json:"attachments"`
}

CommentForm is a comment as the form posts it.

We define this here even though it's a valid subset of the Comment struct and we could've used that, this will give us more protection against attacks that targeted the unreferenced fields. In this, only the fields that a form could populate are provided, the we will perform the mapping to the models/comment.go within the controller, which is inaccessible to an attacker.

In essence this is the write path, and non-Form structs are the read path and that abstraction protects us. It also allows us to define validation here.

func (*CommentForm) Post

func (commentForm *CommentForm) Post(ctx context.Context) (*models.Comment, int, error)

type Params

type Params struct {
	Ctx context.Context
	// Type corresponds to the top level API path.
	// i.e. comments, conversation, events, huddles, legal, microcosms, polls, profiles, roles, updates, users, watchers
	Type string
	// TypeID corresponds to a single item of the given Type
	TypeID string
	// Part corresponds to a child of the Type and TypeID
	// i.e. /comments/17/attachments
	// This would make Part = "attachments"
	Part string
	// PartID corresponds to a single item of the given Part for the given Type and TypeID
	// i.e. /comments/17/attachments/<filehash>
	// This would make PartID = "<filehash>" (assume a SHA file hash is the actual value)
	PartID string
	// Part2 corresponds to a child of the Part
	// i.e. /microcosms/31/roles/18/profiles
	// This would make Part2 = "profiles"
	Part2 string
	// Part2ID corresponds to a single item of the given Part2, for the Given Type + TypeID + Part + PartID
	// i.e. //microcosms/31/roles/18/profiles/68
	// This would make Part2ID = "68"
	Part2ID string
	// Q is the query string
	Q url.Values
}

Params is a deconstruction of a Microcosm API URL into constiuent parts that can be built up to form an API request.

For examples of URLs, see the Microcosm API server handlers.

Jump to

Keyboard shortcuts

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