avst-wizard 0.0.22

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7336268a84e10c7e0effc25dec1ecb0f2f94fa9a
4
+ data.tar.gz: d0b31a0eb531083c8fa1144f8ccee9f9e3dac378
5
+ SHA512:
6
+ metadata.gz: c8de9471d223b86deabee4b37f31009991adfc79680d37e1c65b1f8b3d5de4625b618fb4d89cb22aa5c90a5b291031340940c67bc221707fdfdc033972a4ef50
7
+ data.tar.gz: bb5ddf1a1c706db1c01bdf99cef73cf210b38f7f4e5335b39003970a0c0f6605f7393c17fc955af50b1cbc4f1e6ad02510ac3e04269faa2ea9297d91bab1d0ed
@@ -0,0 +1,11 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 4
6
+
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
@@ -0,0 +1,23 @@
1
+ .idea
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ *.bundle
20
+ *.so
21
+ *.o
22
+ *.a
23
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in avst-wizard.gemspec
4
+ gemspec
@@ -0,0 +1,191 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+
179
+ Copyright 2015 Adaptavist.com Ltd.
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
@@ -0,0 +1,134 @@
1
+ # Avst::Wizard
2
+
3
+ Executable gem that completes wizard of Atlassian products.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'avst-wizard'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install avst-wizard
18
+
19
+ ## Usage
20
+
21
+ avst-wizard --hostname hostname --product_type product_type --base_url url --hiera_config config --custom_config custom_config --ops
22
+
23
+ - hostname - will reference custom hiera config
24
+ - product_type - the product, one of (bamboo, confluence, crowd, fisheye, jira, stash)
25
+ - url - url to access the instance, http://jira.vagrant or http://jira.vagrant:8090
26
+ - hiera_config - custom hiera.yaml file, defaults to hiera.yaml in project root
27
+ - custom_config - file with required params setup, defaults to config/config.yaml
28
+ - ops - Prints out required parameters to set for specified product
29
+
30
+ ## Default usage and configuration
31
+
32
+ Each Atlassian app requires in default usage parameters. The list per product_type can be displayed while running
33
+
34
+ ```
35
+ avst-wizard --product_type "product_type" --ops
36
+ ```
37
+
38
+ In the file defined by "custom_config" you have to specify all required params that will be passed to hiera config.
39
+
40
+ ## Advanced configuration
41
+
42
+ Stages configuration is stored in hiera. Default stages flow is provided with the app and stored in config/hiera/"product_type"/default.yaml. You can specify custom values by providing them in "hostname".yaml file in "product_type" folder of hiera config folder. You can overwrite/add any value in default.yaml config via user_data hash.
43
+
44
+ Look at examples provided for details. The examples are all configuring the app to use local mysql database.
45
+
46
+ ### Config details
47
+
48
+ Each wizard consist of stages.
49
+
50
+ #### Simple setup
51
+ Stage is uniquely identifiable by request_uri part of url without params.
52
+ So http://wiki.vagrant/console/setup/setuplicense.action will be identified by /console/setup/setuplicense.action
53
+ In case this is not possible and two stages have the same url, refer to complex setup.
54
+
55
+ For each stage there is a POST request that will submit a form. You can specify the "post_url" per stage and "values" that will be submitted at this stage.
56
+
57
+ default.yaml
58
+
59
+ ```
60
+ stages:
61
+ '/setup/setupLicense.action':
62
+ post_url: 'setup/validateLicense.action'
63
+ values:
64
+ licenseString: "key"
65
+ app_name: "testing"
66
+ ```
67
+
68
+ "hostname".yaml
69
+
70
+ ```
71
+ user_data:
72
+ '/setup/setupLicense.action':
73
+ values:
74
+ licenseString: |
75
+ AAABEg0ODAoPeNp9kMtugzA
76
+ ```
77
+
78
+ Will result into POST call to "url"/setup/validateLicense.action with params licenseString="AAABEg0ODAoPeNp9kMtugzA" and app_name="testing" for stage accessible via url "url"/setup/setupLicense.action
79
+
80
+ #### Complex setup
81
+
82
+ In case the stage can not be identified uniquely via string, so some ajax calls are done or whatever, you can mark the stage with complex: true and specify substages. Those are uniquely identified by "key=value" pair that has to be present as attribute and value of an element in the html code of the stage.
83
+
84
+ ```
85
+ '/setup':
86
+ complex: true
87
+ substages:
88
+ 'id="database"':
89
+ parse_atl_token: true
90
+ post_url: 'setup'
91
+ values:
92
+ type: "mysql"
93
+ 'id="license"':
94
+ parse_atl_token: true
95
+ post_url: 'setup'
96
+ values:
97
+ 'license': '1234'
98
+ ```
99
+
100
+ This example identifies 2 substages for "url"/setup stage identified by id="database" and id="license" present as attribute and value of some element. And will result into POST request to "url"/setup with params set to type: "mysql" and POST with params 'license': '1234' accordingly.
101
+
102
+ ##### XSRF
103
+
104
+ Flag parse_atl_token: true refers to XSRF token sometimes required to submit the requests and will be parsed from the form from element with name="atl_token" from attribute value. TODO: may do this configurable...
105
+
106
+ ##### Ajax waiting for ready state from server
107
+
108
+ In case of ajax calls where the response is returned and the app is waiting for server side process to finish and only then it will redirect to next stage we can setup wait_for_next_state with param number of retries with sleep 5 sec that will wait and once done will redirect.
109
+
110
+ ## Important
111
+ In case there is proxy in front of the app, as there are stages in wizard that takes long time, make sure you set Proxy timeout to sufficient value.
112
+
113
+ ## Supported versions
114
+
115
+ Tested with versions:
116
+
117
+ - fisheye/cru - 3.4.3, 3.6.2
118
+ - crowd - 2.7.2, 2.6.4, 2.8.0, 2.8.3
119
+ - confl - 5.6.3, 5.2.5, 5.3.1, 5.8.10, 5.7.3
120
+ - bamboo - 5.7.1, 5.6.0, 5.9.4
121
+ - jira - 6.3.6, 6.2.7, 6.4.11
122
+ - bitbucket - 2.0.3, 3.6.0, 4.0.0
123
+
124
+ ## License
125
+
126
+ avst-wizard is released under the terms of the Apache 2.0 license. See LICENSE.txt
127
+
128
+ ## Contributing
129
+
130
+ 1. Fork it ( https://github.com/adaptavist/avst-wizard/fork )
131
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
132
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
133
+ 4. Push to the branch (`git push origin my-new-feature`)
134
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "avst-wizard"
7
+ spec.version = '0.0.22'
8
+ spec.authors = ["Martin Brehovsky"]
9
+ spec.email = ["mbrehovsky@adaptavist.com"]
10
+ spec.summary = %q{Avstwizard}
11
+ spec.description = %q{Avstwizard}
12
+ spec.homepage = "http://www.adaptavist.com"
13
+ spec.license = "Apache-2.0"
14
+
15
+ spec.files = `git ls-files`.split($\)
16
+ spec.executables = ["avst-wizard"]
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+
23
+ spec.add_dependency "docopt", ">= 0.5.0"
24
+ spec.add_dependency "hiera_loader", ">= 0.0.2"
25
+ spec.add_dependency "hiera-eyaml"
26
+ spec.add_dependency "colorize", ">= 0.7.3"
27
+ spec.add_dependency "nokogiri"
28
+ end
29
+
@@ -0,0 +1,249 @@
1
+ # Copyright 2015 Adaptavist.com Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'avst-wizard'
16
+ require 'hiera_loader'
17
+ require 'docopt'
18
+ require 'advanced_hash'
19
+ require 'yaml'
20
+ require 'colorize'
21
+ require 'erb'
22
+
23
+ avst_wizard_base="#{File.expand_path("../../", __FILE__)}"
24
+
25
+ # This heredoc describes the options that the application will recognise and parse: https://github.com/docopt/docopt.rb
26
+ doc = <<DOCOPT
27
+ Adaptavist Wizard
28
+
29
+ Usage:
30
+ avst-wizard [options]
31
+ avst-wizard -h | --help
32
+
33
+ Options:
34
+ -h --help Show this screen.
35
+ -n, --hostname HOST Hostname for the server
36
+ -p, --product_type PRODUCT_TYPE Type of atlassian product (jira, confluence,...)
37
+ -b, --base_url BASE_URL Url where the product is accessible
38
+ -c, --hiera_config CONFIG Hiera config file
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
+ -o, --ops Shows params required to setup the atlassian app
41
+ -v, --version VERSION Version of atlassian app, if not specified, default config is picked
42
+ DOCOPT
43
+
44
+ start_time = Time.now
45
+
46
+ begin
47
+ options = Docopt::docopt(doc)
48
+ rescue Docopt::Exit => e
49
+ abort(e.message).red
50
+ end
51
+
52
+ hostname = options["--hostname"]
53
+ product_type = options["--product_type"]
54
+ base_url = options["--base_url"]
55
+ hiera_config = options["--hiera_config"]
56
+ custom_config = options["--custom_config"]
57
+ ops = options["--ops"]
58
+ version = options["--version"]
59
+
60
+ unless product_type
61
+ abort("Please provide product_type options!!!").red
62
+ end
63
+
64
+ unless File.exists?(custom_config)
65
+ abort("ERROR: Please ensure the file #{custom_config} exists").red
66
+ end
67
+ # read config file with variables to config stages in hiera
68
+ config = YAML.load_file(custom_config)
69
+
70
+ scope = {
71
+ "::product_type" => product_type.to_s
72
+ }
73
+
74
+ if hostname
75
+ scope["::hostname"] = hostname.to_s
76
+ end
77
+
78
+ if version
79
+ scope["::version"] = version.to_s
80
+ end
81
+
82
+ # make custom_config configuration available to hiera
83
+ scope = scope.merge(config)
84
+
85
+ # create fully qualified hiera.yaml based on template, to be able to refer to config/hiera
86
+ unless hiera_config
87
+ hiera_config = "#{avst_wizard_base}/hiera.yaml"
88
+ hiera_config_template = File.read("#{avst_wizard_base}/templates/hiera.yaml.erb")
89
+ File.open("#{hiera_config}", 'w') do |f|
90
+ f.write ERB.new(hiera_config_template).result(binding)
91
+ end
92
+ end
93
+
94
+ unless File.exists?(hiera_config)
95
+ abort("ERROR: Please ensure the file #{hiera_config} exists").red
96
+ end
97
+
98
+ conf = HieraLoader.new(scope, hiera_config)
99
+ required_config = conf.get_config('required_config')
100
+
101
+ if ops
102
+ puts "Required options for product #{product_type} are:".blue
103
+ res = []
104
+ required_config.keys.each do |k|
105
+ res << required_config[k].values
106
+ end
107
+ res.flatten.each do |r|
108
+ puts "#{r}".blue
109
+ end
110
+ exit
111
+ end
112
+
113
+ # merge hiera hashes, default stage setup and custom config
114
+ stages_config = AdvancedHash.new().merge(conf.get_config("stages"))
115
+ user_data = conf.get_config("user_data", false)
116
+ unless user_data
117
+ user_data = {}
118
+ end
119
+ user_data = AdvancedHash.new().merge(user_data)
120
+ merged_data = stages_config.deep_merge(user_data)
121
+ final_stages_config = AdvancedHash.new().merge(merged_data)
122
+
123
+ unless final_stages_config
124
+ abort("ERROR: no stages config data found!!!").red
125
+ end
126
+
127
+ unless base_url
128
+ abort("Please provide base_url and product_type options!!!").red
129
+ end
130
+ begin
131
+ runner = AvstWizard::AvstWizard.new(base_url, required_config)
132
+
133
+
134
+ # wait for app to start
135
+ # until get_stage returns recognized state or time out
136
+ number_of_retries = 60
137
+ # get current state and cookies, follow redirects
138
+ code = runner.get_stage_and_fetch_cookie
139
+ to_search_for = runner.get_current_url
140
+ puts "Searching for #{to_search_for}"
141
+ if to_search_for != "/" and final_stages_config[%r{#{to_search_for}}] != nil
142
+ not_recognized = false
143
+ else
144
+ not_recognized = true
145
+ end
146
+ counter=0
147
+ while not_recognized
148
+ if counter >= number_of_retries
149
+ abort "Waited too long for app to start and return a known stage, please review stages and check that the app is running correctly on #{base_url}".red
150
+ end
151
+ # wait 5 secs
152
+ sleep(5)
153
+ counter=counter+1
154
+ # try to get recognised state
155
+ code = runner.get_stage_and_fetch_cookie
156
+ to_search_for = runner.get_current_url
157
+ puts "Looping: Searching for #{to_search_for}"
158
+ if to_search_for != "/" and code.to_i == 200 and final_stages_config[%r{#{to_search_for}}] != nil
159
+ not_recognized = false
160
+ else
161
+ puts "Stage with url #{to_search_for} not recognized, retrying in 5 secs, attempt #{counter}/#{number_of_retries}, response code #{code}".yellow
162
+ end
163
+ end
164
+
165
+ previous_url = ""
166
+ retries = 0
167
+ done = false
168
+ called = false
169
+ while !done and to_search_for != "/"
170
+ puts "Searching for config for #{to_search_for}".green
171
+ stage_config = final_stages_config[%r{#{to_search_for}}]
172
+ unless stage_config
173
+ abort("Stage #{to_search_for} not found! Plaese add it to default.yaml").red
174
+ end
175
+ previous_url = runner.get_current_url
176
+ if stage_config["complex"] && stage_config["complex"] == true
177
+ puts "Complex condition found, iterating over alternatives".yellow
178
+ # if stage is complex find the post based on substage condition
179
+ found = nil
180
+ stage_config['substages'].keys.each do |key|
181
+ puts "Searching for key: #{key}".yellow
182
+ if ( runner.values_present?(key, "#{base_url}#{to_search_for}") )
183
+ puts "Found match for: #{key}.".yellow
184
+ found = stage_config['substages'][key]
185
+ break
186
+ end
187
+ end
188
+ if !found
189
+ abort("Substage with matching condition not found for page #{to_search_for}").red
190
+ end
191
+ # in case the setup require XSRF token, parse it and store to runner
192
+ if found['parse_atl_token']
193
+ atl = runner.parse_value('name="atl_token"', "value", "#{base_url}#{to_search_for}")
194
+ runner.atl_token = atl
195
+ end
196
+ # in case post is done via ajax and the state if not updated, make GET request until the url changes,
197
+ if found['wait_for_next_state']
198
+ wait_for_next_state = found['wait_for_next_state'].to_i
199
+ else
200
+ wait_for_next_state = nil
201
+ end
202
+ url = "#{base_url}/#{found['post_url']}"
203
+ puts "Posting to #{url} with params: #{found['values']} and with retry: #{wait_for_next_state}".green
204
+ runner.post_form(found['values'], url, wait_for_next_state )
205
+ # in case no further url defined or stage marked as final, we are done
206
+ elsif stage_config["post_url"] == nil || stage_config["post_url"] == "" || stage_config["final"] == true
207
+ done = true
208
+ puts "No further stage specified. I am done here.".green
209
+ else
210
+ # in case post is done via ajax and the state if not updated, make GET request until the url changes,
211
+ if stage_config['wait_for_next_state']
212
+ wait_for_next_state = stage_config['wait_for_next_state'].to_i
213
+ else
214
+ wait_for_next_state = nil
215
+ end
216
+ # handles simple stages, that requires POST on the form and will wait for redirect
217
+ url = "#{base_url}/#{stage_config['post_url']}"
218
+ if !called
219
+ puts "Posting to #{url} with params: #{stage_config['values']}".green
220
+ runner.post_form(stage_config['values'], url, wait_for_next_state)
221
+ called=true
222
+ end
223
+ end
224
+ # check post redirect, in case it is not redirected, try if wizard redirects or wait...
225
+ if (runner.get_current_url == previous_url || wait_for_next_state)
226
+ runner.get_stage_and_fetch_cookie(base_url)
227
+ end
228
+ to_search_for = runner.get_current_url
229
+ if to_search_for == previous_url
230
+ retries=retries+1
231
+ puts "Same url as in previous step. Increasing number of retries to #{retries}/20".yellow
232
+ sleep(10)
233
+ if retries > 20
234
+ abort "Too many retries for same url, please check #{url}, post the same params as in config in case there is an error as this version may differ from supported ones".red
235
+ end
236
+ else
237
+ retries=0
238
+ called=false
239
+ end
240
+ end
241
+ # In case something went wrong on the way
242
+ rescue Exception => e
243
+ message = e.message.force_encoding("utf-8")
244
+ abort(e.message.red)
245
+ end
246
+
247
+ time_taken = ((Time.now - start_time) / 60).round(2)
248
+ puts "Finished in #{time_taken} minutes".green
249
+