Class: FabricCA::FaradayMiddleware::BasicAuth

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/fabric_ca/faraday_middleware/basic_auth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, username, password) ⇒ BasicAuth

Returns a new instance of BasicAuth.



20
21
22
23
24
# File 'lib/fabric_ca/faraday_middleware/basic_auth.rb', line 20

def initialize(app, username, password)
  @app = app
  @username = username
  @password = password
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/fabric_ca/faraday_middleware/basic_auth.rb', line 7

def app
  @app
end

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/fabric_ca/faraday_middleware/basic_auth.rb', line 7

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



7
8
9
# File 'lib/fabric_ca/faraday_middleware/basic_auth.rb', line 7

def username
  @username
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/fabric_ca/faraday_middleware/basic_auth.rb', line 9

def call(env)
  if username && password
    env[:request_headers] =
      env[:request_headers].merge(
        'Authorization' => "Basic #{generate_auth_header}"
      )
  end

  app.call env
end