sshkit-custom-dsl 0.0.1 → 0.0.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 +4 -4
- data/lib/core_ext/sshkit/runner/abstract.rb +10 -2
- data/lib/core_ext/sshkit/runner/group.rb +2 -2
- data/lib/core_ext/sshkit/runner/parallel.rb +1 -1
- data/lib/core_ext/sshkit/runner/sequential.rb +1 -1
- data/lib/sshkit/custom/{dsl/config_store.rb → config/store.rb} +29 -20
- data/lib/sshkit/custom/dsl.rb +6 -5
- data/lib/sshkit/custom/dsl/config_statements.rb +55 -0
- data/lib/sshkit/custom/dsl/exec_statements.rb +43 -0
- data/lib/sshkit/custom/dsl/helper.rb +12 -0
- data/lib/sshkit/custom/dsl/version.rb +1 -1
- data/sshkit-custom-dsl.gemspec +1 -0
- metadata +19 -5
- data/lib/sshkit/custom/dsl/configuration.rb +0 -75
- data/lib/sshkit/custom/dsl/execution.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd78c52e9066b2a20a58ec0a15a582c18421d2bb
|
4
|
+
data.tar.gz: 676a5a5944f1eb99a1d6af444301602d83bae625
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6494485ae41a1c46ddeac63acd849df3992abb06c7a577c6cf173be699af18754498ca17efab7cab609eff7f2e6314c1f0741a02643de64138e6a9e17eb50aea
|
7
|
+
data.tar.gz: 23fdd8841b78db4226f7ebe7985b1c9005e9469c4ea8faf684a3aa5dcc9358eb1708b3887e1cf95936c478bf38afb7d8d3b5e2502665605b3310b69ec3aac020
|
@@ -11,12 +11,20 @@ module SSHKit
|
|
11
11
|
self.class.active_backend=new_backend
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.scope_storage
|
15
|
+
ScopedStorage::ThreadLocalStorage
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.scope
|
19
|
+
@scope ||= ScopedStorage::Scope.new('sshkit_runner', scope_storage)
|
20
|
+
end
|
21
|
+
|
14
22
|
def self.active_backend
|
15
|
-
|
23
|
+
scope[:active_backend]
|
16
24
|
end
|
17
25
|
|
18
26
|
def self.active_backend=(new_backend)
|
19
|
-
|
27
|
+
scope[:active_backend]=new_backend
|
20
28
|
end
|
21
29
|
|
22
30
|
def send_cmd(cmd, *args, &block)
|
@@ -4,12 +4,12 @@ module SSHKit
|
|
4
4
|
class Group < Sequential
|
5
5
|
attr_writer :group_size
|
6
6
|
|
7
|
-
def
|
7
|
+
def apply_block_to_bcks( &block)
|
8
8
|
backends.each_slice(group_size).collect do |group_backends|
|
9
9
|
|
10
10
|
Parallel.new(nil, nil).tap do |runner|
|
11
11
|
runner.backends = group_backends
|
12
|
-
runner.
|
12
|
+
runner.apply_block_to_bcks(&block)
|
13
13
|
end
|
14
14
|
|
15
15
|
sleep wait_interval
|
@@ -1,24 +1,31 @@
|
|
1
1
|
module SSHKit
|
2
2
|
module Custom
|
3
|
-
module
|
4
|
-
module
|
3
|
+
module Config
|
4
|
+
module Store
|
5
5
|
|
6
6
|
module_function
|
7
|
-
|
8
|
-
def runner_opts=(opts)
|
9
|
-
@runner = nil
|
10
|
-
@runner_opts = { in: :parallel }.merge(opts)
|
11
|
-
end
|
12
7
|
|
13
|
-
def
|
14
|
-
|
8
|
+
def scope_storage
|
9
|
+
ScopedStorage::ThreadLocalStorage
|
10
|
+
end
|
11
|
+
|
12
|
+
def config_scope
|
13
|
+
@config_scope ||= ScopedStorage::Scope.new('sshkit_dsl_config', scope_storage)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_runner(opts)
|
17
|
+
opts_with_defaults = { in: :parallel }.merge(opts)
|
18
|
+
|
19
|
+
@runner ||= case opts_with_defaults[:in]
|
15
20
|
when :parallel then SSHKit::Runner::Parallel
|
16
21
|
when :sequence then SSHKit::Runner::Sequential
|
17
22
|
when :groups then SSHKit::Runner::Group
|
18
23
|
else
|
19
|
-
raise RuntimeError, "Don't know how to handle run style #{
|
20
|
-
end.new(nil,
|
24
|
+
raise RuntimeError, "Don't know how to handle run style #{opts_with_defaults[:in].inspect}"
|
25
|
+
end.new(nil, opts_with_defaults)
|
26
|
+
end
|
21
27
|
|
28
|
+
def runner
|
22
29
|
@runner.tap{|r| r.backends = backends}
|
23
30
|
end
|
24
31
|
|
@@ -31,22 +38,22 @@ module SSHKit
|
|
31
38
|
end
|
32
39
|
|
33
40
|
def add_pwd(directory)
|
34
|
-
|
41
|
+
active_backend.pwd ||= []; active_backend.pwd << directory
|
35
42
|
end
|
36
43
|
|
37
44
|
def pop_pwd
|
38
|
-
|
45
|
+
active_backend.pwd ||= []; active_backend.pwd.pop
|
39
46
|
end
|
40
47
|
|
41
48
|
def _envs
|
42
|
-
|
49
|
+
config_scope[:_envs] ||= []
|
43
50
|
end
|
44
51
|
|
45
52
|
def add_env(env)
|
46
53
|
old_env = backends.first.env.clone
|
47
54
|
_envs << old_env
|
48
55
|
env = old_env.merge(env)
|
49
|
-
|
56
|
+
active_backend.env = env
|
50
57
|
end
|
51
58
|
|
52
59
|
def pop_env
|
@@ -55,20 +62,22 @@ module SSHKit
|
|
55
62
|
end
|
56
63
|
|
57
64
|
def _user_groups
|
58
|
-
|
65
|
+
config_scope[:_user_groups] ||= []
|
59
66
|
end
|
60
67
|
|
61
68
|
def add_user_group(user, group)
|
62
|
-
_user_groups << {user:
|
63
|
-
|
69
|
+
_user_groups << {user: active_backend.user, group: active_backend.group }
|
70
|
+
active_backend.user = user
|
71
|
+
active_backend.group = group
|
64
72
|
end
|
65
73
|
|
66
74
|
def pop_user_group
|
67
75
|
old_user_group = _user_groups.pop || {}
|
68
|
-
|
76
|
+
active_backend.user = old_user_group[:user]
|
77
|
+
active_backend.group = old_user_group[:group]
|
69
78
|
end
|
70
79
|
|
71
|
-
def
|
80
|
+
def active_backend
|
72
81
|
SSHKit::Runner::Abstract.active_backend
|
73
82
|
end
|
74
83
|
end
|
data/lib/sshkit/custom/dsl.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
require 'sshkit/custom/dsl/version'
|
2
2
|
require 'core_ext/sshkit'
|
3
|
+
require 'scoped_storage'
|
3
4
|
|
4
|
-
require 'sshkit/custom/
|
5
|
-
require 'sshkit/custom/dsl/
|
6
|
-
require 'sshkit/custom/dsl/
|
5
|
+
require 'sshkit/custom/config/store'
|
6
|
+
require 'sshkit/custom/dsl/config_statements'
|
7
|
+
require 'sshkit/custom/dsl/exec_statements'
|
7
8
|
require 'sshkit/custom/dsl/helper'
|
8
9
|
|
9
10
|
module SSHKit
|
10
11
|
module Custom
|
11
12
|
module DSL
|
12
|
-
include
|
13
|
-
include
|
13
|
+
include ConfigStatements
|
14
|
+
include ExecStatements
|
14
15
|
include Helper
|
15
16
|
end
|
16
17
|
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module SSHKit
|
2
|
+
module Custom
|
3
|
+
module DSL
|
4
|
+
module ConfigStatements
|
5
|
+
|
6
|
+
def on(hosts, options={}, &block)
|
7
|
+
hosts = Array(hosts).map { |rh| Host(rh) }.uniq
|
8
|
+
|
9
|
+
_config_store.backends = hosts
|
10
|
+
_config_store.create_runner options
|
11
|
+
|
12
|
+
_config_store.runner.apply_block_to_bcks(&block) if block_given?
|
13
|
+
end
|
14
|
+
|
15
|
+
def within(directory)
|
16
|
+
_guard_dir!(File.join(_config_store.active_backend.pwd + [directory]))
|
17
|
+
|
18
|
+
_config_store.add_pwd directory
|
19
|
+
|
20
|
+
yield if block_given?
|
21
|
+
ensure
|
22
|
+
_config_store.pop_pwd
|
23
|
+
end
|
24
|
+
|
25
|
+
def with(environment)
|
26
|
+
_config_store.add_env environment
|
27
|
+
yield if block_given?
|
28
|
+
ensure
|
29
|
+
_config_store.pop_env
|
30
|
+
end
|
31
|
+
|
32
|
+
def as(who)
|
33
|
+
|
34
|
+
if who.respond_to? :fetch
|
35
|
+
user = who.fetch(:user, who.fetch("user"))
|
36
|
+
group = who.fetch(:group, who.fetch("group", nil))
|
37
|
+
else
|
38
|
+
user = who
|
39
|
+
group = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
_guard_sudo_user!(user)
|
43
|
+
_guard_sudo_group!(user, group)
|
44
|
+
|
45
|
+
_config_store.add_user_group user, group
|
46
|
+
|
47
|
+
yield if block_given?
|
48
|
+
ensure
|
49
|
+
_config_store.pop_user_group
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SSHKit
|
2
|
+
module Custom
|
3
|
+
module DSL
|
4
|
+
module ExecStatements
|
5
|
+
|
6
|
+
|
7
|
+
[:execute, :make, :rake, :test, :capture, :upload!, :download!].each do |method|
|
8
|
+
define_method method do |*args, &block|
|
9
|
+
_config_store.runner.send_cmd method, *args, &block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def _guard_sudo_user!(user)
|
14
|
+
execute <<-EOTEST, verbosity: Logger::DEBUG
|
15
|
+
if ! sudo -u #{user} whoami > /dev/null
|
16
|
+
then echo "You cannot switch to user '#{user}' using sudo, please check the sudoers file" 1>&2
|
17
|
+
false
|
18
|
+
fi
|
19
|
+
EOTEST
|
20
|
+
end
|
21
|
+
|
22
|
+
def _guard_sudo_group!(user, group)
|
23
|
+
execute <<-EOTEST, verbosity: Logger::DEBUG if group
|
24
|
+
if ! sudo -u #{user} -g #{group} whoami > /dev/null
|
25
|
+
then echo "You cannot switch to group '#{group}' using sudo, please check the sudoers file" 1>&2
|
26
|
+
false
|
27
|
+
fi
|
28
|
+
EOTEST
|
29
|
+
end
|
30
|
+
|
31
|
+
def _guard_dir!(dir_to_check)
|
32
|
+
execute <<-EOTEST, verbosity: Logger::DEBUG
|
33
|
+
if test ! -d #{dir_to_check}
|
34
|
+
then echo "Directory does not exist '#{dir_to_check}'" 1>&2
|
35
|
+
false
|
36
|
+
fi
|
37
|
+
EOTEST
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/sshkit-custom-dsl.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshkit-custom-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieter Späth
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sshkit
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.5.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: scoped_storage
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -147,10 +161,10 @@ files:
|
|
147
161
|
- lib/core_ext/sshkit/runner/group.rb
|
148
162
|
- lib/core_ext/sshkit/runner/parallel.rb
|
149
163
|
- lib/core_ext/sshkit/runner/sequential.rb
|
164
|
+
- lib/sshkit/custom/config/store.rb
|
150
165
|
- lib/sshkit/custom/dsl.rb
|
151
|
-
- lib/sshkit/custom/dsl/
|
152
|
-
- lib/sshkit/custom/dsl/
|
153
|
-
- lib/sshkit/custom/dsl/execution.rb
|
166
|
+
- lib/sshkit/custom/dsl/config_statements.rb
|
167
|
+
- lib/sshkit/custom/dsl/exec_statements.rb
|
154
168
|
- lib/sshkit/custom/dsl/helper.rb
|
155
169
|
- lib/sshkit/custom/dsl/version.rb
|
156
170
|
- spec/acceptance/.gitkeep
|
@@ -1,75 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module DSL
|
4
|
-
module Configuration
|
5
|
-
|
6
|
-
def config_store
|
7
|
-
@config_store ||= SSHKit::Custom::DSL::ConfigStore
|
8
|
-
end
|
9
|
-
|
10
|
-
def on(hosts, options={}, &block)
|
11
|
-
hosts = Array(hosts).map { |rh| rh.is_a?(SSHKit::Host) ? rh : SSHKit::Host.new(rh) }.uniq
|
12
|
-
config_store.backends = hosts
|
13
|
-
config_store.runner_opts = options
|
14
|
-
config_store.runner.do_it(&block) if block_given?
|
15
|
-
end
|
16
|
-
|
17
|
-
def within(directory)
|
18
|
-
|
19
|
-
dir_to_check = File.join(config_store.backend.pwd + [directory])
|
20
|
-
|
21
|
-
execute <<-EOTEST, verbosity: Logger::DEBUG
|
22
|
-
if test ! -d #{dir_to_check}
|
23
|
-
then echo "Directory does not exist '#{dir_to_check}'" 1>&2
|
24
|
-
false
|
25
|
-
fi
|
26
|
-
EOTEST
|
27
|
-
|
28
|
-
config_store.add_pwd directory
|
29
|
-
|
30
|
-
yield if block_given?
|
31
|
-
ensure
|
32
|
-
config_store.pop_pwd
|
33
|
-
end
|
34
|
-
|
35
|
-
def with(environment)
|
36
|
-
config_store.add_env environment
|
37
|
-
yield if block_given?
|
38
|
-
ensure
|
39
|
-
config_store.pop_env
|
40
|
-
end
|
41
|
-
|
42
|
-
def as(who)
|
43
|
-
if who.is_a? Hash
|
44
|
-
user = who[:user] || who["user"]
|
45
|
-
group = who[:group] || who["group"]
|
46
|
-
else
|
47
|
-
user = who
|
48
|
-
group = nil
|
49
|
-
end
|
50
|
-
|
51
|
-
execute <<-EOTEST, verbosity: Logger::DEBUG
|
52
|
-
if ! sudo -u #{user} whoami > /dev/null
|
53
|
-
then echo "You cannot switch to user '#{user}' using sudo, please check the sudoers file" 1>&2
|
54
|
-
false
|
55
|
-
fi
|
56
|
-
EOTEST
|
57
|
-
|
58
|
-
execute <<-EOTEST, verbosity: Logger::DEBUG if group
|
59
|
-
if ! sudo -u #{user} -g #{group} whoami > /dev/null
|
60
|
-
then echo "You cannot switch to group '#{group}' using sudo, please check the sudoers file" 1>&2
|
61
|
-
false
|
62
|
-
fi
|
63
|
-
EOTEST
|
64
|
-
|
65
|
-
config_store.add_user_group user, group
|
66
|
-
|
67
|
-
yield if block_given?
|
68
|
-
ensure
|
69
|
-
config_store.pop_user_group
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module SSHKit
|
2
|
-
module Custom
|
3
|
-
module DSL
|
4
|
-
module Execution
|
5
|
-
|
6
|
-
|
7
|
-
[:execute, :make, :rake, :test, :capture, :upload!, :download!].each do |method|
|
8
|
-
define_method method do |*args, &block|
|
9
|
-
config_store.runner.send_cmd method, *args, &block
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|