identity

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package identity provides unified identity resolution for ox. It determines user identity from multiple sources with the following priority:

  1. SageOx OAuth (verified via our auth system)
  2. Git provider (GitHub/GitLab/Bitbucket/AWS/GCP based on repo remotes)
  3. 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttributionDisplayName added in v0.6.2

func AttributionDisplayName(ep, configDisplayName string) string

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

func AttributionEmail(ep, configDisplayName string) string

AttributionEmail returns the user's email address. May be "". Use for: git commit author field.

func AttributionName added in v0.6.2

func AttributionName(ep, configDisplayName string) string

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

func AttributionUsername(ep, configDisplayName string) string

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

func FirstNameFromSlug(slug string) string

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

  1. SageOx OAuth (ox login) — verified identity
  2. Config display_name (ox config) — DisplayName only
  3. Git identity (git config user.name / user.email)
  4. OS username ($USER/$USERNAME) — Username only
  5. "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:

  1. configDisplayName — explicit user setting from config.yaml (e.g., "port8080")
  2. name — parsed into "FirstName L." format
  3. email local part — split on delimiters, same format
  4. gitUsername — split on delimiters, same format
  5. 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.

func (*PersonInfo) String

func (p *PersonInfo) String() string

String returns the DisplayName.

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.

Jump to

Keyboard shortcuts

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