Class: Xcflushd::Authorizer
- Inherits:
-
Object
- Object
- Xcflushd::Authorizer
- Defined in:
- lib/xcflushd/authorizer.rb
Defined Under Namespace
Classes: ThreeScaleInternalError
Instance Method Summary collapse
-
#authorizations(service_id, credentials, reported_metrics) ⇒ Object
Returns the authorization status of all the limited metrics of the application identified by the received (service_id, credentials) pair and also, the authorization of those metrics passed in reported_metrics that are not limited.
-
#initialize(threescale_client) ⇒ Authorizer
constructor
A new instance of Authorizer.
Constructor Details
#initialize(threescale_client) ⇒ Authorizer
Returns a new instance of Authorizer.
21 22 23 |
# File 'lib/xcflushd/authorizer.rb', line 21 def initialize(threescale_client) @threescale_client = threescale_client end |
Instance Method Details
#authorizations(service_id, credentials, reported_metrics) ⇒ Object
Returns the authorization status of all the limited metrics of the application identified by the received (service_id, credentials) pair and also, the authorization of those metrics passed in reported_metrics that are not limited.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/xcflushd/authorizer.rb', line 31 def (service_id, credentials, reported_metrics) # We can safely assume that reported metrics that do not have an # associated report usage are non-limited metrics. # First, let's check if there is a problem that has nothing to do with # limits (disabled application, bad credentials, etc.). auth = with_3scale_error_rescue(service_id, credentials) do auths_params = { service_id: service_id, extensions: EXTENSIONS }.merge!(credentials.creds) if credentials.oauth? threescale_client.(auths_params) else threescale_client.(auths_params) end end if !auth.success? && !auth.limits_exceeded? return reported_metrics.inject({}) do |acc, metric| acc[metric] = Authorization.deny(auth.error_code) acc end end auths_according_to_limits(auth, reported_metrics) end |