Class: Proxy::ContainerGateway::Api::AuthorizationHeader
- Inherits:
-
Object
- Object
- Proxy::ContainerGateway::Api::AuthorizationHeader
- Defined in:
- lib/smart_proxy_container_gateway/container_gateway_api.rb
Constant Summary collapse
- UNAUTHORIZED_TOKEN =
'unauthorized'.freeze
Instance Method Summary collapse
- #basic_auth? ⇒ Boolean
- #blank? ⇒ Boolean
-
#initialize(value) ⇒ AuthorizationHeader
constructor
A new instance of AuthorizationHeader.
- #present? ⇒ Boolean
- #raw_header ⇒ Object
- #token_auth? ⇒ Boolean
- #unauthorized_token? ⇒ Boolean
- #user ⇒ Object
-
#v1_foreman_authorized_username ⇒ Object
A special case for the V1 API.
- #valid_user_token? ⇒ Boolean
Constructor Details
#initialize(value) ⇒ AuthorizationHeader
Returns a new instance of AuthorizationHeader.
161 162 163 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 161 def initialize(value) @value = value || '' end |
Instance Method Details
#basic_auth? ⇒ Boolean
189 190 191 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 189 def basic_auth? @value.split(' ')[0] == 'Basic' end |
#blank? ⇒ Boolean
193 194 195 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 193 def blank? Base64.decode64(@value.split(' ')[1]) == ':' end |
#present? ⇒ Boolean
177 178 179 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 177 def present? !@value.nil? && @value != "" end |
#raw_header ⇒ Object
173 174 175 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 173 def raw_header @value end |
#token_auth? ⇒ Boolean
185 186 187 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 185 def token_auth? @value.split(' ')[0] == 'Bearer' end |
#unauthorized_token? ⇒ Boolean
181 182 183 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 181 def @value.split(' ')[1] == UNAUTHORIZED_TOKEN end |
#user ⇒ Object
165 166 167 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 165 def user ContainerGateway.token_user(@value.split(' ')[1]) end |
#v1_foreman_authorized_username ⇒ Object
A special case for the V1 API. Defer authentication to Foreman and return the username. ‘nil` if not authorized.
198 199 200 201 202 203 204 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 198 def username = Base64.decode64(@value.split(' ')[1]).split(':')[0] auth_response = ForemanApi.new.fetch_token(raw_header, { 'account' => username }) return username if auth_response.code.to_i == 200 && (JSON.parse(auth_response.body)['token'] != 'unauthenticated') nil end |
#valid_user_token? ⇒ Boolean
169 170 171 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 169 def valid_user_token? token_auth? && ContainerGateway.valid_token?(@value.split(' ')[1]) end |