teams

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 30 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 teams holds the Teams of C-25: a name and a slug, each unique among the Teams that are not deleted, a description, the people added by hand, the groups of the identity provider whose people are in the Team and the Working hours, the Team's own or the Organization's, and its Team mentions, the group that mentions it through each Connection whose messenger can mention a group (mentions.go). A Team grants no Permission and limits none (ADR-0018). Every change is recorded in the Audit log and announced with the live hint team, and the package exports muster_team_info. Deleting a Team keeps its row, marked deleted, removes its people, entries and Working hours and leaves the Routes and Destinations it owned without an owner, through its own queries, so that the package imports no other domain than internal/oidc, whose rule of matching groups it shares.

Index

Constants

View Source
const (
	RuleLabel   = "label"
	RuleMatcher = "matcher"
)

The rules by which an Alert belongs to a Team (C-25.FR-5): the value of the Team label equal to the Team's slug, or one of the Team's Team matchers.

View Source
const (
	ConditionAny           = "any"
	ConditionCritical      = "critical"
	ConditionBelowCritical = "below_critical"
)

The Severity conditions of the Destinations of a Team (C-26.FR-1), as routing names them: any level, only critical, or every level below critical.

View Source
const (
	MaxIdpEntries     = 100
	MaxIdpEntryLength = 200
)

The limits of the identity provider entries of a Team.

View Source
const (
	ReasonTelegramNoGroups      = "telegram_no_groups"
	ReasonUsergroupsReadMissing = "usergroups_read_missing"
	ReasonBridgeNoGroupMentions = "bridge_no_group_mentions"
)

The reasons a Connection cannot mention a group (MentionUnavailableReason, C-25.FR-8, C-28.FR-2): Telegram has no group mentions; the last check of a Slack Connection found no usergroups:read; a bridge declares no group mentions in its info, or is a Notification gateway only.

View Source
const (
	CodeGroupMentionsUnsupported = "group_mentions_unsupported"
	CodeUnsupported              = "unsupported"
)

CodeGroupMentionsUnsupported is the FieldError code of a Team mention for a Connection that cannot mention a group (C-25.FR-8), and CodeUnsupported that of a Slack user group's id given for another type.

View Source
const (
	ActionCreated     = "team.created"
	ActionUpdated     = "team.updated"
	ActionDeleted     = "team.deleted"
	ActionUserAdded   = "team.user_added"
	ActionUserRemoved = "team.user_removed"
	ResourceTeam      = "team"
	Hint              = "team"
)

The Audit log actions and resource type, and the live hint, of Teams (C-25.FR-11).

View Source
const (
	KindTeamEvaluation      = "team_evaluation"
	KindTeamName            = "team_name"
	KindTeamDestinations    = "team_destinations"
	OpenGroupUpdatesChannel = "muster_open_group_updates"
)

KindTeamEvaluation is the kind of the open_group_updates row that a save of a Team writes (C-25.FR-13), KindTeamName that of a rename, whose new name the Root messages of the open Alert Groups that have the Team show (C-29.FR-1), KindTeamDestinations that of a change of the Team's Destination entries or of its deletion, which publishes the open Alert Groups that have the Team Quietly where they now reach and gives the final edit where no entry names a Destination any more (C-26.FR-6, C-25.FR-10), and OpenGroupUpdatesChannel the LISTEN/NOTIFY channel that wakes the workers of internal/groups, which claim them.

View Source
const (
	MaxNameLength        = 200
	MaxDescriptionLength = 2000
)

The limits of a Team, in characters.

View Source
const (
	CodeRequired      = "required"
	CodeInvalidFormat = "invalid_format"
	CodeTooLong       = "too_long"
	CodeOutOfRange    = "out_of_range"
	CodeDuplicate     = "duplicate"
	CodeUnknownID     = "unknown_id"
	CodeInvalidRegex  = "invalid_regex"
)

The codes of FieldError, as the API names them.

View Source
const HolderChain = "escalation_chain"

HolderChain is the kind of an Escalation chain that its owning Team holds (C-25.FR-10).

View Source
const HolderSchedule = "schedule"

HolderSchedule is the kind of a Schedule that holds its Team.

