domain

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 7 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 domain defines the types, interfaces, and errors shared by the rest of the application. It imports no other internal package.

Index

Constants

View Source
const (
	TeamPrivacyClosed = "closed"
	TeamPrivacySecret = "secret"
)

Team privacy values accepted by the GitHub API.

View Source
const (
	ViolationInsufficientReviews = "insufficient_reviews"
	ViolationMissingStatusCheck  = "missing_status_check"
)

Compliance violation types.

View Source
const (
	SeverityLow      = "low"
	SeverityMedium   = "medium"
	SeverityHigh     = "high"
	SeverityCritical = "critical"
)

Security alert severities, from lowest to highest.

Variables

View Source
var (
	ErrValidation = errors.New("validation error")
	ErrAuth       = errors.New("auth error")
	ErrAPI        = errors.New("api error")
	ErrConfig     = errors.New("config error")
)

Error kinds classify failures so callers, such as the HTTP layer, can react to a kind of failure without knowing every specific error. Check them with errors.Is.

View Source
var (
	ErrMissingPRData       = newKindError(ErrValidation, "pr data missing")
	ErrInvalidPayload      = newKindError(ErrValidation, "invalid webhook payload")
	ErrInvalidSignature    = newKindError(ErrAuth, "invalid webhook signature")
	ErrMissingSignature    = newKindError(ErrAuth, "webhook signature missing")
	ErrInvalidPattern      = newKindError(ErrValidation, "invalid regex pattern")
	ErrEmptyPattern        = newKindError(ErrValidation, "pattern cannot be empty")
	ErrUnknownAction       = newKindError(ErrValidation, "unknown scheduled action")
	ErrFeatureDisabled     = newKindError(ErrConfig, "feature not enabled")
	ErrGroupNotFound       = newKindError(ErrAPI, "okta group not found")
	ErrTeamNotFound        = newKindError(ErrAPI, "github team not found")
	ErrInstallationMissing = newKindError(ErrConfig, "github app is not installed on the organization")
)

Sentinel errors for common failures.

Functions

func HighestSeverity added in v1.0.0

func HighestSeverity(alerts []SecurityAlert) string

HighestSeverity returns the highest severity among alerts, or "unknown".

func IsSeverity added in v1.0.0

func IsSeverity(s string) bool

IsSeverity returns true if s is one of the known severities.

func IsValidGitHubLogin added in v1.0.0

func IsValidGitHubLogin(s string) bool

IsValidGitHubLogin returns true if s can be a GitHub login.

func MeetsSeverity added in v1.0.0

func MeetsSeverity(severity, minSeverity string) bool

MeetsSeverity returns true if severity is at or above minSeverity.

func SeverityRank added in v1.0.0

func SeverityRank(severity string) int

SeverityRank returns a number that orders severities, or 0 for an unknown severity.

func TeamSlug added in v1.0.0

func TeamSlug(name string) string

TeamSlug returns the slug GitHub gives a team with the given name. A slug is returned unchanged.

Types

type ComplianceViolation

type ComplianceViolation struct {
	Type        string
	Description string
}

ComplianceViolation represents a single branch protection rule violation.

type GitHubClient

type GitHubClient interface {
	// CheckPRCompliance verifies whether a merged PR met the branch
	// protection and ruleset requirements of its base branch.
	CheckPRCompliance(ctx context.Context, owner, repo string, prNumber int) (*PRComplianceResult, error)

	// ResolveTeam returns the slug of the team with the given name. If the
	// team does not exist, it is created when create is true, and
	// ErrTeamNotFound is returned otherwise.
	ResolveTeam(ctx context.Context, name, privacy string, create bool) (string, error)

	// SyncTeamMembers adds and removes members to match desired state.
	SyncTeamMembers(ctx context.Context, teamSlug string, desiredMembers []string, safetyThreshold float64) (*TeamSyncResult, error)

	// GetTeamMembers returns the logins of all team members.
	GetTeamMembers(ctx context.Context, teamSlug string) ([]string, error)

	// ListOrgMembers returns the logins of all organization members.
	ListOrgMembers(ctx context.Context) ([]string, error)

	// GetAppSlug returns the GitHub App's slug.
	GetAppSlug(ctx context.Context) (string, error)

	// ListSecurityAlerts fetches open security alerts across the org that
	// are older than minAgeDays and at or above minSeverity. It covers
	// dependabot, code scanning, and secret scanning alerts.
	ListSecurityAlerts(ctx context.Context, minAgeDays int, minSeverity string) (*SecurityAlertsReport, error)
}

