msgraph

package
v2.0.5-main.4 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 31 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	ToldNotification = "notification"
	ToldSubscribed   = "subscribed"
	ToldRenewed      = "renewed"
	ToldRemoved      = "removed"
	ToldFailed       = "failed"
)

Kinds of what happened

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

View Source
const Provider = "microsoft"

Provider name a chat app of Microsoft gives its sign-in under, which Graph shares

Variables

This section is empty.

Functions

func Feature

func Feature(owner string) string

The feature an owner is of: the word before its first colon

func Folder

func Folder(cfg *config.Config) string

Folder of the profile's Microsoft Graph, and its files

func Sources

func Sources(cfg *config.Config) ([]netip.Prefix, []string)

The networks the settings take notifications from, and the entries that name none

func StatusOf

func StatusOf(err error) int

Status of a failure of Graph, 0 for any other error

Types

type Client

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

A Graph client of an app registration

func (*Client) As

func (c *Client) As(token string) *Client

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

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, query url.Values, out any) error

Reads the JSON answer of a GET into out

func (*Client) Health

func (c *Client) Health() Health

How the token of the client stands

func (*Client) Send

func (c *Client) Send(ctx context.Context, method, path string, body, out any) error

Sends the body and reads the JSON answer into out, nil out for none

func (*Client) Token

func (c *Client) Token(ctx context.Context, fresh bool) (string, error)

A token of the app, the one kept while it lasts unless a fresh one is asked for

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

type Failure struct {
	Status        int
	Code, Message string
	Method, Path  string
	Wait          time.Duration
}

A failure Microsoft Graph answered: its status, its code and words, and how long it asked to wait

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) Passing

func (f *Failure) Passing() bool

Whether the failure passes, so the same request may go again later

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 New

func New(cfg *config.Config, chats *gateway.Gateway) *Graph

func (*Graph) Address

func (g *Graph) Address(cfg *config.Config) string

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

func (g *Graph) Client(cfg *config.Config) (*Client, error)

The Graph client of the profile's app registration, refused with what is missing

func (*Graph) Closed

func (g *Graph) Closed(cfg *config.Config) string

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

func (g *Graph) Counted() map[string]Counts

Counts of what the receiver took of each profile since this process started

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

func (g *Graph) Health(cfg *config.Config, r *http.Request) (int, map[string]any)

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

func (g *Graph) Keep(ctx context.Context, cfg *config.Config, dry bool) (Upkeep, error)

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

func (g *Graph) Looked(cfg *config.Config) time.Time

When the keeper last looked at the subscriptions of the profile

func (*Graph) Reauthorize

func (g *Graph) Reauthorize(ctx context.Context, cfg *config.Config, id string) error

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

func (g *Graph) Refusals(cfg *config.Config, owner string) ([]Refusal, []string)

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

func (g *Graph) Remove(ctx context.Context, cfg *config.Config, id string) error

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

func (g *Graph) Serve(w http.ResponseWriter, r *http.Request, cfg *config.Config)

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

func (g *Graph) Subscriptions(ctx context.Context, cfg *config.Config) ([]Listed, error)

Every subscription Graph has of the app, those the profile keeps or that carry its secret marked

func (*Graph) Telling

func (g *Graph) Telling(tell func(Told))

Hands over what tells monitoring what happened at the receiver and the keeper

func (*Graph) Unaddressed

func (g *Graph) Unaddressed(cfg *config.Config) string

Why Graph can't post to the address of the profile, in words a user reads. Empty when it can

func (*Graph) Used

func (g *Graph) Used(cfg *config.Config) bool

Whether any registrant keeps subscriptions of the profile now, or the profile keeps any still to be let go of

func (*Graph) Wake

func (g *Graph) Wake()

Has the keeper look at the subscriptions of every profile now, such as after a feature asked for one

func (*Graph) Watch

func (g *Graph) Watch(ctx context.Context) error

Watch keeps every profile's subscriptions until the context ends, one icebath on this computer per profile at a time. It sleeps until the first renewal is due, and Wake or a settings change wakes it.

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

func (r *Registry) Host() *Graph

Host the registry is nested in, through which plugins reach Microsoft Graph

func (*Registry) Register

func (r *Registry) Register(registrant Registrant)

func (*Registry) Wants

func (r *Registry) Wants(cfg *config.Config) []Want

Subscriptions every registrant keeps for the profile of the settings, in the order they were registered

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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