deploy-agent 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 3aadc6e314dba14514c9015a73252decf65bb13f
4
- data.tar.gz: fc71bae393b1edeff76eaee62e131f62f49fe989
3
+ metadata.gz: 5e1c889d6e8699972cf1452a86c42d9be633cc65
4
+ data.tar.gz: dd2f460d6e6d8fbaeac3da023719f7a5c04b62fe
5
5
  SHA512:
6
- metadata.gz: 10e1cd86b9db41700f5d9aa7013f12af2e6d159f6ba8e2645e46c8691a36ca33fba613e56540bcb7a53aa8d0c3d1d8e91a3a3fe59994a7c0d4caf45a8478daa6
7
- data.tar.gz: cbbb62930a9504f883e51e9fca32ee824760902d333cd28de98a92eee7d645631d714dc86490b0d786848a48ea7a7b124bb5b985a35e05152a56d285711bb13f
6
+ metadata.gz: 6eb91a06b4226c38fbd7e5ca0f8f28897a36e3c19e4079e52a2f6b1702e3d67883fa2561840977d024ecf3f28815e5f29b39793b8f39a30fb8d1a7f175c00259
7
+ data.tar.gz: 9e3bca578a01b6b578c48a353f447db801f70d661b1b395a120467613f0990b3e3df516c99f315f550115f5b76964184c12b154eb3e312bf185c339def5af10d
data/lib/deploy_agent.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'deploy_agent/certificate_manager'
1
+ require 'deploy_agent/configuration_generator'
2
2
  require 'deploy_agent/server_connection'
3
3
  require 'deploy_agent/destination_connection'
4
4
  require 'deploy_agent/cli'
@@ -13,7 +13,7 @@ module DeployAgent
13
13
  end
14
14
 
15
15
  def setup
16
- CertificateManager.new.generate_certificate
16
+ ConfigurationGenerator.new.configure
17
17
  end
18
18
 
19
19
  def restart
@@ -0,0 +1,119 @@
1
+ require 'readline'
2
+ require 'net/https'
3
+ require 'json'
4
+ require 'fileutils'
5
+
6
+ module DeployAgent
7
+ class ConfigurationGenerator
8
+ attr_accessor :claim_code
9
+
10
+ def configure
11
+ if File.file?(CERTIFICATE_PATH) || File.file?(ACCESS_PATH)
12
+ puts "***************************** WARNING *****************************"
13
+ puts "The Deploy agent has already been configured. Are you sure you wish"
14
+ puts "to remove the existing configuration and generate a new one?"
15
+ puts
16
+
17
+ response = ask("Remove existing configuration? [no]: ")
18
+ Process.exit(1) unless response == 'yes'
19
+ puts
20
+ end
21
+
22
+ generate_certificate
23
+ generate_access_list
24
+
25
+ puts
26
+ puts "You can now associate this Agent with your Deploy account."
27
+ puts "Browse to Settings -> Agents in your account and enter the code below:"
28
+ puts
29
+ puts " >> #{claim_code} <<"
30
+ puts
31
+ puts "You can start the agent using the following command:"
32
+ puts
33
+ puts " # deploy-agent start"
34
+ puts
35
+ end
36
+
37
+ def generate_certificate
38
+ puts 'This tool will assist you in generating a certificate for your Deploy agent.'
39
+ puts 'Please enter a name for this agent.'
40
+
41
+ name = ask("Agent Name: ")
42
+ if name.length < 2
43
+ puts "Name must be at least 2 characters."
44
+ Process.exit(1)
45
+ else
46
+ uri = certificate_uri
47
+ Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
48
+ request = Net::HTTP::Post.new(uri)
49
+ request.body = {:name => name}.to_json
50
+ request['Content-Type'] = 'application/json'
51
+ response = http.request request
52
+ response_hash = JSON.parse(response.body)
53
+ if response_hash['status'] == 'success'
54
+ self.claim_code = response_hash['data']['claim_code']
55
+
56
+ File.write(CERTIFICATE_PATH, response_hash['data']['certificate'])
57
+ File.write(KEY_PATH, response_hash['data']['private_key'])
58
+ puts
59
+ puts "Certificate has been successfully generated and installed."
60
+ puts
61
+ else
62
+ puts
63
+ puts "An error occurred obtaining a certificate."
64
+ puts "Please contact support, quoting the debug information below:"
65
+ puts
66
+ puts response.inspect
67
+ puts response.body
68
+ puts
69
+ Process.exit(1)
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def generate_access_list
76
+ puts "By default this utility only allows connections from DeployHQ to localhost."
77
+ puts "To to deploy to other hosts or networks enter their addresses below:\n"
78
+
79
+ user_hosts = []
80
+ loop do
81
+ host = ask("IP Address [leave blank to finish]: ")
82
+ if host.empty?
83
+ break
84
+ else
85
+ user_hosts << host
86
+ end
87
+ end
88
+
89
+ begin
90
+ access_list = File.open(ACCESS_PATH, 'w')
91
+
92
+ # Add header and localhost entries
93
+ access_list.write("# This file contains a list of host and network addresses the Deploy agent\n# will allow connections to. Add IPs or networks (CIDR format) as needed.\n\n# Allow deployments to localhost\n127.0.0.1\n::1\n")
94
+
95
+ # Add user entries (if any)
96
+ access_list.write("\n# User defined destinations\n")
97
+ user_hosts.each do |host|
98
+ access_list.write("#{host}\n")
99
+ end
100
+ ensure
101
+ access_list.close if access_list
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def ask(question)
108
+ Readline.completion_proc = Proc.new {}
109
+ Readline.readline(question, true)
110
+ rescue Interrupt => e
111
+ puts
112
+ Process.exit(1)
113
+ end
114
+
115
+ def certificate_uri
116
+ URI(ENV['DEPLOY_AGENT_CERTIFICATE_URL'] || 'https://api.deployhq.com/api/v1/agents/create')
117
+ end
118
+ end
119
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deploy-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aTech Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-30 00:00:00.000000000 Z
11
+ date: 2018-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.5.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.16'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.16'
55
69
  description: This gem allows you to configure a secure proxy through which Deploy
