Update for new repository location
Some checks failed
Test / lint (push) Has been cancelled
Test / test (1.17.x) (push) Has been cancelled
Test / test (1.18.x) (push) Has been cancelled
Test / test (1.19.x) (push) Has been cancelled
Test / test (1.20.x) (push) Has been cancelled
Test / test (1.21.x) (push) Has been cancelled
Test / test (1.22.x) (push) Has been cancelled
Test / test (1.23.x) (push) Has been cancelled
Test / test (1.24.x) (push) Has been cancelled

This commit is contained in:
T. R. Bernstein
2025-08-04 22:19:22 +02:00
parent 511052e2fd
commit 37928fabb8
9 changed files with 52 additions and 98 deletions

View File

@@ -4,21 +4,21 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: WillAbides/setup-go-faster@main
with:
go-version: 1.24.x
- uses: actions/checkout@v4
with:
path: './src/github.com/kevinburke/ssh_config'
# staticcheck needs this for GOPATH
- run: |
echo "GO111MODULE=on" >> $GITHUB_ENV
echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "PATH=$GITHUB_WORKSPACE/bin:$PATH" >> $GITHUB_ENV
- name: Run tests
run: make lint
working-directory: './src/github.com/kevinburke/ssh_config'
- name: Install Go
uses: WillAbides/setup-go-faster@main
with:
go-version: 1.24.x
- uses: actions/checkout@v4
with:
path: './src/github.com/tabshift-gh/go-ssh-config'
# staticcheck needs this for GOPATH
- run: |
echo "GO111MODULE=on" >> $GITHUB_ENV
echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "PATH=$GITHUB_WORKSPACE/bin:$PATH" >> $GITHUB_ENV
- name: Run tests
run: make lint
working-directory: './src/github.com/tabshift-gh/go-ssh-config'
test:
strategy:
@@ -26,17 +26,17 @@ jobs:
go-version: [1.17.x, 1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x]
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: WillAbides/setup-go-faster@main
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
with:
path: './src/github.com/kevinburke/ssh_config'
- run: |
echo "GO111MODULE=off" >> $GITHUB_ENV
echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "PATH=$GITHUB_WORKSPACE/bin:$PATH" >> $GITHUB_ENV
- name: Run tests with race detector on
run: make race-test
working-directory: './src/github.com/kevinburke/ssh_config'
- name: Install Go
uses: WillAbides/setup-go-faster@main
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v4
with:
path: './src/github.com/tabshift-gh/go-ssh-config'
- run: |
echo "GO111MODULE=off" >> $GITHUB_ENV
echo "GOPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "PATH=$GITHUB_WORKSPACE/bin:$PATH" >> $GITHUB_ENV
- name: Run tests with race detector on
run: make race-test
working-directory: './src/github.com/tabshift-gh/go-ssh-config'

View File

@@ -7,3 +7,4 @@ Scott Lessans <slessans@gmail.com>
Sergey Lukjanov <me@slukjanov.name>
Wayne Ashley Berry <wayneashleyberry@gmail.com>
santosh653 <70637961+santosh653@users.noreply.github.com>
T. R. Bernstein <137705289+trbernstein@users.noreply.github.com>

View File

