train-core 3.8.5 → 3.8.6
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.
- checksums.yaml +4 -4
 - data/lib/train/transports/ssh.rb +29 -24
 - data/lib/train/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 677b8d64465040ada12f33f5c2fe7689b81922b10482ca7c78e0b57e10b5139a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 8c3f7518f0453329897de457e4ea4e6f24d6262dd77f5731b42b5cd44ea706c5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8998652d978144993b1768c71d25d8b06f6501c661e827576ecbb06d3e2d8748296d26d68578d6c451a2a20617c1750a5cb66c096adb020b5bc3c0e2ad6bfb4e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 68cad9574d5282fea0d90fc00104506d0d33ecfd5e5d6879f33f88109aec9b881d0c9d49748e178c4b8ca05896827425d4bb283bb7d52aedbcc722d2817b6b27
         
     | 
    
        data/lib/train/transports/ssh.rb
    CHANGED
    
    | 
         @@ -43,7 +43,7 @@ module Train::Transports 
     | 
|
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                # common target configuration
         
     | 
| 
       45 
45 
     | 
    
         
             
                option :host, required: true
         
     | 
| 
       46 
     | 
    
         
            -
                option :ssh_config_file, default:  
     | 
| 
      
 46 
     | 
    
         
            +
                option :ssh_config_file, default: true
         
     | 
| 
       47 
47 
     | 
    
         
             
                option :port, default: 22, coerce: proc { |v| read_options_from_ssh_config(v, :port) }, required: true
         
     | 
| 
       48 
48 
     | 
    
         
             
                option :user, default: "root", coerce: proc { |v| read_options_from_ssh_config(v, :user) }, required: true
         
     | 
| 
       49 
49 
     | 
    
         
             
                option :key_files, default: nil
         
     | 
| 
         @@ -87,29 +87,30 @@ module Train::Transports 
     | 
|
| 
       87 
87 
     | 
    
         
             
                  end
         
     | 
| 
       88 
88 
     | 
    
         
             
                end
         
     | 
| 
       89 
89 
     | 
    
         | 
| 
      
 90 
     | 
    
         
            +
                # Returns the ssh config option like user, port from config files
         
     | 
| 
      
 91 
     | 
    
         
            +
                # Params options [Hash], option_type [String]
         
     | 
| 
      
 92 
     | 
    
         
            +
                # Return String
         
     | 
| 
       90 
93 
     | 
    
         
             
                def self.read_options_from_ssh_config(options, option_type)
         
     | 
| 
       91 
     | 
    
         
            -
                   
     | 
| 
       92 
     | 
    
         
            -
             
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
       94 
     | 
    
         
            -
                    config_options[option_type]
         
     | 
| 
       95 
     | 
    
         
            -
                  end
         
     | 
| 
      
 94 
     | 
    
         
            +
                  files = options[:ssh_config_file].nil? || options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
         
     | 
| 
      
 95 
     | 
    
         
            +
                  config_options = Net::SSH::Config.for(options[:host], files)
         
     | 
| 
      
 96 
     | 
    
         
            +
                  config_options[option_type]
         
     | 
| 
       96 
97 
     | 
    
         
             
                end
         
     | 
| 
       97 
98 
     | 
    
         | 
| 
       98 
99 
     | 
    
         
             
                def apply_ssh_config_file(host)
         
     | 
| 
       99 
     | 
    
         
            -
                   
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                     
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                       
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                       
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
             
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
             
     | 
| 
       112 
     | 
    
         
            -
                       
     | 
| 
      
 100 
     | 
    
         
            +
                  files = options[:ssh_config_file] == true ? Net::SSH::Config.default_files : options[:ssh_config_file]
         
     | 
| 
      
 101 
     | 
    
         
            +
                  host_cfg = ssh_config_file_for_host(host, files)
         
     | 
| 
      
 102 
     | 
    
         
            +
                  host_cfg.each do |key, value|
         
     | 
