eventhub-command 0.3.13 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ desc 'enable/disable proxy'
2
+
3
+ command :proxy do |c|
4
+
5
+ c.switch([:v, :verbose], :desc => 'Show additional output.')
6
+ c.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where proxy is', default_value: Eh::Settings.current.default_stage)
7
+
8
+ c.command :off do |c|
9
+
10
+ c.action do |global_options, options, arguments|
11
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).unset
12
+ end
13
+ end
14
+
15
+ c.command :on do |c|
16
+ c.arg_name 'name'
17
+ c.action do |global_options, options, arguments|
18
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).set(arguments[0])
19
+ end
20
+
21
+ end
22
+
23
+ c.command :list do |c|
24
+ c.action do |global_options, options, arguments|
25
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).list
26
+ end
27
+ end
28
+
29
+ c.arg_name 'name'
30
+ c.command :remove do |c|
31
+ c.action do |global_options, options, arguments|
32
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).remove(arguments[0])
33
+ end
34
+ end
35
+
36
+ c.arg_name 'name'
37
+ c.arg_name 'proxy'
38
+ c.command :add do |c|
39
+ c.action do |global, options, arguments|
40
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).add(arguments[0], arguments[1])
41
+ end
42
+ end
43
+
44
+ c.arg_name 'name'
45
+ c.command :select do |c|
46
+ c.action do |global_options, options, arguments|
47
+ Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).select(arguments[0])
48
+ end
49
+ end
50
+ end
@@ -1,81 +1,81 @@
1
- desc "manage repositories"
2
-
3
- command :repository do |command|
4
- command.desc "Lists all avaiable repositories"
5
- command.command :list do |command|
6
- command.action do |global_options,options,args|
7
-
8
- Eh::Settings.current.repositories.each_with_index do |repository, index|
9
- if repository.current?
10
- puts "#{index + 1}: #{repository.url} (current)"
11
- else
12
- puts "#{index + 1}: #{repository.url}"
13
- end
14
- end
15
- end
16
- end
17
-
18
- command.desc "selects a repository: eh repository select INDEX"
19
- command.command :select do |command|
20
- command.action do |global_options,options,args|
21
- if Eh::Settings.current.repositories.length == 0
22
- raise "No repository configured so far"
23
- end
24
- if args.length != 1
25
- raise "Need exactly 1 arguments: index"
26
- end
27
- selected = args[0].to_i
28
- Eh::Settings.current.data['repositories'].each_with_index do |repository, index|
29
- repository['current'] = (index + 1) == selected
30
- end
31
- puts "Selected #{Eh::Settings.current.repository.url}"
32
- Eh::Settings.current.write
33
- end
34
- end
35
-
36
- command.desc 'add a repository to the config: eh repository add URL DIR USERNAME PASSWORD'
37
- command.command :add do |command|
38
- command.action do |global_options, options, args|
39
- if args.length != 4
40
- raise "Need exactly 4 arguments: URL, DIR, USERNAME, PASSWORD"
41
- end
42
- Eh::Settings.current.data['repositories'] ||= []
43
-
44
- # check if same repo already exists
45
- exists = Eh::Settings.current.data['repositories'].any? do |repository|
46
- repository['url'] == args[0]
47
- end
48
- if exists
49
- raise "Already configured repository for '#{args[0]}'"
50
- end
51
-
52
- Eh::Settings.current.data['repositories'] << {
53
- 'url' => args[0],
54
- 'dir' => args[1],
55
- 'deploy_username' => args[2],
56
- 'deploy_password' => args[3],
57
- 'current' => (Eh::Settings.current.data['repositories'].length == 0)
58
- }
59
- Eh::Settings.current.write
60
- end
61
- end
62
-
63
-
64
- command.desc 'remove a repository from the config: eh repository remove INDEX'
65
- command.command :remove do |command|
66
- command.action do |global_options, options, args|
67
-
68
- if args.length != 1
69
- raise "Need exactly 1 arguments: index"
70
- end
71
- selected = args[0].to_i
72
-
73
- if Eh::Settings.current.repositories[selected - 1].nil?
74
- raise "No repository with index #{selected}"
75
- end
76
-
77
- Eh::Settings.current.data['repositories'].delete_at(selected - 1)
78
- Eh::Settings.current.write
79
- end
80
- end
81
- end
1
+ desc "manage repositories"
2
+
3
+ command :repository do |command|
4
+ command.desc "Lists all avaiable repositories"
5
+ command.command :list do |command|
6
+ command.action do |global_options,options,args|
7
+
8
+ Eh::Settings.current.repositories.each_with_index do |repository, index|
9
+ if repository.current?
10
+ puts "#{index + 1}: #{repository.url} (current)"
11
+ else
12
+ puts "#{index + 1}: #{repository.url}"
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ command.desc "selects a repository: eh repository select INDEX"
19
+ command.command :select do |command|
20
+ command.action do |global_options,options,args|
21
+ if Eh::Settings.current.repositories.length == 0
22
+ raise "No repository configured so far"
23
+ end
24
+ if args.length != 1
25
+ raise "Need exactly 1 arguments: index"
26
+ end
27
+ selected = args[0].to_i
28
+ Eh::Settings.current.data['repositories'].each_with_index do |repository, index|
29
+ repository['current'] = (index + 1) == selected
30
+ end
31
+ puts "Selected #{Eh::Settings.current.repository.url}"
32
+ Eh::Settings.current.write
33
+ end
34
+ end
35
+
36
+ command.desc 'add a repository to the config: eh repository add URL DIR USERNAME PASSWORD'
37
+ command.command :add do |command|
38
+ command.action do |global_options, options, args|
39
+ if args.length != 4
40
+ raise "Need exactly 4 arguments: URL, DIR, USERNAME, PASSWORD"
41
+ end
42
+ Eh::Settings.current.data['repositories'] ||= []
43
+
44
+ # check if same repo already exists
45
+ exists = Eh::Settings.current.data['repositories'].any? do |repository|
46
+ repository['url'] == args[0]
47
+ end
48
+ if exists
49
+ raise "Already configured repository for '#{args[0]}'"
50
+ end
51
+
52
+ Eh::Settings.current.data['repositories'] << {
53
+ 'url' => args[0],
54
+ 'dir' => args[1],
55
+ 'deploy_username' => args[2],
56
+ 'deploy_password' => args[3],
57
+ 'current' => (Eh::Settings.current.data['repositories'].length == 0)
58
+ }
59
+ Eh::Settings.current.write
60
+ end
61
+ end
62
+
63
+
64
+ command.desc 'remove a repository from the config: eh repository remove INDEX'
65
+ command.command :remove do |command|
66
+ command.action do |global_options, options, args|
67
+
68
+ if args.length != 1
69
+ raise "Need exactly 1 arguments: index"
70
+ end
71
+ selected = args[0].to_i
72
+
73
+ if Eh::Settings.current.repositories[selected - 1].nil?
74
+ raise "No repository with index #{selected}"
75
+ end
76
+
77
+ Eh::Settings.current.data['repositories'].delete_at(selected - 1)
78
+ Eh::Settings.current.write
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,98 @@
1
+ module Eh
2
+ module Proxy
3
+ require_relative 'settings/git'
4
+ require_relative 'settings/svn'
5
+ require_relative 'settings/shell'
6
+
7
+ class Proxy
8
+ def initialize(stage_name, verbose)
9
+ @stage_name = stage_name
10
+ @verbose = verbose
11
+ end
12
+
13
+ def set(name = nil)
14
+ proxy = find_proxy_by_name(name) || find_default_proxy
15
+ if proxy.nil?
16
+ raise "No proxy found"
17
+ end
18
+ Eh::Proxy::Settings::Git.new(stage, verbose).set(proxy.url)
19
+ Eh::Proxy::Settings::Svn.new(stage, verbose).set(proxy.url)
20
+ Eh::Proxy::Settings::Shell.new(stage, verbose).set(proxy.url)
21
+ end
22
+
23
+ def unset
24
+ Eh::Proxy::Settings::Git.new(stage, verbose).unset
25
+ Eh::Proxy::Settings::Svn.new(stage, verbose).unset
26
+ Eh::Proxy::Settings::Shell.new(stage, verbose).unset
27
+ end
28
+
29
+ def remove(name)
30
+ proxy = find_proxy_by_name(name)
31
+ if proxy.nil?
32
+ raise "No proxy with name #{name}"
33
+ end
34
+
35
+ Eh::Settings.current.data['proxies'].reject! { |json| json['name'] == name}
36
+ Eh::Settings.current.write
37
+ end
38
+
39
+ def add(name, url)
40
+ if name.nil? || url.nil?
41
+ raise "Please provide name and url"
42
+ end
43
+ if find_proxy_by_name(name) || find_proxy_by_url(url)
44
+ raise "Already configured proxy for '#{name} -> #{url}'"
45
+ end
46
+
47
+ Eh::Settings.current.data['proxies'] << {
48
+ 'url' => url,
49
+ 'name' => name,
50
+ 'default' => (Eh::Settings.current.proxies.length == 0)
51
+ }
52
+ Eh::Settings.current.write
53
+ end
54
+
55
+ def select(name)
56
+ proxy = find_proxy_by_name(name)
57
+ if proxy.nil?
58
+ raise "No proxy found with name #{name}"
59
+ end
60
+
61
+ Eh::Settings.current.data['proxies'].each do |json|
62
+ json['default'] = (json['name'] == name)
63
+ end
64
+ Eh::Settings.current.write
65
+ end
66
+
67
+ def list
68
+ Eh::Settings.current.proxies.each do |proxy|
69
+ puts proxy.label
70
+ end
71
+ end
72
+
73
+ private
74
+ attr_reader :stage_name, :verbose
75
+
76
+ def stage
77
+ @stage ||= Deployer::Stage.load(stage_name, stage_path)
78
+ end
79
+
80
+ def stage_path
81
+ File.join(Eh::Settings.current.stages_dir, "#{stage_name}.yml")
82
+ end
83
+
84
+ def find_proxy_by_name(name)
85
+ Eh::Settings.current.proxies.find { |proxy| proxy.name == name }
86
+ end
87
+
88
+ def find_proxy_by_url(url)
89
+ Eh::Settings.current.proxies.find { |proxy| proxy.url == url }
90
+ end
91
+
92
+ def find_default_proxy
93
+ Eh::Settings.current.proxies.find { |proxy| proxy.default }
94
+ end
95
+
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,37 @@
1
+ module Eh::Proxy::Settings
2
+ class Git
3
+ def initialize(stage, verbose = true)
4
+ @stage = stage
5
+ @verbose = verbose
6
+ end
7
+
8
+ def set(value)
9
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
10
+ executor.execute(set_command(value), abort_on_error: false)
11
+ end
12
+ end
13
+
14
+ def unset
15
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
16
+ executor.execute(unset_command, abort_on_error: false)
17
+ end
18
+ end
19
+
20
+
21
+ private
22
+
23
+ def verbose?
24
+ @verbose
25
+ end
26
+
27
+ attr_reader :stage
28
+
29
+ def unset_command
30
+ "git config --global --unset http.proxy ; git config --global --unset https.proxy"
31
+ end
32
+
33
+ def set_command(value)
34
+ "git config --global http.proxy http://#{value} ; git config --global https.proxy https://#{value}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,46 @@
1
+ module Eh::Proxy::Settings
2
+ class Shell
3
+ def initialize(stage, verbose = true)
4
+ @stage = stage
5
+ @verbose = verbose
6
+ end
7
+
8
+ def set(value)
9
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
10
+ executor.execute(set_command(value), abort_on_error: false)
11
+
12
+ end
13
+ end
14
+
15
+ def unset
16
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
17
+ executor.execute(unset_command, abort_on_error: false)
18
+ end
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def proxy_file
25
+ '~/.proxy'
26
+ end
27
+
28
+ def verbose?
29
+ @verbose
30
+ end
31
+
32
+ attr_reader :stage
33
+
34
+ def unset_command
35
+ "rm -f #{proxy_file} ; touch #{proxy_file}"
36
+ end
37
+
38
+ def set_command(value)
39
+ "echo '#{set_content(value)}' > #{proxy_file}"
40
+ end
41
+
42
+ def set_content(value)
43
+ "export http_proxy=#{value}\nexport https_proxy=#{value}"
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,61 @@
1
+ require 'tempfile'
2
+ require 'parseconfig'
3
+ module Eh::Proxy::Settings
4
+
5
+ class Svn
6
+ def initialize(stage, verbose = true)
7
+ @stage = stage
8
+ @verbose = verbose
9
+ end
10
+
11
+ def unset
12
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
13
+ executor.download("~/.subversion/servers", temporary_config_file)
14
+ config = ParseConfig.new(temporary_config_file)
15
+
16
+ config['global'].delete('http-proxy-host')
17
+ config['global'].delete('http-proxy-port')
18
+ config['global'].delete('http-proxy-username')
19
+ config['global'].delete('http-proxy-password')
20
+ File.open(temporary_config_file, 'w') do |file|
21
+ config.write(file, false)
22
+ end
23
+ executor.upload(temporary_config_file, "~/.subversion/servers")
24
+ end
25
+
26
+ end
27
+
28
+ def set(value)
29
+ uri = URI.parse("http://#{value}")
30
+
31
+ Deployer::Executor.new(stage, verbose: verbose?) do |executor|
32
+ executor.download("~/.subversion/servers", temporary_config_file)
33
+ config = ParseConfig.new(temporary_config_file)
34
+ config['global']['http-proxy-host'] = uri.host
35
+ config['global']['http-proxy-port'] = uri.port
36
+ File.open(temporary_config_file, 'w') do |file|
37
+ config.write(file, false)
38
+ end
39
+ executor.upload(temporary_config_file, "~/.subversion/servers")
40
+ end
41
+
42
+ end
43
+
44
+ private
45
+
46
+ def verbose?
47
+ @verbose
48
+ end
49
+
50
+ attr_reader :stage
51
+
52
+ def unset_command
53
+
54
+ end
55
+
56
+ def temporary_config_file
57
+ @temporary_config_file ||= Dir::Tmpname.make_tmpname([Dir.tmpdir, 'subversion_servers'], nil)
58
+ end
59
+
60
+ end
61
+ end