sync

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongSyncPassword = errors.New("WRONG_SYNC_PASSWORD")

Functions

func DecryptConfigFiles

func DecryptConfigFiles(srcDir, destDir string, key []byte, kc *Keychain) error

DecryptConfigFiles decrypts config files from srcDir into destDir. kc is used to write decrypted passwords to keychain and clear them from JSON. Pass nil for kc to skip keychain (passwords stay in JSON).

func DeriveKey

func DeriveKey(password string, salt []byte) []byte

DeriveKey derives a 32-byte AES-256 key from a password and salt using PBKDF2-SHA256.

func EncryptConfigFiles

func EncryptConfigFiles(srcDir, destDir string, key []byte, kc *Keychain) error

EncryptConfigFiles encrypts entire config files from srcDir into destDir. kc is used to backfill passwords from keychain before encryption. Pass nil for kc to skip backfill.

func GenerateSalt

func GenerateSalt() ([]byte, error)

GenerateSalt generates a random 16-byte salt.

func ReadSaltFile

func ReadSaltFile(repoPath string) ([]byte, error)

ReadSaltFile reads the .sync-salt file from the repo directory. Returns nil if the file doesn't exist (new repo).

func TestConnection

func TestConnection(repoURL, username, token string) error

TestConnection verifies the repo URL is reachable.

func WriteSaltFile

func WriteSaltFile(repoPath string, salt []byte) error

WriteSaltFile writes the salt to .sync-salt in the repo directory.

Types

type ConflictInfo

type ConflictInfo struct {
	LocalTime  time.Time `json:"localTime"`
	RemoteTime time.Time `json:"remoteTime"`
}

type GitRepo

type GitRepo struct {
	// contains filtered or unexported fields
}

func CloneOrOpen

func CloneOrOpen(repoPath, repoURL, branch, username, token string) (*GitRepo, error)

CloneOrOpen opens the repo at repoPath, or clones it from the given URL.

func (*GitRepo) CompareHeads

func (g *GitRepo) CompareHeads(branch string) (SyncDirection, *time.Time, *time.Time, error)

CompareHeads returns sync direction after fetching.

func (*GitRepo) Fetch

func (g *GitRepo) Fetch(username, token string) error

func (*GitRepo) ForcePush

func (g *GitRepo) ForcePush(username, token string) error

ForcePush pushes with force, overwriting remote.

func (*GitRepo) Pull

func (g *GitRepo) Pull(username, token string) error

func (*GitRepo) Push

func (g *GitRepo) Push(username, token string) error

func (*GitRepo) PushToBranch

func (g *GitRepo) PushToBranch(branch, username, token string) error

PushToBranch pushes the current HEAD to the specified remote branch.

func (*GitRepo) ReadRemoteFile

func (g *GitRepo) ReadRemoteFile(branch, filePath string) ([]byte, error)

ReadRemoteFile reads a file from the remote tracking branch without touching the worktree.

func (*GitRepo) ResetToRemote

func (g *GitRepo) ResetToRemote(branch string) error

ResetToRemote resets local HEAD to match remote branch.

func (*GitRepo) StageAndCommit

func (g *GitRepo) StageAndCommit(msg string) (bool, error)

StageAndCommit stages all files and creates a commit. Returns true if committed.

type Keychain

type Keychain struct{}

func NewKeychain

func NewKeychain() *Keychain

func (*Keychain) Delete

func (k *Keychain) Delete(key string) error

func (*Keychain) DeleteModelAPIKey

func (k *Keychain) DeleteModelAPIKey(modelID string) error

func (*Keychain) DeletePassword

func (k *Keychain) DeletePassword(connID string) error

func (*Keychain) Get

func (k *Keychain) Get(key string) (string, error)

func (*Keychain) GetEncryptionKey

func (k *Keychain) GetEncryptionKey() ([]byte, error)

GetEncryptionKey retrieves the derived encryption key from OS keychain.

func (*Keychain) GetGitToken

func (k *Keychain) GetGitToken() (string, error)

func (*Keychain) GetModelAPIKey

func (k *Keychain) GetModelAPIKey(modelID string) (string, error)

