From 5ff58886b7be1ef1baaa01f2205d4585a751c18b Mon Sep 17 00:00:00 2001
From: Joel Abshier <jabshier@influxdata.com>
Date: Tue, 1 Nov 2022 10:54:20 -0500
Subject: [PATCH] chore(aim): Add Operator Entitlements Endpoints

---
 ...erator_accounts_accountId_entitlements.yml | 31 +++++++
 ..._accountId_entitlements_entitlement_id.yml | 80 +++++++++++++++++++
 src/unity/schemas/Entitlement.yml             | 30 +++++++
 src/unity/schemas/Entitlements.yml            |  3 +
 4 files changed, 144 insertions(+)
 create mode 100644 src/unity/paths/operator_accounts_accountId_entitlements.yml
 create mode 100644 src/unity/paths/operator_accounts_accountId_entitlements_entitlement_id.yml
 create mode 100644 src/unity/schemas/Entitlement.yml
 create mode 100644 src/unity/schemas/Entitlements.yml

diff --git a/src/unity/paths/operator_accounts_accountId_entitlements.yml b/src/unity/paths/operator_accounts_accountId_entitlements.yml
new file mode 100644
index 000000000..d3d4132a8
--- /dev/null
+++ b/src/unity/paths/operator_accounts_accountId_entitlements.yml
@@ -0,0 +1,31 @@
+get:
+  operationId: GetEntitlementsByAccount
+  tags:
+    - Accounts
+    - Entitlements
+    - Operators
+  summary: List all entitlements for an account
+  parameters:
+    - $ref: '../../common/parameters/TraceSpan.yml'
+    - in: path
+      name: accountId
+      schema:
+        type: string
+      required: true
+      description: The ID of the account to get entitlements for.
+  responses:
+    '200':
+      description: all entitlements
+      content:
+        application/json:
+          schema:
+            - $ref: '../schemas/Entitlements.yml'
+    '401':
+      description: Unauthorized
+      $ref: '../../common/responses/ServerError.yml'
+    '404':
+      description: Account not found
+      $ref: '../../common/responses/ServerError.yml'
+    default:
+      description: Unexpected error
+      $ref: '../../common/responses/ServerError.yml'
diff --git a/src/unity/paths/operator_accounts_accountId_entitlements_entitlement_id.yml b/src/unity/paths/operator_accounts_accountId_entitlements_entitlement_id.yml
new file mode 100644
index 000000000..ec95c3746
--- /dev/null
+++ b/src/unity/paths/operator_accounts_accountId_entitlements_entitlement_id.yml
@@ -0,0 +1,80 @@
+post:
+  operationId: OverrideEntitlementByAccount
+  tags:
+    - Accounts
+    - Entitlements
+    - Operators
+  summary: Creates or updates an entitlement override for an account
+  parameters:
+    - $ref: '../../common/parameters/TraceSpan.yml'
+    - in: path
+      name: accountId
+      schema:
+        type: string
+      required: true
+      description: The ID of the account to create the override for
+    - in: path
+      name: entitlementId
+      schema:
+        type: string
+      required: true
+      description: The ID of the entitlement definition to override
+  responses:
+    '200':
+      description: the updated entitlement
+      content:
+        application/json:
+          schema:
+            - $ref: '../schemas/Entitlement.yml'
+    '401':
+      description: Unauthorized
+      $ref: '../../common/responses/ServerError.yml'
+    '404':
+      description: Entitlement or Account not found
+      $ref: '../../common/responses/ServerError.yml'
+    '422':
+      description: Invalid override values
+      $ref: '../../common/responses/ServerError.yml'
+    default:
+      description: Unexpected error
+      $ref: '../../common/responses/ServerError.yml'
+delete:
+  operationId: DeleteEntitlementOverrideByAccount
+  tags:
+    - Accounts
+    - Entitlements
+    - Operators
+  summary: Deletes an entitlement override for an account
+  parameters:
+    - $ref: '../../common/parameters/TraceSpan.yml'
+    - in: path
+      name: accountId
+      schema:
+        type: string
+      required: true
+      description: The ID of the account to delete the override for
+    - in: path
+      name: entitlementId
+      schema:
+        type: string
+      required: true
+      description: The ID of the entitlement definition to delete overrides for
+  responses:
+    '200':
+      description: the updated entitlement
+      content:
+        application/json:
+          schema:
+            - $ref: '../schemas/Entitlement.yml'
+    '401':
+      description: Unauthorized
+      $ref: '../../common/responses/ServerError.yml'
+    '404':
+      description: Entitlement or Account not found
+      $ref: '../../common/responses/ServerError.yml'
+    '422':
+      description: Delete failed
+      $ref: '../../common/responses/ServerError.yml'
+    default:
+      description: Unexpected error
+      $ref: '../../common/responses/ServerError.yml'
diff --git a/src/unity/schemas/Entitlement.yml b/src/unity/schemas/Entitlement.yml
new file mode 100644
index 000000000..b952e7682
--- /dev/null
+++ b/src/unity/schemas/Entitlement.yml
@@ -0,0 +1,30 @@
+properties:
+  id:
+    type: number
+    description: the entitlement definition id
+  name:
+    type: string
+    description: the name of the entitlement
+  description:
+    type: string
+    description: the description of the entitlement
+  value:
+    type: number
+    description: the entitlement value for the account
+  isUnlimited:
+    type: boolean
+    description: flag whether the entitlement value is unlimited
+  defaultValue:
+    type: number
+    description: the entitlement default value for the account type
+  defaultIsUnlimited:
+    type: boolean
+    description: flag whether the entitlement default value is unlimited
+required:
+  - id
+  - name
+  - description
+  - value
+  - isUnlimited
+  - defaultValue
+  - defaultIsUnlimited
diff --git a/src/unity/schemas/Entitlements.yml b/src/unity/schemas/Entitlements.yml
new file mode 100644
index 000000000..0c78855ac
--- /dev/null
+++ b/src/unity/schemas/Entitlements.yml
@@ -0,0 +1,3 @@
+type: array
+items:
+  $ref: './Entitlement.yml'