@@ -1,19 +1,14 @@
# Changes
# Changelog
## Version 1.2
All notable changes to this project will be documented in this file.
Previously, if a Host declaration or a value had trailing whitespace, that
whitespace would have been included as part of the value. This led to unexpected
consequences. For example:
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
```
Host example # A comment
HostName example.com # Another comment
```
## [1.0]
Prior to version 1.2, the value for Host would have been "example " and the
value for HostName would have been "example.com ". Both of these are
unintuitive.
### Added
Instead, we strip the trailing whitespace in the configuration, which leads to
more intuitive behavior.
- Implement percent TOKEN replacement for SSH config files ([PR 49](https://github.com/kevinburke/ssh_config/pull/49) of Kevin Burke's repository)
- Support `~` as user's home directory for `Include` ([PR 58](https://github.com/kevinburke/ssh_config/pull/58) of Kevin Burke's repository)
- Version [1.3](https://github.com/kevinburke/ssh_config/tree/v1.3) of Kevin Burke's version.

View File

@@ -1,4 +1,5 @@
Copyright (c) 2017 Kevin Burke.
Copyright (c) 2025 T. R. Bernstein, Astzweig GmbH & Co. KG
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation

View File

@@ -1,14 +1,18 @@
# ssh_config
# SSH Config for Go
This is a Go parser for `ssh_config` files. Importantly, this parser attempts
to preserve comments in a given file, so you can manipulate a `ssh_config` file
> This project was created, after the original author Kevin Burke had no longer
> enough time to invest into the project maintenance. We thank him very much for
> his efforts and hope to continue his legacy.
This is a Go parser for `ssh` config files. Importantly, this parser attempts
to preserve comments in a given file, so you can manipulate a `ssh` config file
from a program, if your heart desires.
It's designed to be used with the excellent
[x/crypto/ssh](https://golang.org/x/crypto/ssh) package, which handles SSH
negotiation but isn't very easy to configure.
The `ssh_config` `Get()` and `GetStrict()` functions will attempt to read values
The `ssh_config.Get()` and `ssh_config.GetStrict()` functions will attempt to read values
from `$HOME/.ssh/config` and fall back to `/etc/ssh/ssh_config`. The first
argument is the host name to match on, and the second argument is the key you
want to retrieve.
@@ -71,22 +75,4 @@ the `ssh_config` manpage. Unimplemented features should be present in the
Notably, the `Match` directive is currently unsupported.
[issues]: https://github.com/kevinburke/ssh_config/issues
## Errata
This is the second [comment-preserving configuration parser][blog] I've written, after
[an /etc/hosts parser][hostsfile]. Eventually, I will write one for every Linux
file format.
[blog]: https://kev.inburke.com/kevin/more-comment-preserving-configuration-parsers/
[hostsfile]: https://github.com/kevinburke/hostsfile
## Sponsorships
Thank you very much to Tailscale and Indeed for sponsoring development of this
library. [Sponsors][sponsors] will get their names featured in the README.
You can also reach out about a consulting engagement: https://burke.services
[sponsors]: https://github.com/sponsors/kevinburke
[issues]: https://github.com/tabshift-gh/go-ssh-config/issues

View File

@@ -1,32 +1,3 @@
// Package ssh_config provides tools for manipulating SSH config files.
//
// Importantly, this parser attempts to preserve comments in a given file, so
// you can manipulate a `ssh_config` file from a program, if your heart desires.
//
// The Get() and GetStrict() functions will attempt to read values from
// $HOME/.ssh/config, falling back to /etc/ssh/ssh_config. The first argument is
// the host name to match on ("example.com"), and the second argument is the key
// you want to retrieve ("Port"). The keywords are case insensitive.
//
// port := ssh_config.Get("myhost", "Port")
//
// You can also manipulate an SSH config file and then print it or write it back
// to disk.
//
// f, _ := os.Open(filepath.Join(os.Getenv("HOME"), ".ssh", "config"))
// cfg, _ := ssh_config.Decode(f)
// for _, host := range cfg.Hosts {
// fmt.Println("patterns:", host.Patterns)
// for _, node := range host.Nodes {
// fmt.Println(node.String())
// }
// }
//
// // Write the cfg back to disk:
// fmt.Println(cfg.String())
//
// BUG: the Match directive is currently unsupported; parsing a config with
// a Match directive will trigger an error.
package ssh_config
import (

View File

@@ -5,7 +5,7 @@ import (
"path/filepath"
"strings"
"github.com/kevinburke/ssh_config"
"github.com/tabshift-gh/go-ssh-config"
)
func ExampleHost_Matches() {

View File

@@ -1,7 +1,7 @@
//go:build 1.18
// +build 1.18
package ssh_config
package go-ssh-config
import (
"bytes"

2
go.mod
View File

@@ -1,3 +1,3 @@
module github.com/kevinburke/ssh_config
module github.com/tabshift-gh/go-ssh-config
go 1.18