func (*Keychain) GetPassword

func (k *Keychain) GetPassword(connID string) (string, error)

func (*Keychain) Set

func (k *Keychain) Set(key, value string) error

func (*Keychain) SetGitToken

func (k *Keychain) SetGitToken(token string) error

func (*Keychain) SetModelAPIKey

func (k *Keychain) SetModelAPIKey(modelID, apiKey string) error

func (*Keychain) SetPassword

func (k *Keychain) SetPassword(connID, password string) error

func (*Keychain) StoreEncryptionKey

func (k *Keychain) StoreEncryptionKey(key []byte) error

StoreEncryptionKey stores the derived encryption key in OS keychain.

type SyncConfig

type SyncConfig struct {
	RepoURL        string    `json:"repoUrl"`
	Branch         string    `json:"branch"`
	Username       string    `json:"username"`
	AutoSync       bool      `json:"autoSync"`
	LastSyncAt     time.Time `json:"lastSyncAt"`
	LastSyncStatus string    `json:"lastSyncStatus"`
	LastSyncError  string    `json:"lastSyncError"`
}

type SyncConfigStore

type SyncConfigStore struct {
	// contains filtered or unexported fields
}

func NewSyncConfigStore

func NewSyncConfigStore(configDir string) *SyncConfigStore

func (*SyncConfigStore) Load

func (s *SyncConfigStore) Load() (SyncConfig, error)

func (*SyncConfigStore) Save

func (s *SyncConfigStore) Save(config SyncConfig) error

type SyncDirection

type SyncDirection int
const (
	SyncNone SyncDirection = iota
	SyncPush
	SyncPull
	SyncConflict
)

type SyncResult

type SyncResult struct {
	Direction SyncDirection `json:"direction"`
	Message   string        `json:"message"`
	Conflict  *ConflictInfo `json:"conflict,omitempty"`
}

type SyncService

type SyncService struct {
	// contains filtered or unexported fields
}

func NewSyncService

func NewSyncService() (*SyncService, error)

func (*SyncService) ChangePassword

func (s *SyncService) ChangePassword(oldPassword, newPassword string) error

ChangePassword re-encrypts all synced files with a new master password.

func (*SyncService) ConfigureRepo

func (s *SyncService) ConfigureRepo(repoURL, username, token, masterPassword string) (*SyncResult, error)

ConfigureRepo sets up a new or existing sync repository.

func (*SyncService) DeleteRepo

func (s *SyncService) DeleteRepo() error

DeleteRepo removes the local sync repo and credentials.

func (*SyncService) GetConfig

func (s *SyncService) GetConfig() (SyncConfig, error)

GetConfig returns the current sync configuration.

func (*SyncService) IsAutoSyncEnabled

func (s *SyncService) IsAutoSyncEnabled() bool

IsAutoSyncEnabled returns whether auto sync is enabled and configured.

func (*SyncService) PasswordStore

func (s *SyncService) PasswordStore() *Keychain

PasswordStore returns the keychain as a PasswordStore for connection store integration.

func (*SyncService) RepoPath

func (s *SyncService) RepoPath() string

RepoPath returns the local git repo path.

func (*SyncService) ResolveConflict

func (s *SyncService) ResolveConflict(useLocal bool) (*SyncResult, error)

ResolveConflict handles a conflict by forcing push or reset.

func (*SyncService) SaveConfig

func (s *SyncService) SaveConfig(config SyncConfig, token string) error

SaveConfig persists sync configuration and stores the token if provided.

func (*SyncService) Sync

func (s *SyncService) Sync() (*SyncResult, error)

Sync runs a full sync cycle: clone/open → encrypt → commit → fetch → compare → push/pull → decrypt.

func (*SyncService) TestConnection

func (s *SyncService) TestConnection() error

TestConnection verifies the repo is reachable with stored credentials.

func (*SyncService) VerifySyncPassword

func (s *SyncService) VerifySyncPassword(password, username, token string) error

VerifySyncPassword validates credentials against the remote and verifies the password can decrypt the remote config. username and token are the new values from the form; token may be empty to keep the stored one.

Jump to

Keyboard shortcuts

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