Class: Proxy::ContainerGateway::Api::AuthorizationHeader
- Inherits:
-
Object
- Object
- Proxy::ContainerGateway::Api::AuthorizationHeader
- Extended by:
- DependencyInjection
- Defined in:
- lib/smart_proxy_container_gateway/container_gateway_api.rb
Constant Summary collapse
- UNAUTHORIZED_TOKEN =
'unauthorized'.freeze
- UNAUTHENTICATED_TOKEN =
'unauthenticated'.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
- #unauthenticated_token? ⇒ Boolean
- #unauthorized_token? ⇒ Boolean
- #user ⇒ Object
-
#v1_foreman_authorized_username ⇒ Object
A special case for the V1 API.
- #valid_user_token? ⇒ Boolean
Methods included from DependencyInjection
Constructor Details
#initialize(value) ⇒ AuthorizationHeader
Returns a new instance of AuthorizationHeader.
425 426 427 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 425 def initialize(value) @value = value || '' end |
Instance Method Details
#basic_auth? ⇒ Boolean
457 458 459 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 457 def basic_auth? @value.split(' ')[0] == 'Basic' end |
#blank? ⇒ Boolean
461 462 463 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 461 def blank? Base64.decode64(@value.split(' ')[1]) == ':' end |
#present? ⇒ Boolean
441 442 443 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 441 def present? !@value.nil? && @value != "" end |
#raw_header ⇒ Object
437 438 439 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 437 def raw_header @value end |
#token_auth? ⇒ Boolean
453 454 455 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 453 def token_auth? @value.split(' ')[0] == 'Bearer' end |
#unauthenticated_token? ⇒ Boolean
449 450 451 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 449 def unauthenticated_token? @value.split(' ')[1] == UNAUTHENTICATED_TOKEN end |
#unauthorized_token? ⇒ Boolean
445 446 447 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 445 def @value.split(' ')[1] == UNAUTHORIZED_TOKEN end |
#user ⇒ Object
429 430 431 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 429 def user container_gateway_main.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.
466 467 468 469 470 471 472 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 466 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
433 434 435 |
# File 'lib/smart_proxy_container_gateway/container_gateway_api.rb', line 433 def valid_user_token? token_auth? && container_gateway_main.valid_token?(@value.split(' ')[1]) end |