sshkeys

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sshkeys provides SSH key handling functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanDuplicateKeys

func CleanDuplicateKeys(filePath string) error

CleanDuplicateKeys reads an authorized_keys file and removes duplicate keys keeping only the first occurrence of each unique key (based on type and value, not comments)

func WriteToAuthorizedKeys

func WriteToAuthorizedKeys(filePath string, keys []*Key, appendMode bool) error

WriteToAuthorizedKeys writes keys to an authorized_keys file

Types

type Key

type Key struct {
	// Content is the full content of the key
	Content string
	// Type is the key type (e.g., ssh-rsa, ssh-ed25519)
	Type string
	// Fingerprint is the key fingerprint
	Fingerprint string
	// Comment is the key comment (if any)
	Comment string
	// Source is where the key came from
	Source Source
	// SourceValue is the specific value for the source (e.g., GitHub username)
	SourceValue string
}

Key represents an SSH public key with metadata

func FetchFromGitHub

func FetchFromGitHub(username string) ([]*Key, error)

FetchFromGitHub fetches SSH keys from GitHub

func FetchFromGitLab

func FetchFromGitLab(username string) ([]*Key, error)

FetchFromGitLab fetches SSH keys from GitLab

func FetchFromURL

func FetchFromURL(url string) ([]*Key, error)

FetchFromURL fetches SSH keys from a URL

func ParseKeyString

func ParseKeyString(keyString string, source Source, sourceValue string) (*Key, error)

ParseKeyString parses a key string and returns a Key

func ParseKeysFromText

func ParseKeysFromText(text string) ([]*Key, error)

ParseKeysFromText parses SSH keys from a text string

func ReadFromFile

func ReadFromFile(filePath string) ([]*Key, error)

ReadFromFile reads SSH keys from a file

type Source

type Source string

Source represents the source of an SSH key

const (
	// GitHub represents GitHub as a key source
	GitHub Source = "github"
	// GitLab represents GitLab as a key source
	GitLab Source = "gitlab"
	// URL represents a direct URL as a key source
	URL Source = "url"
	// File represents a local file as a key source
	File Source = "file"
	// Text represents a direct text input as a key source
	Text Source = "text"
)

Jump to

Keyboard shortcuts

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