seijaku 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 638106c6524b04b68139b67af16ff6b1f66d74fa82b05d15be1b2c26f42e5684
4
- data.tar.gz: 40b3f7a10c0575df85225a04ebc040c5d6d09521ebc789148a6f888319e9ec31
3
+ metadata.gz: 0b351498f055e85f7e20edc44374616118d0162b479104d18f20b271138a9271
4
+ data.tar.gz: '08c117438ac1e83a15fef55c6973e27fd15ef1d2fbc03a7027774deee4904720'
5
5
  SHA512:
6
- metadata.gz: 4387d2f340c6d3552f6ad91529ae5600e94ce1fd02e49556fef4e8bd1a125b4a078d5fcaca099a5ca766116db8481e08e1889214b92d8422bac1f14ed01ba646
7
- data.tar.gz: 2bd4543e36d3ae4abbeaf8317995c2a689be7fd1ae0409f1b3ed34842ac58779802577399116608242979153d92f271df7db663aa999baa694ae1fbc3dd56c42
6
+ metadata.gz: 23d86d8bad1a17e32a8b52faebe48873369c7eabf8988fbeec15e854d2e4b834aa8d29dab583dbfb121f18de545289bb1f4ab7484cd7bea787c0aba04cfcd33d
7
+ data.tar.gz: '0532610288a45a4e8391f71da9caa73d2ac22f2a02af7a99af4629fdaa9b3efe60a2fdcf7696337030822e2a24d8d1f832855b447f88292e9d92e4774f843134'
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## [Unreleased]
1
+ ## Seijaku
2
+
3
+ Please mind Seijaku is still under heavy development.
4
+
5
+ ## [0.3.0] - 2023-12-14
6
+
7
+ - scheduler has been added to run reccurent payloads
8
+ - fixed a bug related to SSHExecutor set as default executor
2
9
 
3
10
  ## [0.2.0] - 2023-12-12
4
11
 
data/bin/seijaku CHANGED
@@ -41,7 +41,8 @@ module App
41
41
 
42
42
  if options[:payload]
43
43
  payload_file = YAML.safe_load(
44
- File.read(options[:payload])
44
+ File.read(options[:payload]),
45
+ symbolize_names: true
45
46
  )
46
47
 
47
48
  logger.info "Starting Seijaku. Payload: #{payload_file["name"]}"
@@ -6,12 +6,19 @@ require "net/ssh/proxy/jump"
6
6
  module Seijaku
7
7
  # SSHExecutor connects to SSH host and runs command
8
8
  class SSHExecutor
9
- def initialize(raw, variables, task, ssh_hosts)
10
- @command = ["sh", "-c", "'#{raw}'"]
9
+ def initialize(raw, variables, task, ssh_hosts, ssh_settings)
11
10
  @hosts = ssh_hosts
12
- @variables = variables
11
+ @variables = variables.map do |key, value|
12
+ "#{key}='#{value}'"
13
+ end.join(" ")
14
+
15
+ @command = ["#{@variables};", "#{raw}"]
13
16
  @task = task
14
17
  @ssh_hosts = ssh_hosts
18
+ @ssh_settings = ssh_settings.transform_keys(&:to_sym)
19
+ if @ssh_settings[:verify_host_key].eql?("never")
20
+ @ssh_settings[:verify_host_key] = :never
21
+ end
15
22
 
16
23
  raise SSHExecutorError, "no ssh host defined in payload", [] if ssh_hosts.nil?
17
24
  end
@@ -20,12 +27,15 @@ module Seijaku
20
27
  machine = @ssh_hosts.hosts[@task.host]
21
28
  result = { command: @command.join(" "), stdout: nil, stderr: nil }
22
29
  status = {}
23
- options = machine.bastion ? { proxy: bastion_setup } : {}
24
- ssh = Net::SSH.start(machine.host, machine.user, port: machine.port, **options)
30
+ options = machine.bastion ? { proxy: bastion_setup, **@ssh_settings } : @ssh_settings
31
+
32
+ ssh = Net::SSH.start(machine.host, machine.user, {port: machine.port, **@ssh_settings})
33
+
25
34
  ssh.exec!(@command.join(" "), status: status) do |_ch, stream, data|
26
35
  result[:stdout] = data.chomp if stream == :stdout
27
36
  result[:stderr] = data.chomp unless stream == :stdout
28
37
  end
38
+
29
39
  ssh.close
30
40
 
31
41
  result[:exit_status] = status[:exit_code]
@@ -7,11 +7,12 @@ module Seijaku
7
7
  attr_reader :name
8
8
 
9
9
  def initialize(payload, logger)
10
- @name = payload.fetch("name")
11
- @variables = get_variables(payload.fetch("variables"))
12
- @ssh_hosts = SSHGroup.new(payload.fetch("ssh", []))
13
- @tasks = payload.fetch("tasks").map do |task|
14
- Task.new(task, @variables, logger, @ssh_hosts)
10
+ @name = payload.fetch(:name)
11
+ @variables = get_variables(payload.fetch(:variables))
12
+ @ssh_hosts = SSHGroup.new(payload.fetch(:ssh, []))
13
+ @ssh_settings = payload.fetch(:ssh_settings, {})
14
+ @tasks = payload.fetch(:tasks).map do |task|
15
+ Task.new(task, @variables, logger, @ssh_hosts, @ssh_settings)
15
16
  end
