Skip to content

Commit

Permalink
chore(CE): add audit log to connectors controller (#424)
Browse files Browse the repository at this point in the history
Co-authored-by: TivonB-AI2 <[email protected]>
  • Loading branch information
github-actions[bot] and TivonB-AI2 authored Oct 22, 2024
1 parent f1fe8f4 commit a8101c7
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/app/controllers/api/v1/connectors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ module V1
# rubocop:disable Metrics/ClassLength
class ConnectorsController < ApplicationController
include Connectors
include AuditLogger
before_action :set_connector, only: %i[show update destroy discover query_source]
# TODO: Enable this once we have query validation implemented for all the connectors
# before_action :validate_query, only: %i[query_source]
# TODO: Enable this for ai_ml sources
before_action :validate_catalog, only: %i[query_source]
after_action :event_logger
after_action :create_audit_log

def index
@connectors = current_workspace.connectors
Expand All @@ -23,6 +25,7 @@ def index

def show
authorize @connector
@audit_resource = @connector.name
render json: @connector, status: :ok
end

Expand All @@ -35,6 +38,8 @@ def create
)
if result.success?
@connector = result.connector
@audit_resource = @connector.name
@payload = connector_params
render json: @connector, status: :created
else
render_error(
Expand All @@ -54,6 +59,8 @@ def update

if result.success?
@connector = result.connector
@audit_resource = @connector.name
@payload = connector_params
render json: @connector, status: :ok
else
render_error(
Expand All @@ -66,6 +73,7 @@ def update

def destroy
authorize @connector
@audit_resource = @connector.name
@connector.destroy!
head :no_content
end
Expand All @@ -79,6 +87,8 @@ def discover

if result.success?
@catalog = result.catalog
@audit_resource = @connector.name
@payload = @catalog
render json: @catalog, status: :ok
else
render_error(
Expand All @@ -100,6 +110,8 @@ def query_source

if result.success?
@records = result.records.map(&:record).map(&:data)
@audit_resource = @connector.name
@payload = @records
render json: { data: @records }, status: :ok
else
render_error(
Expand Down Expand Up @@ -145,6 +157,10 @@ def validate_query
)
end

def create_audit_log
audit!(resource_id: params[:id], resource: @audit_resource, payload: @payload)
end

def connector_params
params.require(:connector).permit(:workspace_id,
:connector_type,
Expand Down
Loading

0 comments on commit a8101c7

Please sign in to comment.