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
- Variables
- func HighestSeverity(alerts []SecurityAlert) string
- func IsSeverity(s string) bool
- func IsValidGitHubLogin(s string) bool
- func MeetsSeverity(severity, minSeverity string) bool
- func SeverityRank(severity string) int
- func TeamSlug(name string) string
- type ComplianceViolation
- type GitHubClient
- type GroupInfo
- type GroupMembersResult
- type Notifier
- type OktaClient
- type OrphanedUsersReport
- type PRComplianceResult
- type SecurityAlert
- type SecurityAlertsReport
- type SyncReport
- type SyncResult
- type SyncRule
- type TeamSyncResult
Constants ¶
const ( TeamPrivacyClosed = "closed" TeamPrivacySecret = "secret" )
Team privacy values accepted by the GitHub API.
const ( ViolationInsufficientReviews = "insufficient_reviews" ViolationMissingStatusCheck = "missing_status_check" )
Compliance violation types.
const ( SeverityLow = "low" SeverityMedium = "medium" SeverityHigh = "high" SeverityCritical = "critical" )
Security alert severities, from lowest to highest.
Variables ¶
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.
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
IsSeverity returns true if s is one of the known severities.
func IsValidGitHubLogin ¶ added in v1.0.0
IsValidGitHubLogin returns true if s can be a GitHub login.
func MeetsSeverity ¶ added in v1.0.0
MeetsSeverity returns true if severity is at or above minSeverity.
func SeverityRank ¶ added in v1.0.0
SeverityRank returns a number that orders severities, or 0 for an unknown severity.
Types ¶
type ComplianceViolation ¶
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 ¶
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
}
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 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) ShouldSyncMembers ¶
ShouldSyncMembers returns true if members should be synced (defaults to true).
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.