function

package
v0.0.0-...-df564f5 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Individual subscriptions are stored in the "s" namespace, as "[s]{id}",
	// where id is the generated ID of the subscription, also known as channel
	// ID in Google terms.
	KVSubPrefix = "s"

	// Indices of subscriptions are stored in the "si" namespace, as
	// "[si]{userID}". The global (channel) subscriptions are stored under the
	// "bot_subs".
	KVSubIndexPrefix = "si"

	// Individual events are stored in the "e" namespace, as
	// "[e]base64({googleEmail}/{calID}/{eventID})".
	KVEventPrefix = "e"

	// The name of the key that stores the list of global subscriptions.
	KVBotSubscriptionsKey = "bot_subs"
)

KV store: subscriptions

View Source
const IconPath = "icon.png"

Variables

View Source
var AppPathPrefix = ""
View Source
var BuildDate string
View Source
var BuildHash string
View Source
var BuildHashShort string
View Source
var OAuth2Scopes = []string{
	calendar.CalendarScope,
	"https://www.googleapis.com/auth/userinfo.profile",
	"https://www.googleapis.com/auth/userinfo.email",
}

Functions

func EventAttendeesString

func EventAttendeesString(e *calendar.Event) string

func EventDateTimeString

func EventDateTimeString(e *calendar.Event) string

func EventDiffString

func EventDiffString(before *Event, after *calendar.Event, calSummary string) string

func EventSummaryString

func EventSummaryString(e *calendar.Event) string

func HandleCall

func HandleCall(p string, h HandlerFunc)

func HandleCommand

func HandleCommand(command Command)

func Init

func Init()

func RespondWithJSON

func RespondWithJSON(creq CallRequest, message string, v interface{}) apps.CallResponse

Types

type CallRequest

type CallRequest struct {
	apps.CallRequest
	// contains filtered or unexported fields
}

func (CallRequest) DeleteEvent

func (creq CallRequest) DeleteEvent(googleEmail, calID, eventID string) error

func (CallRequest) DeleteSub

func (creq CallRequest) DeleteSub(s *Sub) error

func (CallRequest) ListSubs

func (creq CallRequest) ListSubs(creatorID string) ([]Sub, error)

func (CallRequest) LoadEvent

func (creq CallRequest) LoadEvent(googleEmail, calID, eventID string) (*Event, error)

func (CallRequest) LoadSub

func (creq CallRequest) LoadSub(subID string) (*Sub, error)

func (CallRequest) StoreEvent

func (creq CallRequest) StoreEvent(googleEmail, calID string, e *Event) error

func (CallRequest) StoreSub

func (creq CallRequest) StoreSub(s *Sub, updateIndex bool) error

StoreSub stores the sub key, and updates the corresponding sub index key making sure it's included.

type Command

type Command struct {
	Name        string
	Hint        string
	Description string
	BaseSubmit  *apps.Call
	BaseForm    *apps.Form

	Handler func(CallRequest) apps.CallResponse
}

func (Command) Binding

func (c Command) Binding(creq CallRequest) apps.Binding

func (Command) Form

func (c Command) Form(creq CallRequest) *apps.Form

func (Command) Path

func (c Command) Path() string

func (Command) Submit

func (c Command) Submit(creq CallRequest) *apps.Call

type Event

type Event struct {
	Event *calendar.Event

	RootPostID string
}

type HandlerFunc

type HandlerFunc func(CallRequest) apps.CallResponse

func FormHandler

func FormHandler(h func(CallRequest) (apps.Form, error)) HandlerFunc

func LookupHandler

func LookupHandler(h func(CallRequest) []apps.SelectOption) HandlerFunc

func RequireAdmin

func RequireAdmin(h HandlerFunc) HandlerFunc

func RequireGoogleAuth

func RequireGoogleAuth(h HandlerFunc) HandlerFunc

func RequireGoogleUser

func RequireGoogleUser(h HandlerFunc) HandlerFunc

type ServiceAccount

type ServiceAccount struct {
	// Mode is either "api_key", "account_json", or "" implying no service
	// account is to be used, and the corresponding functionality disabled.
	Mode        string `json:"mode,omitempty"`         // fMode
	APIKey      string `json:"api_key,omitempty"`      // fAPIKey
	AccountJSON string `json:"account_json,omitempty"` // fAccountJSON
}

func NewServiceAccount

func NewServiceAccount(mode, apiKey, serviceAccout string) ServiceAccount

func ServiceAccountFromRequest

func ServiceAccountFromRequest(creq CallRequest) ServiceAccount

func (ServiceAccount) AuthOption

func (sa ServiceAccount) AuthOption(ctx context.Context, userEmail string) (option.ClientOption, error)

func (ServiceAccount) String

func (sa ServiceAccount) String() string

type Sub

type Sub struct {
	// SubID is a unique ID generated at the creation of the Sub. It is also
	// used as the channel ID on the Google side.
	SubID string `json:"id"`

	// CreatorID is the Mattermost ID of the user who created the subscription.
	// It is used to namespace the cached events for the user as they are stored
	// by the webhook handler.
	CreatorID string `json:"creator_id,omitempty"`

	// GoogleEmail is the email ID of the Google user, used for impersonation
	// with a service account.
	GoogleEmail string `json:"google_user_id"`

	// CalendarID of the calendar subscribed to.
	CalendarID string `json:"calendar_id,omitempty"`

	// CalendarSummary is the summary (title) of the calendar, also used as the
	// Sub name. Updated on change every time Events.List is invoked, so should
	// be in sync with the actual name of the calendar.
	CalendarSummary string `json:"calendar_summary,omitempty"`

	// Google channel for the webhook.
	Google *calendar.Channel `json:"google,omitempty"`

	// SyncToken to use for the the next update.
	SyncToken string `json:"next_sync_token,omitempty"`

	// MattermostUserID to DM on updates.
	// TODO: support subscribing to channels
	MattermostUserID string `json:"mattermost_user_id"`
}

type User

type User struct {
	Token *oauth2.Token
	Email string
	ID    string
}

Jump to

Keyboard shortcuts

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