This module provides functionality to completely wipe the vault by force-pushing an empty repository state to GitHub.
fmt: String formatting and printingtime: Time package for commit timestampsgithub.com/go-git/go-billy/v5/memfs: In-memory filesystemgithub.com/go-git/go-git/v5: Git operations librarygithub.com/go-git/go-git/v5/config: Git configurationgithub.com/go-git/go-git/v5/plumbing/object: Git object typesgithub.com/go-git/go-git/v5/plumbing/transport/ssh: SSH transport for gitgithub.com/go-git/go-git/v5/storage/memory: In-memory git storagegolang.org/x/crypto/ssh: SSH cryptography utilities
func PurgeVault(session *Session) errorCompletely wipes the remote vault by force-pushing an empty commit history to GitHub. This is a destructive operation that removes all files and history from the vault.
Parameters:
session: The active session containing user credentials and vault information
Return:
error: Returns error if any operation fails (private key loading, commit, or push)
Process:
- Construct Repo URL: Builds the git repository URL from session username
- Create Fresh Git Environment: Initializes a new, empty git repository in memory
- Setup SSH Authentication: Loads the private key from the session
- Create Wipe Commit: Creates an empty commit with message "Nexus: Updated Vault"
- Connect Remote: Adds the GitHub repository as the remote origin
- Force Push: Force-pushes the empty state to GitHub, overwriting all history
- Clear Memory Cache: Resets the session index to an empty vault
Error Handling:
- Returns error if private key loading fails
- Returns error if commit creation fails
- Returns error if push fails
Important Notes:
- Permanently deletes all files in the vault
- Erases all commit history
- Cannot be undone
Use with extreme caution!
Security Considerations:
- Requires SSH authentication with the vault's private key
- Force push requires write access to the repository
- Completely clears the in-memory index (
session.Index)
Example Usage:
// WARNING: This is a destructive operation!
err := PurgeVault(session)
if err != nil {
log.Fatal(err)
}
fmt.Println("Vault purged successfully")// After confirming user intent
fmt.Println("WARNING: This will permanently delete all vault data!")
fmt.Print("Type 'DELETE' to confirm: ")
var confirm string
fmt.Scanln(&confirm)
if confirm == "DELETE" {
err := PurgeVault(session)
if err != nil {
fmt.Println("Purge failed:", err)
} else {
fmt.Println("Vault has been purged")
}
}- DisconnectAndDelete: Removes local config file
- DeletePath: Removes specific files without purging entire vault
- Disconnect: Clears memory cache without affecting remote
- Uses shallow clone for efficiency when checking repo state
- Ignores SSH host key verification (for automation)
- Empty commit is allowed via
AllowEmptyCommits: true - Force push (
Force: true) overwrites remote history - After purge, the session index is reset to
NewIndex()(empty)