aws_account_utils 0.1.0

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.
@@ -0,0 +1,80 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class ConsolidatedBilling < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def request(master_account_email, master_account_password, account_email)
13
+ logger.debug "Submitting consolidated billing request from master account #{master_account_email} to #{account_email}"
14
+ Login.new(logger, browser).execute billing_request_url,
15
+ master_account_email,
16
+ master_account_password
17
+
18
+ browser.text_field(:name => "emailaddresses").when_present.set account_email
19
+ screenshot(browser, "1")
20
+ browser.button(:class => "btn btn-primary margin-left-10").when_present.click
21
+ browser.h2(:text => /Manage Requests and Accounts/).wait_until_present
22
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
23
+ screenshot(browser, "error")
24
+ raise StandardError, "#{self.class.name} - #{e}"
25
+ end
26
+
27
+ def confirm(account_email, account_password, confirmation_link)
28
+ logger.debug "Confirming consolidated billing"
29
+
30
+ Login.new(logger, browser).execute confirmation_link,
31
+ account_email,
32
+ account_password
33
+
34
+ browser.button(:class => "btn btn-primary").when_present.click
35
+ screenshot(browser, "1")
36
+ browser.span(:text => /Accepting Request/).wait_while_present(timeout = 120)
37
+ screenshot(browser, "2")
38
+ true
39
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout, StandardError => e
40
+ screenshot(browser, "error")
41
+ page_error?
42
+ raise StandardError, "#{self.class.name} - #{e}"
43
+ end
44
+
45
+ def existing?(account_email, account_password)
46
+ logger.debug "Checking to see if Consolidated Billing is already setup"
47
+
48
+ Login.new(logger, browser).execute billing_established_url,
49
+ account_email,
50
+ account_password
51
+ browser.h2(:text => /Consolidated Billing/).wait_until_present
52
+ screenshot(browser, "1")
53
+ billing_setup?
54
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
55
+ screenshot(browser, "error")
56
+ raise StandardError, "#{self.class.name} - #{e}"
57
+ end
58
+
59
+ private
60
+ def billing_setup?
61
+ browser.text.include? 'Your account currently appears on the Consolidated Bill for the account below'
62
+ end
63
+
64
+ def page_error?
65
+ if browser.text.include? 'error'
66
+ logger.warn 'AWS webpage contains an error.'
67
+ screenshot(browser, "aws_page_error")
68
+ true
69
+ end
70
+ end
71
+
72
+ def billing_request_url
73
+ 'https://console.aws.amazon.com/billing/home?#/consolidatedbilling/sendrequest'
74
+ end
75
+
76
+ def billing_established_url
77
+ 'https://console.aws.amazon.com/billing/home?#/consolidatedbilling'
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,39 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class CustomerInformation < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def submit(account_email, account_password, customer_details)
13
+ logger.debug "Entering customer details."
14
+ Login.new(logger, browser).execute url,
15
+ account_email,
16
+ account_password
17
+ browser.link(:text => /AWS Customer Agreement/).wait_until_present
18
+ browser.select_list(:class =>'control-select ng-pristine ng-valid').when_present.select 'United States'
19
+ customer_details.each do |k,v|
20
+ browser.text_field(:name => k).when_present.set v
21
+ end
22
+ browser.checkbox(:name, /ccepted/).when_present.set
23
+ screenshot(browser, "1")
24
+ browser.button(:text=> /Continue/).when_present.click
25
+
26
+ browser.h2(:text => /Payment Information/).wait_until_present
27
+ screenshot(browser, "2")
28
+ raise StandardError if browser.text.include? 'error'
29
+ browser.input(:id => "accountId", :value => "").wait_while_present(30)
30
+ browser.input(:id => "accountId").value
31
+ rescue StandardError
32
+ screenshot(browser, 'error')
33
+ raise StandardError, 'Steps: AwsCustomerInformation Aws returned error on page.'
34
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
35
+ screenshot(browser, "error")
36
+ raise StandardError, "#{self.class.name} - #{e}"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class CustomizeUrl < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def execute(account_email, account_password, url_alias)
13
+ logger.debug "Creating URL alias: #{url_alias}"
14
+ Login.new(logger, browser).execute url,
15
+ account_email,
16
+ account_password
17
+ browser.goto url
18
+ browser.h2(:text => /Welcome to Identity and Access Management/).wait_until_present
19
+ browser.button(:text => /Customize/).when_present.click
20
+ browser.input(:id => 'alias_input').when_present.to_subtype.set url_alias
21
+ screenshot(browser, "1")
22
+ browser.button(:text => /Yes, Create/).when_present.click
23
+ screenshot(browser, "2")
24
+ browser.strong(:text => "https://#{url_alias}.signin.aws.amazon.com/console").wait_until_present
25
+ "https://#{url_alias}.signin.aws.amazon.com/console"
26
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
27
+ screenshot(browser, "error")
28
+ raise StandardError, "#{self.class.name} - #{e}"
29
+ end
30
+
31
+ private
32
+ def url
33
+ 'https://console.aws.amazon.com/iam/home?#home'
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class EmailPreferences < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def opt_out(account_email, account_password)
13
+ Login.new(logger, browser).execute url,
14
+ account_email,
15
+ account_password
16
+ browser.input(:id => 'email_preferences_optout_all_true').when_present.click
17
+ screenshot(browser, "1")
18
+ browser.input(:value => 'Save Changes').when_present.click
19
+ browser.h3(:text => /You have successfully updated your email preferences/).wait_until_present
20
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
21
+ screenshot(browser, "error")
22
+ raise StandardError, "#{self.class.name} - #{e}"
23
+ end
24
+
25
+ private
26
+ def url
27
+ 'https://aws.amazon.com/email-preferences/'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,64 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class EnterpriseSupport < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def enable(account_email,account_password)
13
+ logger.debug 'Enabling enterprise support.'
14
+ Login.new(logger, browser).execute support_registration_url,
15
+ account_email,
16
+ account_password
17
+ browser.input(:value => "AWSSupportEnterprise").when_present(timeout = 60).click
18
+ browser.span(:text => /Continue/).when_present(timeout = 60).click
19
+ screenshot(browser, "1")
20
+ browser.p(:text => confirmation_text).wait_until_present(timeout = 60)
21
+ screenshot(browser, "2")
22
+ true
23
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
24
+ page_error?
25
+ screenshot(browser, "error")
26
+ raise StandardError, "#{self.class.name} - #{e}"
27
+ end
28
+
29
+ def existing_support?(account_email,account_password)
30
+ logger.debug 'Checking to see if enterprise support is enabled.'
31
+ Login.new(logger, browser).execute support_status_url,
32
+ account_email,
33
+ account_password
34
+
35
+ screenshot(browser, "1")
36
+ browser.text.include? 'Enterprise Support Plan'
37
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
38
+ page_error?
39
+ screenshot(browser, "error")
40
+ raise StandardError, "#{self.class.name} - #{e}"
41
+ end
42
+
43
+ private
44
+ def page_error?
45
+ if browser.text.include? 'error'
46
+ logger.warn 'AWS webpage contains an error.'
47
+ screenshot(browser, "aws_page_error")
48
+ true
49
+ end
50
+ end
51
+
52
+ def confirmation_text
53
+ "Thank you for creating an Amazon Web Services (AWS) Account. We are in the process of activating your account. For most customers, activation only takes a couple minutes, but it can sometimes take a few hours if additional account verification is required. We will notify you by email when your account is activated."
54
+ end
55
+
56
+ def support_registration_url
57
+ 'https://portal.aws.amazon.com/gp/aws/developer/registration/index.html'
58
+ end
59
+
60
+ def support_status_url
61
+ 'https://console.aws.amazon.com/support/home'
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,32 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class IamBilling < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def enable(account_email, account_password)
13
+ logger.debug "Enabling IAM User Access to Billing Information"
14
+ Login.new(logger, browser).execute url,
15
+ account_email,
16
+ account_password
17
+ browser.a(:xpath => '//a[@ng-click="toggleEditingIAMPreferencesInfoState()"]').when_present(timeout = 120).click
18
+ browser.label(:xpath => '//label[@ng-show="isEditingIAMPreferencesInfo"]').when_present.click
19
+ screenshot(browser, "1")
20
+ browser.button(:xpath => '//button[@ng-click="updateIAMPreferences()"]').when_present.click
21
+ browser.strong(:text => /IAM user access to billing information is activated./).wait_until_present
22
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
23
+ screenshot(browser, "error")
24
+ raise StandardError, "#{self.class.name} - #{e}"
25
+ end
26
+
27
+ private
28
+ def url
29
+ 'https://portal.aws.amazon.com/gp/aws/manageYourAccount'
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class Login < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def execute(url, aws_email, password)
13
+ browser.goto url
14
+ return true unless login_page?
15
+ logger.debug "Logging into AWS."
16
+ screenshot(browser, "1")
17
+ browser.text_field(:id => 'ap_email').when_present.set aws_email
18
+ browser.text_field(:id => 'ap_password').when_present.set password
19
+ screenshot(browser, "2")
20
+ browser.button(:id => 'signInSubmit-input').when_present.click
21
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
22
+ screenshot(browser, "error")
23
+ raise StandardError, "#{self.class.name} - #{e}"
24
+ end
25
+
26
+ def login_page?
27
+ browser.url.include? 'ap/signin?'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class Logout < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def execute
13
+ logger.debug "Logging out of AWS."
14
+ browser.goto url
15
+ screenshot(browser, "1")
16
+ #Watir::Wait.until{browser.url == 'https://aws.amazon.com/'}
17
+ browser.wait_until{ browser.url.include? 'https://aws.amazon.com/'}
18
+ browser.text.include?('Sign In to the Console') || browser.text.include?('Create a Free Account')
19
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
20
+ screenshot(browser, "error")
21
+ raise StandardError, "#{self.class.name} - #{e}"
22
+ end
23
+
24
+ private
25
+ def url
26
+ 'https://console.aws.amazon.com/support/logout!doLogout'
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,53 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class Password < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def change(account_email, account_password, new_password)
13
+ logger.debug 'Changing root password.'
14
+ Login.new(logger, browser).execute url,
15
+ account_email,
16
+ account_password
17
+ browser.h1(:text => /Change Name, E-mail Address, or Password/).wait_until_present
18
+ screenshot(browser, "1")
19
+ browser.button(:id => 'cnep_1A_change_password_button-input').when_present.click
20
+ screenshot(browser, "2")
21
+ browser.text_field(:id =>"ap_password").when_present.set account_password
22
+ browser.text_field(:id =>"ap_password_new").when_present.set new_password
23
+ browser.text_field(:id =>"ap_password_new_check").when_present.set new_password
24
+ screenshot(browser, "3")
25
+ browser.button(:id => "cnep_1D_submit_button-input").when_present.click
26
+ raise StandardError if browser.div(:id => /message_(error|warning)/).exist?
27
+ browser.h6(:text => /Success/).exist?
28
+ rescue StandardError => e
29
+ screenshot(browser, "error")
30
+ logger.debug "Standard error in #{self.class.name} - #{e}"
31
+ error_header = browser.div(:id => /message_(error|warning)/).h6.text
32
+ error_body = browser.div(:id => /message_(error|warning)/).p.text
33
+ logger.debug "AWS Password Change Error: \"#{error_header}: #{error_body}\""
34
+ false
35
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
36
+ screenshot(browser, "error")
37
+ raise StandardError, "#{self.class.name} - #{e}"
38
+ end
39
+
40
+ private
41
+ def url
42
+ url = "https://www.amazon.com/ap/cnep?_encoding=UTF8"
43
+ url<< "&openid.assoc_handle=aws"
44
+ url<< "&openid.return_to=https%3A%2F%2Fconsole.aws.amazon.com%2Fbilling%2Fhome%23%2Faccount"
45
+ url<< "&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0"
46
+ url<< "&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select"
47
+ url<< "&openid.pape.max_auth_age=600"
48
+ url<< "&openid.pape.preferred_auth_policies=http%3A%2F%2Fschemas.openid.net%2Fpape%2Fpolicies%2F2007%2F06%2Fmulti-factor-physical"
49
+ url<< "&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0"
50
+ url<< "&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,86 @@
1
+ require 'aws_account_utils/base'
2
+
3
+ module AwsAccountUtils
4
+ class RootAccessKeys < Base
5
+ attr_reader :logger, :browser
6
+
7
+ def initialize(logger, browser)
8
+ @logger = logger
9
+ @browser = browser
10
+ end
11
+
12
+ def create(account_email, account_password)
13
+ logger.debug "Creating root access/secret key"
14
+ Login.new(logger, browser).execute url,
15
+ account_email,
16
+ account_password
17
+ clear_warning if browser.div(:id => 'modal-content', :text => warning_text)
18
+ browser.i(:xpath => "id('credaccordion')/div[3]/div[1]/div/div[1]/i").when_present.click
19
+ browser.button(:text => /Create New Access Key/).when_present.click
20
+ browser.a(:text => /Show Access Key/).when_present.click
21
+ screenshot(browser, "1")
22
+ parse_keys browser.text
23
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
24
+ screenshot(browser, "error")
25
+ raise StandardError, "#{self.class.name} - #{e}"
26
+ end
27
+
28
+ def delete(account_email, account_password)
29
+ logger.debug "Deleting root access/secret key"
30
+ Login.new(logger, browser).execute url,
31
+ account_email,
32
+ account_password
33
+ clear_warning if browser.div(:id => 'modal-content', :text => warning_text)
34
+ browser.i(:xpath => "id('credaccordion')/div[3]/div[1]/div/div[1]/i").when_present.click
35
+ keys_to_delete? ? delete_all_keys : true
36
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
37
+ screenshot(browser, "error")
38
+ raise StandardError, "#{self.class.name} - #{e}"
39
+ end
40
+
41
+ private
42
+ def delete_all_keys
43
+ tries ||= 4
44
+ browser.link(:text => 'Delete').when_present.click
45
+ logger.debug "Deleting access_key: #{browser.div(:id => 'modal-content').strong.text}"
46
+ browser.div(:text => /Are you sure you want to delete the access key/).wait_until_present
47
+ browser.link(:text => /Yes/).when_present.click
48
+ screenshot(browser, "2")
49
+ browser.link(:text => /Yes/).wait_while_present
50
+ screenshot(browser, "3")
51
+ raise StandardError if keys_to_delete?
52
+ rescue StandardError
53
+ retry unless (tries -= 1).zero?
54
+ false
55
+ else
56
+ true
57
+ end
58
+
59
+ def url
60
+ 'https://console.aws.amazon.com/iam/home?#security_credential'
61
+ end
62
+
63
+ def warning_text
64
+ 'You are accessing the security credentials page for your AWS account. The account credentials provide unlimited access to your AWS resources.'
65
+ end
66
+
67
+ def keys_to_delete?
68
+ a = browser.a(:class => 'Delete').exist?
69
+ a
70
+ end
71
+
72
+ def clear_warning
73
+ browser.label(:text => /Don't show me this message again/).wait_until_present
74
+ screenshot(browser, "4")
75
+ browser.element(:id => 'continue').when_present.click
76
+ rescue Watir::Wait::TimeoutError, Net::ReadTimeout => e
77
+ screenshot(browser, "error")
78
+ raise StandardError, "#{self.class.name} - #{e}"
79
+ end
80
+
81
+ def parse_keys(text)
82
+ { access_key: text.split("\n")[-4],
83
+ secret_key: text.split("\n")[-2] }
84
+ end
85
+ end
86
+ end