Class: ThreeScale::Backend::API::Internal

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
app/api/internal/internal.rb

Constant Summary collapse

@@status =

using a class variable instead of settings because we want this to be as fast as possible when responding, since we hit /status a lot.

{ status: :ok,
version: { backend: ThreeScale::Backend::VERSION } }.to_json

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username: nil, password: nil, allow_insecure: false) ⇒ Internal

Returns a new instance of Internal.

Raises:



48
49
50
51
52
53
# File 'app/api/internal/internal.rb', line 48

def initialize(username: nil, password: nil, allow_insecure: false)
  @username = username
  @password = password
  raise InvalidCredentials unless allow_insecure or credentials_set?
  super()
end

Class Method Details

.define_private_endpoints?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/api/internal/internal.rb', line 44

def self.define_private_endpoints?
  ThreeScale::Backend.test? || ThreeScale::Backend.development?
end

Instance Method Details

#check_password(username, password) ⇒ Object



62
63
64
# File 'app/api/internal/internal.rb', line 62

def check_password(username, password)
  username == @username && password == @password
end

#credentials_set?Boolean

the two methods below are used by the Rack application for auth you can access them through the .helpers method after calling .new

Returns:

  • (Boolean)


57
58
59
60
# File 'app/api/internal/internal.rb', line 57

def credentials_set?
  (!@username.nil? && !@username.empty?) ||
      (!@password.nil? && !@password.empty?)
end