Class: Services::PublicKeysController

Inherits:
ApplicationController show all
Defined in:
app/controllers/services/public_keys_controller.rb

Constant Summary

Constants inherited from ApplicationController

ApplicationController::MAX_LIST_LENGTH

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#public_keyObject (readonly)

Returns the value of attribute public_key.



4
5
6
# File 'app/controllers/services/public_keys_controller.rb', line 4

def public_key
  @public_key
end

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
# File 'app/controllers/services/public_keys_controller.rb', line 14

def create
  pk = CreatePublicKeyContext.call(safe_params)
  if pk.errors.empty?
    render json: { id: pk.id }
  else
    render json: { validation_error: pk.errors.full_messages }, status: 403
  end
end

#destroyObject



32
33
34
35
# File 'app/controllers/services/public_keys_controller.rb', line 32

def destroy
  public_key.destroy
  render json: { id: public_key.id }
end

#indexObject



10
11
12
# File 'app/controllers/services/public_keys_controller.rb', line 10

def index
  @public_keys = PublicKey.order("valid_until DESC").limit(MAX_LIST_LENGTH)
end

#updateObject



23
24
25
26
27
28
29
30
# File 'app/controllers/services/public_keys_controller.rb', line 23

def update
  UpdatePublicKeyContext.call(public_key, safe_params)
  if public_key.errors.empty?
    render json: { id: public_key.id }
  else
    render json: { validation_error: public_key.errors.full_messages }, status: 403
  end
end