GitHubClient defines the GitHub API operations the application uses. Implemented by internal/github/client.Client.

type GroupInfo

type GroupInfo struct {
	ID                      string
	Name                    string
	Members                 []string
	SkippedNoGitHubUsername []string
	// Err is set when the group's members could not be fetched. Such a
	// group must not be synced, since its member list is incomplete.
	Err error
}

GroupInfo contains Okta group details and member list.

type GroupMembersResult

type GroupMembersResult struct {
	Members                 []string
	SkippedNoGitHubUsername []string
}

GroupMembersResult contains the results of fetching group members.

type Notifier

type Notifier interface {
	// NotifyPRBypass sends a notification when branch protection is
	// bypassed.
	NotifyPRBypass(ctx context.Context, result *PRComplianceResult, repoFullName string) error

	// NotifyOktaSync sends a notification with Okta sync results.
	NotifyOktaSync(ctx context.Context, reports []*SyncReport, githubOrg string) error

	// NotifyOrphanedUsers sends a notification about organization members
	// not in any synced teams.
	NotifyOrphanedUsers(ctx context.Context, report *OrphanedUsersReport) error

	// NotifySecurityAlerts sends a notification about stale security
	// alerts across the organization.
	NotifySecurityAlerts(ctx context.Context, report *SecurityAlertsReport, githubOrg string) error

	// ReplyToCommand answers a Slack slash command through the response
	// URL Slack sent with it. Only the user who ran the command sees the
	// reply.
	ReplyToCommand(ctx context.Context, responseURL, text string) error
}

Notifier defines the interface for sending notifications. Implemented by internal/notifiers.SlackNotifier.

type OktaClient

type OktaClient interface {
	// GetGroupsByPattern fetches all Okta groups matching a regex pattern.
	GetGroupsByPattern(ctx context.Context, pattern string) ([]*GroupInfo, error)

	// GetGroupInfo fetches details for a single Okta group by name.
	GetGroupInfo(ctx context.Context, groupName string) (*GroupInfo, error)
}

OktaClient defines the Okta API operations the application uses. Implemented by internal/okta.Client.

type OrphanedUsersReport

type OrphanedUsersReport struct {
	OrphanedUsers []string
}

OrphanedUsersReport contains users who are org members but not in any synced teams.

type PRComplianceResult

type PRComplianceResult struct {
	PR               *github.PullRequest
	BaseBranch       string
	Protection       *github.Protection
	BranchRules      *github.BranchRules
	Violations       []ComplianceViolation
	UserHasBypass    bool
	UserBypassReason string
}

PRComplianceResult contains PR compliance check results including violations and the merger's bypass permissions.

func (*PRComplianceResult) HasViolations

func (r *PRComplianceResult) HasViolations() bool

HasViolations returns true if any compliance violations were detected.

func (*PRComplianceResult) WasBypassed

func (r *PRComplianceResult) WasBypassed() bool

WasBypassed returns true if the PR was merged even though it did not meet the branch's requirements. GitHub blocks such merges unless someone bypasses the rules: an admin, a ruleset bypass actor, or a role allowed to skip branch protection.

type SecurityAlert added in v0.22.0

type SecurityAlert struct {
	Type      string
	Repo      string
	Number    int
	Severity  string
	Summary   string
	HTMLURL   string
	CreatedAt time.Time
	AgeDays   int
}

SecurityAlert represents a normalized security alert from any source (dependabot, code scanning, or secret scanning).

type SecurityAlertsReport added in v0.22.0

type SecurityAlertsReport struct {
	MinAgeDays   int
	MinSeverity  string
	TotalAlerts  int
	AlertsByRepo map[string][]SecurityAlert
	Errors       []string
}

SecurityAlertsReport contains stale security alerts grouped by repo.

