Class: Scaled::Auth::ApiToken

Inherits:
Object
  • Object
show all
Defined in:
lib/scaled/auth/api_token.rb

Overview

API token authentication strategy. Стратегія автентифікації через API токен.

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ void

Note: token is normalized with ‘strip` to reduce accidental whitespace issues. Нотатка: токен нормалізується через `strip`, щоб уникнути проблем з пробілами.

Parameters:

  • token (String)

    Tailscale API access token

Raises:

  • (ArgumentError)


12
13
14
15
16
17
# File 'lib/scaled/auth/api_token.rb', line 12

def initialize(token)
  normalized = token.to_s.strip
  raise ArgumentError, "api token must be provided" if normalized.empty?

  @token = normalized
end

Instance Method Details

#apply(headers) ⇒ Hash{String => String}

Note: mutates and returns the same hash to avoid unnecessary allocations. Нотатка: змінює і повертає той самий hash для уникнення зайвих алокацій.

Parameters:

  • headers (Hash{String => String})

    mutable request headers

Returns:

  • (Hash{String => String})

    same headers hash with Authorization included



23
24
25
26
# File 'lib/scaled/auth/api_token.rb', line 23

def apply(headers)
  headers["Authorization"] = "Bearer #{@token}"
  headers
end