fedihelper

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextActivityStreams contains the context document for activity streams
	ContextActivityStreams = "https://www.w3.org/ns/activitystreams"
	// HostMetaWebFingerTemplateRel matches a webfinger link relationship.
	HostMetaWebFingerTemplateRel = "lrdd"
	// NodeInfo20Schema the schema url for nodeinfo 2.0.
	NodeInfo20Schema = "http://nodeinfo.diaspora.software/ns/schema/2.0"
	// SoftwareMastodon is the software keyword for Mastodon.
	SoftwareMastodon SoftwareName = "mastodon"

	// TypeAccept is the Accept activity Type
	TypeAccept ActivityType = "Accept"
	// TypeAnnounce is the Announce activity Type
	TypeAnnounce ActivityType = "Announce"
	// TypeCreate is the Create activity Type
	TypeCreate ActivityType = "Create"
	// TypeDelete is the Delete activity Type
	TypeDelete ActivityType = "Delete"
	// TypeFollow is the Follow activity Type
	TypeFollow ActivityType = "Follow"
	// TypeUndo is the Undo activity Type
	TypeUndo ActivityType = "Undo"
	// TypeUpdate is the Update activity Type
	TypeUpdate ActivityType = "Update"

	// TypeApplication is the Application actor type
	TypeApplication ActorType = "Application"
	// TypePerson is the Person actor type
	TypePerson ActorType = "Person"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account interface {
	GetActorURI() (actorURI string)
	GetDisplayName() (displayName string)
	GetID() (id int64)
	GetInstance() (instance Instance)
	GetLastFinger() (lastFinger time.Time)
	GetUsername() (username string)

	SetActorURI(actorURI string)
	SetDisplayName(displayName string)
	SetInstance(instance Instance)
	SetLastFinger(lastFinger time.Time)
	SetUsername(username string)
}

type Activity

type Activity map[string]interface{}

func (Activity) ID

func (a Activity) ID() (string, error)

func (Activity) ObjectID

func (a Activity) ObjectID() (string, error)

func (Activity) ObjectType

func (a Activity) ObjectType() (ActivityType, error)

func (Activity) Type

func (a Activity) Type() (ActivityType, error)

type ActivityType

type ActivityType string

func (ActivityType) String

func (a ActivityType) String() string

type Actor

type Actor struct {
	Context           interface{} `json:"@context"`
	Endpoints         Endpoints   `json:"endpoints"`
	Followers         string      `json:"followers"`
	Following         string      `json:"following"`
	Inbox             string      `json:"inbox"`
	Name              string      `json:"name"`
	Type              ActorType   `json:"type"`
	ID                string      `json:"id"`
	PublicKey         PublicKey   `json:"publicKey"`
	Summary           string      `json:"summary"`
	PreferredUsername string      `json:"preferredUsername"`
	URL               string      `json:"url"`
}

Actor is an actor response.

func (*Actor) MakeInstance

func (a *Actor) MakeInstance(instance Instance) error

func (*Actor) RSAPublicKey

func (a *Actor) RSAPublicKey() (*rsa.PublicKey, error)

type ActorType

type ActorType string

func (ActorType) String

func (a ActorType) String() string

type CreateAccountHandler

type CreateAccountHandler func(ctx context.Context, account Account) (err error)

type Endpoints

type Endpoints struct {
	SharedInbox string `json:"sharedInbox"`
}

Endpoints represents known activity pub endpoints

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error represents a fedihelper specific error.

func NewError

func NewError(m string) *Error

NewError wraps a message in a Error object.

func NewErrorf

func NewErrorf(m string, args ...interface{}) *Error

NewErrorf wraps a message in a Error object.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message as a string.

type FediHelper

type FediHelper struct {
	CreateAccountHandler CreateAccountHandler
	GetAccountHandler    GetAccountHandler
	NewAccountHandler    NewAccountHandler
	// contains filtered or unexported fields
}

FediHelper is a module for working with federated social instances.

func New

func New(k KV, t *Transport, clientName string, helpers []Helper) (*FediHelper, error)

New creates a new fedi module.

func (*FediHelper) FetchActor

func (f *FediHelper) FetchActor(ctx context.Context, actorIRI *url.URL) (*Actor, error)

func (*FediHelper) FetchHostMeta

