swagger: '2.0'
info:
  title: Internal Portal API
  description: RESTful API definitions for internal-portal
  version: 1.0.0
schemes:
  - http
  - https
consumes:
  - application/json
produces:
  - application/json
paths:
  /ping:
    get:
      operationId: ping
      responses:
        '200':
          description: get service status
          schema:
            $ref: '#/definitions/ResponseMessage'
        '400':
          description: the request is invalid
          schema:
            $ref: '#/definitions/ResponseMessage'
  /healthz:
    get:
      operationId: healthz
      responses:
        '200':
          description: get service status
          schema:
            $ref: '#/definitions/ResponseMessage'
        '400':
          description: the request is invalid
          schema:
            $ref: '#/definitions/ResponseMessage'
  /api/useralerts/v1/alert:
    post:
      operationId: fireAlert
      responses:
        '200':
          description: request accepted
          schema:
            $ref: '#/definitions/ResponseMessage'
        '400':
          description: the request is invalid
          schema:
            $ref: '#/definitions/ResponseMessage'
  /api/userdebug/v1/{organization}/features:
    get:
      operationId: getUserDebugFeatureList
      parameters:
        - name: organization
          in: path
          type: string
          required: true
      responses:
        '200':
          description: list of current valid auth codes
          schema:
            $ref: '#/definitions/UserDebugFeatureList'
  /api/userdebug/v1/{organization}/authorizations:
    get:
      operationId: getUserDebugAuthorizationList
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: page
          description: page number
          in: query
          type: integer
        - name: per_page
          description: items per page
          in: query
          type: integer
        - name: user
          description: user requesting the auth code
          in: query
          type: string
      responses:
        '200':
          description: list of current valid auth codes
          schema:
            type: array
            items:
              $ref: '#/definitions/UserDebugAuthorizationList'
  /api/userdebug/v1/{organization}/{cluster}/authorization:
    get:
      operationId: getUserDebugAuthorizationStatus
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
      responses:
        '200':
          description: current valid auth code
          schema:
            type: array
            items:
              $ref: '#/definitions/UserDebugAuthorization'
        '401':
          description: the user credentials are not valid
          schema:
            $ref: '#/definitions/ResponseMessage'
        '404':
          description: cluster not found
          schema:
            $ref: '#/definitions/ResponseMessage'
    post:
      operationId: newUserDebugAuthorization
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
        - name: expires
          description: time in hours the auth code shoud be valid
          in: body
          schema:
            type: integer
      responses:
        '202':
          description: new auth code granted
        '401':
          description: the user credentials are not valid
          schema:
            $ref: '#/definitions/ResponseMessage'
        '403':
          description: user does not have permission to create auth code
          schema:
            $ref: '#/definitions/ResponseMessage'
        '404':
          description: cluster not found
          schema:
            $ref: '#/definitions/ResponseMessage'
    delete:
      operationId: revokeUserDebugAuthorization
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
        - name: id
          description: id of auth code to revoke
          in: body
          schema:
            type: string
      responses:
        '200':
          description: auth code revoked
          schema:
            $ref: '#/definitions/ResponseMessage'
        '403':
          description: user does not have permission to revoke auth code
          schema:
            $ref: '#/definitions/ResponseMessage'
        '404':
          description: auth code not found
          schema:
            $ref: '#/definitions/ResponseMessage'
  /api/userdebug/v1/{organization}/{cluster}/authorization/details/{auth_id}:
    get:
      operationId: getUserDebugAuthorizationDetail
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
        - name: auth_id
          in: path
          type: string
          required: true
      responses:
        '200':
          description: detail of specified auth code
          schema:
            type: array
            items:
              $ref: '#/definitions/UserDebugAuthorizationDetail'
        '401':
          description: the user credentials are not valid
          schema:
            $ref: '#/definitions/ResponseMessage'
        '404':
          description: cluster or auth code not found
          schema:
            $ref: '#/definitions/ResponseMessage'
  /api/userdebug/v1/{organization}/{cluster}/authorization/records:
    get:
      operationId: getUserDebugAuthorizationRecords
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
        - name: page
          description: page number
          in: query
          type: integer
        - name: per_page
          description: items per page
          in: query
          type: integer
      responses:
        '200':
          description: auth records of the cluster
          schema:
            $ref: '#/definitions/UserDebugAuthorizationRecords'
        '404':
          description: cluster or auth code not found
          schema:
            $ref: '#/definitions/ResponseMessage'
  /api/userdebug/v1/{organization}/{cluster}/authorization/records/{auth_id}:
    get:
      operationId: getUserDebugAuthorizationRecordsForAuth
      parameters:
        - name: organization
          in: path
          type: string
          required: true
        - name: cluster
          in: path
          type: string
          required: true
        - name: auth_id
          in: path
          type: string
          required: true
        - name: page
          description: page number
          in: query
          type: integer
        - name: per_page
          description: items per page
          in: query
          type: integer
      responses:
        '200':
          description: auth records of the cluster
          schema:
            $ref: '#/definitions/UserDebugAuthorizationRecords'
        '404':
          description: cluster or auth code not found
          schema:
            $ref: '#/definitions/ResponseMessage'
definitions:
  ResponseMessage:
    type: object
    properties:
      code:
        type: integer
      message:
        type: string
  UserDebugFeatureList:
    type: object
    properties:
      org_id:
        type: string
      features:
        type: array
        items:
          type: object
          properties:
            key:
              type: string
            status:
              type: string
  UserDebugAuthorization:
    type: object
    properties:
      token:
        type: string
      valid:
        type: boolean
  UserDebugAuthorizedBy:
    type: object
    properties:
      id:
        type: string
        x-omitempty: false
      first_name:
        type: string
        x-omitempty: false
      last_name:
        type: string
        x-omitempty: false
      email:
        type: string
        x-omitempty: false
  UserDebugAuthorizationDetail:
    type: object
    properties:
      id:
        type: string
      project_id:
        type: string
      project_name:
        type: string
      cluster_id:
        type: string
      cluster_name:
        type: string
      status:
        type: string
      expires_at:
        type: integer
      created_at:
        type: integer
      updated_at:
        type: integer
      authorized_by:
        $ref: '#/definitions/UserDebugAuthorizedBy'
  UserDebugAuthorizationList:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/UserDebugAuthorizationDetail'
      total:
        type: integer
        x-omitempty: false
  UserDebugAuthorizationRecordItem:
    type: object
    properties:
      auth_id:
        type: string
      user:
        $ref: '#/definitions/UserDebugAuthorizedBy'
      operation:
        type: string
      created_at:
        type: integer
      expires_at:
        type: integer
      time_span:
        type: integer
  UserDebugAuthorizationRecords:
    type: object
    properties:
      items:
        type: array
        items:
          $ref: '#/definitions/UserDebugAuthorizationRecordItem'
      total:
        type: integer
        x-omitempty: false
