34 Commits

Author SHA1 Message Date
Sylvie Crowe 6409e4292f fix: persist ignoreMatchDirective to included file (#6)
The ignoreMatchDirective flag did not exist in the newConfig function.
Because this function is called when generating a config for connections
in an included file, those connections automatically assumed the value
was false. This change adds the flag so it can be changed to true if it
is also set for the outer configuration.
2024-12-19 12:37:47 -08:00
Sylvie Crowe ed12436768 Allow User to Ignore Match Directive (#5)
* Add the possibility to ignore the Match directive

* cleanup

* cleanup

* cleanup

* cleanup

* fix: duplicated code leftover from merge

* fix: match directive bypass for GetAll

The new ignoreMatchDirective flag needed to be added in one other place.

---------

Co-authored-by: fferro <francesco.ferro@yahooinc.com>
2024-10-27 16:23:32 -07:00
Sylvie Crowe 17e2087ebd Update IdentityFile Defaults to Match Documentation (#4)
Credit to @virtuald for the original implementation of this fix.

* Add support for retrieving all IdentityFile directives via DefaultAll

* fix: set IdentityFile defaults to match man page

The existing default IdentityFile list was incomplete and out of order.
This updates it to match the defaults listed here:
https://man7.org/linux/man-pages/man5/ssh_config.5.html

---------

Co-authored-by: Dustin Spicuzza <dustin@virtualroadside.com>
2024-03-05 20:10:34 -08:00
Sylvie Crowe cba6b6a60f Add reload config (#2)
* add function that can clear cached config files

Once the first call to `Get()`, `GetStrict()`, `GetAll()`,
or`GetAllStrict()` has been made, the contents of the config files will
be cached for all future calls to any of those functions. This can be
frustrating if the user wants to capture changes to the config file that
were made externally. This
change adds the `ClearCachedConfigs()` function to provide control over
that.

* change ClearCachedConfigs to ReloadConfigs

Clearing cached data is somewhat vague and could be more confusing to
users who are not familiar with this library. But Reloading the config
data is very straightforward. For this reason, the ability to clear the
cache has been replaced with the ability to reload.

The reload simply clears the cache and then loads the contents again.

Additionally, this contains a bug fix that ensure the loadConfigs
pointer is set to a non-null value before it is used.

* add tests for reloading ssh config files

This adds 2 tests. The first checks that ssh config data is cached and
does not update if the file changes afterward. The second checks that
the `ReloadConfigs()` function will discard the cached data and load the
current config file contents.
2024-03-05 19:38:17 -08:00
Kevin Burke 5724bd1279 config: add UserSettings.ConfigFinder
Fixes #48.
2022-06-05 12:47:11 -07:00
Kevin Burke aae6f39972 1.2 2022-03-31 11:37:00 -07:00
Kevin Burke df4d8e6716 config: update version to match git tags 2022-03-31 11:36:52 -07:00
Scott Lessans 9b1b4df300 config: fix EOL whitespace for key/value pairs and Host lines
See the description in the CHANGELOG - we were handling this
incorrectly and attaching whitespace to the end of values where that
didn't make much sense to do.
2022-03-31 10:57:24 -07:00
Carlos A Becker 91cd224c7f config: add DecodeBytes to directly read a byte array
Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
2022-03-31 09:49:09 -07:00
Kevin Burke 6ad71ac26e config: remove io/ioutil
It's deprecated now.
2022-03-31 09:26:24 -07:00
Dustin Spicuzza 124166206d Support retrieving multiple values for a given keyword
IdentityFile among others supports being provided multiple times and
aggregated across, potentially, multiple files. Support that workflow
by adding GetAll and GetAllStrict alongside the current functions.
2021-03-27 13:38:21 -07:00
Kevin Burke 6cfae18c12 1.0 2019-07-24 10:58:21 -10:00
Mark Nevill 14846fb743 all: rewrite the lexer to consume the entire input first
Previously we used the buffruneio package to buffer input. However,
the error handling was not good, and we would often panic when parsing
inputs.

SSH config files are generally not large, on the order of kilobytes or
megabytes, and it's fine to just read the entire thing into memory and
then parse from there. This also simplifies the parser significantly
and lets us remove a dependency and several defer calls.

Add a test that panicked with the old version and then modify the code
to ensure the test no longer panics.

Thanks to Mark Nevill (@devnev) for the initial error report and
failing test case.

Fixes #10.
Fixes #24.
2019-07-24 10:52:01 -10:00
Kevin Burke 2e50c44127 all: fix lint issues
staticcheck updated, and it requires inline fixes as well as dropping
support for 1.9 and 1.10.
2019-06-29 21:04:20 -07:00
Kevin Burke f648cfb84b all: use ints instead of uints
Files are small and these are cheap enough that we should be more
worried about overflow errors than the space cost.
2019-06-29 20:37:49 -07:00
Kevin Burke 81db2a7582 0.5 2018-08-30 14:53:28 -06:00
Kevin Burke 9fc7bb800b 0.4 2018-03-17 10:55:31 -07:00
Kevin Burke 0ff8514904 0.3 2018-01-27 11:48:58 -08:00
Kevin Burke 802051befe Implement encoding.TextMarshaler interface 2017-10-13 14:14:58 -07:00
Kevin Burke 2b54512628 switch staticcheck for megacheck and fix things it complains about 2017-05-26 10:01:24 -07:00
Kevin Burke 6dcd4cf595 update README and add more examples 2017-05-25 22:05:04 -07:00
Kevin Burke fa48d7ff1c 0.2 2017-05-25 08:11:05 -07:00
Kevin Burke 4a3c8dfaf0 add a version constant 2017-05-25 08:11:01 -07:00
Kevin Burke e05b90745b more doc tweaks 2017-05-25 08:09:30 -07:00
Kevin Burke 7897293c53 Cleanup for public release
- Test Include string representation

- Add docs and examples
2017-05-25 08:00:10 -07:00