services

package
v0.0.0-...-e28afbe Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2021 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NotUniqueEmail    error = errors.New("user does not have a unique email address")
	NotUniqueUsername error = errors.New("user does not have a unique preferredUsername")
)

Functions

func CreateKeyFile

func CreateKeyFile(file string) (err error)

CreateKeyFile writes a symmetric key of random bytes to a file.

func DoCollectionPagination

func DoCollectionPagination(c util.Context, iri *url.URL, defaultSize, maxSize int, any AnyCPageFn, last LastCPageFn) (p vocab.ActivityStreamsCollectionPage, err error)

DoCollectionPagination examines the query parameters of an IRI, and uses it to either fetch the bare ordered collection without values, the very last ordered collection page, or an arbitrary ordered collection page using the provided fetching functions.

func DoOrderedCollectionPagination

func DoOrderedCollectionPagination(c util.Context, iri *url.URL, defaultSize, maxSize int, any AnyOCPageFn, last LastOCPageFn) (p vocab.ActivityStreamsOrderedCollectionPage, err error)

DoPagination examines the query parameters of an IRI, and uses it to either fetch the bare ordered collection without values, the very last ordered collection page, or an arbitrary ordered collection page using the provided fetching functions.

func UpdateCollectionToPrependCalls

func UpdateCollectionToPrependCalls(c util.Context, updated vocab.ActivityStreamsCollection, defaultSize, maxSize int, firstPageFn AnyCPageFn, prependFn PrependFn) error

UpdateCollectionToPrependCalls takes new beginning elements of a collection in order to generate calls to PrependFn in order.

This function only prepends to the very beginning of the collection, and expects the page to be the first one, though it is written as if for the general case.

TODO: Could generalize this to apply a diff to a portion of the collection

Types

type Any

type Any struct {
	DB *sql.DB
}

func (*Any) Begin

func (a *Any) Begin() app.TxBuilder

type AnyCPageFn

type AnyCPageFn func(c util.Context, iri *url.URL, min, n int) (vocab.ActivityStreamsCollectionPage, error)

AnyCPageFn fetches any arbitrary CollectionPage

type AnyOCPageFn

type AnyOCPageFn func(c util.Context, iri *url.URL, min, n int) (vocab.ActivityStreamsOrderedCollectionPage, error)

AnyOCPageFn fetches any arbitrary OrderedCollectionPage

type CreateUserParameters

type CreateUserParameters struct {
	// Scheme is the server's scheme for serving the ActivityPub actor
	// representing this user.
	Scheme string
	// Host is this server's hostname for the ActivityPub actor representing
	// this user.
	Host string
	// Username is the user-facing username to give the initial ActivityPub
	// actor representing the user.
	Username string
	// Email is the email address of the user.
	Email string
	// HashParams are the parameters used to hash this user's password.
	HashParams HashPasswordParameters
	// RSAKeySize is the size of the RSA private key to create for this
	// user, in bits.
	RSAKeySize int
}

CreateUserParameters contains all parameters needed to create a user & Actor.

type Crypto

type Crypto struct {
	DB    *sql.DB
	Users *models.Users
}

Crypto service provides high level service methods relating to crypto operations.

func (*Crypto) Valid

func (c *Crypto) Valid(ctx util.Context, email, pass string) (uuid string, valid bool, err error)

Valid determines whether the provided password is valid for the user associated with the email address.

type Data

type Data struct {
	DB                    *sql.DB
	Hostname              string
	FedData               *models.FedData
	LocalData             *models.LocalData
	Users                 *models.Users
	Following             *Following
	Followers             *Followers
	Liked                 *Liked
	DefaultCollectionSize int
	MaxCollectionPageSize int
}

func (*Data) Create

func (d *Data) Create(c util.Context, v vocab.Type) (err error)

Create stores the ActivityStreams payload locally or federated.

func (*Data) Delete

func (d *Data) Delete(c util.Context, iri *url.URL) (err error)

Delete removes the ActivityStreams payload locally or federated.

func (*Data) Exists

func (d *Data) Exists(c util.Context, id *url.URL) (exists bool, err error)

Exists determines if this ActivityStreams ID already exists locally or federated.

func (*Data) Get

func (d *Data) Get(c util.Context, id *url.URL) (v vocab.Type, err error)

Get obtains the federated or local ActivityStreams data.

func (*Data) Owns

func (d *Data) Owns(id *url.URL) bool

Owns determines if this IRI is a local or federated piece of data.

func (*Data) Update

func (d *Data) Update(c util.Context, v vocab.Type) (err error)

Update updates the ActivityStreams payload locally or federated.

type DeliveryAttempts

type DeliveryAttempts struct {
	DB               *sql.DB
	DeliveryAttempts *models.DeliveryAttempts
}

func (*DeliveryAttempts) FirstPageRetryableFailures

