vagrant-ssh-config-manager 0.8.3 → 1.0.0.alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.bundle/config +1 -1
  3. data/.gitignore +2 -1
  4. data/.rspec +2 -0
  5. data/.rubocop.yml +62 -0
  6. data/Gemfile +11 -9
  7. data/README.md +2 -2
  8. data/Rakefile +10 -8
  9. data/TESTING.md +82 -0
  10. data/lib/vagrant/ssh/config/manager.rb +5 -0
  11. data/lib/vagrant_ssh_config_manager/action/destroy.rb +82 -0
  12. data/lib/vagrant_ssh_config_manager/action/halt.rb +66 -0
  13. data/lib/vagrant_ssh_config_manager/action/provision.rb +81 -0
  14. data/lib/vagrant_ssh_config_manager/action/reload.rb +105 -0
  15. data/lib/vagrant_ssh_config_manager/action/up.rb +98 -0
  16. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/config.rb +45 -49
  17. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/file_locker.rb +35 -37
  18. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/file_manager.rb +90 -80
  19. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/include_manager.rb +54 -53
  20. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/plugin.rb +15 -13
  21. data/lib/vagrant_ssh_config_manager/ssh_config_manager.rb +1152 -0
  22. data/lib/{vagrant-ssh-config-manager → vagrant_ssh_config_manager}/ssh_info_extractor.rb +129 -141
  23. data/lib/vagrant_ssh_config_manager/version.rb +7 -0
  24. data/lib/{vagrant-ssh-config-manager.rb → vagrant_ssh_config_manager.rb} +15 -12
  25. data/test-all.sh +11 -0
  26. data/test-integration.sh +4 -0
  27. data/test-unit.sh +4 -0
  28. data/vagrant-ssh-config-manager.gemspec +25 -21
  29. metadata +28 -18
  30. data/lib/vagrant-ssh-config-manager/action/destroy.rb +0 -84
  31. data/lib/vagrant-ssh-config-manager/action/halt.rb +0 -68
  32. data/lib/vagrant-ssh-config-manager/action/provision.rb +0 -82
  33. data/lib/vagrant-ssh-config-manager/action/reload.rb +0 -106
  34. data/lib/vagrant-ssh-config-manager/action/up.rb +0 -99
  35. data/lib/vagrant-ssh-config-manager/ssh_config_manager.rb +0 -2150
  36. data/lib/vagrant-ssh-config-manager/version.rb +0 -5
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-ssh-config-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.3
4
+ version: 1.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Ruzicka
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-07-14 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: bundler
@@ -90,23 +91,30 @@ extra_rdoc_files: []
90
91
  files:
91
92
  - ".bundle/config"
92
93
  - ".gitignore"
94
+ - ".rspec"
95
+ - ".rubocop.yml"
93
96
  - Gemfile
94
97
  - README.md
95
98
  - Rakefile
96
- - lib/vagrant-ssh-config-manager.rb
97
- - lib/vagrant-ssh-config-manager/action/destroy.rb
98
- - lib/vagrant-ssh-config-manager/action/halt.rb
99
- - lib/vagrant-ssh-config-manager/action/provision.rb
100
- - lib/vagrant-ssh-config-manager/action/reload.rb
101
- - lib/vagrant-ssh-config-manager/action/up.rb
102
- - lib/vagrant-ssh-config-manager/config.rb
103
- - lib/vagrant-ssh-config-manager/file_locker.rb
104
- - lib/vagrant-ssh-config-manager/file_manager.rb
105
- - lib/vagrant-ssh-config-manager/include_manager.rb
106
- - lib/vagrant-ssh-config-manager/plugin.rb
107
- - lib/vagrant-ssh-config-manager/ssh_config_manager.rb
108
- - lib/vagrant-ssh-config-manager/ssh_info_extractor.rb
109
- - lib/vagrant-ssh-config-manager/version.rb
99
+ - TESTING.md
100
+ - lib/vagrant/ssh/config/manager.rb
101
+ - lib/vagrant_ssh_config_manager.rb
102
+ - lib/vagrant_ssh_config_manager/action/destroy.rb
103
+ - lib/vagrant_ssh_config_manager/action/halt.rb
104
+ - lib/vagrant_ssh_config_manager/action/provision.rb
105
+ - lib/vagrant_ssh_config_manager/action/reload.rb
106
+ - lib/vagrant_ssh_config_manager/action/up.rb
107
+ - lib/vagrant_ssh_config_manager/config.rb
108
+ - lib/vagrant_ssh_config_manager/file_locker.rb
109
+ - lib/vagrant_ssh_config_manager/file_manager.rb
110
+ - lib/vagrant_ssh_config_manager/include_manager.rb
111
+ - lib/vagrant_ssh_config_manager/plugin.rb
112
+ - lib/vagrant_ssh_config_manager/ssh_config_manager.rb
113
+ - lib/vagrant_ssh_config_manager/ssh_info_extractor.rb
114
+ - lib/vagrant_ssh_config_manager/version.rb
115
+ - test-all.sh
116
+ - test-integration.sh
117
+ - test-unit.sh
110
118
  - vagrant-ssh-config-manager.gemspec
