Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ~/.ssh/config custom hosts to connect and find commands #8

Closed
valentinocossar opened this issue Mar 15, 2021 · 8 comments · Fixed by #21
Closed

Add ~/.ssh/config custom hosts to connect and find commands #8

valentinocossar opened this issue Mar 15, 2021 · 8 comments · Fixed by #21
Assignees
Labels
enhancement New feature or request

Comments

@valentinocossar
Copy link
Contributor

Add ~/.ssh/config custom hosts to connect and find commands. Allow using custom hosts not added by the sync command but added manually to the ~/.ssh/config file.

@valentinocossar valentinocossar added the enhancement New feature or request label Mar 15, 2021
@CasvalDOT
Copy link
Contributor

CasvalDOT commented Mar 15, 2021

Ok, I understand the request. Maybe we can follow the logic applied to my version of SSH. The file host to read match the pattern config. For example:

.ssh
  - config.hssh.d
    - host01
    - host02
  - config.agency.d
    - host_a
    - host_b
  - config
  - config.2

The system matches each file contained in a folder with name contains config and the same for the files.
In this case the file to read will be:

- config.hssh.d/host01
- config.hssh.d/host02
- config.agency.d/host_a
- config.agency.d/host_b
- config
- config.2

Or maybe we can read a config file and take all files included.

# config

Include config.hssh.d/*
Include config.agency.d/*
Include config.2

This alternative maybe is more declarative and less prone to errors.

@valentinocossar
Copy link
Contributor Author

@CasvalDOT yes, I prefer the first option, we can find valid hosts inside the .ssh folder with these 2 criteria:

  1. Files that match config as pattern in the name
  2. Files inside folders that match config as pattern in the name

But the CLI will only include config.hssh.d folder inside .ssh/config file automatically, other includes have to be added manually to the file.

What do you think?

@CasvalDOT
Copy link
Contributor

I really like the first solution, but in my opinion the second is more robust as it would not generate errors due to the lack of the host

@CasvalDOT
Copy link
Contributor

CasvalDOT commented Mar 16, 2021

@valentinocossar, I've created the first possible implementation about this improvement.
Now the list command (find and connect use the same logic) use this procedure:

  1. Read the config file and search for includes folder and files, furthermore the system take host configurations inside
  2. For each file included the system parse int and save in the connections array

I've also tried to optimize the read / parsing process adding goroutines. A nice to have will be discriminated unique host configurations.

When you have a moment try it to develop branch.

NOTE:

This is a first approach. An analysis must be performed to understand which patterns are allowed in the Include syntax.
Currently, the system know a folder if the string have the * or / as final character, but what's happen if the included have this pattern?

# Using wildcard in the middle of the string
Include config*meta/*

It is allowed and must be managed?
If so, the reading of files and folders should be managed differently.

@valentinocossar
Copy link
Contributor Author

@CasvalDOT Super! As far as I know, the most used includes patterns are:

  • Include folder/*
  • Include folder/file
  • Include /absolute/path/folder/*
  • Include /absolute/pathfolder/file
  • Include ~/folder/*
  • Include ~/folder/file

So at this time, we can only support these integrations.

But I discovered that in the Include declaration you can use the wildcard in each step of the path. More info in the Include description below:

Include
    Include the specified configuration file(s).  Mul‐
    tiple pathnames may be specified and each pathname
    may contain glob(3) wildcards and, for user config‐
    urations, shell-like “~” references to user home
    directories.  Files without absolute paths are
    assumed to be in ~/.ssh if included in a user con‐
    figuration file or /etc/ssh if included from the
    system configuration file.  Include directive may
    appear inside a Match or Host block to perform con‐
    ditional inclusion.

The support for the wildcard in each pathname can be a further improvement to consider in the next releases.

At this point, I'll test the integration as soon as possible to give you feedback about any improvement or bug.

@CasvalDOT
Copy link
Contributor

Ok! I miss handling the ~ character.

@CasvalDOT
Copy link
Contributor

@valentinocossar, I've push another version. I reduced the logic and using filepath.Glob(...) I can now resolve every wildcard.
I've also add the ~ handler

@valentinocossar
Copy link
Contributor Author

valentinocossar commented Mar 17, 2021

👍🏻 I'll test it along with all other features!

@CasvalDOT CasvalDOT linked a pull request Apr 12, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants