fedihelper

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: GPL-3.0 Imports: 26 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"
	// SoftwarePleroma is the software keyword for Pleroma.
	SoftwarePleroma SoftwareName = "pleroma"

	// TypeAccept is the Accept activity Type.
	TypeAccept ActivityType = "Accept"
	// TypeAdd is the Add activity Type.
	TypeAdd ActivityType = "Add"
	// 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"
	// TypeMove is the Move activity Type.
	TypeMove ActivityType = "Move"
	// TypeRemove is the Remove activity Type.
	TypeRemove ActivityType = "Remove"
	// 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)
	GetID() (id int64)
	GetInstance() (instance Instance)
	GetInstanceAccountID() (instanceAccountID string)
	GetLastFinger() (lastFinger time.Time)
	GetUsername() (username string)

	SetActorURI(actorURI string)
	SetInstance(instance Instance)
	SetInstanceAccountID(instanceAccountID string)
	SetLastFinger(lastFinger time.Time)
	SetUsername(username string)

	SetInfoAvatarURL(avatarURL string)
	SetInfoDisplayName(displayName string)
	SetInfoHeaderURL(headerURL string)
	SetInfoIsBot(isBot bool)
	SetInfoIsLocked(isLocked bool)
	SetInfoIsMoved(isMoved bool)
	SetInfoURL(url string)
	SetInfoLastUpdate(lastUpdate time.Time)
}

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, infoURI *url.URL) (*lib.NodeInfo, error)

GetNodeInfo20 retrieves wellknown nodeinfo from a federated instance.

func (*FediHelper) GetOrCreateAccount added in v0.17.0

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

GetOrCreateAccount gets an account from the database or .

func (*FediHelper) GetWellknownNodeInfo

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

GetWellknownNodeInfo retrieves wellknown nodeinfo from a federated instance.

func (*FediHelper) Helper

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

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) UpdateAccountInfo added in v0.17.0

func (f *FediHelper) UpdateAccountInfo(ctx context.Context, account Account) error

UpdateAccountInfo updates the account info.

func (*FediHelper) UpdateInstanceInfo added in v0.17.0

func (f *FediHelper) UpdateInstanceInfo(ctx context.Context, instance Instance) error

UpdateInstanceInfo updated the instance info.

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)
	UpdateAccountInfo(ctx context.Context, account Account) error
	UpdateInstanceInfo(ctx context.Context, instance Instance) 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)

	SetInfoTitle(title string)
	SetInfoDescription(description string)
	SetContactAccount(account Account)
	SetVersion(version string)
	SetLastUpdate(lastUpdate time.Time)
}

type InstanceInfo added in v0.17.0

type InstanceInfo struct {
	Title          string
	Description    string
	ContactAccount Account
	Version        string
}

InstanceInfo represents a instance.

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 NoHelperError added in v0.17.0

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

NoHelperError represents a missing helper error.

func NewNoHelperError added in v0.17.0

func NewNoHelperError(software string) *NoHelperError

NewNoHelperError wraps a message in a NoHelperError object.

func (*NoHelperError) Error added in v0.17.0

func (e *NoHelperError) Error() string

Error returns the error message as a string.

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 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 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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