Documentation
¶
Overview ¶
Package identity provides unified identity resolution for ox. It determines user identity from multiple sources with the following priority:
- SageOx OAuth (verified via our auth system)
- Git provider (GitHub/GitLab/Bitbucket/AWS/GCP based on repo remotes)
- Git config (unverified, user-declared)
Privacy-first: Only probes providers that match the repo's actual remotes. We never make unnecessary API calls or leak credential presence.
Index ¶
- func AttributionDisplayName(ep, configDisplayName string) string
- func AttributionEmail(ep, configDisplayName string) string
- func AttributionName(ep, configDisplayName string) string
- func AttributionUsername(ep, configDisplayName string) string
- func FirstNameFromSlug(slug string) string
- func GetGitHubToken() string
- func IsGitHubAvailable() bool
- type Attribution
- type Config
- type Identity
- type PersonInfo
- type ProviderType
- type ResolvedIdentities
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttributionDisplayName ¶ added in v0.6.2
AttributionDisplayName returns a privacy-safe abbreviated name. PRIVACY: SAFE FOR SHARING — use for all team-visible metadata. Use for: session meta.json, murmur files, session list/view.
func AttributionEmail ¶ added in v0.6.2
AttributionEmail returns the user's email address. May be "". Use for: git commit author field.
func AttributionName ¶ added in v0.6.2
AttributionName returns the full, unabbreviated name. PRIVACY: LOCAL ONLY — do not write to ledger or shared contexts. Use for: local git commit author, login display, internal audit.
func AttributionUsername ¶ added in v0.6.2
AttributionUsername returns a lowercase, filesystem-safe slug for the current user. Use for: folder names, file paths, principal IDs.
func FirstNameFromSlug ¶ added in v0.6.2
FirstNameFromSlug extracts and capitalizes the first name from a principal slug. "ryan-snodgrass" → "Ryan", "ryan" → "Ryan", "" → "".
func GetGitHubToken ¶ added in v0.5.0
func GetGitHubToken() string
GetGitHubToken retrieves GitHub token from environment or gh CLI config.
func IsGitHubAvailable ¶ added in v0.5.0
func IsGitHubAvailable() bool
IsGitHubAvailable returns true if a GitHub token can be resolved from any source.
Types ¶
type Attribution ¶ added in v0.6.2
type Attribution struct {
// Username is a short, lowercase, filesystem-safe slug.
// NOT an email. NOT a display name.
// Examples: "ryan", "port8080", "anonymous"
// Always lowercase. Always non-empty.
// Use for: folder names, file paths, principal IDs, slug matching.
Username string
// Email is the full email address.
// NOT a username. NOT a display name.
// Examples: "ryan@example.com", ""
// May be "" if no email source is available.
// Use for: git commit author field, internal contact identity.
Email string
// Name is the full, unabbreviated name as provided by the source.
// NOT a username. NOT an email.
// Examples: "Albert Einstein" (not PII — illustrative), "Anonymous"
// Always non-empty.
// PRIVACY: LOCAL ONLY. Do NOT write to ledger or shared contexts.
// Use for: local git commit author, login display, internal audit.
Name string
// DisplayName is a privacy-safe abbreviated name for shared contexts.
// NOT a username. NOT an email. NOT the full name.
// Examples: "Albert E.", "port8080", "Anonymous"
// Always non-empty.
// PRIVACY: SAFE FOR SHARING. Use for ALL team-visible metadata.
// Use for: session meta.json, murmur files, session list/view,
// any output that could be seen by teammates.
DisplayName string
}
Attribution holds user identity for attributing work. Each field has a precise definition — do not conflate them.
PRIVACY RULE:
Anything written to the ledger, murmur files, or shared with teammates MUST use DisplayName (not Name). The ledger is a shared repo — full names are PII that teammates and future team members can read. Name (full, unabbreviated) is ONLY for: - Local git commit author (git config, not shared via ledger) - Internal audit logs - Display to the user themselves (e.g., "Signed in as ...") DisplayName (privacy-abbreviated) is for EVERYTHING ELSE: - Session meta.json in the ledger (team-visible) - Murmur files (team-visible) - Session list/view output (may be shown to teammates) - Any UI or metadata that could be shared beyond the user
Fallback chain (best → worst):
- SageOx OAuth (ox login) — verified identity
- Config display_name (ox config) — DisplayName only
- Git identity (git config user.name / user.email)
- OS username ($USER/$USERNAME) — Username only
- "Anonymous"/"anonymous"/"" — absolute fallback
For auth checks, use auth.GetTokenForEndpoint() directly. Attribution intentionally never fails — it always returns something.
func ResolveAttribution ¶ added in v0.6.2
func ResolveAttribution(ep, configDisplayName string) Attribution
ResolveAttribution determines user attribution from all available sources. Never fails — always returns a valid Attribution with non-empty Username, Name, and DisplayName.
ep is the normalized SageOx endpoint (used to look up OAuth token). configDisplayName is the user's configured display_name from ox config. Pass "" for either if unavailable.
type Config ¶
type Config struct {
// Collection controls how many identities to collect:
// - "all": Collect all available identities (default)
// - "primary-only": Only determine and send the primary identity
// - "none": Only use git config identity (no API calls)
Collection string `yaml:"collection"`
// Disable lists providers to skip (e.g., ["bitbucket"])
Disable []string `yaml:"disable"`
}
Config controls identity collection behavior.
type Identity ¶
type Identity struct {
UserID string `json:"user_id,omitempty"` // provider-specific ID (e.g., "github:1234567")
Email string `json:"email,omitempty"` // email from provider
Name string `json:"name,omitempty"` // display name from provider
Username string `json:"username,omitempty"` // provider username (e.g., GitHub login)
Source string `json:"source"` // where this identity came from (see below)
Verified bool `json:"-"` // internal only - server must verify, not trust client claims
}
Identity represents a user identity from a specific source.
type PersonInfo ¶
type PersonInfo struct {
DisplayName string // "port8080" or "FirstName L." — team-recognizable, public-safe
Email string // original email, preserved for internal/audit use
}
PersonInfo holds a privacy-aware display identity for session rendering. DisplayName is safe for inclusion in shared ledgers (no full PII). Email is preserved for internal/audit use only.
func NewPersonInfo ¶
func NewPersonInfo(email, name, gitUsername, configDisplayName string) *PersonInfo
NewPersonInfo creates a PersonInfo with privacy-aware display name derivation.
Priority for DisplayName:
- configDisplayName — explicit user setting from config.yaml (e.g., "port8080")
- name — parsed into "FirstName L." format
- email local part — split on delimiters, same format
- gitUsername — split on delimiters, same format
- All empty — "Anonymous"
func NewPersonInfoFromAuth ¶
func NewPersonInfoFromAuth(info auth.UserInfo, configDisplayName string) *PersonInfo
NewPersonInfoFromAuth creates a PersonInfo from auth.UserInfo and a config display name.
type ProviderType ¶
type ProviderType string
ProviderType represents a git hosting provider.
const ( ProviderGitHub ProviderType = "github" ProviderGitLab ProviderType = "gitlab" ProviderBitbucket ProviderType = "bitbucket" ProviderAzureDevOps ProviderType = "azure-devops" ProviderAWS ProviderType = "aws" ProviderGCP ProviderType = "gcp" ProviderGitea ProviderType = "gitea" ProviderNone ProviderType = "" )
type ResolvedIdentities ¶
type ResolvedIdentities struct {
Primary *Identity `json:"primary"`
SageOx *Identity `json:"sageox,omitempty"`
GitHub *Identity `json:"github,omitempty"`
GitLab *Identity `json:"gitlab,omitempty"`
Bitbucket *Identity `json:"bitbucket,omitempty"`
AzureDevOps *Identity `json:"azure_devops,omitempty"`
AWS *Identity `json:"aws,omitempty"`
GCP *Identity `json:"gcp,omitempty"`
Gitea *Identity `json:"gitea,omitempty"`
Git *Identity `json:"git,omitempty"`
}
ResolvedIdentities contains all resolved identities for a user. Primary is the highest-priority verified identity found. Other fields contain identities from each source (if available).
func Resolve ¶
func Resolve() (*ResolvedIdentities, error)
Resolve determines user identity from all available sources. It follows the priority: SageOx → Provider (from remotes) → Git config. Privacy-first: only probes providers matching the repo's actual remotes.
func ResolveWithConfig ¶
func ResolveWithConfig(cfg *Config) (*ResolvedIdentities, error)
ResolveWithConfig determines user identity with custom configuration.