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 +4 -4
- data/CHANGELOG.md +8 -1
- data/bin/seijaku +2 -1
- data/lib/seijaku/executors/ssh.rb +15 -5
- data/lib/seijaku/payload.rb +6 -5
- data/lib/seijaku/ssh/group.rb +1 -1
- data/lib/seijaku/ssh/host.rb +4 -4
- data/lib/seijaku/step.rb +8 -7
- data/lib/seijaku/task.rb +6 -6
- data/lib/seijaku/version.rb +1 -1
- data/sig/seijaku.rbs +11 -0
- 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: 0b351498f055e85f7e20edc44374616118d0162b479104d18f20b271138a9271
|
4
|
+
data.tar.gz: '08c117438ac1e83a15fef55c6973e27fd15ef1d2fbc03a7027774deee4904720'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d86d8bad1a17e32a8b52faebe48873369c7eabf8988fbeec15e854d2e4b834aa8d29dab583dbfb121f18de545289bb1f4ab7484cd7bea787c0aba04cfcd33d
|
7
|
+
data.tar.gz: '0532610288a45a4e8391f71da9caa73d2ac22f2a02af7a99af4629fdaa9b3efe60a2fdcf7696337030822e2a24d8d1f832855b447f88292e9d92e4774f843134'
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
##
|
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
@@ -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
|
-
|
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]
|
data/lib/seijaku/payload.rb
CHANGED
@@ -7,11 +7,12 @@ module Seijaku
|
|
7
7
|
attr_reader :name
|
8
8
|
|
9
9
|
def initialize(payload, logger)
|
10
|
-
@name = payload.fetch(
|
11
|
-
@variables = get_variables(payload.fetch(
|
12
|
-
@ssh_hosts = SSHGroup.new(payload.fetch(
|
13
|
-
@
|
14
|
-
|
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
|
|
data/lib/seijaku/ssh/group.rb
CHANGED
data/lib/seijaku/ssh/host.rb
CHANGED
@@ -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(
|
10
|
-
@port = host.fetch(
|
11
|
-
@bastion = host.fetch(
|
12
|
-
@user = host.fetch(
|
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(
|
11
|
-
@bash = step.fetch(
|
12
|
-
@ssh = step.fetch(
|
13
|
-
@soft_fail = step.fetch(
|
14
|
-
@output = step.fetch(
|
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!
|
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(
|
10
|
-
@host = task.fetch(
|
11
|
-
@steps = task.fetch(
|
12
|
-
@pre_steps = task.fetch(
|
13
|
-
@post_steps = task.fetch(
|
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?
|
data/lib/seijaku/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2024-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt_pbkdf
|