Class: Conify::Sso
- Inherits:
-
Object
- Object
- Conify::Sso
- Defined in:
- lib/conify/sso.rb
Instance Attribute Summary collapse
-
#external_uuid ⇒ Object
Returns the value of attribute external_uuid.
-
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#token ⇒ Object
Returns the value of attribute token.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #find_available_port ⇒ Object
- #full_url ⇒ Object (also: #get_url)
-
#initialize(data) ⇒ Sso
constructor
A new instance of Sso.
- #make_token(t) ⇒ Object
- #message ⇒ Object
- #path ⇒ Object
- #POST? ⇒ Boolean
- #post_url ⇒ Object
- #query_data ⇒ Object
- #query_params ⇒ Object
- #querystring ⇒ Object
- #sso_url ⇒ Object
Constructor Details
#initialize(data) ⇒ Sso
Returns a new instance of Sso.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/conify/sso.rb', line 8 def initialize(data) @external_uuid = data[:external_uuid] @external_username = data[:external_username] @salt = data['api']['sso_salt'] env = data.fetch('env', 'test') if @url = data['api'][env]['sso_url'] @use_post = true @proxy_port = find_available_port else @url = data['api'][env].chomp('/') end @timestamp = Time.now.to_i @token = make_token(@timestamp) end |
Instance Attribute Details
#external_uuid ⇒ Object
Returns the value of attribute external_uuid.
6 7 8 |
# File 'lib/conify/sso.rb', line 6 def external_uuid @external_uuid end |
#proxy_port ⇒ Object
Returns the value of attribute proxy_port.
6 7 8 |
# File 'lib/conify/sso.rb', line 6 def proxy_port @proxy_port end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
6 7 8 |
# File 'lib/conify/sso.rb', line 6 def @timestamp end |
#token ⇒ Object
Returns the value of attribute token.
6 7 8 |
# File 'lib/conify/sso.rb', line 6 def token @token end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/conify/sso.rb', line 6 def url @url end |
Instance Method Details
#find_available_port ⇒ Object
81 82 83 84 85 86 |
# File 'lib/conify/sso.rb', line 81 def find_available_port server = TCPServer.new('127.0.0.1', 0) server.addr[1] ensure server.close if server end |
#full_url ⇒ Object Also known as: get_url
37 38 39 |
# File 'lib/conify/sso.rb', line 37 def full_url [ url, path, querystring ].join end |
#make_token(t) ⇒ Object
51 52 53 |
# File 'lib/conify/sso.rb', line 51 def make_token(t) Digest::SHA1.hexdigest([external_uuid, @salt, t].join(':')) end |
#message ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/conify/sso.rb', line 73 def if self.POST? "POSTing #{query_data} to #{post_url} via proxy on port #{@proxy_port}" else "Opening #{full_url}" end end |
#path ⇒ Object
25 26 27 |
# File 'lib/conify/sso.rb', line 25 def path self.POST? ? URI.parse(url).path : "/conflux/resources/#{external_uuid}" end |
#POST? ⇒ Boolean
29 30 31 |
# File 'lib/conify/sso.rb', line 29 def POST? @use_post end |
#post_url ⇒ Object
42 43 44 |
# File 'lib/conify/sso.rb', line 42 def post_url url end |
#query_data ⇒ Object
60 61 62 |
# File 'lib/conify/sso.rb', line 60 def query_data query_params.map{|p| p.join('=')}.join('&') end |
#query_params ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/conify/sso.rb', line 64 def query_params { 'id' => external_uuid, 'token' => @token, 'timestamp' => @timestamp.to_s, 'email' => @external_username } end |
#querystring ⇒ Object
55 56 57 58 |
# File 'lib/conify/sso.rb', line 55 def querystring return '' unless @salt '?' + query_data end |
#sso_url ⇒ Object
33 34 35 |
# File 'lib/conify/sso.rb', line 33 def sso_url self.POST? ? "http://localhost:#{@proxy_port}/" : full_url end |