func (d *DeliveryAttempts) FirstPageRetryableFailures(c util.Context, n int) (rf []RetryableFailure, err error)

func (*DeliveryAttempts) InsertAttempt

func (d *DeliveryAttempts) InsertAttempt(c util.Context, from paths.UUID, toActor *url.URL, payload []byte) (id string, err error)

func (*DeliveryAttempts) MarkAbandonedAttempt

func (d *DeliveryAttempts) MarkAbandonedAttempt(c util.Context, id string) (err error)

func (*DeliveryAttempts) MarkRetryFailureAttempt

func (d *DeliveryAttempts) MarkRetryFailureAttempt(c util.Context, id string) (err error)

func (*DeliveryAttempts) MarkSuccessfulAttempt

func (d *DeliveryAttempts) MarkSuccessfulAttempt(c util.Context, id string) (err error)

func (*DeliveryAttempts) NextPageRetryableFailures

func (d *DeliveryAttempts) NextPageRetryableFailures(c util.Context, prevID string, fetch time.Time, n int) (rf []RetryableFailure, err error)

type Followers

type Followers struct {
	DB        *sql.DB
	Followers *models.Followers
}

func (*Followers) Contains

func (f *Followers) Contains(c util.Context, followers, id *url.URL) (has bool, err error)

func (*Followers) ContainsForActor

func (f *Followers) ContainsForActor(c util.Context, actor, id *url.URL) (has bool, err error)

func (*Followers) DeleteItem

func (f *Followers) DeleteItem(c util.Context, followers, item *url.URL) error

func (*Followers) GetAllForActor

func (f *Followers) GetAllForActor(c util.Context, actor *url.URL) (col vocab.ActivityStreamsCollection, err error)

func (*Followers) GetLastPage

func (f *Followers) GetLastPage(c util.Context, followers *url.URL, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Followers) GetPage

func (f *Followers) GetPage(c util.Context, followers *url.URL, min, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Followers) OpenFollowRequests

func (f *Followers) OpenFollowRequests(c util.Context, actorIRI *url.URL) (r []vocab.ActivityStreamsFollow, err error)

func (*Followers) PrependItem

func (f *Followers) PrependItem(c util.Context, followers, item *url.URL) error

type Following

type Following struct {
	DB        *sql.DB
	Following *models.Following
}

func (*Following) Contains

func (f *Following) Contains(c util.Context, following, id *url.URL) (has bool, err error)

func (*Following) ContainsForActor

func (f *Following) ContainsForActor(c util.Context, actor, id *url.URL) (has bool, err error)

func (*Following) DeleteItem

func (f *Following) DeleteItem(c util.Context, following, item *url.URL) error

func (*Following) GetAllForActor

func (f *Following) GetAllForActor(c util.Context, actor *url.URL) (col vocab.ActivityStreamsCollection, err error)

func (*Following) GetLastPage

func (f *Following) GetLastPage(c util.Context, following *url.URL, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Following) GetPage

func (f *Following) GetPage(c util.Context, following *url.URL, min, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Following) PrependItem

func (f *Following) PrependItem(c util.Context, following, item *url.URL) error

type HashPasswordParameters

type HashPasswordParameters struct {
	// Size of the salt in number of bytes.
	SaltSize int
	// Strength of the bcrypt hashing.
	BCryptStrength int
}

HashPasswordParameters contains values used in generating secrets.

type Inboxes

type Inboxes struct {
	DB      *sql.DB
	Inboxes *models.Inboxes
}

func (*Inboxes) Contains

func (i *Inboxes) Contains(c util.Context, inbox, id *url.URL) (has bool, err error)

func (*Inboxes) ContainsForActor

func (i *Inboxes) ContainsForActor(c util.Context, actor, id *url.URL) (has bool, err error)

func (*Inboxes) DeleteItem

func (i *Inboxes) DeleteItem(c util.Context, inbox, item *url.URL) error

func (*Inboxes) GetLastPage

func (i *Inboxes) GetLastPage(c util.Context, inbox *url.URL, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Inboxes) GetPage

func (i *Inboxes) GetPage(c util.Context, inbox *url.URL, min, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Inboxes) GetPublicLastPage

func (i *Inboxes) GetPublicLastPage(c util.Context, inbox *url.URL, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Inboxes) GetPublicPage

func (i *Inboxes) GetPublicPage(c util.Context, inbox *url.URL, min, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Inboxes) PrependItem

func (i *Inboxes) PrependItem(c util.Context, inbox, item *url.URL) error

type LastCPageFn

type LastCPageFn func(c util.Context, iri *url.URL, n int) (vocab.ActivityStreamsCollectionPage, error)

LastCPageFn fetches the last page of an Collection.

type LastOCPageFn

