Class: ActionAgent::Api::ApiKeysController

Inherits:
BaseController show all
Defined in:
app/controllers/action_agent/api/api_keys_controller.rb

Overview

Platform API keys (Settings -> API Keys). The full token is returned exactly once — in the create response — and masked everywhere else.

Instance Method Summary collapse

Methods inherited from ActionAgent::ApplicationController

allow_unauthenticated_access

Instance Method Details

#createObject

POST /api/api_keys



18
19
20
21
22
23
24
# File 'app/controllers/action_agent/api/api_keys_controller.rb', line 18

def create
  api_key = owned(ApiKey).create!(name: params.require(:name))

  render json: {
    api_key: serialize(api_key).merge(token: api_key.token)
  }, status: :created
end

#destroyObject

DELETE /api/api_keys/:id



27
28
29
30
# File 'app/controllers/action_agent/api/api_keys_controller.rb', line 27

def destroy
  owned(ApiKey).find(params[:id]).destroy!
  head :no_content
end

#indexObject

GET /api/api_keys



11
12
13
14
15
# File 'app/controllers/action_agent/api/api_keys_controller.rb', line 11

def index
  render json: {
    api_keys: owned(ApiKey).order(created_at: :desc).map { |key| serialize(key) }
  }
end