teuton 2.7.0 → 2.7.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7fa647498d568e303c8c02ea44277a595f3796a404a523daf6c1b0408110de97
4
- data.tar.gz: b733858b7e97b373aca8477a359649b5e6614cdd60caffbdd052e450aa12dffa
3
+ metadata.gz: 49783f5731dfc4f6344649a794f17b02e0d79e6f197068dde010414cdb6f7873
4
+ data.tar.gz: 0a4c44633bc0f101e5095678edf9da2e2c22372641302647244917c573a777c2
5
5
  SHA512:
6
- metadata.gz: 60b94cd2ef2632e1fdbe81515909be71bce35d011f739ecc97806c1cfaa8115a7b743ee4369b54dffe366f1d7b06486fe451827c2fb4ce7fd37448fbf56b549b
7
- data.tar.gz: 312bd19998b3ef68cc61780dda49cf1711033736a2593206501d5f428cd64780974a2adfc4198dd1097b178f6202637dcc10e11131c90495de553fc33547520f
6
+ metadata.gz: ea56789646f536090a8afb7a28aef46e89daec281b7fe7c95bad0ff7170c27f1f1937540c899bf9d6e9b16c8126871facde4bedf97d5c7269bb8e51d49778066
7
+ data.tar.gz: e1ed282d52fbbe1519bbf597669680b46b680c5b3fa7164a0edf6e1472b7b356fce9bdc7e13ab68448a9e2318139a37a1adb6eda62a667dd00a3ba0ae2b6c339
@@ -7,11 +7,23 @@
7
7
  ## Example
8
8
 
9
9
  ```ruby
10
- target "Exist user root"
10
+ target "Exist user root (exit code ok)"
11
11
  run "id root"
12
12
  expect_exit 0
13
13
 
14
- target "No user vader"
14
+ target "No user vader (exit code fail)"
15
15
  run "id vader"
16
16
  expect_exit 1
17
17
  ```
18
+
19
+ ## More examples
20
+
21
+ ```ruby
22
+ target "Using a range"
23
+ run "id vader"
24
+ expect_exit 1..3
25
+
26
+ target "Using a list"
27
+ run "id vader"
28
+ expect_exit [1, 3, 7]
29
+ ```
@@ -0,0 +1,70 @@
1
+ require "net/ssh"
2
+ require "net/sftp"
3
+ require "rainbow"
4
+ require_relative "../../utils/project"
5
+ require_relative "../../utils/verbose"
6
+ require_relative "execute_base"
7
+
8
+ class CopySSH < ExecuteBase
9
+ def call(host, localfilename)
10
+ # Check params
11
+ unless config.get("#{host}_route".to_sym) == "NODATA"
12
+ log("'copy script' requires direct host access!", :error)
13
+ return false
14
+ end
15
+
16
+ host = host.to_s
17
+
18
+ begin
19
+ if sessions[host].nil?
20
+ # Open new SSH session
21
+ ip = config.get("#{host}_ip".to_sym).to_s
22
+ username = config.get("#{host}_username".to_sym).to_s
23
+ password = config.get("#{host}_password".to_sym).to_s
24
+ port = config.get("#{host}_port".to_sym).to_i
25
+ port = 22 if port.zero?
26
+
27
+ sessions[host] = Net::SSH.start(
28
+ ip,
29
+ username,
30
+ port: port,
31
+ password: password,
32
+ keepalive: true,
33
+ timeout: 30,
34
+ non_interactive: true
35
+ )
36
+ end
37
+ if sessions[host].instance_of? Net::SSH::Connection::Session
38
+ copy_to(host, localfilename)
39
+ else
40
+ "SSH: NO CONNECTION!"
41
+ end
42
+ rescue => e
43
+ sessions[host] = :nosession
44
+ conn_status[host] = :error
45
+ log("[#{e.class}] SSH on <#{username}@#{ip}>", :error)
46
+ end
47
+ end
48
+
49
+ def copy_to(host, localfilename)
50
+ ip = get((host + "_ip").to_sym)
51
+ username = get((host + "_username").to_sym).to_s
52
+ password = get((host + "_password").to_sym).to_s
53
+ port = get((host + "_port").to_sym).to_i
54
+ port = 22 if port.zero?
55
+
56
+ localfilepath = File.join(Dir.pwd, localfilename)
57
+ remotefilepath = File.join(".", File.basename(localfilename))
58
+
59
+ # Upload a file or directory to the remote host
60
+ begin
61
+ Net::SFTP.start(ip, username, password: password, port: port) do |sftp|
62
+ sftp.upload!(localfilepath, remotefilepath)
63
+ end
64
+ rescue
65
+ log("copy file: #{localfilename} => #{remotefilepath}", :error)
66
+ return false
67
+ end
68
+ true
69
+ end
70
+ end
@@ -26,8 +26,8 @@ class ExecuteManager
26
26
  @parent.config
27
27
  end
28
28
 
29
- def log
30
- @parent.log
29
+ def log(...)
30
+ @parent.log(...)
31
31
  end
32
32
 
33
33
  def run_on(host)
@@ -95,7 +95,7 @@ class ShowReport
95
95
  puts lines[0]
96
96
  else
97
97
  lines.each do |i|
98
- if i.class.to_s == "Hash"
98
+ if i.instance_of?(::Hash)
99
99
  value = 0.0
100
100
  value = i[:weight] if i[:check]
101
101
  print tab + "%03d" % i[:id].to_i
@@ -67,6 +67,7 @@ class ArrayFormatter < BaseFormatter
67
67
 
68
68
  if options[:feedback] == false
69
69
  target[:command] = "*" * i[:command].size
70
+ i[:output] = "" if i[:output].nil?
70
71
  target[:output] = "*" * i[:output].size
71
72
  target[:alterations] = "*" * i[:alterations].size
72
73
  target[:expected] = "*" * i[:expected].size
@@ -48,7 +48,7 @@ module Formatter
48
48
  report2 = report.clone
49
49
  report2.groups.each do |group|
50
50
  group.each do |item|
51
- puts item.to_s
51
+ puts item
52
52
  end
53
53
  end
54
54
  end
@@ -1,5 +1,5 @@
1
1
  module Teuton
2
- VERSION = "2.7.0"
2
+ VERSION = "2.7.2"
3
3
  APPNAME = "teuton"
4
4
  GEMNAME = "teuton"
5
5
  DOCKERNAME = "dvarrui/#{GEMNAME}"
data/lib/teuton.rb CHANGED
@@ -41,7 +41,7 @@ module Teuton
41
41
  begin
42
42
  require_relative Project.value[:script_path]
43
43
  rescue => e
44
- warn e.to_s
44
+ warn e
45
45
  warn Rainbow.new("[FAIL ] Reading file #{Project.value[:script_path]}").red
46
46
  warn Rainbow.new("[ERROR] Syntax Error!").red
47
47
  exit 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teuton
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Vargas Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-17 00:00:00.000000000 Z
11
+ date: 2023-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow
@@ -281,6 +281,7 @@ files:
281
281
  - lib/teuton/case/dsl/send.rb
282
282
  - lib/teuton/case/dsl/target.rb
283
283
  - lib/teuton/case/dsl/unique.rb
284
+ - lib/teuton/case/execute/copy_ssh.rb
284
285
  - lib/teuton/case/execute/execute_base.rb
285
286
  - lib/teuton/case/execute/execute_local.rb
286
287
  - lib/teuton/case/execute/execute_manager.rb