56
70
  can forward connections
57
71
  email:
@@ -65,8 +79,8 @@ files:
65
79
  - ca.crt
66
80
  - lib/deploy_agent.rb
67
81
  - lib/deploy_agent/agent.rb
68
- - lib/deploy_agent/certificate_manager.rb
69
82
  - lib/deploy_agent/cli.rb
83
+ - lib/deploy_agent/configuration_generator.rb
70
84
  - lib/deploy_agent/destination_connection.rb
71
85
  - lib/deploy_agent/server_connection.rb
72
86
  homepage: https://www.deployhq.com/
@@ -88,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
102
  version: '0'
89
103
  requirements: []
90
104
  rubyforge_project:
91
- rubygems_version: 2.6.11
105
+ rubygems_version: 2.6.14
92
106
  signing_key:
93
107
  specification_version: 4
94
108
  summary: The Deploy agent
@@ -1,88 +0,0 @@
1
- gem 'rb-readline', '0.5.4'
2
- require 'readline'
3
- require 'net/https'
4
- require 'json'
5
- require 'fileutils'
6
-
7
- module DeployAgent
8
- class CertificateManager
9
-
10
- def certificate_uri
11
- URI(ENV['DEPLOY_AGENT_CERTIFICATE_URL'] || 'https://api.deployhq.com/api/v1/agents/create')
12
- end
13
-
14
- def generate_certificate
15
- FileUtils.mkdir_p(CONFIG_PATH)
16
- unless File.file?(ACCESS_PATH)
17
- File.write(ACCESS_PATH, "# This file contains a list of host and network addresses the Deploy agent\n # will allow connections to. Add IPs or networks (CIDR format) as needed.\n\n# Allow deployments to localhost\n127.0.0.1\n::1\n")
18
- end
19
-
20
- puts 'This tool will assist you in generating a certificate for your Deploy agent.'
21
- puts
22
- if File.file?(CERTIFICATE_PATH)
23
- puts "***************************** WARNING *****************************"
24
- puts "The Deploy agent has already been configured. Are you sure you wish"
25
- puts "to remove the existing certificate and generate a new one?"
26
- puts
27
- Readline.completion_proc = Proc.new {}
28
- begin
29
- response = Readline.readline("Remove existing certificate? [no]: ", true)
30
- rescue Interrupt => e
31
- puts
32
- Process.exit(1)
33
- end
34
- unless response == 'yes'
35
- Process.exit(1)
36
- end
37
- puts
38
- end
39
- puts 'Please enter a name for this agent.'
40
- Readline.completion_proc = Proc.new {}
41
- begin
42
- name = Readline.readline("Agent Name: ", true)
43
- rescue Interrupt => e
44
- puts
45
- Process.exit(1)
46
- end
47
- if name.length < 2
48
- puts "Name must be at least 2 characters."
49
- Process.exit(1)
50
- else
51
- uri = certificate_uri
52
- Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
53
- request = Net::HTTP::Post.new(uri)
54
- request.body = {:name => name}.to_json
55
- request['Content-Type'] = 'application/json'
56
- response = http.request request
57
- response_hash = JSON.parse(response.body)
58
- if response_hash['status'] == 'success'
59
- File.write(CERTIFICATE_PATH, response_hash['data']['certificate'])
60
- File.write(KEY_PATH, response_hash['data']['private_key'])
61
- puts
62
- puts "Certificate has been successfully generated and installed."
63
- puts
64
- puts "You can now associate this Agent with your Deploy account."
65
- puts "Browse to Settings -> Agents in your account and enter the code below:"
66
- puts
67
- puts " >> #{response_hash['data']['claim_code']} <<"
68
- puts
69
- puts "You can start the agent using the following command:"
70
- puts
71
- puts " # deploy-agent start"
72
- puts
73
- else
74
- puts
75
- puts "An error occurred obtaining a certificate."
76
- puts "Please contact support, quoting the debug information below:"
77
- puts
78
- puts response.inspect
79
- puts response.body
80
- puts
81
- Process.exit(1)
82
- end
83
- end
84
- end
85
- end
86
-
87
- end
88
- end