avst-wizard 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZWU2YzdhN2Y2NjE3MTlmZDI0NDJlZTVjZjk4YzQwNGJjNWQ2ZjFkOQ==
4
+ OTdjNGJlNjNiNTM5ODkzN2MyOWY1YTMzZWYzYTRmYjkyNDJkNGRjYw==
5
5
  data.tar.gz: !binary |-
6
- ZmI4ZjA2ODcxMTNiYzk0NDg0NTM3YjNjNzEzYWZkZWVmOTg0NWZmNA==
6
+ MGVjMGY3NGMwZmQ2NTk1YzBlYWNjNTgzNGI3YTEwODAxM2FlZTcwZg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTdiN2YzM2RmZjBhNTRlOWZjYjk2ZjQxMjlkY2Q4NjNiMTE1ZjFhNzdjNWZl
10
- MmJmMTM5ZDhlZWFjZTdiNzkyODk0ZjkwNTkxYmZhOTk4ZWMxMDM1NWQ0ODA1
11
- YTQxNDVhMzFiNjBlY2QxMmQ5OTI1NjVjYWIxMTllOGMyYzIwN2Q=
9
+ YmRkNzllMmExZjBmYTVmMTcwMTQzYTExMTI0Yzg3MWUzYTlmNTRlYTdkNGVh
10
+ MTk5NmJkMWM0MjFjNGY3NGU0YzFiMDc4NzMzNzQxN2IyNWM1Zjg0ZWQ4YmUy
11
+ NmQ5MzRmMWJkNjc2OGJmZTFkOGFlMzlkMzVjNzQ3NGE4Nzg0MDk=
12
12
  data.tar.gz: !binary |-
13
- NmY3ZmFjMDU1NDIxOTQ2ZDA2NzEwMThhMDhlN2Y1NjU1Njg1NGFjMmYyMjQz
14
- ZGU5MmI2ZmFkMTcwNGQzNGIwZTI0NWU3MGQyOTEzNWE1Y2ExZDFhZTdiZjk1
15
- ZWFjM2JhZjgzY2I5ZDYyNTMyMWEyOGI2MzhjN2I3ZDdkMTI2NzY=
13
+ ODJkNmQ1NmYwNjE3MWNmODZlMTkxZjU4MzI0Nzg0MGY0YjNjYzE0ZmZjOTg3
14
+ MWM4OWJkYmVkNjUwMjFhYzFlYTUzOWZiNjYyOGFkYTIwZDJmZjgyNzc4NDNi
15
+ YTM2ODQ4YTRiNzYzM2FjNDhhOTdlOTkzNDc1YzY2ZjFmMmM1OGE=
data/README.md CHANGED
@@ -26,6 +26,7 @@ avst-wizard --hostname hostname --product_type product_type --base_url url --hie
26
26
  - hiera_config - custom hiera.yaml file, defaults to hiera.yaml in project root
27
27
  - custom_config - file with required params setup, defaults to config/config.yaml
28
28
  - ops - Prints out required parameters to set for specified product
29
+ -p, --use_tomcat_port PORT - Use tomcat port to connect to the application
29
30
 
30
31
  ## Default usage and configuration
31
32
 
data/avst-wizard.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "avst-wizard"
7
- spec.version = '0.0.24'
7
+ spec.version = '0.0.25'
8
8
  spec.authors = ["Martin Brehovsky"]
9
9
  spec.email = ["mbrehovsky@adaptavist.com"]
10
10
  spec.summary = %q{Avstwizard}
data/bin/avst-wizard CHANGED
@@ -37,6 +37,7 @@ Options:
37
37
  -b, --base_url BASE_URL Url where the product is accessible
38
38
  -c, --hiera_config CONFIG Hiera config file
