Skip to content

lkmavi/gopriv

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gopriv

English | Русский

A small helper that runs Go commands against private repositories with the right git and Go environment. Supports SSH or HTTPS rewriting, a simple TOML config, and optional persistence of settings.


English

What it does

  • Detects private hosts from your go get / go install arguments.
  • Sets GOPRIVATE / GONOSUMDB automatically for those hosts.
  • Rewrites git URLs in-process to prefer SSH or HTTPS, without touching global git config.
  • Optionally saves defaults to ~/.gopriv/config.toml (stores configuration values, including the original path to your SSH key if requested).

Install

go install github.com/salivare-io/gopriv/cmd/gopriv@latest

Usage

Use -- to separate gopriv flags from the Go command:

gopriv --ssh -- go get github.com/private/repo
gopriv --ssh -- go install github.com/private/repo@latest
gopriv --https -- go get github.com/private/repo
gopriv --ssh-key ~/.ssh/id_ed25519 -- go get github.com/private/repo
gopriv --save --ssh -- go get github.com/private/repo

Flags

  • -s, --ssh — Use SSH for git fetches
  • -H, --https — Use HTTPS for git fetches
  • -S, --save — Save detected hosts and auth method to config
  • -c, --config — Print config path and exit
  • -d, --debug — Enable debug logging
  • -i, --ssh-key — Use a specific SSH private key (forces SSH)

Config

Default path: ~/.gopriv/config.toml

Important change: gopriv no longer copies or encrypts SSH key files. When saving is requested (--save or cli.auto_save_ssh_key = true), gopriv stores the original path you provided (or the path from config) in cfg.Auth.SSHKeyPath. No key material is moved or encrypted by gopriv in this mode.

Example:

[auth]
method = "ssh"
ssh_key_path = "~/.ssh/id_ed25519"

hosts = ["github.com", "gitlab.com"]

[cli]
# When true, using --ssh-key will persist the original path into the config.
auto_save_ssh_key = true

How it works

  • Extracts hosts from command arguments (module paths, https, ssh, git@).
  • Sets GOPRIVATE and GONOSUMDB for those hosts.
  • For SSH mode, applies in-process git config:
    • url.ssh://git@HOST/.insteadOf=https://HOST/
  • For HTTPS mode, applies in-process git config:
    • url.https://HOST/.insteadOf=ssh://git@HOST/
    • url.https://HOST/.insteadOf=git@HOST:
  • If --ssh is set and no key is provided, it tries default keys: ~/.ssh/id_ed25519, then ~/.ssh/id_rsa.

Nothing is written to your global git config.

Security note

  • gopriv only stores the path to your SSH key when configured to persist settings. It does not copy, encrypt, or otherwise manage the key file contents. Ensure the original key file is stored securely and has appropriate filesystem permissions (e.g., 0600).
  • If you need gopriv to copy keys into a managed store or to integrate with a system keychain, that can be added as an explicit opt-in feature later.

Русский

Что делает

  • Находит приватные хосты в аргументах go get / go install.
  • Автоматически выставляет GOPRIVATE и GONOSUMDB.
  • На лету переписывает git URL для SSH или HTTPS без правки глобального git config.
  • По желанию сохраняет настройки в ~/.gopriv/config.toml — при сохранении записывается оригинальный путь к SSH‑ключу, а не содержимое ключа.

Установка

go install github.com/salivare-io/gopriv/cmd/gopriv@latest

Использование

Обязательно разделяйте флаги gopriv и команду Go через --:

gopriv --ssh -- go get github.com/private/repo
gopriv --ssh -- go install github.com/private/repo@latest
gopriv --https -- go get github.com/private/repo
gopriv --ssh-key ~/.ssh/id_ed25519 -- go get github.com/private/repo
gopriv --save --ssh -- go get github.com/private/repo

Флаги

  • -s, --ssh — Использовать SSH для git
  • -H, --https — Использовать HTTPS для git
  • -S, --save — Сохранить хосты и метод авторизации в конфиг
  • -c, --config — Показать путь к конфигу и выйти
  • -d, --debug — Включить debug‑логи
  • -i, --ssh-key — Использовать конкретный приватный ключ SSH (включает SSH)

Конфиг

Путь по умолчанию: ~/.gopriv/config.toml

Важное изменение: gopriv не копирует и не шифрует SSH‑ключи. При сохранении (--save или cli.auto_save_ssh_key = true) в конфиг записывается оригинальный путь к ключу. gopriv не перемещает и не шифрует содержимое ключа.

Пример:

[auth]
method = "ssh"
ssh_key_path = "~/.ssh/id_ed25519"

hosts = ["github.com", "gitlab.com"]

[cli]
# Когда true, использование --ssh-key сохранится в конфиг как путь (копирование не выполняется).
auto_save_ssh_key = true

Как работает

  • Извлекает хосты из аргументов (module path, https, ssh, git@).
  • Выставляет GOPRIVATE и GONOSUMDB для этих хостов.
  • В режиме SSH добавляет in‑process правила git:
    • url.ssh://git@HOST/.insteadOf=https://HOST/
  • В режиме HTTPS добавляет in‑process правила git:
    • url.https://HOST/.insteadOf=ssh://git@HOST/
    • url.https://HOST/.insteadOf=git@HOST:
  • Если указан --ssh и путь к ключу не передан, пробует ключи по умолчанию: ~/.ssh/id_ed25519, затем ~/.ssh/id_rsa.

Глобальный git config не меняется.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Go 100.0%