111
119
  homepage: https://github.com/marekruzicka/vagrant-ssh-config-manager
112
120
  licenses:
@@ -116,6 +124,7 @@ metadata:
116
124
  source_code_uri: https://github.com/marekruzicka/vagrant-ssh-config-manager
117
125
  changelog_uri: https://github.com/marekruzicka/vagrant-ssh-config-manager/blob/main/CHANGELOG.md
118
126
  vagrant_plugin: 'true'
127
+ post_install_message:
119
128
  rdoc_options: []
120
129
  require_paths:
121
130
  - lib
@@ -123,14 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
123
132
  requirements:
124
133
  - - ">="
125
134
  - !ruby/object:Gem::Version
126
- version: 2.6.0
135
+ version: 3.0.0
127
136
  required_rubygems_version: !ruby/object:Gem::Requirement
128
137
  requirements:
129
138
  - - ">="
130
139
  - !ruby/object:Gem::Version
131
140
  version: '0'
132
141
  requirements: []
133
- rubygems_version: 3.6.7
142
+ rubygems_version: 3.5.22
143
+ signing_key:
134
144
  specification_version: 4
135
145
  summary: Vagrant plugin that automatically manages SSH configurations
136
146
  test_files: []
@@ -1,84 +0,0 @@
1
- module VagrantPlugins
2
- module SshConfigManager
3
- module Action
4
- class Destroy
5
- def initialize(app, env)
6
- @app = app
7
- @env = env
8
- @logger = Log4r::Logger.new("vagrant::plugins::ssh_config_manager::action::destroy")
9
- end
10
-
11
- def call(env)
12
- machine = env[:machine]
13
-
14
- # Handle SSH config removal before destroying the machine
15
- if machine
16
- config = machine.config.sshconfigmanager
17
- if config && config.enabled && config.auto_remove_on_destroy
18
- handle_ssh_config_removal(machine, config)
19
- end
20
- end
21
-
22
- # Call the next middleware (actual destroy)
23
- @app.call(env)
24
- end
25
-
26
- private
27
-
28
- def handle_ssh_config_removal(machine, config)
29
- begin
30
- @logger.info("Removing SSH config file for machine: #{machine.name}")
31
-
32
- # Lazy load required classes with error handling
33
- begin
34
- require 'vagrant-ssh-config-manager/file_manager'
35
- require 'vagrant-ssh-config-manager/include_manager'
36
- rescue LoadError => e
37
- @logger.error("Failed to load required classes: #{e.message}")
38
- machine.ui.warn("SSH config manager: Failed to load required components, skipping SSH config removal")
39
- return
40
- end
41
-
42
- # Create file manager and include manager
43
- file_manager = FileManager.new(config)
44
- include_manager = IncludeManager.new(config)
45
-
46
- # Check if SSH config file exists
47
- unless file_manager.ssh_config_file_exists?(machine)
48
- @logger.debug("No SSH config file found for machine: #{machine.name}")
49
- machine.ui.info("No SSH config file found to remove for machine: #{machine.name}")
50
- return
51
- end
52
-
53
- # Remove SSH config file with logging
54
- @logger.info("Attempting to remove SSH config file for #{machine.name}")
55
-
56
- if file_manager.remove_ssh_config_file(machine)
57
- machine.ui.info("SSH config file removed for machine '#{machine.name}'")
58
- @logger.info("Successfully removed SSH config file for #{machine.name}")
59
-
60
- # Manage Include directive after file removal
61
- include_manager.manage_include_directive
62
- else
63
- machine.ui.warn("Failed to remove SSH config file for machine: #{machine.name}")
64
- @logger.warn("Failed to remove SSH config file for #{machine.name}")
65
- end
66
-
67
- rescue Errno::EACCES => e
68
- @logger.error("Permission denied accessing SSH config for #{machine.name}: #{e.message}")
69
- machine.ui.warn("SSH config manager: Permission denied. Check file permissions.")
70
- rescue Errno::EIO => e
71
- @logger.error("I/O error for #{machine.name}: #{e.message}")
72
- machine.ui.warn("SSH config manager: I/O error accessing SSH config files.")
73
- rescue => e
74
- @logger.error("Error removing SSH config for #{machine.name}: #{e.message}")
75
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
76
-
77
- # Don't fail the vagrant destroy process, just warn
78
- machine.ui.warn("SSH config manager encountered an error during cleanup: #{e.message}")
79
- end
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,68 +0,0 @@
1
- module VagrantPlugins
2
- module SshConfigManager
3
- module Action
4
- class Halt
5
- def initialize(app, env)
6
- @app = app
7
- @env = env
8
- @logger = Log4r::Logger.new("vagrant::plugins::ssh_config_manager::action::halt")
9
- end
10
-
11
- def call(env)
12
- machine = env[:machine]
13
-
14
- # Handle SSH config for halt/suspend operations
15
- if machine
16
- config = machine.config.sshconfigmanager
17
- if config && config.enabled && config.keep_config_on_halt
18
- handle_ssh_config_for_halt(machine, config, env)
19
- end
20
- end
21
-
22
- # Call the next middleware (actual halt/suspend)
23
- @app.call(env)
24
- end
25
-
26
- private
27
-
28
- def handle_ssh_config_for_halt(machine, config, env)
29
- begin
30
- # Determine the type of operation
31
- operation = determine_operation_type(env)
32
- @logger.info("Handling SSH config for #{operation} operation on machine: #{machine.name}")
33
-
34
- # With separate files, we keep the SSH config file during halt/suspend
35
- # This allows users to quickly resume and reconnect
36
- case operation
37
- when :halt, :suspend, :poweroff, :force_halt
38
- machine.ui.info("Machine #{operation}ed - SSH config file retained")
39
- @logger.debug("Keeping SSH config file for #{operation}ed machine: #{machine.name}")
40
- else
41
- @logger.debug("No SSH config action needed for operation: #{operation}")
42
- end
43
-
44
- rescue => e
45
- @logger.error("Error handling SSH config for halt/suspend #{machine.name}: #{e.message}")
46
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
47
-
48
- # Don't fail the halt/suspend process
49
- machine.ui.warn("SSH config manager encountered an error: #{e.message}")
50
- end
51
- end
52
-
53
- def determine_operation_type(env)
54
- # Try to determine what type of halt operation this is
55
- if env[:force_halt]
56
- :force_halt
57
- elsif env[:suspend]
58
- :suspend
59
- elsif env[:graceful_halt] == false
60
- :poweroff
61
- else
62
- :halt
63
- end
64
- end
65
- end
66
- end
67
- end
68
- end
@@ -1,82 +0,0 @@
1
- module VagrantPlugins
2
- module SshConfigManager
3
- module Action
4
- class Provision
5
- def initialize(app, env)
6
- @app = app
7
- @env = env
8
- @logger = Log4r::Logger.new("vagrant::plugins::ssh_config_manager::action::provision")
9
- end
10
-
11
- def call(env)
12
- # Call the next middleware first (actual provisioning)
13
- @app.call(env)
14
-
15
- # Only proceed if the machine is running and SSH is ready
16
- machine = env[:machine]
17
- return unless machine && machine.state.id == :running
18
-
19
- # Check if plugin is enabled
20
- config = machine.config.sshconfigmanager
21
- return unless config && config.enabled && config.refresh_on_provision
22
-
23
- # Handle SSH config file refresh after provisioning
24
- handle_ssh_config_refresh(machine, config)
25
- end
26
-
27
- private
28
-
29
- def handle_ssh_config_refresh(machine, config)
30
- begin
31
- @logger.info("Refreshing SSH config file after provisioning for machine: #{machine.name}")
32
-
33
- # Lazy load required classes with error handling
34
- begin
35
- require 'vagrant-ssh-config-manager/ssh_info_extractor'
36
- require 'vagrant-ssh-config-manager/file_manager'
37
- require 'vagrant-ssh-config-manager/include_manager'
38
- rescue LoadError => e
39
- @logger.error("Failed to load required classes: #{e.message}")
40
- machine.ui.warn("SSH config manager: Failed to load required components, skipping SSH config refresh")
41
- return
42
- end
43
-
44
- # Extract SSH information
45
- extractor = SshInfoExtractor.new(machine)
46
-
47
- # Check if machine supports SSH
48
- unless extractor.ssh_capable?
49
- @logger.debug("Machine #{machine.name} does not support SSH, skipping")
50
- return
51
- end
52
-
53
- # Create file manager and include manager
54
- file_manager = FileManager.new(config)
55
- include_manager = IncludeManager.new(config)
56
-
57
- # Refresh SSH config file (regenerate it)
58
- # Provisioning might have changed SSH configuration
59
- if file_manager.write_ssh_config_file(machine)
60
- host_name = file_manager.send(:generate_host_name, machine)
61
- machine.ui.info("SSH config file refreshed for machine '#{machine.name}' after provisioning")
62
- @logger.info("SSH config file refreshed due to provisioning")
63
-
64
- # Ensure Include directive is managed
65
- include_manager.manage_include_directive
66
- else
67
- machine.ui.warn("Failed to refresh SSH config file for machine: #{machine.name}")
68
- @logger.warn("Failed to refresh SSH config file for #{machine.name}")
69
- end
70
-
71
- rescue => e
72
- @logger.error("Error refreshing SSH config for #{machine.name}: #{e.message}")
73
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
74
-
75
- # Don't fail the vagrant provision process, just warn
76
- machine.ui.warn("SSH config manager encountered an error during refresh: #{e.message}")
77
- end
78
- end
79
- end
80
- end
81
- end
82
- end
@@ -1,106 +0,0 @@
1
- module VagrantPlugins
2
- module SshConfigManager
3
- module Action
4
- class Reload
5
- def initialize(app, env)
6
- @app = app
7
- @env = env
8
- @logger = Log4r::Logger.new("vagrant::plugins::ssh_config_manager::action::reload")
9
- end
10
-
11
- def call(env)
12
- # Call the next middleware first
13
- @app.call(env)
14
-
15
- # Only proceed if the machine is running and SSH is ready
16
- machine = env[:machine]
17
- return unless machine && machine.state.id == :running
18
-
19
- # Check if plugin is enabled
20
- config = machine.config.sshconfigmanager
21
- return unless config && config.enabled
22
-
23
- # Handle SSH config update
24
- handle_ssh_config_update(machine, config)
25
- end
26
-
27
- private
28
-
29
- def handle_ssh_config_update(machine, config)
30
- begin
31
- @logger.info("Updating SSH config entry for machine: #{machine.name}")
32
-
33
- # Lazy load required classes with error handling
34
- begin
35
- require 'vagrant-ssh-config-manager/ssh_info_extractor'
36
- require 'vagrant-ssh-config-manager/file_manager'
37
- require 'vagrant-ssh-config-manager/include_manager'
38
- rescue LoadError => e
39
- @logger.error("Failed to load required classes: #{e.message}")
40
- machine.ui.warn("SSH config manager: Failed to load required components, skipping SSH config update")
41
- return
42
- end
43
-
44
- # Extract SSH information
45
- extractor = SshInfoExtractor.new(machine)
46
-
47
- # Check if machine supports SSH
48
- unless extractor.ssh_capable?
49
- @logger.debug("Machine #{machine.name} does not support SSH, skipping")
50
- machine.ui.info("Machine #{machine.name} does not support SSH, skipping SSH config update")
51
- return
52
- end
53
-
54
- # Create file manager and include manager
55
- file_manager = FileManager.new(config)
56
- include_manager = IncludeManager.new(config)
57
-
58
- # Check if file exists and compare content
59
- if file_manager.ssh_config_file_exists?(machine)
60
- # Update SSH config file (always regenerate for simplicity)
61
- @logger.info("SSH config file exists, updating for #{machine.name}")
62
- if file_manager.write_ssh_config_file(machine)
63
- host_name = file_manager.send(:generate_host_name, machine)
64
- machine.ui.info("SSH config file updated for machine '#{machine.name}' (#{host_name})")
65
- @logger.info("SSH config file updated due to reload")
66
-
67
- # Ensure Include directive is managed
68
- include_manager.manage_include_directive
69
- else
70
- machine.ui.warn("Failed to update SSH config file for machine: #{machine.name}")
71
- @logger.warn("Failed to update SSH config file for #{machine.name}")
72
- end
73
- else
74
- # Add new SSH config file (machine might have been added during reload)
75
- @logger.info("No existing SSH config file found, creating new file for #{machine.name}")
76
- if file_manager.write_ssh_config_file(machine)
77
- host_name = file_manager.send(:generate_host_name, machine)
78
- machine.ui.info("SSH config file created for machine '#{machine.name}' as '#{host_name}'")
79
- @logger.info("Successfully created new SSH config file for #{machine.name}")
80
-
81
- # Manage Include directive after file creation
82
- include_manager.manage_include_directive
83
- else
84
- machine.ui.warn("Failed to create SSH config file for machine: #{machine.name}")
85
- @logger.warn("Failed to create SSH config file for #{machine.name}")
86
- end
87
- end
88
-
89
- rescue Errno::EACCES => e
90
- @logger.error("Permission denied accessing SSH config for #{machine.name}: #{e.message}")
91
- machine.ui.warn("SSH config manager: Permission denied. Check file permissions.")
92
- rescue Errno::EIO => e
93
- @logger.error("I/O error for #{machine.name}: #{e.message}")
94
- machine.ui.warn("SSH config manager: I/O error accessing SSH config files.")
95
- rescue => e
96
- @logger.error("Error updating SSH config for #{machine.name}: #{e.message}")
97
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
98
-
99
- # Don't fail the vagrant reload process, just warn
100
- machine.ui.warn("SSH config manager encountered an error: #{e.message}")
101
- end
102
- end
103
- end
104
- end
105
- end
106
- end
@@ -1,99 +0,0 @@
1
- module VagrantPlugins
2
- module SshConfigManager
3
- module Action
4
- class Up
5
- def initialize(app, env)
6
- @app = app
7
- @env = env
8
- @logger = Log4r::Logger.new("vagrant::plugins::ssh_config_manager::action::up")
9
- end
10
-
11
- def call(env)
12
- # Call the next middleware first
13
- @app.call(env)
14
-
15
- # Only proceed if the machine is running and SSH is ready
16
- machine = env[:machine]
17
- return unless machine
18
- return unless machine.state.id == :running
19
-
20
- # Check if plugin is enabled
21
- config = machine.config.sshconfigmanager
22
- return unless config && config.enabled
23
-
24
- @logger.info("SSH Config Manager: Creating SSH config file for machine: #{machine.name}")
25
-
26
- # Handle SSH config file creation
27
- handle_ssh_config_creation(machine, config)
28
- rescue => e
29
- @logger.error("SSH Config Manager: Error in Up action: #{e.message}")
30
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
31
- end
32
-
33
- private
34
-
35
- def handle_ssh_config_creation(machine, config)
36
- begin
37
- @logger.info("Creating SSH config file for machine: #{machine.name}")
38
-
39
- # Lazy load required classes with error handling
40
- begin
41
- require 'vagrant-ssh-config-manager/ssh_info_extractor'
42
- require 'vagrant-ssh-config-manager/file_manager'
43
- require 'vagrant-ssh-config-manager/include_manager'
44
- rescue LoadError => e
45
- @logger.error("Failed to load required classes: #{e.message}")
46
- machine.ui.warn("SSH config manager: Failed to load required components, skipping SSH config creation")
47
- return
48
- end
49
-
50
- # Extract SSH information
51
- extractor = SshInfoExtractor.new(machine)
52
-
53
- # Check if machine supports SSH
54
- unless extractor.ssh_capable?
55
- @logger.debug("Machine #{machine.name} does not support SSH, skipping")
56
- return
57
- end
58
-
59
- # Create file manager and include manager
60
- file_manager = FileManager.new(config)
61
- include_manager = IncludeManager.new(config)
62
-
63
- # Write SSH config file
64
- @logger.info("Attempting to create SSH config file for #{machine.name}")
65
-
66
- if file_manager.write_ssh_config_file(machine)
67
- host_name = file_manager.send(:generate_host_name, machine)
68
- machine.ui.info("SSH config file created for machine '#{machine.name}' as '#{host_name}'")
69
- machine.ui.info("You can now connect with: ssh #{host_name}")
70
- @logger.info("Successfully created SSH config file for #{machine.name}")
71
-
72
- # Manage Include directive after file creation
73
- include_manager.manage_include_directive
74
- else
75
- machine.ui.warn("Failed to create SSH config file for machine: #{machine.name}")
76
- @logger.warn("Failed to create SSH config file for #{machine.name}")
77
- end
78
-
79
- rescue Errno::EACCES => e
80
- @logger.error("Permission denied accessing SSH config for #{machine.name}: #{e.message}")
81
- machine.ui.warn("SSH config manager: Permission denied. Check file permissions.")
82
- rescue Errno::ENOSPC => e
83
- @logger.error("No space left on device for #{machine.name}: #{e.message}")
84
- machine.ui.warn("SSH config manager: No space left on device.")
85
- rescue Errno::EIO => e
86
- @logger.error("I/O error for #{machine.name}: #{e.message}")
87
- machine.ui.warn("SSH config manager: I/O error accessing SSH config files.")
88
- rescue => e
89
- @logger.error("Error creating SSH config for #{machine.name}: #{e.message}")
90
- @logger.debug("Backtrace: #{e.backtrace.join("\n")}")
91
-
92
- # Don't fail the vagrant up process, just warn
93
- machine.ui.warn("SSH config manager encountered an error: #{e.message}")
94
- end
95
- end
96
- end
97
- end
98
- end
99
- end