func (f *FediHelper) FetchHostMeta(ctx context.Context, domain string) (*HostMeta, error)

func (*FediHelper) FetchWebFinger

func (f *FediHelper) FetchWebFinger(ctx context.Context, wfURI WebfingerURI, username, domain string) (*WebFinger, error)

FetchWebFinger retrieves web finger resource from a federated instance.

func (*FediHelper) FetchWellknownWebFinger

func (f *FediHelper) FetchWellknownWebFinger(ctx context.Context, serverHostname, username, domain string) (*WebFinger, error)

FetchWellknownWebFinger retrieves wellknown web finger resource from a federated instance.

func (*FediHelper) GenerateFediAccountFromUsername

func (f *FediHelper) GenerateFediAccountFromUsername(ctx context.Context, username string, instance Instance, account Account) error

GenerateFediAccountFromUsername creates an Account object by querying the apis of the federated instance.

func (*FediHelper) GenerateFediInstanceFromDomain

func (f *FediHelper) GenerateFediInstanceFromDomain(ctx context.Context, domain string, instance Instance) error

GenerateFediInstanceFromDomain created a Instance object by querying the apis of the federated instance.

func (*FediHelper) GetLoginURL

func (f *FediHelper) GetLoginURL(ctx context.Context, redirectURI *url.URL, instance Instance) (*url.URL, bool, error)

GetLoginURL retrieves an oauth url for a federated instance, returns true if instance was updated.

func (*FediHelper) GetNodeInfo20

func (f *FediHelper) GetNodeInfo20(ctx context.Context, domain string, infoURI *url.URL) (*NodeInfoV2, error)

GetNodeInfo20 retrieves wellknown nodeinfo from a federated instance.

func (*FediHelper) GetWellknownNodeInfo

func (f *FediHelper) GetWellknownNodeInfo(ctx context.Context, domain string) (*WellKnownNodeInfo, error)

GetWellknownNodeInfo retrieves wellknown nodeinfo from a federated instance.

func (*FediHelper) Helper

func (f *FediHelper) Helper(s SoftwareName) Helper

Helper returns a helper for a given software package.

func (*FediHelper) SetCreateAccountHandler

func (f *FediHelper) SetCreateAccountHandler(handler CreateAccountHandler)

func (*FediHelper) SetGetAccountHandler

func (f *FediHelper) SetGetAccountHandler(handler GetAccountHandler)

func (*FediHelper) SetNewAccountHandler

func (f *FediHelper) SetNewAccountHandler(handler NewAccountHandler)

func (*FediHelper) WebfingerURIFromHostMeta

func (*FediHelper) WebfingerURIFromHostMeta(hostMeta *HostMeta) (string, error)

type GetAccountHandler

type GetAccountHandler func(ctx context.Context, instance Instance, username string) (account Account, found bool, err error)

type Helper

type Helper interface {
	GetAccessToken(ctx context.Context, redirectURI *url.URL, instance Instance, code string) (accessToken string, err error)
	GetCurrentAccount(ctx context.Context, instance Instance, accessToken string) (user Account, err error)
	GetSoftware() SoftwareName
	RegisterApp(ctx context.Context, redirectURI *url.URL, instance Instance) (clientID string, clientSecret string, err error)
	SetFedi(f *FediHelper)
	MakeLoginURI(ctx context.Context, redirectURI *url.URL, instance Instance) (loginURI *url.URL, err error)
}

Helper interacts with a federated social instance.

type HostMeta

type HostMeta struct {
	XMLNS string `xml:"xmlns,attr"`
	Links []Link `xml:"Link"`
}

func (*HostMeta) WebfingerURI

func (h *HostMeta) WebfingerURI() WebfingerURI

type HttpClient

type HttpClient interface {
	pub.HttpClient
	Transport() (transport http.RoundTripper)
}

type Instance

type Instance interface {
	GetActorURI() (actorURI string)
	GetOAuthClientID() (clientID string)
	GetOAuthClientSecret() (clientSecret string, err error)
	GetDomain() (domain string)
	GetID() (id int64)
	GetServerHostname() (hostname string)
	GetSoftware() (software string)

	SetActorURI(actorURI string)
	SetOAuthClientID(clientID string)
	SetOAuthClientSecret(clientSecret string) error
	SetDomain(domain string)
	SetInboxURI(inboxURI string)
	SetServerHostname(hostname string)
	SetSoftware(software string)
}