func (*SecurityAlertsReport) HasAlerts added in v0.22.0

func (r *SecurityAlertsReport) HasAlerts() bool

HasAlerts returns true if any stale alerts were found.

func (*SecurityAlertsReport) HasErrors added in v0.22.0

func (r *SecurityAlertsReport) HasErrors() bool

HasErrors returns true if any errors occurred during alert fetching.

func (*SecurityAlertsReport) RepoCount added in v0.22.0

func (r *SecurityAlertsReport) RepoCount() int

RepoCount returns the number of repos with stale alerts.

type StateStore added in v1.1.0

type StateStore interface {
	// Get returns the record stored under key, or nil if there is none.
	Get(ctx context.Context, key string) ([]byte, error)

	// Put stores a record under key, replacing any record already there.
	Put(ctx context.Context, key string, value []byte) error
}

StateStore keeps small records that must outlive a run, such as what each report last posted and when. Implemented by internal/state.

type SyncReport

type SyncReport struct {
	Rule                       string
	OktaGroup                  string
	GitHubTeam                 string
	MembersAdded               []string
	MembersRemoved             []string
	MembersSkippedExternal     []string
	MembersSkippedNoGHUsername []string
	Errors                     []string
	// TeamResolved is true when GitHubTeam is the slug of an existing team.
	TeamResolved bool
	// Members are the team's members after the sync, when its members were
	// synced.
	Members []string
}

SyncReport contains the results of syncing a single Okta group to a GitHub team.

func (*SyncReport) HasChanges

func (r *SyncReport) HasChanges() bool

HasChanges returns true if members were added or removed.

func (*SyncReport) HasErrors

func (r *SyncReport) HasErrors() bool

HasErrors returns true if any errors occurred during sync.

type SyncResult

type SyncResult struct {
	Reports []*SyncReport
}

SyncResult contains the report for every synced group.

func (*SyncResult) Complete added in v1.0.0

func (r *SyncResult) Complete() bool

Complete returns true if every report's team was resolved, so the result names every team the rules manage. A rule or group that failed before its team was found leaves the result incomplete.

func (*SyncResult) ManagedTeams added in v1.0.0

func (r *SyncResult) ManagedTeams() []string

ManagedTeams returns the slug of every team the sync targeted, whether or not its sync succeeded.

type SyncRule

type SyncRule struct {
	Name                string `json:"name"`
	Enabled             *bool  `json:"enabled,omitempty"`
	OktaGroupPattern    string `json:"okta_group_pattern,omitempty"`
	OktaGroupName       string `json:"okta_group_name,omitempty"`
	GitHubTeamPrefix    string `json:"github_team_prefix,omitempty"`
	GitHubTeamName      string `json:"github_team_name,omitempty"`
	StripPrefix         string `json:"strip_prefix,omitempty"`
	SyncMembers         *bool  `json:"sync_members,omitempty"`
	CreateTeamIfMissing bool   `json:"create_team_if_missing"`
	TeamPrivacy         string `json:"team_privacy,omitempty"`
}

SyncRule defines how to sync Okta groups to GitHub teams.

func (SyncRule) GetName

func (r SyncRule) GetName() string

GetName returns the rule name, defaulting to the team or group name.

func (SyncRule) IsEnabled

func (r SyncRule) IsEnabled() bool

IsEnabled returns true if the rule is enabled (defaults to true).

func (SyncRule) Privacy added in v1.0.0

func (r SyncRule) Privacy() string

Privacy returns the privacy for teams the rule creates.

func (SyncRule) ShouldSyncMembers

func (r SyncRule) ShouldSyncMembers() bool

ShouldSyncMembers returns true if members should be synced (defaults to true).

func (SyncRule) Validate added in v1.0.0

func (r SyncRule) Validate() error

Validate reports every problem with the rule.

type TeamSyncResult

type TeamSyncResult struct {
	TeamName               string
	MembersAdded           []string
	MembersRemoved         []string
	MembersSkippedExternal []string
	Errors                 []string
	// Members are the team's members after the sync, including members of
	// its child teams.
	Members []string
}

TeamSyncResult contains the results of syncing team membership.

Jump to

Keyboard shortcuts

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