Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Add api_key.get endpoint #994

Merged
merged 1 commit into from
May 9, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,26 @@ defmodule AdminAPI.V1.APIKeyController do
end

def update(conn, _attrs) do
handle_error(conn, :invalid_parameter, "`id` is required")
handle_error(conn, :missing_id)
end

@doc """
Retrieves a specific api key by its id.
"""
@spec get(Plug.Conn.t(), map()) :: Plug.Conn.t()
def get(conn, %{"id" => id} = attrs) do
with %APIKey{} = api_key <- APIKey.get(id) || {:error, :unauthorized},
{:ok, _} <- authorize(:get, conn.assigns, api_key),
{:ok, api_key} <- Orchestrator.one(api_key, APIKeyOverlay, attrs) do
render(conn, :api_key, %{api_key: api_key})
else
{:error, code} ->
handle_error(conn, code)
end
end

def get(conn, _attrs) do
handle_error(conn, :missing_id)
end

@doc """
Expand Down
1 change: 1 addition & 0 deletions apps/admin_api/lib/admin_api/v1/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ defmodule AdminAPI.V1.Router do
# API Key endpoints
post("/api_key.all", APIKeyController, :all)
post("/api_key.create", APIKeyController, :create)
post("/api_key.get", APIKeyController, :get)
post("/api_key.enable_or_disable", APIKeyController, :enable_or_disable)
post("/api_key.delete", APIKeyController, :delete)

Expand Down
238 changes: 238 additions & 0 deletions apps/admin_api/priv/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -38181,6 +38181,244 @@
}
}
},
"/api_key.get": {
"post": {
"tags": [
"API Access"
],
"summary": "Get a specific api key",
"operationId": "api_key_get",
"security": [
{
"ProviderAuth": []
},
{
"AdminAuth": []
}
],
"requestBody": {
"description": "The parameters to use for retrieving a specific api key",
"required": true,
"content": {
"application/vnd.omisego.v1+json": {
"schema": {
"properties": {
"id": {
"type": "string"
}
},
"required": [
"id"
],
"example": {
"id": "api_01d744xm9cy3qx8hdwv4ax3k1h"
}
}
}
}
},
"responses": {
"200": {
"description": "Returns a single API key",
"content": {
"application/vnd.omisego.v1+json": {
"schema": {
"description": "The response schema for an API key",
"allOf": [
{
"description": "The response schema for a successful operation",
"type": "object",
"properties": {
"version": {
"type": "string"
},
"success": {
"type": "boolean"
},
"data": {
"type": "object"
}
},
"required": [
"version",
"success",
"data"
],
"example": {
"version": "1",
"success": true,
"data": {}
}
},
{
"type": "object",
"properties": {
"data": {
"description": "The object schema for an API key",
"type": "object",
"properties": {
"object": {
"type": "string"
},
"id": {
"type": "string"
},
"key": {
"type": "string"
},
"owner_app": {
"type": "string"
},
"enabled": {
"type": "boolean"
},
"account_id": {
"type": "string"
},
"creator_user_id": {
"type": "string"
},
"creator_key_id": {
"type": "string"
},
"created_at": {
"type": "string",
"format": "date-time"
},
"updated_at": {
"type": "string",
"format": "date-time"
},
"deleted_at": {
"type": "string",
"format": "date-time",
"nullable": true
}
},
"required": [
"object",
"id",
"key",
"owner_app",
"enabled",
"account_id",
"created_at",
"updated_at",
"deleted_at"
]
}
},
"example": {
"data": {
"object": "api_key",
"id": "api_01ce844d5w9e81snekr5kprvem",
"name": "my_key",
"key": "jZKpGKgwy5LJTWwXqSD4jVWYDdnTKHlRYkaNB6SqsaQ",
"owner_app": "ewallet_api",
"enabled": true,
"account_id": null,
"created_at": "2018-01-01T00:00:00Z",
"updated_at": "2018-01-01T10:00:00Z",
"deleted_at": null
}
}
}
]
}
}
}
},
"500": {
"description": "Returns an internal server error",
"content": {
"application/vnd.omisego.v1+json": {
"schema": {
"description": "The response schema for an error",
"allOf": [
{
"description": "The response schema for a successful operation",
"type": "object",
"properties": {
"version": {
"type": "string"
},
"success": {
"type": "boolean"
},
"data": {
"type": "object"
}
},
"required": [
"version",
"success",
"data"
],
"example": {
"version": "1",
"success": true,
"data": {}
}
},
{
"type": "object",
"properties": {
"data": {
"description": "The object schema for an error",
"type": "object",
"properties": {
"object": {
"type": "string"
},
"code": {
"type": "string"
},
"description": {
"type": "string"
},
"messages": {
"type": "object"
}
},
"required": [
"object",
"code",
"description",
"messages"
],
"example": {
"object": "error",
"code": "server:internal_server_error",
"description": "Something went wrong on the server",
"messages": {
"error_key": "error_reason"
}
}
}
},
"required": [
"data"
],
"example": {
"success": false,
"data": {
"object": "error",
"code": "server:internal_server_error",
"description": "Something went wrong on the server",
"messages": {
"error_key": "error_reason"
}
}
}
}
]
}
}
}
}
}
}
},
"/api_key.update": {
"post": {
"tags": [
Expand Down
25 changes: 25 additions & 0 deletions apps/admin_api/priv/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5462,6 +5462,31 @@ paths:
updated_at: '2018-01-01T10:00:00Z'
deleted_at: null
'500': *ref_2
/api_key.get:
post:
tags:
- API Access
summary: Get a specific api key
operationId: api_key_get
security:
- ProviderAuth: []
- AdminAuth: []
requestBody:
description: The parameters to use for retrieving a specific api key
required: true
content:
application/vnd.omisego.v1+json:
schema:
properties:
id:
type: string
required:
- id
example:
id: api_01d744xm9cy3qx8hdwv4ax3k1h
responses:
'200': *ref_62
'500': *ref_2
/api_key.update:
post:
tags:
Expand Down
16 changes: 16 additions & 0 deletions apps/admin_api/priv/swagger/api_key/paths.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,22 @@ api_key.create:
$ref: 'responses.yaml#/APIKeyResponse'
'500':
$ref: '../../../../ewallet/priv/swagger/shared/responses.yaml#/InternalServerError'
api_key.get:
post:
tags:
- API Access
summary: Get a specific api key
operationId: api_key_get
security:
- ProviderAuth: []
- AdminAuth: []
requestBody:
$ref: 'request_bodies.yaml#/APIKeyGetBody'
responses:
'200':
$ref: 'responses.yaml#/APIKeyResponse'
'500':
$ref: '../../../../ewallet/priv/swagger/shared/responses.yaml#/InternalServerError'
api_key.update:
post:
tags:
Expand Down
14 changes: 14 additions & 0 deletions apps/admin_api/priv/swagger/api_key/request_bodies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ APIKeyCreateBody:
example:
name: my_api_key

APIKeyGetBody:
description: The parameters to use for retrieving a specific api key
required: true
content:
application/vnd.omisego.v1+json:
schema:
properties:
id:
type: string
required:
- id
example:
id: api_01d744xm9cy3qx8hdwv4ax3k1h

APIKeyUpdateBody:
description: The parameters to use for updating an API key
required: true
Expand Down
2 changes: 2 additions & 0 deletions apps/admin_api/priv/swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ paths:
$ref: 'api_key/paths.yaml#/api_key.all'
/api_key.create:
$ref: 'api_key/paths.yaml#/api_key.create'
/api_key.get:
$ref: 'api_key/paths.yaml#/api_key.get'
/api_key.update:
$ref: 'api_key/paths.yaml#/api_key.update'
/api_key.enable_or_disable:
Expand Down
Loading