View Source
const MaxTeamMentions = 100

MaxTeamMentions is the most Team mentions a Team has, one per Connection.

View Source
const SourceByHand = "by_hand"

SourceByHand is how a person an Admin added is in a Team.

View Source
const SourceIdp = "idp"

SourceIdp is how a person whom an identity provider entry of the Team matched is in it (C-25.FR-4).

View Source
const TeamValuesWindow = 14 * 24 * time.Hour

TeamValuesWindow is organization.team_values_window (P-75): the values of the Team label without a Team seen in the last 14 days, like organization.severity_values_window.

Variables

View Source
var (
	// ErrNotFound is a Team that does not exist in the Organization or is deleted.
	ErrNotFound = errors.New("no such team")
	// ErrNameTaken is a name another Team that is not deleted has, ignoring case.
	ErrNameTaken = errors.New("another team has this name")
	// ErrSlugTaken is a slug another Team that is not deleted has.
	ErrSlugTaken = errors.New("another team has this slug")
	// ErrVersionMismatch is an If-Match that names another version of the Team.
	ErrVersionMismatch = errors.New("the team changed since it was read")
	// ErrNotInTeam is a removal of a User who is not in the Team.
	ErrNotInTeam = errors.New("the user is not in the team")
	// ErrInUse is the deletion of a Team that has Schedules or owns Escalation chains (team_in_use, P-64);
	// InUseError names them.
	ErrInUse = errors.New("the team has schedules or escalation chains")
)
View Source
var Weekdays = []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"}

Weekdays are the days of the week as the API and the CHECKs name them, Monday first.

Functions

func ValidTimeZone

func ValidTimeZone(name string) bool

ValidTimeZone reports whether name is an IANA time zone that time.LoadLocation knows, never Local, the zone of the server.

Types

type ChainEntry

type ChainEntry struct {
	ChainID   string `json:"chain_id"`
	Condition string `json:"severity_condition"`
}

ChainEntry is an Escalation chain of the Team with its Severity condition, by the chain's public_id (C-32.FR-2).

type ChainOwner

type ChainOwner struct {
	PublicID string
	Name     string
	Slug     string
	Deleted  bool
}

ChainOwner is the Team that owns an Escalation chain, marked deleted once deleted.

type ChainRef

type ChainRef struct {
	PublicID   string
	Name       string
	OwningTeam *ChainOwner
}

ChainRef is an Escalation chain of the Team as a read names it, with its owning Team, nil when none owns it.

type Classes

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

Classes are the Teams that are not deleted as of a Stamp, ready to classify Alerts.

func (*Classes) Classify

func (c *Classes) Classify(labels map[string]string) Classification

Classify answers, for the labels of an Alert with the Static labels of its Integration applied, the Teams it belongs to (C-25.FR-5): the Team whose slug equals the value of the Team label exactly, by the rule label, and every Team one of whose Team matchers picks it, a missing label counting as the empty value, by the rule matcher with the first such matcher; a Team both pick belongs by the label. A value of the Team label that names no Team is UnknownValue.

type Classification

type Classification struct {
	Teams        []Membership
	UnknownValue string
}

Classification is what the classification answers for the labels of one Alert: the Teams it belongs to, ordered by Team, and the value of the Team label that names no Team, empty when the label is missing, empty or names a Team.

type Classifier

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

Classifier classifies the Alerts that start firing by their Teams (C-25.FR-5) for the Router. The Teams that are not deleted, their slugs and their compiled Team matchers are cached per replica: each Snapshot reads the Stamp in its own transaction, as the Routes' stamp, and a Stamp that differs from the cached one reads the Teams again in that transaction, so that a change made on any replica applies to the next Snapshot. The cache holds one state only.

func NewClassifier

func NewClassifier(orgID int64) *Classifier

NewClassifier returns the Classifier of the Organization orgID.

func (*Classifier) At

At returns the Teams as of the Stamp st: the cached ones when their Stamp is the same, otherwise those q reads, which then replace the cache.

type ClassifyQueries

