Class: Scooter::HttpDispatchers::ConsoleDispatcher
- Inherits:
-
HttpDispatcher
- Object
- Beaker::Http::Connection
- HttpDispatcher
- Scooter::HttpDispatchers::ConsoleDispatcher
- Includes:
- Activity, Classifier, Rbac
- Defined in:
- lib/scooter/httpdispatchers/consoledispatcher.rb
Overview
Quick-start guide
example creating a ConsoleDispatcher with certificates and credentials
require 'scooter'
include Scooter::HttpDispatcher
console_dispatcher = ConsoleDispatcher.new(dashboard)
# creates a new user and returns a new ConsoleDispatcher
new_user = console_dispatcher.generate_local_user('login' => 'Chuck')
# because the new_user has credentials, it can signin
new_user.signin
# this will trigger the middleware error handler, because you cannot
# create two users with the same login
console_dispatcher.create_local_user('login' => 'Chuck')
# this will return Chuck's data
certificate_dispatcher.get_console_dispatcher_data(new_user)
# this will trigger a middleware error handler, because Chuck has no
# privilege to create new users
new_user.generate_local_user
# this will delete Chuck from RBAC
certificate_dispatcher.delete_local_console_dispatcher(new_user)
# this method will now return nil because new_user is deleted
certificate_dispatcher.get_console_dispatcher_data(new_guy)
Defined Under Namespace
Classes: Credentials
Constant Summary
Constants included from Classifier
Scooter::HttpDispatchers::Classifier::Rootuuid
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
Attributes inherited from HttpDispatcher
#connection, #faraday_logger, #host, #send_auth_token_as_query_param, #token
Instance Method Summary collapse
-
#configure_private_key_and_cert_with_puppet(host = self.host) ⇒ Object
This is overridden from the parent class; in the case of ConsoleDispatcher objects, there are often cases where the Dispatcher is not a certificate dispatcher, but representing an LDAP or local user.
-
#initialize(host, credentials = nil, log_level = Logger::DEBUG, log_body = true) ⇒ ConsoleDispatcher
constructor
This class is designed to interact with any of the pe-console-services: RBAC, Node Classifier, and the Activity Service.
- #log_out ⇒ Object
- #reset_local_user_password(token, new_password) ⇒ Object
- #set_url_prefix(connection = self.connection) ⇒ Object
- #signin(login = self.credentials.login, password = self.credentials.password) ⇒ Object
Methods included from Activity
#activity_database_matches_self?, #set_activity_service_path
Methods included from Activity::V1
#get_classifier_events, #get_rbac_events
Methods included from Classifier
#classes_match?, #classifier_database_matches_self?, #create_new_node_group_model, #delete_all_node_groups, #delete_node_group_descendents, #delete_tree_recursion, #environments_match?, #find_or_create_node_group_model, #get_node_group_by_name, #get_node_group_id_by_name, #get_node_group_trees_of_direct_descendents, #groups_match?, #import_baseline_hierarchy, #nodes_match?, #refresh_node_group_model, #replace_node_group_with_update_hash, #set_classifier_path, #update_node_group_with_node_group_model
Methods included from Scooter::HttpDispatchers::Classifier::V1
#create_node_group, #delete_node_group, #get_list_of_classes, #get_list_of_environments, #get_list_of_node_groups, #get_list_of_nodes, #get_node_group, #import_hierarchy, #pin_nodes, #replace_node_group, #unpin_nodes, #update_classes, #update_node_group
Methods included from Rbac
#acquire_token_with_credentials, #add_user_to_role, #delete_local_console_dispatcher, #delete_role_by_name, #generate_local_user, #generate_role, #get_console_dispatcher_data, #get_current_user_id, #get_group_data_by_name, #get_group_id, #get_password_reset_token_for_console_dispatcher, #get_role_by_name, #get_role_id, #get_user_id_by_login_name, #get_user_id_of_console_dispatcher, #rbac_database_matches_self?, #remove_user_from_role, #reset_console_dispatcher_password, #reset_console_dispatcher_password_to_default, #revoke_console_dispatcher, #set_rbac_path, #update_console_dispatcher
Methods included from Rbac::V1
#acquire_token, #create_local_user, #create_password_reset_token, #create_role, #delete_local_user, #delete_role, #get_current_user_data, #get_list_of_groups, #get_list_of_roles, #get_list_of_users, #get_single_user_data, #import_ldap_group, #replace_role, #update_local_user
Methods included from Rbac::V1::DirectoryService
#attach_ds_to_rbac, #ds_default_settings, #test_attach_ds_to_rbac
Methods inherited from HttpDispatcher
#create_default_connection, #is_resolvable
Constructor Details
#initialize(host, credentials = nil, log_level = Logger::DEBUG, log_body = true) ⇒ ConsoleDispatcher
This class is designed to interact with any of the pe-console-services: RBAC, Node Classifier, and the Activity Service. The most common use case will be for tests executed with beaker, for which you will want to pass in the dashboard for initialization. The other parameter that you can pass in optionally is credentials, if you wish to get a web session and use that to talk to various other parts of PE.
If you are using this class outside of beaker, you can initialize an object without any parameters and supply your own dashboard as a String, credentials, Faraday connection object, and ssl parameters. Note that this is largely untested. Use outside of a Beaker test run at your own risk.
63 64 65 66 67 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 63 def initialize(host, credentials=nil, log_level=Logger::DEBUG, log_body=true) @credentials = Credentials.new(credentials[:login], credentials[:password]) if credentials super(host, log_level, log_body) end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
45 46 47 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 45 def credentials @credentials end |
Instance Method Details
#configure_private_key_and_cert_with_puppet(host = self.host) ⇒ Object
This is overridden from the parent class; in the case of ConsoleDispatcher objects, there are often cases where the Dispatcher is not a certificate dispatcher, but representing an LDAP or local user. If credentials are supplied during initialization, then this overrides the parent class and only acquires a ca_cert.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 79 def configure_private_key_and_cert_with_puppet(host=self.host) if credentials == nil super(host) else if !host.is_a?(Unix::Host) raise 'Can only acquire SSL certs if the host is a Unix::Host' end configure_cacert_with_puppet(host) end end |
#log_out ⇒ Object
107 108 109 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 107 def log_out response = @connection.get "https://#{host}/auth/logout" end |
#reset_local_user_password(token, new_password) ⇒ Object
111 112 113 114 115 116 117 118 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 111 def reset_local_user_password(token, new_password) @connection.post "https://#{host}/auth/reset" do |request| request.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8' request.body = "password=#{new_password}&token=#{token}" connection.port = 443 end set_url_prefix end |
#set_url_prefix(connection = self.connection) ⇒ Object
69 70 71 72 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 69 def set_url_prefix(connection=self.connection) connection.url_prefix.port = 4433 super(connection) end |
#signin(login = self.credentials.login, password = self.credentials.password) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/scooter/httpdispatchers/consoledispatcher.rb', line 90 def signin(login=self.credentials.login, password=self.credentials.password) response = @connection.post "/auth/login" do |request| request.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8' request.body = "username=#{login}&password=#{CGI.escape(password)}" connection.port = 443 end return response if response.status != 200 # This just had to be a string...*sigh* header_array = response.headers['Set-Cookie'].split(';') pl_ssti = header_array.select{|s| s =~ /pl_ssti/} pl_ssti_value = pl_ssti[0].partition('pl_ssti=').last @connection.headers['Cookie'] = response.headers['Set-Cookie'] @connection.headers['X-Authentication'] = pl_ssti_value # Reset the connection port, since we have to hardcode it to 443 signin set_url_prefix end |