Class: Iated::MCP
- Inherits:
-
Object
- Object
- Iated::MCP
- Defined in:
- lib/iated/mcp.rb
Overview
The Master Control Progrom
Yes, I’ve been watching Tron lately, why do ask?
Instance Attribute Summary collapse
-
#browser_token_db ⇒ Object
readonly
Returns the value of attribute browser_token_db.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#prefs ⇒ SysPref
readonly
The current System Preferencs object.
Instance Method Summary collapse
-
#begin! ⇒ Object
Called by the main program to get everything started.
-
#confirm_secret(guess) ⇒ Boolean
Confirm the secret.
- #cucumber_coverage_check ⇒ Object
-
#generate_secret ⇒ String
The magic value shown to user to confirm a connection.
-
#generate_token(user_agent) ⇒ String
The magic value registering a browser.
-
#hide_secret ⇒ nil
Hide the secret again.
-
#initialize ⇒ MCP
constructor
A new instance of MCP.
-
#is_token_valid?(token) ⇒ Boolean
Is the auth token a valid one?.
- #rspec_coverage_check ⇒ Object
-
#secret ⇒ String, Symbol
The currently showing secret or the symbol ‘:notset`.
-
#show_secret ⇒ nil
Show the secret to the user.
-
#showing_secret? ⇒ Boolean
Is the secret being shown to the user?.
- #start_server ⇒ Object
- #stop_server ⇒ Object
- #ui ⇒ Object
- #ui=(ui_type) ⇒ Object
Constructor Details
#initialize ⇒ MCP
Returns a new instance of MCP.
23 24 25 26 27 |
# File 'lib/iated/mcp.rb', line 23 def initialize @debug = false @prefs = SysPref.new @browser_token_db = Iated::BrowserTokenDB.new(@prefs.config_dir + 'browser_tokens.yml') end |
Instance Attribute Details
#browser_token_db ⇒ Object (readonly)
Returns the value of attribute browser_token_db.
18 19 20 |
# File 'lib/iated/mcp.rb', line 18 def browser_token_db @browser_token_db end |
#debug ⇒ Object
Returns the value of attribute debug.
16 17 18 |
# File 'lib/iated/mcp.rb', line 16 def debug @debug end |
#prefs ⇒ SysPref (readonly)
Returns The current System Preferencs object.
21 22 23 |
# File 'lib/iated/mcp.rb', line 21 def prefs @prefs end |
Instance Method Details
#begin! ⇒ Object
Called by the main program to get everything started.
30 31 32 |
# File 'lib/iated/mcp.rb', line 30 def begin! start_server end |
#confirm_secret(guess) ⇒ Boolean
Confirm the secret
43 44 45 46 47 |
# File 'lib/iated/mcp.rb', line 43 def confirm_secret guess success = (guess == secret) hide_secret return success end |
#cucumber_coverage_check ⇒ Object
135 136 137 |
# File 'lib/iated/mcp.rb', line 135 def cucumber_coverage_check @cucumber_check = true end |
#generate_secret ⇒ String
The magic value shown to user to confirm a connection
82 83 84 85 86 |
# File 'lib/iated/mcp.rb', line 82 def generate_secret @secret = (1..4).map{ rand(10).to_s }.join "" @is_showing_secret = true return @secret end |
#generate_token(user_agent) ⇒ String
The magic value registering a browser.
90 91 92 |
# File 'lib/iated/mcp.rb', line 90 def generate_token user_agent @browser_token_db.add user_agent end |
#hide_secret ⇒ nil
Hide the secret again
75 76 77 78 |
# File 'lib/iated/mcp.rb', line 75 def hide_secret @is_showing_secret = false # TODO secret should be using a JPanel or something, not a dialog. end |
#is_token_valid?(token) ⇒ Boolean
Is the auth token a valid one?
96 97 98 |
# File 'lib/iated/mcp.rb', line 96 def is_token_valid? token @browser_token_db.has_token? token end |
#rspec_coverage_check ⇒ Object
139 140 141 |
# File 'lib/iated/mcp.rb', line 139 def rspec_coverage_check @rspec_check = true end |
#secret ⇒ String, Symbol
Returns The currently showing secret or the symbol ‘:notset`.
35 36 37 |
# File 'lib/iated/mcp.rb', line 35 def secret showing_secret? ? @secret : :notset end |
#show_secret ⇒ nil
Show the secret to the user
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/iated/mcp.rb', line 56 def show_secret generate_secret # TODO This should do something different for text, vs. gui. puts " ** A browser requested authorization: #{@secret}" unless :test == ui ## require 'java' ## Thread.new do ## puts " ** A browser requested authorization: #{@secret}" ### TODO This needs to be abstracted. There is no reason a purely command line version can't be done. Also, loading swing will break CI. ### import javax.swing.JOptionPane ### JOptionPane.showMessageDialog(nil, ### "A browser has requested authorization: #{@secret}\nDo not press 'OK' until after you enter the number", ### "Authorize Browser", ### JOptionPane::INFORMATION_MESSAGE) ## @is_showing_secret = false ## end end |
#showing_secret? ⇒ Boolean
Returns Is the secret being shown to the user?.
50 51 52 |
# File 'lib/iated/mcp.rb', line 50 def showing_secret? @is_showing_secret end |
#start_server ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/iated/mcp.rb', line 113 def start_server # TODO this needs to be in a separate thread. set :server, %w[webrick] set :bind, 'localhost' set :port, prefs.port if @debug set :show_exceptions, true set :environment, :development else set :show_exceptions, false set :environment, :production end @is_running = true Sinatra::Application.run! end |
#stop_server ⇒ Object
130 131 132 133 |
# File 'lib/iated/mcp.rb', line 130 def stop_server @is_running = false Sinatra::Application.quit! end |
#ui ⇒ Object
108 109 110 111 |
# File 'lib/iated/mcp.rb', line 108 def ui # Default UI @ui ||= (:test == Iated.environment ? :test : :text) end |
#ui=(ui_type) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/iated/mcp.rb', line 100 def ui= ui_type if [:text, :test, :gui].include? ui_type @ui = ui_type else raise "Invalid UI type: #{ui_type.inspect}" end end |