type LastOCPageFn func(c util.Context, iri *url.URL, n int) (vocab.ActivityStreamsOrderedCollectionPage, error)

LastOCPageFn fetches the last page of an OrderedCollection.

type Liked

type Liked struct {
	DB    *sql.DB
	Liked *models.Liked
}

func (*Liked) Contains

func (f *Liked) Contains(c util.Context, liked, id *url.URL) (has bool, err error)

func (*Liked) ContainsForActor

func (f *Liked) ContainsForActor(c util.Context, actor, id *url.URL) (has bool, err error)

func (*Liked) DeleteItem

func (f *Liked) DeleteItem(c util.Context, liked, item *url.URL) error

func (*Liked) GetAllForActor

func (f *Liked) GetAllForActor(c util.Context, actor *url.URL) (col vocab.ActivityStreamsCollection, err error)

func (*Liked) GetLastPage

func (f *Liked) GetLastPage(c util.Context, liked *url.URL, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Liked) GetPage

func (f *Liked) GetPage(c util.Context, liked *url.URL, min, n int) (page vocab.ActivityStreamsCollectionPage, err error)

func (*Liked) PrependItem

func (f *Liked) PrependItem(c util.Context, liked, item *url.URL) error

type NodeInfo

type NodeInfo struct {
	DB        *sql.DB
	Users     *models.Users
	LocalData *models.LocalData
	Rand      *rand.Rand

	CacheInvalidated time.Duration
	// contains filtered or unexported fields
}

func (*NodeInfo) GetAnonymizedStats

func (n *NodeInfo) GetAnonymizedStats(c util.Context) (t NodeInfoStats, err error)

type NodeInfoStats

type NodeInfoStats struct {
	TotalUsers     int
	ActiveHalfYear int
	ActiveMonth    int
	ActiveWeek     int
	NLocalPosts    int
	NLocalComments int
}

type OAuth2

type OAuth2 struct {
	DB     *sql.DB
	Client *models.ClientInfos
	Token  *models.TokenInfos
	Creds  *models.Credentials
}

OAuth2 implements services for the oauth2 server package.

func (*OAuth2) Create

func (o *OAuth2) Create(ctx context.Context, info oauth2.TokenInfo) error

func (*OAuth2) DeleteExpiredFirstPartyCredentials

func (o *OAuth2) DeleteExpiredFirstPartyCredentials(ctx context.Context) error

func (*OAuth2) GetByAccess

func (o *OAuth2) GetByAccess(ctx context.Context, access string) (ti oauth2.TokenInfo, err error)

func (*OAuth2) GetByCode

func (o *OAuth2) GetByCode(ctx context.Context, code string) (ti oauth2.TokenInfo, err error)

func (*OAuth2) GetByID

func (o *OAuth2) GetByID(ctx context.Context, id string) (ci oauth2.ClientInfo, err error)

func (*OAuth2) GetByRefresh

func (o *OAuth2) GetByRefresh(ctx context.Context, refresh string) (ti oauth2.TokenInfo, err error)

func (*OAuth2) ProxyCreateCredential

func (o *OAuth2) ProxyCreateCredential(ctx context.Context, ti oauth2.TokenInfo) (id string, err error)

func (*OAuth2) ProxyGetCredential

func (o *OAuth2) ProxyGetCredential(ctx context.Context, id string) (ti oauth2.TokenInfo, err error)

func (*OAuth2) ProxyRemoveCredential

func (o *OAuth2) ProxyRemoveCredential(ctx context.Context, id string) error

func (*OAuth2) ProxyUpdateCredential

func (o *OAuth2) ProxyUpdateCredential(ctx context.Context, id string, ti oauth2.TokenInfo) error

func (*OAuth2) RemoveByAccess

func (o *OAuth2) RemoveByAccess(ctx context.Context, access string) error

func (*OAuth2) RemoveByCode

func (o *OAuth2) RemoveByCode(ctx context.Context, code string) error

func (*OAuth2) RemoveByRefresh

func (o *OAuth2) RemoveByRefresh(ctx context.Context, refresh string) error

type Outboxes

type Outboxes struct {
	DB       *sql.DB
	Outboxes *models.Outboxes
}

func (*Outboxes) DeleteItem

func (i *Outboxes) DeleteItem(c util.Context, outbox, item *url.URL) error

func (*Outboxes) GetLastPage

func (i *Outboxes) GetLastPage(c util.Context, outbox *url.URL, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Outboxes) GetPage

func (i *Outboxes) GetPage(c util.Context, outbox *url.URL, min, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Outboxes) GetPublicLastPage

func (i *Outboxes) GetPublicLastPage(c util.Context, outbox *url.URL, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Outboxes) GetPublicPage

func (i *Outboxes) GetPublicPage(c util.Context, outbox *url.URL, min, n int) (page vocab.ActivityStreamsOrderedCollectionPage, err error)