16
17
  end
17
18
 
@@ -8,7 +8,7 @@ module Seijaku
8
8
  def initialize(ssh_group)
9
9
  @hosts = {}
10
10
  ssh_group.each do |host|
11
- @hosts[host["host"]] = Host.new(host)
11
+ @hosts[host[:host]] = Host.new(host)
12
12
  end
13
13
  end
14
14
  end
@@ -6,10 +6,10 @@ module Seijaku
6
6
  attr_reader :host, :port, :user, :bastion
7
7
 
8
8
  def initialize(host)
9
- @host = host.fetch("host", "localhost")
10
- @port = host.fetch("port", 22)
11
- @bastion = host.fetch("bastion", nil)
12
- @user = host.fetch("user", "root")
9
+ @host = host.fetch(:host, "localhost")
10
+ @port = host.fetch(:port, 22)
11
+ @bastion = host.fetch(:bastion, nil)
12
+ @user = host.fetch(:user, "root")
13
13
  end
14
14
  end
15
15
  end
data/lib/seijaku/step.rb CHANGED
@@ -6,17 +6,18 @@ module Seijaku
6
6
  class Step
7
7
  attr_reader :command, :pipeline
8
8
 
9
- def initialize(step, variables, pipeline, logger, task, ssh_hosts = nil)
10
- @sh = step.fetch("sh", nil)
11
- @bash = step.fetch("bash", nil)
12
- @ssh = step.fetch("ssh", nil)
13
- @soft_fail = step.fetch("soft_fail", false)
14
- @output = step.fetch("output", false)
9
+ def initialize(step, variables, pipeline, logger, task, ssh_hosts = nil, ssh_settings = {})
10
+ @sh = step.fetch(:sh, nil)
11
+ @bash = step.fetch(:bash, nil)
12
+ @ssh = step.fetch(:ssh, nil)
13
+ @soft_fail = step.fetch(:soft_fail, false)
14
+ @output = step.fetch(:output, false)
15
15
  @variables = variables
16
16
  @pipeline = pipeline
17
17
  @logger = logger
18
18
  @task = task
19
19
  @ssh_hosts = ssh_hosts
20
+ @ssh_settings = ssh_settings
20
21
 
21
22
  @command = (@sh || @bash) || @ssh
22
23
  end
@@ -24,7 +25,7 @@ module Seijaku
24
25
  def execute!
25
26
  result = SHExecutor.new(@sh, @variables).run! if @sh
26
27
  result = BashExecutor.new(@bash, @variables).run! if @bash
27
- result = SSHExecutor.new(@ssh, @variables, @task, @ssh_hosts).run! if @ssh
28
+ result = SSHExecutor.new(@ssh, @variables, @task, @ssh_hosts, @ssh_settings).run!
28
29
 
29
30
  if result[:exit_status] != 0
30
31
  logger_output(result)
data/lib/seijaku/task.rb CHANGED
@@ -5,12 +5,12 @@ module Seijaku
5
5
  class Task
6
6
  attr_reader :host
7
7
 
8
- def initialize(task, variables, logger, ssh_hosts = nil)
9
- @name = task.fetch("name", nil)
10
- @host = task.fetch("host", nil)
11
- @steps = task.fetch("steps", []).map { |step| Step.new(step, variables, :steps, logger, self, ssh_hosts) }
12
- @pre_steps = task.fetch("pre", []).map { |step| Step.new(step, variables, :pre, logger, self, ssh_hosts) }
13
- @post_steps = task.fetch("post", []).map { |step| Step.new(step, variables, :post, logger, self, ssh_hosts) }
8
+ def initialize(task, variables, logger, ssh_hosts = nil, ssh_settings = {})
9
+ @name = task.fetch(:name, nil)
10
+ @host = task.fetch(:host, nil)
11
+ @steps = task.fetch(:steps, []).map { |step| Step.new(step, variables, :steps, logger, self, ssh_hosts, ssh_settings) }
12
+ @pre_steps = task.fetch(:pre, []).map { |step| Step.new(step, variables, :pre, logger, self, ssh_hosts, ssh_settings) }
13
+ @post_steps = task.fetch(:post, []).map { |step| Step.new(step, variables, :post, logger, self, ssh_hosts, ssh_settings) }
14
14
  @logger = logger
15
15
 
16
16
  raise TaskError, "no name set in task", [] if @name.nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Seijaku
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/sig/seijaku.rbs CHANGED
@@ -1,4 +1,15 @@
1
1
  module Seijaku
2
2
  VERSION: String
3
3
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ class Error < StandardError
5
+ end
6
+
7
+ class TaskError < Error
8
+ end
9
+
10
+ class VariableError < Error
11
+ end
12
+
13
+ class SSHExecutorError < Error
14
+ end
4
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seijaku
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohlrabbit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-14 00:00:00.000000000 Z
11
+ date: 2024-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt_pbkdf