Documentation
¶
Overview ¶
Package msgraph is icebath's one way to Microsoft Graph: the app registration a profile reaches it with (its own settings, otherwise the sign-in a chat app of the same organisation keeps), the subscriptions every feature asks for, made and renewed before Graph ends them and made again when Graph removes them, and the one receiver of the change notifications Graph posts, which checks each against the secret of its subscription, takes it once, decrypts the resource data it carries and hands it to the feature the subscription is for. The host names no feature: what a feature subscribes to and what it does with what comes is a registrant
Index ¶
- Constants
- func Feature(owner string) string
- func Folder(cfg *config.Config) string
- func Sources(cfg *config.Config) ([]netip.Prefix, []string)
- func StatusOf(err error) int
- type Client
- func (c *Client) As(token string) *Client
- func (c *Client) Collect(ctx context.Context, path string, query url.Values) ([]json.RawMessage, error)
- func (c *Client) Credentials() Credentials
- func (c *Client) Download(ctx context.Context, path, file string, accept string) (int64, string, error)
- func (c *Client) Get(ctx context.Context, path string, query url.Values, out any) error
- func (c *Client) Health() Health
- func (c *Client) Send(ctx context.Context, method, path string, body, out any) error
- func (c *Client) Token(ctx context.Context, fresh bool) (string, error)
- type Counts
- type Credentials
- type Failure
- type Graph
- func (g *Graph) Address(cfg *config.Config) string
- func (g *Graph) Client(cfg *config.Config) (*Client, error)
- func (g *Graph) Closed(cfg *config.Config) string
- func (g *Graph) Counted() map[string]Counts
- func (g *Graph) Credentials(cfg *config.Config) (Credentials, string)
- func (g *Graph) Health(cfg *config.Config, r *http.Request) (int, map[string]any)
- func (g *Graph) Keep(ctx context.Context, cfg *config.Config, dry bool) (Upkeep, error)
- func (g *Graph) Kept(cfg *config.Config, owner string) []Subscription
- func (g *Graph) Looked(cfg *config.Config) time.Time
- func (g *Graph) Reauthorize(ctx context.Context, cfg *config.Config, id string) error
- func (g *Graph) Refusals(cfg *config.Config, owner string) ([]Refusal, []string)
- func (g *Graph) Register(registrant Registrant)
- func (g *Graph) Remove(ctx context.Context, cfg *config.Config, id string) error
- func (g *Graph) Renew(ctx context.Context, cfg *config.Config, id string, to time.Time) (Subscription, error)
- func (g *Graph) Serve(w http.ResponseWriter, r *http.Request, cfg *config.Config)
- func (g *Graph) Subscriptions(ctx context.Context, cfg *config.Config) ([]Listed, error)
- func (g *Graph) Telling(tell func(Told))
- func (g *Graph) Unaddressed(cfg *config.Config) string
- func (g *Graph) Used(cfg *config.Config) bool
- func (g *Graph) Wake()
- func (g *Graph) Watch(ctx context.Context) error
- type Health
- type Listed
- type Refusal
- type Registrant
- type Registry
- type State
- type Subscription
- type Taker
- type Told
- type Upkeep
- type Want
Constants ¶
const ( ToldNotification = "notification" ToldSubscribed = "subscribed" ToldRenewed = "renewed" ToldRemoved = "removed" ToldFailed = "failed" )
Kinds of what happened
const ( // Graph has it and tells of the resource until it ends Active = "active" // It ended before it was renewed Expired = "expired" // Graph no longer lists it Missing = "missing" // Graph told that it removed it Removed = "removed" )
States of a subscription
const Provider = "microsoft"
Provider name a chat app of Microsoft gives its sign-in under, which Graph shares
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Graph client of an app registration
func (*Client) As ¶
The client sending a user's token in place of the app's, such as one that may post in a chat
func (*Client) Collect ¶
func (c *Client) Collect(ctx context.Context, path string, query url.Values) ([]json.RawMessage, error)
Every item of a collection of Graph, following @odata.nextLink from page to page
func (*Client) Credentials ¶
func (c *Client) Credentials() Credentials
The app registration the client reaches Graph with
func (*Client) Download ¶
func (c *Client) Download(ctx context.Context, path, file string, accept string) (int64, string, error)
Downloads what the path holds into the file, through a part file renamed once it is whole: its size and type
type Counts ¶
type Counts struct {
Accepted, Duplicates, Refused, Other, Undecrypted int64
// When it last took a notification
Last time.Time
}
Counts of what the receiver took of a profile since this process started
type Credentials ¶
type Credentials struct {
Tenant, Client, Secret, Login, Scope, Graph string
// The settings of Microsoft Graph, or the chat app whose sign-in they share, by its title
From string
}
How the app reaches Microsoft Graph for a profile: its organisation, client id and secret, where it signs in and what its token is asked for, Graph's address, and whose they are
type Failure ¶
A failure Microsoft Graph answered: its status, its code and words, and how long it asked to wait
type Graph ¶
type Graph struct {
Registry
// contains filtered or unexported fields
}
Microsoft Graph for every profile: the client of each app registration, the keeper of the subscriptions and the receiver of the notifications
func (*Graph) Address ¶
The address Graph posts the notifications of the profile to: the one the settings name, otherwise the server's public address with the profile's path to the receiver. Empty when neither is set
func (*Graph) Client ¶
The Graph client of the profile's app registration, refused with what is missing
func (*Graph) Closed ¶
Why notifications of the profile are refused whoever sends them, as alpha refused to listen: the server answers other computers and no source is allowed. Empty when they are taken
func (*Graph) Credentials ¶
func (g *Graph) Credentials(cfg *config.Config) (Credentials, string)
The app registration of the profile: the settings of Microsoft Graph, each empty one taken from the chat app of the organisation that signs in at Microsoft. What is missing, in words a user reads
func (*Graph) Health ¶
How the receiver stands for the profile, as its health route answers: whether it takes notifications and what it took since the process started
func (*Graph) Keep ¶
Looks at the subscriptions of the profile: those its features keep are made where none tells of their resource, renewed as their end nears by as long as Graph lets each resource last, made again where Graph lost or removed them or a feature changed what it asks of them. One no feature wants any more is deleted at Graph. Only looks, changing nothing, when dry. One icebath of this computer keeps a profile's subscriptions at a time
func (*Graph) Kept ¶
func (g *Graph) Kept(cfg *config.Config, owner string) []Subscription
The subscriptions the profile keeps, the soonest to end first: every one for no owner, those of a feature for an owner ending in a colon, otherwise those of the owner. Never with their secrets
func (*Graph) Reauthorize ¶
Signs the subscription in again as Graph asks before its token runs out, by a renewal, which does that too. Nothing when it was renewed within the ten minutes Graph asks to keep the two apart
func (*Graph) Refusals ¶
What Graph refused of the wants of the profile the last time they were asked for, and what the last look at the subscriptions could not do, those of an owner or a feature as Kept picks them
func (*Graph) Register ¶
func (g *Graph) Register(registrant Registrant)
Adds a registrant. A registry nested in the host reaches it through Host
func (*Graph) Remove ¶
Deletes the subscription at Graph and forgets it. One Graph no longer has is only forgotten. A feature that still wants it has it made again at the next look
func (*Graph) Renew ¶
func (g *Graph) Renew(ctx context.Context, cfg *config.Config, id string, to time.Time) (Subscription, error)
Extends the subscription until the time given, or as long as Graph lets its resource last, which signs it in again too. A subscription whose resource data is encrypted for a certificate older than the newest is handed the newest
func (*Graph) Serve ¶
Answers what Graph made of the profile's address: its check of the address with the token, otherwise a batch of notifications, each checked against the secret of its subscription and taken once, its resource data decrypted, and handed to the feature its subscription is for. News of the subscriptions is acted on after the answer: one to be signed in again is renewed, one removed made again, and missed notifications noted
func (*Graph) Subscriptions ¶
Every subscription Graph has of the app, those the profile keeps or that carry its secret marked
func (*Graph) Telling ¶
Hands over what tells monitoring what happened at the receiver and the keeper
func (*Graph) Unaddressed ¶
Why Graph can't post to the address of the profile, in words a user reads. Empty when it can
func (*Graph) Used ¶
Whether any registrant keeps subscriptions of the profile now, or the profile keeps any still to be let go of
type Health ¶
type Health struct {
Cached bool
Expires time.Time
Tenant string
Client string
From string
Login string
}
How the token of an app registration stands, as a user checks it
type Listed ¶
type Listed struct {
Subscription
Ours bool
}
A subscription Graph has of the app, and whether the profile keeps it
type Refusal ¶
type Refusal struct {
Owner string `json:"owner"`
Title string `json:"title,omitempty"`
Resource string `json:"resource"`
Problem string `json:"problem"`
At time.Time `json:"at"`
}
What Graph refused of a feature's want the last time it was asked, kept until it is taken
type Registrant ¶
type Registrant interface {
// Subscriptions the feature keeps for the profile of the settings, none while it is off. Read quickly, no I/O
Wants(cfg *config.Config) []Want
}
A feature that keeps subscriptions of Microsoft Graph
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Register ¶
func (r *Registry) Register(registrant Registrant)
type State ¶
type State struct {
Subscriptions map[string]*Subscription `json:"subscriptions"`
// By the owner of the want refused
Refused map[string]Refusal `json:"refused,omitempty"`
// Certificates resource data is encrypted for, the newest last. One is let go of once no subscription names it
Certificates []graph.Certificate `json:"certificates,omitempty"`
// When the keeper last looked at the subscriptions, and what that look could not do
Kept time.Time `json:"kept,omitzero"`
Problems []string `json:"problems,omitempty"`
}
What a profile keeps of Microsoft Graph across restarts
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
// The feature and thing it is for, as the feature's want names it, and what a user calls it
Owner string `json:"owner"`
Title string `json:"title,omitempty"`
// Resource and kinds of change it tells of, and whether its notifications carry the resource encrypted
Resource string `json:"resource"`
Change string `json:"change"`
Data bool `json:"data,omitempty"`
// Where Graph posts its notifications and its news
Address string `json:"address"`
Lifecycle string `json:"lifecycle,omitempty"`
// What each of its notifications carries to show it is Graph's, never shown. Empty in what the host hands out
Secret string `json:"secret,omitempty"`
// Certificate the resource data of its notifications is encrypted for
Certificate string `json:"certificate,omitempty"`
Expires time.Time `json:"expires"`
Made time.Time `json:"made"`
Renewed time.Time `json:"renewed,omitzero"`
// When it last brought a notification, and when Graph last told it missed some
LastNotice time.Time `json:"last_notice,omitzero"`
MissedAt time.Time `json:"missed,omitzero"`
Status string `json:"status"`
}
A subscription of Graph the keeper made, or took over, for a feature
func (Subscription) Live ¶
func (s Subscription) Live() bool
Whether the subscription tells of its resource now
func (Subscription) Missed ¶
func (s Subscription) Missed() bool
Whether Graph told within the last week that it could not deliver some notifications of the subscription, so what changed then reached no feature
type Taker ¶
type Taker interface {
// Takes the notifications of the subscription of the owner, each checked against its secret, taken once and its resource data
// decrypted. The news that Graph removed it or could not deliver some of it among them, with Lifecycle set. An error is answered to
// Graph as a failure, which posts them again later, so take quickly: Graph waits three seconds, and what takes longer goes on after
Take(ctx context.Context, cfg *config.Config, owner string, notifications []graph.Notification) error
}
Registrant that takes the notifications of its subscriptions
type Told ¶
type Told struct {
// notification, subscribed, renewed, removed or failed
Kind string
// For a notification: what became of it, accepted, duplicate, refused, other or undecrypted. For the rest the resource's kind
Outcome string
Count int
}
What happened at the receiver or the keeper, as monitoring is told it
type Upkeep ¶
type Upkeep struct {
// Subscriptions Graph has of the app, and those of them the profile keeps
Remote, Ours int
// Made, renewed, let go of and lost by Graph, and those due to be renewed, by id or resource
Made, Renewed, Removed, Lost, Due []string
// What failed, a sentence each
Problems []string
}
What one look at the subscriptions of a profile found and did
type Want ¶
type Want struct {
// Who it is for, unique within the profile and the same from one look to the next, the feature first: "teams_pipeline:<resource>",
// "webhook:<name>:<resource>"
Owner string
// What a user calls what it is for, such as "Teams meetings" or "the webhook mail"
Title string
// Resource of Graph as Graph names it, without Graph's address: communications/onlineMeetings/getAllTranscripts
Resource string
// Kinds of change it tells of, Graph's own choice for the resource when none
Changes []string
// The changed resource comes with each notification, encrypted for this computer
Data bool
}
One subscription a feature keeps for a profile