Skip to content

Major refactor of code#22

Merged
cezmunsta merged 46 commits into
masterfrom
refactor
May 6, 2021
Merged

Major refactor of code#22
cezmunsta merged 46 commits into
masterfrom
refactor

Conversation

@cezmunsta
Copy link
Copy Markdown
Owner

Some issues were hit with the original code structure and so we have a considerable rewrite to solve those and hopefully avoid similar ones in the future.

Usage:
  ssh_ms [flags]
  ssh_ms [command]

Available Commands:
  completion  Generate completion script
  connect     Connect to a host
  delete      Delete a connection
  help        Help about any command
  list        List available connections
  print       Print out the SSH command for a connection
  purge       Purge the cache
  show        Display a connection
  version     Show the version
  write       Add a new connection to storage

Flags:
  -d, --debug                Provide addition output
  -n, --dry-run              Prevent certain commands without full execution
  -h, --help                 help for ssh_ms
  -s, --storage string       Storage path for caching (default "/home/user/.ssh/cache")
      --stored-token         Use a stored token from 'vault login' (overrides --vault-token, auto-enabled when no token is specified)
  -u, --user string          Your SSH username for templated configs (default "user")
      --vault-addr string    Specify the Vault address (default "http://127.0.0.1:8200")
      --vault-token string   Specify the Vault token
  -v, --verbose              Provide addition output

Use "ssh_ms [command] --help" for more information about a command.

Unit tests have been added for the majority of functionality

cezmunsta added 16 commits May 4, 2021 21:59
* Added `cmd.printCmd`
* Added `cmd.printConnection` that works in a similar fashion to
  `cmd.showConnection`, but print the command instead of the entry
  for a config
* Updated config.Settings and config.GetConfig to store EnvSSHDefaultUsername,
  EnvSSHIdentityFile, and EnvSSHUsername
* Removed EnvSSHUsername and EnvSSHIdentityFile from cmd
* Updated ssh.generateUserName to bypass templated names
* Fixed issue of template referencing
* Updated ssh.Placeholders to add @@USER_FIRSTNAME.@@USER_LASTNAME and
  cfg.EnvSSHUsername
* Fixed issue with templates due to input for tempUser.generateUserName
  and tempUser.rewriteUsername
* Added cmd.deleteCmd
* Added cmd.deleteConnection, which first of all checks
  to see if the connection exists before attempting to
  remove it
* Added vault.secretData map
* Updated vault.WriteSecret to normalise the options passed in
  by the user, e.g. hostname -> HostName
* Added cmd.writeCmd
* Added cmd.writeConnection, which will currently refuse to write to an
  existing entry until the partial update logic is added
* Added ConfigComment to config.Settings
* Added --comment flag for use with writeCmd
* Added --dry-run
* Added output for cmd.writeCmd and cmd.deleteCmd when using Simulate
* Fixed issue where an empty/misconfigured EnvSSHUsername
  produces an empty (@@) placeholder, causing other placeholders
  to be modified during the rewrite
* Added comment before ssh.EnvSSHDefaultUsername to note how to
  override during build
* Added caching mechanism:
  * `cmd.CacheExpireAfter` controls the expiry threshold, default 7 days
  * `cmd.getCachePath()` generates the path to use for a connection
  * `cmd.makeCachePath()` creates the storage directory
  * `cmd.getRemoteCache()` generates a cache file from the remote data
  * `cmd.saveCache()` writes JSON data to disk as a cache
  * `cmd.getCache()` reads JSON data from disk to save a look-up from live
  * `cmd.removeCache()` removes a single cached connection
  * `cmd.expireCache()` removes a single cached connection when the expiry
    threshold has been exceeded
  * `cmd.purgeCache()` wipes out the local cache storage, since it is possible
    to use `--storage-path` with this, care should be taken with its use.
    This will be improved in the near future
* Added unittests for caching, `cmd.TestCache()`
* Added `cmd.connectCmd` and `cmd.purgeCmd`
@cezmunsta cezmunsta added the enhancement New feature or request label May 6, 2021
@cezmunsta cezmunsta self-assigned this May 6, 2021
@cezmunsta cezmunsta merged commit 773faab into master May 6, 2021
@cezmunsta cezmunsta deleted the refactor branch May 6, 2021 11:18
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 this pull request may close these issues.

1 participant