type KV

type KV interface {
	DeleteAccessToken(ctx context.Context, accountID int64) (err error)
	GetAccessToken(ctx context.Context, accountID int64) (accessToken string, err error)
	SetAccessToken(ctx context.Context, accountID int64, accessToken string) (err error)

	DeleteActor(ctx context.Context, actorURI string) (err error)
	GetActor(ctx context.Context, actorURI string) (actor []byte, err error)
	SetActor(ctx context.Context, actorURI string, actor []byte, expire time.Duration) (err error)

	DeleteHostMeta(ctx context.Context, domain string) (err error)
	GetHostMeta(ctx context.Context, domain string) (hostmeta []byte, err error)
	SetHostMeta(ctx context.Context, domain string, hostmeta []byte, expire time.Duration) (err error)

	DeleteFediNodeInfo(ctx context.Context, domain string) (err error)
	GetFediNodeInfo(ctx context.Context, domain string) (nodeinfo []byte, err error)
	SetFediNodeInfo(ctx context.Context, domain string, nodeinfo []byte, expire time.Duration) (err error)
}
type Link struct {
	Href     string `json:"href,omitempty"`
	Rel      string `json:"rel,omitempty" xml:"rel,attr"`
	Template string `json:"template,omitempty" xml:"template,attr"`
	Type     string `json:"type,omitempty"`
}

Link represents a link

type NewAccountHandler

type NewAccountHandler func(ctx context.Context) (account Account, err error)

type NodeInfoV2

type NodeInfoV2 struct {
	Metadata          map[string]interface{} `json:"metadata"`
	OpenRegistrations bool                   `json:"openRegistrations"`
	Protocols         []string               `json:"protocols"`
	Services          Services               `json:"services"`
	Software          Software               `json:"software"`
	Usage             Usage                  `json:"usage"`
	Version           string                 `json:"version"`
}

NodeInfoV2 is a federated node info 2.0 object.

type PublicKey

type PublicKey struct {
	ID           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPEM string `json:"publicKeyPem"`
}

PublicKey represents an actor's public key

type Services

type Services struct {
	Inbound  []string `json:"inbound"`
	Outbound []string `json:"outbound"`
}

Services contains the supported services of the node

type Software

type Software struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Software contains the software and version of the node

type SoftwareName

type SoftwareName string

func (SoftwareName) String

func (s SoftwareName) String() string

type Transport

type Transport struct {
	// contains filtered or unexported fields
}

Transport handled signing outgoing requests to federated instances

func NewTransport

func NewTransport(clock pub.Clock, client HttpClient, pubKeyID string, privkey crypto.PrivateKey) (*Transport, error)

NewTransport creates a new Transport module

func (*Transport) Client

func (t *Transport) Client() HttpClient

func (*Transport) InstanceGet

func (t *Transport) InstanceGet(ctx context.Context, uri *url.URL, accepts ...libhttp.Mime) ([]byte, error)

func (*Transport) InstancePost

func (t *Transport) InstancePost(ctx context.Context, uri *url.URL, body []byte, contentType libhttp.Mime, accepts ...libhttp.Mime) ([]byte, error)

type Usage

type Usage struct {
	LocalPosts int64      `json:"localPosts"`
	Users      UsageUsers `json:"users"`
}

Usage contains usage statistics

type UsageUsers

type UsageUsers struct {
	Total int64 `json:"total"`
}

UsageUsers contains usage statistics about users

type WebFinger

type WebFinger struct {
	Aliases []string `json:"aliases,omitempty"`
	Links   []Link   `json:"links,omitempty"`
	Subject string   `json:"subject,omitempty"`
}

WebFinger is a web finger response.

func (*WebFinger) ActorURI

func (w *WebFinger) ActorURI() (*url.URL, error)

ActorURI an actor uri.

type WebfingerURI

type WebfingerURI string

func (WebfingerURI) FTemplate

func (w WebfingerURI) FTemplate() string

func (WebfingerURI) String

func (w WebfingerURI) String() string

type WellKnownNodeInfo

type WellKnownNodeInfo struct {
	Links []Link `json:"links"`
}

WellKnownNodeInfo is a federated well known node info object.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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