Skip to content

Commit

Permalink
improve admin api (#1622)
Browse files Browse the repository at this point in the history
* normalize namespaces in Admin API
* remove Knock auth
  • Loading branch information
senid231 authored Nov 18, 2024
1 parent b1bdd3c commit f9a75d1
Show file tree
Hide file tree
Showing 295 changed files with 1,254 additions and 1,752 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ gem 'net-ldap', '~> 0.16.0'

# Seamless JWT authentication for Rails API
gem 'jwt'
gem 'knock', github: 'nsarno/knock'

# ActiveAdmin
gem 'activeadmin'
Expand Down
10 changes: 0 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ GIT
jquery-ui-rails (7.0.0)
railties (>= 3.2.16)

GIT
remote: https://github.com/nsarno/knock.git
revision: 37e403a7c6d44f585b56a086245e41566a8d6fe1
specs:
knock (2.2.0)
bcrypt (~> 3.1)
jwt (~> 2.2.1)
rails (>= 5)

GIT
remote: https://github.com/senid231/excelinator.git
revision: 25afcc544a6f287a2ace9018adbe6fc96ea29cb2
Expand Down Expand Up @@ -900,7 +891,6 @@ DEPENDENCIES
jrpc!
jsonapi-resources (~> 0.9.12)
jwt
knock!
listen
matrix (~> 0.4.2)
mini_racer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::AccountingProfilesController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/area_prefixes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::AreaPrefixesController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/areas_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::AreasController < Api::Rest::Admin::BaseController
end
34 changes: 22 additions & 12 deletions app/controllers/api/rest/admin/auth_controller.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
# frozen_string_literal: true

class Api::Rest::Admin::AuthController < Knock::AuthTokenController
class Api::Rest::Admin::AuthController < ApplicationController
skip_before_action :verify_authenticity_token

include Memoizable
include WithPayloads

rescue_from Authentication::AdminAuth::AuthenticationError, with: :handle_authentication_error
rescue_from Authentication::AdminAuth::IpAddressNotAllowedError, with: :handle_ip_not_allowed

define_memoizable :debug_mode, apply: -> { System::ApiLogConfig.exists?(controller: self.class.name) }

before_action :authenticate

def create
render json: { jwt: @auth_token }, status: 201
end

def meta
nil
end

private

def entity_name
'AdminUser'
def authenticate
result = Authentication::AdminAuth.authenticate!(
auth_params[:username],
auth_params[:password],
remote_ip: request.remote_ip
)
@auth_token = result.token
end

def auth_params
params.require(:auth).permit :username, :password
params.require(:auth).permit(:username, :password)
end

def not_found
def handle_authentication_error
error = JSONAPI::Exceptions::AuthenticationFailed.new
render status: 401, json: { errors: error.errors.map(&:to_hash) }
end

def ip_not_allowed
def handle_ip_not_allowed
error = JSONAPI::Exceptions::AuthenticationFailed.new(
detail: 'Your IP address is not allowed.'
)
render status: 401, json: { errors: error.errors.map(&:to_hash) }
end

def authenticate
super

ip_not_allowed unless entity.ip_allowed?(request.remote_ip)
end
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/auth_logs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::AuthLogsController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/auth_profiles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::AuthProfilesController < Api::Rest::Admin::BaseController
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions app/controllers/api/rest/admin/billing/services_controller.rb

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions app/controllers/api/rest/admin/cdr/auth_logs_controller.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Api::Rest::Admin::Cdr::CdrExportsController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::CdrExportsController < Api::Rest::Admin::BaseController
before_action :find_cdr_export, only: :download

def download
Expand All @@ -19,7 +19,7 @@ def download
private

def find_cdr_export
resource_klass = Api::Rest::Admin::Cdr::CdrExportResource
resource_klass = Api::Rest::Admin::CdrExportResource
key = resource_klass.verify_key(params[:id], context)
@cdr_export = resource_klass.find_by_key(key, context: context)._model
rescue StandardError => e
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Api::Rest::Admin::Cdr::CdrsController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::CdrsController < Api::Rest::Admin::BaseController
before_action :find_cdr, only: :recording
def recording
if @cdr.has_recording?
Expand All @@ -17,7 +17,7 @@ def recording
private

def find_cdr
resource_klass = Api::Rest::Admin::Cdr::CdrResource
resource_klass = Api::Rest::Admin::CdrResource
key = resource_klass.verify_key(params[:id], context)
@cdr = resource_klass.find_by_key(key, context: context)._model
rescue StandardError => e
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/countries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::CountriesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::DestinationNextRatesController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/destinations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::DestinationsController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::DtmfReceiveModesController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/dtmf_send_modes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::DtmfSendModesController < Api::Rest::Admin::BaseController
end

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::GatewayDiversionSendModesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::Equipment::Radius::AuthProfilesController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::GatewayInbandDtmfFilteringModesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::Billing::InvoiceServiceDataController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::GatewayMediaEncryptionModesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::GatewayNetworkProtocolPrioritiesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::GatewayRel100ModesController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::Equipment::GatewayRel100ModesController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::InvoiceOriginatedDestinationsController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::InvoiceOriginatedNetworksController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::InvoiceServiceDataController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/invoice_template_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::InvoiceTemplateController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::Equipment::TransportProtocolsController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::InvoiceTerminatedDestinationsController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::InvoiceTerminatedNetworksController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Api::Rest::Admin::Billing::InvoicesController < Api::Rest::Admin::BaseController
class Api::Rest::Admin::InvoicesController < Api::Rest::Admin::BaseController
def pdf
doc = ::Billing::InvoiceDocument.find_by(invoice_id: params[:id])
return head 404 if doc.nil? || doc.pdf_data.blank?
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/network_types_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::NetworkTypesController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/networks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::NetworksController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/numberlist_items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::NumberlistItemsController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/numberlists_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::NumberlistsController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/rate_groups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::RateGroupsController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/rateplans_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::RateplansController < Api::Rest::Admin::BaseController
end
4 changes: 4 additions & 0 deletions app/controllers/api/rest/admin/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::RegistrationsController < Api::Rest::Admin::BaseController
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

class Api::Rest::Admin::RoutesetDiscriminatorsController < Api::Rest::Admin::BaseController
end

This file was deleted.

4 changes: 0 additions & 4 deletions app/controllers/api/rest/admin/routing/areas_controller.rb

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit f9a75d1

Please sign in to comment.