type ClassifyQueries interface {
	ListClassifiedTeams(ctx context.Context, orgID int64) ([]dbgen.ListClassifiedTeamsRow, error)
	ListClassifiedMatchers(ctx context.Context, orgID int64) ([]dbgen.ListClassifiedMatchersRow, error)
}

ClassifyQueries are the queries of the classification, run in the Snapshot's transaction.

type Config

type Config struct {
	OrgID    int64
	Store    Store
	Audit    *audit.Writer
	Business clock.Clock
}

Config is what a Service needs: the Organization, the Store, the Audit log writer and the business clock, which dates the rows.

type DestinationEntry

type DestinationEntry struct {
	DestinationID string `json:"destination_id"`
	Condition     string `json:"severity_condition"`
}

DestinationEntry is a Destination of the Team with its Severity condition, by the Destination's public_id (C-26.FR-1): where the Alert Groups of the Team arrive from the Routes that deliver to the Teams from the label.

type DestinationRef

type DestinationRef struct {
	PublicID     string
	Name         string
	Type         string
	Health       string
	BrokenSince  *time.Time
	BrokenReason *string
}

DestinationRef is a Destination of the Team as a read names it, with its type and health.

type FieldError

type FieldError struct {
	Pointer string
	Code    string
	Detail  string
}

FieldError is a field of a request that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem.

func (*FieldError) Error

func (e *FieldError) Error() string

type Holder

type Holder struct {
	Type     string
	PublicID string
	Name     string
}

Holder is an object that keeps a Team from being deleted: its kind, public_id and name.

type IdpEntry

type IdpEntry struct {
	Claim string `json:"claim,omitempty"`
	Group string `json:"group"`
}

