mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-24 04:10:57 -05:00
Currently requests to the API made from the admin app are going from PaaS admin app to the nginx router ELB, which then routes them back to the api app on PaaS. This makes sense for external requests, but for requests made from the admin app we could skip nginx and go directly to the api PaaS host, which should reduce load on the nginx instances and potentially reduce latency of the api requests. API apps on PaaS are checking the X-Custom-Forwarder header (which is set by nginx on proxy_pass requests) to only allow requests going through the proxy. This adds the custom header to the API client requests, so that they can pass that header check without going through nginx.
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
from app.notify_client import NotifyAdminAPIClient
|
|
|
|
|
|
class BillingAPIClient(NotifyAdminAPIClient):
|
|
# Fudge assert in the super __init__ so
|
|
# we can set those variables later.
|
|
def __init__(self):
|
|
super().__init__("a" * 73, "b")
|
|
|
|
def get_billable_units(self, service_id, year):
|
|
return self.get(
|
|
'/service/{0}/billing/monthly-usage'.format(service_id),
|
|
params=dict(year=year)
|
|
)
|
|
|
|
def get_service_usage(self, service_id, year=None):
|
|
return self.get(
|
|
'/service/{0}/billing/yearly-usage-summary'.format(service_id),
|
|
params=dict(year=year)
|
|
)
|
|
|
|
def get_free_sms_fragment_limit_for_year(self, service_id, year=None):
|
|
result = self.get(
|
|
'/service/{0}/billing/free-sms-fragment-limit'.format(service_id),
|
|
params=dict(financial_year_start=year)
|
|
)
|
|
return result['free_sms_fragment_limit']
|
|
|
|
def get_free_sms_fragment_limit_for_all_years(self, service_id, year=None):
|
|
return self.get(
|
|
'/service/{0}/billing/free-sms-fragment-limit'.format(service_id))
|
|
|
|
def create_or_update_free_sms_fragment_limit(self, service_id, free_sms_fragment_limit, year=None):
|
|
# year = None will update current and future year in the API
|
|
data = {
|
|
"financial_year_start": year,
|
|
"free_sms_fragment_limit": free_sms_fragment_limit
|
|
}
|
|
|
|
return self.post(
|
|
url='/service/{0}/billing/free-sms-fragment-limit'.format(service_id),
|
|
data=data
|
|
)
|