func (*Outboxes) OutboxForInbox

func (i *Outboxes) OutboxForInbox(c util.Context, inboxIRI *url.URL) (outboxIRI *url.URL, err error)

func (*Outboxes) PrependItem

func (i *Outboxes) PrependItem(c util.Context, outbox, item *url.URL) error

type Policies

type Policies struct {
	Clock       pub.Clock
	DB          *sql.DB
	Policies    *models.Policies
	Resolutions *models.Resolutions
}

func (*Policies) IsBlocked

func (p *Policies) IsBlocked(c util.Context, actorID *url.URL, a pub.Activity) (blocked bool, err error)

type Preferences

type Preferences struct {
	OnFollow       pub.OnFollowBehavior
	AppPreferences interface{}
}

type PrependFn

type PrependFn func(c util.Context, collectionID, item *url.URL) error

PrependFn are functions that prepend items to a collection.

type PrivateKeys

type PrivateKeys struct {
	Scheme      string
	Host        string
	DB          *sql.DB
	PrivateKeys *models.PrivateKeys
}

func (*PrivateKeys) GetUserHTTPSignatureKey

func (p *PrivateKeys) GetUserHTTPSignatureKey(c util.Context, userID paths.UUID) (k *rsa.PrivateKey, iri *url.URL, err error)

func (*PrivateKeys) GetUserHTTPSignatureKeyForInstanceActor

func (p *PrivateKeys) GetUserHTTPSignatureKeyForInstanceActor(c util.Context) (k *rsa.PrivateKey, iri *url.URL, err error)

type Privileges

type Privileges struct {
	Admin         bool
	InstanceActor bool
	AppPrivileges interface{}
}

type RetryableFailure

type RetryableFailure struct {
	ID          string
	UserID      string
	FetchTime   time.Time
	DeliverTo   *url.URL
	Payload     []byte
	NAttempts   int
	LastAttempt time.Time
}

type ServerPreferences

type ServerPreferences struct {
	OnFollow          pub.OnFollowBehavior
	OpenRegistrations bool
	ServerBaseURL     string
	ServerName        string
	OrgName           string
	OrgContact        string
	OrgAccount        string
	Payload           json.RawMessage
}

type User

type User struct {
	ID    string
	Email string
	Actor vocab.Type
}

type Users

type Users struct {
	App         app.Application
	DB          *sql.DB
	Users       *models.Users
	PrivateKeys *models.PrivateKeys
	Inboxes     *models.Inboxes
	Outboxes    *models.Outboxes
	Followers   *models.Followers
	Following   *models.Following
	Liked       *models.Liked
	// contains filtered or unexported fields
}

func (*Users) ActorIDForInbox

func (u *Users) ActorIDForInbox(c util.Context, inboxIRI *url.URL) (actorIRI *url.URL, err error)

func (*Users) ActorIDForOutbox

func (u *Users) ActorIDForOutbox(c util.Context, outboxIRI *url.URL) (actorIRI *url.URL, err error)

func (*Users) CreateAdminUser

func (u *Users) CreateAdminUser(c util.Context, params CreateUserParameters, password string) (userID string, err error)

func (*Users) CreateInstanceActorSingleton

func (u *Users) CreateInstanceActorSingleton(c util.Context, scheme, host string, rsaKeySize int) (userID string, err error)

func (*Users) CreateUser

func (u *Users) CreateUser(c util.Context, params CreateUserParameters, password string) (userID string, err error)

func (*Users) GetServerPreferences

func (u *Users) GetServerPreferences(c util.Context) (p ServerPreferences, err error)

func (*Users) Preferences

func (u *Users) Preferences(c util.Context, uuid paths.UUID, appPref interface{}) (p *Preferences, err error)

Preferences returns the preferences associated with the user.

Fetches the application-specific preferences if appPref is non-nil and JSON compatible struct.

func (*Users) Privileges

func (u *Users) Privileges(c util.Context, uuid string, appPriv interface{}) (p *Privileges, err error)

Privileges returns the privileges associated with the user.

Fetches the application-specific privileges if appPriv is non-nil and JSON compatible struct.

func (*Users) SetServerPreferences

func (u *Users) SetServerPreferences(c util.Context, p ServerPreferences) (err error)

func (*Users) UpdatePreferences

func (u *Users) UpdatePreferences(c util.Context, uuid string, p *Preferences) (err error)

func (*Users) UpdatePrivileges

func (u *Users) UpdatePrivileges(c util.Context, uuid string, p *Privileges) (err error)

func (*Users) UserByID

func (u *Users) UserByID(c util.Context, id paths.UUID) (s *User, err error)

func (*Users) UserByUsername

func (u *Users) UserByUsername(c util.Context, name string) (s *User, err error)

Jump to

Keyboard shortcuts

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