Class: ChefWebui::Session
- Inherits:
-
Object
- Object
- ChefWebui::Session
- Defined in:
- lib/chef_webui/session.rb
Instance Attribute Summary collapse
-
#account_url ⇒ Object
readonly
Returns the value of attribute account_url.
-
#manage_url ⇒ Object
readonly
Returns the value of attribute manage_url.
Instance Method Summary collapse
- #create_org(orgname) ⇒ Object
- #create_user(username, password, first_name, last_name, email) ⇒ Object
- #current_environment ⇒ Object
- #current_org ⇒ Object
- #current_user ⇒ Object
-
#initialize(manage_url, account_url) ⇒ Session
constructor
A new instance of Session.
- #logged_in ⇒ Object
- #login(username, password) ⇒ Object
- #organizations ⇒ Object
- #regenerate_user_key ⇒ Object
- #regenerate_validator_key(orgname) ⇒ Object
- #switch_to_org(orgname) ⇒ Object
Constructor Details
#initialize(manage_url, account_url) ⇒ Session
Returns a new instance of Session.
9 10 11 12 13 14 15 |
# File 'lib/chef_webui/session.rb', line 9 def initialize(manage_url, account_url) @manage_url = manage_url @account_url = account_url @agent = Mechanize.new @agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE get('login') end |
Instance Attribute Details
#account_url ⇒ Object (readonly)
Returns the value of attribute account_url.
7 8 9 |
# File 'lib/chef_webui/session.rb', line 7 def account_url @account_url end |
#manage_url ⇒ Object (readonly)
Returns the value of attribute manage_url.
6 7 8 |
# File 'lib/chef_webui/session.rb', line 6 def manage_url @manage_url end |
Instance Method Details
#create_org(orgname) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/chef_webui/session.rb', line 34 def create_org(orgname) post('organizations', { 'id' => orgname, 'full_name' => orgname }) end |
#create_user(username, password, first_name, last_name, email) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/chef_webui/session.rb', line 46 def create_user(username, password, first_name, last_name, email) post('users', { 'authenticity_token' => @authenticity_token, 'user[username]' => username, 'user[first_name]' => first_name, 'user[last_name]' => last_name, 'user[email]' => email, 'user[password]' => password, 'user[password_confirmation]' => password, 'commit' => 'Submit' }) if !@agent.page.content =~ /Your Private Chef user account has been created./ raise_webui_error end end |
#current_environment ⇒ Object
96 97 98 |
# File 'lib/chef_webui/session.rb', line 96 def current_environment @agent.page.at('#Environment option[selected="selected"]').text.gsub(/\s+/, ' ') end |
#current_org ⇒ Object
92 93 94 |
# File 'lib/chef_webui/session.rb', line 92 def current_org @agent.page.at('#header h1 a[href="/nodes"]').text.gsub(/\s+/, ' ') end |
#current_user ⇒ Object
88 89 90 |
# File 'lib/chef_webui/session.rb', line 88 def current_user @agent.page.at('#user-navigation a').text.gsub(/\s+/, ' ') end |
#logged_in ⇒ Object
30 31 32 |
# File 'lib/chef_webui/session.rb', line 30 def logged_in return @agent.page.content =~ /Logged in as/ end |
#login(username, password) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/chef_webui/session.rb', line 17 def login(username, password) results = post('login_exec', { 'name' => username, 'password' => password, 'commit' => 'Login' }) if !logged_in raise_webui_error end end |
#organizations ⇒ Object
79 80 81 82 83 84 85 86 |
# File 'lib/chef_webui/session.rb', line 79 def organizations get('organizations') result = [] @agent.page.search('#all_associated_organizations td.name_column').each do |org| result << org.text.gsub(/\s+/, ' ') end result end |
#regenerate_user_key ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/chef_webui/session.rb', line 71 def regenerate_user_key @agent.post("#{account_url}/account/regen_key", { 'commit' => 'Get a new key', 'authenticity_token' => @authenticity_token }).content end |
#regenerate_validator_key(orgname) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/chef_webui/session.rb', line 63 def regenerate_validator_key(orgname) @agent.post("#{manage_url}/organizations/#{orgname}/_regenerate_key", { '_method' => 'put', 'authenticity_token' => @authenticity_token }).content end |
#switch_to_org(orgname) ⇒ Object
42 43 44 |
# File 'lib/chef_webui/session.rb', line 42 def switch_to_org(orgname) post("organizations/#{orgname}/select", {}) end |