Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds refresh bank keys endpoint #223

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions box/apis/v2/management/ebics_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ class EbicsUsers < Grape::API
end
end

params do
requires :id, type: Integer, desc: 'ID of the ebics_user'
end
post ':id/refresh_bank_keys' do
ebics_user = @account.ebics_users_dataset.first!(Sequel.qualify(:ebics_users, :id) => params[:id])
if ebics_user.refresh_bank_keys!
present ebics_user, with: Entities::EbicsUser
else
error!({ message: 'Bank keys could not be refreshed!' }, 500)
end
end

###
### GET /management/accounts/DExx/ebics_users
###
Expand Down
13 changes: 13 additions & 0 deletions box/models/ebics_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ def activate!
false
end

def refresh_bank_keys!
Box.logger.info("Refresh bank keys for account #{id}")
client.HPB

self.encryption_keys = client.send(:dump_keys)
save
true
salimhb marked this conversation as resolved.
Show resolved Hide resolved
rescue StandardError => e
# TODO: show the error to the user
Box.logger.error("Failed to refresh bank keys for account #{id}: #{e}")
false
end

def state
if active?
'active'
Expand Down