IdpEntry is an identity provider entry of a Team: a group, or a subtree a/b/*, of a claim, by default the groups claim of the OIDC settings, matched as the entries of the Role mapping are (C-25.FR-4, C-03.FR-5).

type InUseError

type InUseError struct {
	Holders []Holder
}

InUseError is ErrInUse with the objects that hold the Team.

func (*InUseError) Error

func (e *InUseError) Error() string

func (*InUseError) Unwrap

func (e *InUseError) Unwrap() error

type Input

type Input struct {
	Name            string
	Slug            string
	Description     *string
	OwnWorkingHours bool
	WorkingHours    *WorkingHours
	Matchers        *[]Matcher
	IdpEntries      *[]IdpEntry
	// DestinationEntries replace the Destinations of the Team as a whole (C-26.FR-1).
	DestinationEntries *[]DestinationEntry
	// ChainEntries replace the Escalation chains of the Team as a whole (C-32.FR-2); nil keeps them on an update and
	// is none on a creation.
	ChainEntries *[]ChainEntry
	// Mentions replace the Team mentions of the Team as a whole (C-25.FR-8); nil keeps them on an update and is none
	// on a creation.
	Mentions *[]MentionInput
	// ManagedBy is the mark of the tool that keeps the Team as code (C-33.FR-11).
	ManagedBy managedby.Input
}

Input is what createTeam and updateTeam write. A nil Description, IdpEntries or DestinationEntries keeps the stored one on an update and is empty on a creation; WorkingHours are read only with OwnWorkingHours, and nil keeps the Team's own on an update; nil Matchers keep the stored ones on an update and are none on a creation, and others replace them as a whole.

type LabelValue

type LabelValue struct {
	Value      string
	LastSeenAt time.Time
	Alerts     int64
	ValidSlug  bool
}

LabelValue is a value of the Team label that names no Team (C-25.FR-7): when an Alert that carries it was last seen, how many Alerts last seen within the window carry it, and whether it is a valid slug (team.slug_format), which a Team could take; one that is not reaches a Team only through a Team matcher.

type LabelValues

type LabelValues struct {
	Label      string
	WindowDays int
	Items      []LabelValue
}

LabelValues are the values of the Team label Label without a Team, seen within the window of WindowDays days.

type LinkedMessenger

type LinkedMessenger struct {
	Type               string
	ConnectionPublicID string
	ConnectionName     string
}

LinkedMessenger is an Account link of a person: the type of its Connection and the Connection.

type ListFilter

type ListFilter struct {
	Query string
	After *Position
	Limit int
}

ListFilter selects a page of Teams by name: matching Query when it is set, after the position After.

type Matcher

type Matcher struct {
	Label string `json:"label"`
	Op    string `json:"op"`
	Value string `json:"value"`
}

Matcher is a Team matcher (C-25.FR-5): a condition on one label in the syntax of Route Matchers.

type Membership

type Membership struct {
	TeamID  int64
	Rule    string
	Matcher string
}

Membership is a Team an Alert belongs to, with the rule that decided it and, for the rule matcher, the Team matcher in the Alertmanager syntax.

type Mention

type Mention struct {
	MentionInput
	Connection        MentionConnectionRef
	Available         bool
	UnavailableReason string
}

Mention is a Team mention as a read gives it: its input, its Connection, and whether the Connection can carry it now, with the reason when it cannot. A Team mention whose Connection lost the ability stays and mentions nobody.

type MentionConnection

type MentionConnection struct {
	Connection        MentionConnectionRef
	Available         bool
	UnavailableReason string
	Mention           *Mention
}

MentionConnection is a Connection that may have a Destination, for the field of each Connection on the Team page (C-25.FR-8): whether it can mention a group now, the reason when it cannot, and the Team's Team mention for it, nil without one.

type MentionConnectionRef

type MentionConnectionRef struct {
	PublicID string
	Name     string
	Type     string
}

MentionConnectionRef is a Connection as a Team mention names it: its public_id, name and type.

type MentionInput

type MentionInput struct {
	ConnectionID string `json:"connection_id"`
	Group        string `json:"group"`
	GroupID      string `json:"group_id,omitempty"`
}

MentionInput is a Team mention as a save gives it and as the Audit log diff of its Team shows it: the Connection by public_id, the group that mentions the Team through it and, for a Slack Connection, the user group's id.

type Page

type Page struct {
	Teams []Team
	Next  *Position
}

Page is a page of Teams; Next, the position to continue after, is nil on the last page.

type Person

type Person struct {
	ID         int64
	PublicID   string
	Name       string
	Login      string
	Role       string
	Sources    []string
	IdpEntries []IdpEntry
	Linked     []LinkedMessenger
}

Person is someone in a Team with their Role, how they are in it, the identity provider entries that matched them and the messengers they linked.

type Position

type Position struct {
	Name string `json:"n"`
	ID   int64  `json:"i"`
}

Position is the place of a Team in the list by name: its lowered name and its id.

type Queries

type Queries interface {
	GetOrganizationWorkingHours(ctx context.Context, orgID int64) (dbgen.GetOrganizationWorkingHoursRow, error)
	ListTeams(ctx context.Context, arg dbgen.ListTeamsParams) ([]dbgen.ListTeamsRow, error)
	GetTeam(ctx context.Context, arg dbgen.GetTeamParams) (dbgen.GetTeamRow, error)
	LockTeam(ctx context.Context, arg dbgen.LockTeamParams) (int64, error)
	InsertTeam(ctx context.Context, arg dbgen.InsertTeamParams) (int64, error)
	UpdateTeam(ctx context.Context, arg dbgen.UpdateTeamParams) error
	DeleteTeam(ctx context.Context, arg dbgen.DeleteTeamParams) error
	DeleteTeamUsers(ctx context.Context, arg dbgen.DeleteTeamUsersParams) error
	ListTeamSchedules(ctx context.Context, arg dbgen.ListTeamSchedulesParams) ([]dbgen.ListTeamSchedulesRow, error)
	ListTeamOwnedChains(ctx context.Context, arg dbgen.ListTeamOwnedChainsParams) ([]dbgen.ListTeamOwnedChainsRow,
		error)
	ListTeamChains(ctx context.Context, arg dbgen.ListTeamChainsParams) ([]dbgen.ListTeamChainsRow, error)
	ResolveTeamChains(ctx context.Context, arg dbgen.ResolveTeamChainsParams) ([]dbgen.ResolveTeamChainsRow, error)
	DeleteTeamChainsExcept(ctx context.Context, arg dbgen.DeleteTeamChainsExceptParams) error
	UpsertTeamChains(ctx context.Context, arg dbgen.UpsertTeamChainsParams) error
	ReleaseOwnedDestinations(ctx context.Context, arg dbgen.ReleaseOwnedDestinationsParams) (
		[]dbgen.ReleaseOwnedDestinationsRow, error)
	ReleaseOwnedRoutes(ctx context.Context, arg dbgen.ReleaseOwnedRoutesParams) ([]dbgen.ReleaseOwnedRoutesRow, error)
	ListTeamUsers(ctx context.Context, arg dbgen.ListTeamUsersParams) ([]dbgen.ListTeamUsersRow, error)
	ListLinkedMessengers(ctx context.Context, arg dbgen.ListLinkedMessengersParams) (
		[]dbgen.ListLinkedMessengersRow, error)
	LockTeamUser(ctx context.Context, arg dbgen.LockTeamUserParams) (dbgen.LockTeamUserRow, error)
	GetTeamUser(ctx context.Context, arg dbgen.GetTeamUserParams) (dbgen.GetTeamUserRow, error)
	LockTeamMember(ctx context.Context, arg dbgen.LockTeamMemberParams) (dbgen.LockTeamMemberRow, error)
	InsertTeamUser(ctx context.Context, arg dbgen.InsertTeamUserParams) (int64, error)
	DeleteTeamUser(ctx context.Context, arg dbgen.DeleteTeamUserParams) (int64, error)
	DeleteUserTeams(ctx context.Context, arg dbgen.DeleteUserTeamsParams) ([]dbgen.DeleteUserTeamsRow, error)
	ListTeamInfo(ctx context.Context, orgID int64) ([]dbgen.ListTeamInfoRow, error)
	ListTeamMatchers(ctx context.Context, arg dbgen.ListTeamMatchersParams) ([]dbgen.ListTeamMatchersRow, error)
	DeleteTeamMatchers(ctx context.Context, arg dbgen.DeleteTeamMatchersParams) error
	InsertTeamMatchers(ctx context.Context, arg dbgen.InsertTeamMatchersParams) error
	LockTeamsVersion(ctx context.Context, orgID int64) (int64, error)
	BumpTeamsVersion(ctx context.Context, orgID int64) error
	InsertTeamUpdate(ctx context.Context, arg dbgen.InsertTeamUpdateParams) error
	NotifyOpenGroupUpdates(ctx context.Context, channel string) error
	GetTeamLabel(ctx context.Context, orgID int64) (string, error)
	ListTeamLabelValues(ctx context.Context, arg dbgen.ListTeamLabelValuesParams) ([]dbgen.ListTeamLabelValuesRow,
		error)
	ClearByHand(ctx context.Context, arg dbgen.ClearByHandParams) (int64, error)
	ListTeamIdpEntries(ctx context.Context, arg dbgen.ListTeamIdpEntriesParams) ([]dbgen.ListTeamIdpEntriesRow, error)
	DeleteTeamIdpEntries(ctx context.Context, arg dbgen.DeleteTeamIdpEntriesParams) error
	InsertTeamIdpEntries(ctx context.Context, arg dbgen.InsertTeamIdpEntriesParams) error
	ListIdpEntryClaims(ctx context.Context, orgID int64) ([]string, error)
	ListIdpEntries(ctx context.Context, orgID int64) ([]dbgen.ListIdpEntriesRow, error)
	LockUserMemberships(ctx context.Context, arg dbgen.LockUserMembershipsParams) (
		[]dbgen.LockUserMembershipsRow, error)
	GetMember(ctx context.Context, arg dbgen.GetMemberParams) (dbgen.GetMemberRow, error)
	DeleteUserRowsOfDeletedTeams(ctx context.Context, arg dbgen.DeleteUserRowsOfDeletedTeamsParams) (int64, error)
	JoinThroughIdp(ctx context.Context, arg dbgen.JoinThroughIdpParams) error
	SetIdpMatches(ctx context.Context, arg dbgen.SetIdpMatchesParams) error
	LeaveThroughIdp(ctx context.Context, arg dbgen.LeaveThroughIdpParams) error
	ListTeamDestinations(ctx context.Context, arg dbgen.ListTeamDestinationsParams) ([]dbgen.ListTeamDestinationsRow,
		error)
	ResolveTeamDestinations(ctx context.Context, arg dbgen.ResolveTeamDestinationsParams) (
		[]dbgen.ResolveTeamDestinationsRow, error)
	DeleteTeamDestinations(ctx context.Context, arg dbgen.DeleteTeamDestinationsParams) error
	DropDeletedTeamDestinations(ctx context.Context, arg dbgen.DropDeletedTeamDestinationsParams) error
	UpsertTeamDestinations(ctx context.Context, arg dbgen.UpsertTeamDestinationsParams) error
	DeleteAllTeamDestinations(ctx context.Context, arg dbgen.DeleteAllTeamDestinationsParams) error
	InsertTeamDestinationsUpdate(ctx context.Context, arg dbgen.InsertTeamDestinationsUpdateParams) error
	LockTeamMembership(ctx context.Context, arg dbgen.LockTeamMembershipParams) error
	ListTeamMentions(ctx context.Context, arg dbgen.ListTeamMentionsParams) ([]dbgen.ListTeamMentionsRow, error)
	ListMentionConnections(ctx context.Context, orgID int64) ([]dbgen.ListMentionConnectionsRow, error)
	ResolveMentionConnections(ctx context.Context, arg dbgen.ResolveMentionConnectionsParams) (
		[]dbgen.ResolveMentionConnectionsRow, error)
	DeleteTeamMentions(ctx context.Context, arg dbgen.DeleteTeamMentionsParams) error
	InsertTeamMentions(ctx context.Context, arg dbgen.InsertTeamMentionsParams) error
	GetTeamMention(ctx context.Context, arg dbgen.GetTeamMentionParams) (dbgen.GetTeamMentionRow, error)
	// AddTeamEntry adds the Mention entry "Team {Team}" to a Destination the Team names (mentions.AddTeamEntry).
	AddTeamEntry(ctx context.Context, org, destinationID, teamID int64, teamPublicID string, now time.Time) (
		mentions.TeamEntry, bool, error)
	audit.Store
	Notify(ctx context.Context, h db.Hint) error
}

Queries are the queries of the package, with the insert of the Audit log and the live hint.

type Requester

type Requester struct {
	Actor     audit.Actor
	Transport audit.Transport
	Address   netip.Addr
}

Requester is who asks for a change and how: the actor and the Transport of the Audit log entry, and the client address.

type Service

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

Service holds the Teams of the Organization.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) AddUser

func (s *Service) AddUser(ctx context.Context, r Requester, teamID, userID string) (Person, bool, error)

AddUser adds the User userID to the Team teamID by hand (C-25.FR-3) and reports whether it added them: a User already in the Team by hand changes nothing, and one in it through the identity provider gets the source by_hand too. A User that does not exist or is deleted is an unknown_id FieldError; a disabled one may be added.

func (*Service) Create

func (s *Service) Create(ctx context.Context, r Requester, in Input) (Team, error)

Create creates a Team, and requests in its transaction the evaluation of the open Alert Groups, which brings the Team those of its Alerts (C-25.FR-13). A name or a slug another Team that is not deleted has is ErrNameTaken or ErrSlugTaken.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, r Requester, publicID string, version *int64) error

Delete deletes the Team publicID (C-25.FR-10); a non-nil version must be its current one. A Team that has Schedules or owns Escalation chains is refused with InUseError, read under the lock that every change of its Schedules takes and that a save of a chain naming it as its owner waits for (P-64); the chains the Team names leave it. The row stays, marked deleted, for the names that point at it, and its name and slug are free at once; its people, Working hours and Team mentions are removed, and the Destinations, then the Routes, it owned are left without an owner, each with a new version and its own Audit log entry by the system, in the same transaction. Its Destination entries are removed last, under its membership lock, with the row team_destinations that gives their final edits to the open Alert Groups that had the Team wherever no other entry names them (C-25.FR-10, C-26.FR-6).

func (*Service) EntryClaims

func (s *Service) EntryClaims(ctx context.Context) ([]string, error)

EntryClaims lists the claims the entries of the Teams read, the empty string for the groups claim; it is half of the Membership of internal/oidc.

func (*Service) ForConnection

func (s *Service) ForConnection(ctx context.Context, db mentions.DBTX, teamID, connectionID int64) (TeamMention, bool,
	error)

ForConnection is the Team mention of the Team teamID for the Connection connectionID, by their ids, and whether there is one that the Connection can carry now: none for a deleted Team or Connection, without a Team mention, or when the Connection lost the ability, so that the Team is mentioned as nobody and never by its On-call (C-25.FR-8, C-28.FR-3). It reads through db, the transaction of the resolution, or the main pool for a nil one, so that a caller that holds a connection of the pool takes no second one. It satisfies the interface TeamMentions that internal/mentions declares.

func (*Service) Get

func (s *Service) Get(ctx context.Context, publicID string) (Team, error)

Get reads the Team publicID; a deleted or unknown one is ErrNotFound.

func (*Service) InfoChanged

func (s *Service) InfoChanged()

InfoChanged asks RunInfo to refresh muster_team_info: a hint said a Team changed, maybe on another replica. It never blocks.

func (*Service) LabelValues

func (s *Service) LabelValues(ctx context.Context) (LabelValues, error)

LabelValues lists the values of the Organization's Team label, with the Static labels of their Integrations, that the Alerts last seen within TeamValuesWindow of the business clock carried and that name no Team that is not deleted, the most recently seen first (C-25.FR-7, AC-1).

func (*Service) List

func (s *Service) List(ctx context.Context, f ListFilter) (Page, error)

List lists a page of the Teams that are not deleted, by name.

func (*Service) OrganizationHours

func (s *Service) OrganizationHours(ctx context.Context) (WorkingHours, error)

OrganizationHours reads the Organization's Working hours, which every Team without its own follows.

func (*Service) RefreshInfo

func (s *Service) RefreshInfo(ctx context.Context) error

RefreshInfo makes muster_team_info list exactly the Teams that are not deleted, as the database has them, whichever replica changed them (C-25.FR-11).

func (*Service) RemoveUser

func (s *Service) RemoveUser(ctx context.Context, r Requester, teamID, userID string) error

RemoveUser takes away the source by_hand of the User userID in the Team teamID (C-25.FR-3, FR-4): a person also in it through the identity provider stays in it with the source idp, any other leaves it. A User with no source by_hand in the Team, such as one in it only through the identity provider, is ErrNotInTeam. The row is read locked, so that a sign-in that changes the same row meanwhile is waited for and its outcome decides.

func (*Service) RemoveUserTeams

func (s *Service) RemoveUserTeams(ctx context.Context, tx usersdb.DBTX, userID int64, actor audit.Actor,
	t audit.Transport, addr netip.Addr) (func(context.Context), error)

RemoveUserTeams takes the deleted User userID out of every Team (C-03.FR-13 revised, C-25.FR-3), in the transaction tx of the deletion, each recorded as team.user_removed by the actor of the deletion, with the User — named as the deletion left them — and the reason user_deleted. It is the users package's TeamRemover; it has nothing to run once tx committed.

func (*Service) RunInfo

func (s *Service) RunInfo(ctx context.Context, ticks <-chan time.Time)

RunInfo keeps muster_team_info current until ctx ends: it refreshes it at once, after InfoChanged and at every tick, which also repairs a refresh that failed.

func (*Service) SyncMembership

func (s *Service) SyncMembership(ctx context.Context, tx oidcdb.DBTX, userID int64, groupsClaim string,
	claims oidc.Claims) error

SyncMembership follows the identity provider entries of the Teams at an OIDC sign-in, a link or a successful re-check (C-25.FR-4, C-03.FR-30), in the transaction tx of that success, which holds the row of the User locked; it is the other half of the Membership of internal/oidc. The User joins each Team with an entry that matches the claims, with the source idp beside by_hand for a person added by hand, and leaves each Team they are in through the identity provider when no entry matches any more: a person added by hand keeps by_hand. Only the entries whose claim is in claims are decided; an entry that matched before and whose claim was not read keeps the person in. Each join and leave is recorded as team.user_added or team.user_removed by the system with the source idp and the entry, with the live hint team. It never changes a Role. It first removes the User's rows in deleted Teams, which a sign-in that raced a deletion may have left.

func (*Service) Update

func (s *Service) Update(ctx context.Context, r Requester, publicID string, version *int64, in Input) (Team, error)

Update replaces the configured fields of the Team publicID; a non-nil version must be its current one (If-Match). An update that changes nothing writes nothing. A changed slug or changed Team matchers request in the transaction the evaluation of the open Alert Groups (C-25.FR-13); a change of the name, the description or the Working hours does not. A changed name requests the re-render of the Root messages of the open Alert Groups that have the Team (C-29.FR-1), and changed Destination entries the row team_destinations, under the Team's membership lock (C-26.FR-6). Team mentions are checked against what each Connection can mention now, an unchanged stored one kept whatever its Connection can mention, and replaced as a whole when they changed (C-25.FR-8); they request neither.

func (*Service) Users

func (s *Service) Users(ctx context.Context, publicID string) ([]Person, error)

Users lists the people in the Team publicID, by name.

type Stamp

type Stamp struct {
	Label   string
	Version int64
}

Stamp identifies a state of the Teams and of the Team label: organizations.teams_version, which every change of a Team or of the Team label raises, and the Team label itself.

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
	On(tx dbgen.DBTX) Queries
}

Store runs the queries alone, in one transaction, or in a caller's transaction tx (On).

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

type Team

type Team struct {
	ID           int64
	PublicID     string
	Name         string
	Slug         string
	Description  string
	Own          *WorkingHours
	WorkingHours WorkingHours
	Matchers     []Matcher
	IdpEntries   []IdpEntry
	UserCount    int64
	CreatedAt    time.Time
	Version      int64
	// ManagedBy is the tool that keeps the Team as code, nil for none (C-33.FR-11).
	ManagedBy *string

	DestinationEntries []DestinationEntry
	Destinations       []DestinationRef

	// ChainEntries are the Escalation chains of the Team with their Severity conditions by public_id, and Chains the
	// same chains by name (C-32.FR-2).
	ChainEntries []ChainEntry
	Chains       []ChainRef

	// Mentions are the Team mentions of Connections that are not deleted, by Connection name, and MentionConnections
	// the Connections that may have a Destination with the Team's Team mention for each (C-25.FR-8).
	Mentions           []Mention
	MentionConnections []MentionConnection
}

Team is a Team as the API reads it. Own are its own Working hours, nil when it follows the Organization's; WorkingHours are the effective ones. Matchers are its Team matchers in their order (C-25.FR-5). DestinationEntries are the Destinations of the Team with their Severity conditions by public_id, and Destinations the same Destinations by name (C-26.FR-1).

type TeamMention

type TeamMention = mentions.TeamMention

TeamMention is the Team mention that mentions a Team through a Connection, as delivery renders it: the group and, for a Slack Connection, the user group's id; the type internal/mentions declares for its interface TeamMentions.

type WorkingHours

type WorkingHours struct {
	Days     []string `json:"days"`
	Start    string   `json:"start"`
	End      string   `json:"end"`
	TimeZone string   `json:"time_zone"`
}

WorkingHours are days of the week, a start and an end on the 24-hour clock and an IANA time zone (C-25.FR-9): the Organization's (organization.working_hours) or a Team's own (team.working_hours). The end is later than the start on the same day, so Working hours never span midnight (P-63).

func Effective

func Effective(t Team, org WorkingHours) WorkingHours

Effective are the Working hours that apply to the Team t: its own when it has them, else the Organization's org.

func (WorkingHours) Contains

func (w WorkingHours) Contains(at time.Time) bool

Contains reports whether the instant at falls in the Working hours: on one of their days, at or after their start and before their end, in their time zone. Hours whose time zone does not load contain nothing.

func (WorkingHours) Validate

func (w WorkingHours) Validate(base string) (WorkingHours, error)

Validate refuses Working hours that are not valid, at the pointer base of the request body: no day, a day that is not a weekday or is given twice, a start or an end that is not HH:MM, an end not later than the start (out_of_range at the end) and a time zone that is not an IANA time zone. It returns the hours with their days in the order of the week.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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