-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2584 from internetee/api-user-management
Added ApiUser and WhiteIp endpoints to REPP API
- Loading branch information
Showing
32 changed files
with
934 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
require 'serializers/repp/api_user' | ||
module Repp | ||
module V1 | ||
class ApiUsersController < BaseController | ||
load_and_authorize_resource | ||
|
||
THROTTLED_ACTIONS = %i[index show create update destroy].freeze | ||
include Shunter::Integration::Throttle | ||
|
||
api :GET, '/repp/v1/api_users' | ||
desc 'Get all api users' | ||
def index | ||
users = current_user.registrar.api_users | ||
|
||
render_success(data: { users: serialized_users(users), | ||
count: users.count }) | ||
end | ||
|
||
api :GET, '/repp/v1/api_users/:id' | ||
desc 'Get a specific api user' | ||
def show | ||
serializer = Serializers::Repp::ApiUser.new(@api_user) | ||
render_success(data: { user: serializer.to_json, roles: ApiUser::ROLES }) | ||
end | ||
|
||
api :POST, '/repp/v1/api_users' | ||
desc 'Create a new api user' | ||
def create | ||
@api_user = current_user.registrar.api_users.build(api_user_params) | ||
@api_user.active = api_user_params[:active] | ||
unless @api_user.save | ||
handle_non_epp_errors(@api_user) | ||
return | ||
end | ||
|
||
render_success(data: { api_user: { id: @api_user.id } }) | ||
end | ||
|
||
api :PUT, '/repp/v1/api_users/:id' | ||
desc 'Update api user' | ||
def update | ||
unless @api_user.update(api_user_params) | ||
handle_non_epp_errors(@api_user) | ||
return | ||
end | ||
|
||
render_success(data: { api_user: { id: @api_user.id } }) | ||
end | ||
|
||
api :DELETE, '/repp/v1/api_users/:id' | ||
desc 'Delete a specific api user' | ||
def destroy | ||
unless @api_user.destroy | ||
handle_non_epp_errors(@api_user) | ||
return | ||
end | ||
|
||
render_success | ||
end | ||
|
||
private | ||
|
||
def api_user_params | ||
params.require(:api_user).permit(:username, :plain_text_password, :active, | ||
:identity_code, { roles: [] }) | ||
end | ||
|
||
def serialized_users(users) | ||
users.map { |i| Serializers::Repp::ApiUser.new(i).to_json } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Repp | ||
module V1 | ||
class WhiteIpsController < BaseController | ||
load_and_authorize_resource | ||
|
||
THROTTLED_ACTIONS = %i[index show create update destroy].freeze | ||
include Shunter::Integration::Throttle | ||
|
||
api :GET, '/repp/v1/white_ips' | ||
desc 'Get all whitelisted IPs' | ||
def index | ||
ips = current_user.registrar.white_ips | ||
|
||
render_success(data: { ips: ips.as_json, | ||
count: ips.count }) | ||
end | ||
|
||
api :GET, '/repp/v1/white_ips/:id' | ||
desc 'Get a specific whitelisted IP address' | ||
def show | ||
render_success(data: { ip: @white_ip.as_json, interfaces: WhiteIp::INTERFACES }) | ||
end | ||
|
||
api :POST, '/repp/v1/white_ips' | ||
desc 'Add new whitelisted IP' | ||
def create | ||
@white_ip = current_user.registrar.white_ips.build(white_ip_params) | ||
unless @white_ip.save | ||
handle_non_epp_errors(@white_ip) | ||
return | ||
end | ||
|
||
render_success(data: { ip: { id: @white_ip.id } }) | ||
end | ||
|
||
api :PUT, '/repp/v1/white_ips/:id' | ||
desc 'Update whitelisted IP address' | ||
def update | ||
unless @white_ip.update(white_ip_params) | ||
handle_non_epp_errors(@white_ip) | ||
return | ||
end | ||
|
||
render_success(data: { ip: { id: @white_ip.id } }) | ||
end | ||
|
||
api :DELETE, '/repp/v1/white_ips/:id' | ||
desc 'Delete a specific whitelisted IP address' | ||
def destroy | ||
unless @white_ip.destroy | ||
handle_non_epp_errors(@white_ip) | ||
return | ||
end | ||
|
||
render_success | ||
end | ||
|
||
private | ||
|
||
def white_ip_params | ||
params.require(:white_ip).permit(:ipv4, :ipv6, interfaces: []) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.