| 
      
 103 
     | 
    
         
            +
                    # setting the key_files option to the private keys set in ssh config file
         
     | 
| 
      
 104 
     | 
    
         
            +
                    if key == :keys && options[:key_files].nil? && !host_cfg[:keys].nil? && options[:password].nil?
         
     | 
| 
      
 105 
     | 
    
         
            +
                      options[:key_files] = host_cfg[key]
         
     | 
| 
      
 106 
     | 
    
         
            +
                    elsif options[key].nil?
         
     | 
| 
      
 107 
     | 
    
         
            +
                      # Precedence is given to the option set by the user manually.
         
     | 
| 
      
 108 
     | 
    
         
            +
                      # And only assigning value to the option from the ssh config file when it is not set by the user
         
     | 
| 
      
 109 
     | 
    
         
            +
                      # in the option. When the option has a default value for e.g. option "keepalive_interval" has the "60" as the default
         
     | 
| 
      
 110 
     | 
    
         
            +
                      # value, then the default value will be used even though the value for "user" is present in the ssh
         
     | 
| 
      
 111 
     | 
    
         
            +
                      # config file. That is because the precedence is to the options set manually, and currently we don't have
         
     | 
| 
      
 112 
     | 
    
         
            +
                      # any way to differentiate between the value set by the user or is it the default. This has a future of improvement.
         
     | 
| 
      
 113 
     | 
    
         
            +
                      options[key] = host_cfg[key]
         
     | 
| 
       113 
114 
     | 
    
         
             
                    end
         
     | 
| 
       114 
115 
     | 
    
         
             
                  end
         
     | 
| 
       115 
116 
     | 
    
         
             
                end
         
     | 
| 
         @@ -133,14 +134,18 @@ module Train::Transports 
     | 
|
| 
       133 
134 
     | 
    
         
             
                  key_files = Array(options[:key_files])
         
     | 
| 
       134 
135 
     | 
    
         
             
                  options[:auth_methods] ||= ["none"]
         
     | 
| 
       135 
136 
     | 
    
         | 
| 
       136 
     | 
    
         
            -
                   
     | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
      
 137 
     | 
    
         
            +
                  # by default auth_methods has a default values [none publickey password keyboard-interactive]
         
     | 
| 
      
 138 
     | 
    
         
            +
                  # REF: https://github.com/net-ssh/net-ssh/blob/master/lib/net/ssh/authentication/session.rb#L48
         
     | 
| 
      
 139 
     | 
    
         
            +
                  if key_files.empty?
         
     | 
| 
      
 140 
     | 
    
         
            +
                    options[:auth_methods].delete("publickey")
         
     | 
| 
      
 141 
     | 
    
         
            +
                  else
         
     | 
| 
       138 
142 
     | 
    
         
             
                    options[:keys_only] = true if options[:password].nil?
         
     | 
| 
       139 
143 
     | 
    
         
             
                    options[:key_files] = key_files
         
     | 
| 
       140 
144 
     | 
    
         
             
                  end
         
     | 
| 
       141 
145 
     | 
    
         | 
| 
       142 
     | 
    
         
            -
                   
     | 
| 
       143 
     | 
    
         
            -
                    options[:auth_methods]. 
     | 
| 
      
 146 
     | 
    
         
            +
                  if options[:password].nil?
         
     | 
| 
      
 147 
     | 
    
         
            +
                    options[:auth_methods].delete("password")
         
     | 
| 
      
 148 
     | 
    
         
            +
                    options[:auth_methods].delete("keyboard-interactive")
         
     | 
| 
       144 
149 
     | 
    
         
             
                  end
         
     | 
| 
       145 
150 
     | 
    
         | 
| 
       146 
151 
     | 
    
         
             
                  if options[:auth_methods] == ["none"]
         
     | 
    
        data/lib/train/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: train-core
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 3.8. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 3.8.6
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Chef InSpec Team
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2021- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2021-12-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: addressable
         
     |