62 lines
2.1 KiB
Go
62 lines
2.1 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// GitCredential stores encrypted git authentication credentials.
|
|
// The encrypted_data field contains JSON: { "token": "..." } for PAT,
|
|
// { "username": "...", "password": "..." } for basic auth, or
|
|
// { "private_key": "...", "passphrase": "..." } for SSH keys.
|
|
type GitCredential struct {
|
|
ID string `json:"id" db:"id"`
|
|
UserID string `json:"user_id" db:"user_id"`
|
|
Name string `json:"name" db:"name"`
|
|
AuthType string `json:"auth_type" db:"auth_type"` // https_pat, https_basic, ssh_key
|
|
EncryptedData []byte `json:"-" db:"encrypted_data"` // never expose
|
|
Nonce []byte `json:"-" db:"nonce"` // never expose
|
|
CreatedAt time.Time `json:"created_at" db:"created_at"`
|
|
}
|
|
|
|
// GitCredentialSummary is the safe-to-expose version (no encrypted data).
|
|
type GitCredentialSummary struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"`
|
|
AuthType string `json:"auth_type"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// Summary returns a safe version without encrypted fields.
|
|
func (c *GitCredential) Summary() GitCredentialSummary {
|
|
return GitCredentialSummary{
|
|
ID: c.ID,
|
|
Name: c.Name,
|
|
AuthType: c.AuthType,
|
|
CreatedAt: c.CreatedAt,
|
|
}
|
|
}
|
|
|
|
// GitStatus represents the output of git status.
|
|
type GitStatus struct {
|
|
Branch string `json:"branch"`
|
|
Clean bool `json:"clean"`
|
|
Ahead int `json:"ahead"`
|
|
Behind int `json:"behind"`
|
|
Staged []GitFileStatus `json:"staged,omitempty"`
|
|
Modified []GitFileStatus `json:"modified,omitempty"`
|
|
Untracked []string `json:"untracked,omitempty"`
|
|
}
|
|
|
|
// GitFileStatus represents a single file in git status output.
|
|
type GitFileStatus struct {
|
|
Path string `json:"path"`
|
|
Status string `json:"status"` // M, A, D, R, C, U
|
|
}
|
|
|
|
// GitLogEntry represents a single commit in git log.
|
|
type GitLogEntry struct {
|
|
Hash string `json:"hash"`
|
|
ShortHash string `json:"short_hash"`
|
|
Author string `json:"author"`
|
|
Date time.Time `json:"date"`
|
|
Message string `json:"message"`
|
|
}
|