39
39
  -f, --custom_config CUSTOM Contains key-values that will be available to hiera to configure stages [default: #{avst_wizard_base}/config/config.yaml]
40
+ -p, --use_tomcat_port PORT Use tomcat port to connect to the application
40
41
  -o, --ops Shows params required to setup the atlassian app
41
42
  -v, --version VERSION Version of atlassian app, if not specified, default config is picked
42
43
  DOCOPT
@@ -52,6 +53,8 @@ end
52
53
  hostname = options["--hostname"]
53
54
  product_type = options["--product_type"]
54
55
  base_url = options["--base_url"]
56
+ use_tomcat_port = options["--use_tomcat_port"]
57
+
55
58
  hiera_config = options["--hiera_config"]
56
59
  custom_config = options["--custom_config"]
57
60
  ops = options["--ops"]
@@ -135,7 +138,15 @@ unless base_url
135
138
  end
136
139
  begin
137
140
  url_required_part = conf.get_config("url_required_part", false)
138
- runner = AvstWizard::AvstWizard.new(base_url, required_config, url_required_part)
141
+ if use_tomcat_port
142
+ host_url = base_url
143
+ base_url = "http://localhost:#{use_tomcat_port}"
144
+ puts "Using direct tomcat connection to #{base_url}"
145
+ else
146
+ host_url = nil
147
+ puts "Going via #{base_url}"
148
+ end
149
+ runner = AvstWizard::AvstWizard.new(base_url, required_config, url_required_part, host_url)
139
150
 
140
151
 
141
152
  # wait for app to start
@@ -249,6 +260,7 @@ begin
249
260
  # In case something went wrong on the way
250
261
  rescue Exception => e
251
262
  message = e.message.force_encoding("utf-8")
263
+ puts e.backtrace.inspect
252
264
  abort(e.message.red)
253
265
  end
254
266
 
data/lib/avst-wizard.rb CHANGED
@@ -24,63 +24,88 @@ module AvstWizard
24
24
 
25
25
  attr_writer :atl_token
26
26
 
27
- def initialize(url, required_config = {}, url_required_part=nil)
27
+ def initialize(url, required_config = {}, url_required_part=nil, host_url)
28
28
  @url = url
29
29
  @cookie = ""
30
30
  @current_url = ""
31
31
  @atl_token = ""
32
32
  @required_config = required_config
33
33
  @url_required_part = url_required_part
34
+ @host_url = host_url
34
35
  end
35
36
 
36
37
  # Does GET requests to url, follows redirects, stores cookies and xsrf.token if present
37
- def get_stage_and_fetch_cookie(url = @url , limit = 10)
38
+ def get_stage_and_fetch_cookie(request_url = @url , limit = 10)
38
39
  # You should choose better exception.
39
40
  raise ArgumentError, 'HTTP redirect too deep' if limit <= 0
40
- puts "Trying to GET #{url}".yellow
41
- url = URI.parse(url)
41
+ puts "Trying to GET #{request_url}".yellow
42
+ url = URI.parse(request_url)
42
43
  req = Net::HTTP::Get.new(url.request_uri)
43
44
  if @cookie != ""
44
45
  req['Cookie'] = get_cookie
45
46
  end
47
+ if @host_url
48
+ req.add_field("Host", @host_url)
49
+ end
46
50
  use_ssl = false
47
51
  if url.instance_of? URI::HTTPS
48
52
  use_ssl = true
49
53
  end
50
- response = Net::HTTP.start(url.host, url.port, use_ssl: use_ssl, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http| http.request(req) }
51
- if response['set-cookie']
52
- @cookie = response['set-cookie'].split('; ')[0]
53
- response['set-cookie'].split(';').each do |part|
54
- if ((part and part.include? "atl.xsrf.token") and (part.match(/atl.xsrf.token=(.*)/)))
55
- # parse only the token
56
- @atl_token = part.match(/atl.xsrf.token=(.*)/).captures[0]
57
- break
54
+ begin
55
+ response = Net::HTTP.start(url.host, url.port, use_ssl: use_ssl, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http| http.request(req) }
56
+ if response['set-cookie']
57
+ @cookie = response['set-cookie'].split('; ')[0]
58
+ response['set-cookie'].split(';').each do |part|
59
+ if ((part and part.include? "atl.xsrf.token") and (part.match(/atl.xsrf.token=(.*)/)))
60
+ # parse only the token
61
+ @atl_token = part.match(/atl.xsrf.token=(.*)/).captures[0]
62
+ break
63
+ end
58
64
  end
65
+ puts "Found new cookie #{get_cookie}".yellow
59
66
  end
60
- puts "Found new cookie #{get_cookie}".yellow
61
- end
62
- if response['location']
63
- redirection_url = compose_redirection_url(response['location'])
64
- puts "Redirected to: #{redirection_url}".yellow
65
- else
66
- @current_url = url.request_uri
67
- puts "Ended in: #{@current_url}".yellow
68
- end
69
- case response
70
- when Net::HTTPSuccess then response.code.to_i
71
- when Net::HTTPRedirection then get_stage_and_fetch_cookie(redirection_url, limit - 1)
72
- else
73
- puts response.body
74
- puts response.code.to_s
75
- response.code.to_i
67
+ if response['location']
68
+ redirection_url = compose_redirection_url(response['location'])
69
+ puts "Redirected to: #{redirection_url}".yellow
70
+ else
71
+ @current_url = url.request_uri
72
+ puts "Ended in: #{@current_url}".yellow
73
+ end
74
+ case response
75
+ when Net::HTTPSuccess then response.code.to_i
76
+ when Net::HTTPRedirection then get_stage_and_fetch_cookie(redirection_url, limit - 1)
77
+ else
78
+ puts response.body
79
+ puts response.code.to_s
80
+ response.code.to_i
81
+ end
82
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ECONNREFUSED,
83
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
84
+ @current_url = request_url
85
+ 404
76
86
  end
77
87
  end
78
88
 
79
89
  def compose_redirection_url(location)
90
+
91
+ # in case we do tomcat and the redirection returns http*://host_url/path
92
+ if @host_url and location.include? @host_url and location.start_with? "http"
93
+ begin
94
+ uri = URI::parse(location)
95
+ location = uri.path
96
+ rescue Exception => e
97
+ puts "Can not parse URI from #{location}"
98
+ end
99
+ end
80
100
  # in case response['location'] is not full url we need to compose it
81
101
  # if it does contain base_url we assume it is ok
82
102
  if location.include? @url
83
- location
103
+ location
104
+ # in case redirection contains the startup string, the system has not started yet
105
+ elsif location.include? "startup.jsp?returnTo="
106
+ puts "System starting up staying on #{@url}"
107
+ sleep(10)
108
+ @url
84
109
  else
85
110
  # in Jira 7.1.7 location is databaseSetup.jspa not secure/databaseSetup.jspa
86
111
  if @url_required_part and !location.include? "/#{@url_required_part}/"
@@ -91,6 +116,7 @@ module AvstWizard
91
116
  "#{@url}#{location}"
92
117
  end
93
118
  end
119
+
94
120
  end
95
121
 
96
122
  # add atl_token to cookie in case it is present
@@ -122,6 +148,9 @@ module AvstWizard
122
148
  if url.instance_of? URI::HTTPS
123
149
  use_ssl = true
124
150
  end
151
+ if @host_url
152
+ req.add_field("Host", @host_url)
153
+ end
125
154
  response = Net::HTTP.start(url.host, url.port, use_ssl: use_ssl, verify_mode: OpenSSL::SSL::VERIFY_NONE) { |http| http.request(req) }
126
155
  # TODO: is it possible that this might be a redirect? Can Net::HTTP follow redirects automatically?
127
156
  if response.code.to_i != 200
@@ -177,6 +206,9 @@ module AvstWizard
177
206
  if uri.instance_of? URI::HTTPS
178
207
  use_ssl = true
179
208
  end
209
+ if @host_url
210
+ req.add_field("Host", @host_url)
211
+ end
180
212
  Net::HTTP.start(uri.hostname, uri.port, use_ssl: use_ssl, verify_mode: OpenSSL::SSL::VERIFY_NONE, :read_timeout => 1000) do |http|
181
213
  response = http.request(req)
182
214
  puts "Response: #{response.inspect}".yellow
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avst-wizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Brehovsky
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-16 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler