Skip to content

Commit

Permalink
Merge pull request #1 from blueshift-labs/feature/index-type-sanitize…
Browse files Browse the repository at this point in the history
…-api

Add index type sanitizer API client code
  • Loading branch information
vishwajitparasar-bsft authored Sep 15, 2022
2 parents c7c86ef + 872be62 commit f3e8f2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/apollo/clients/accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def initialize(account)
@account = account
end

def sanitizer
handle_request("sanitizers/account/#{@account}", :get)
end

def run_sanitizer(type:, document:, sanitizer: nil)
handle_request("sanitize/accounts/#{@account}/types/#{type}", :get, body: {
document: document,
Expand Down
7 changes: 7 additions & 0 deletions lib/apollo/clients/indices.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ def sanitizer
def update_sanitizer(sanitizer:, override:false)
handle_request("sanitizers/#{@index}", :put, params: {override: override}, body: sanitizer)
end

def run_sanitizer(type:, document:, sanitizer: nil)
handle_request("sanitize/indices/#{@index}/types/#{type}", :get, body: {
document: document,
sanitizer: sanitizer
}.delete_if { |_, v| v.nil? })
end
end
end
17 changes: 14 additions & 3 deletions lib/apollo/models/sanitizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ def type_mapping(key:nil, value:nil)
end

def fetch
if @index.nil?
if !@index.nil?
Apollo.indices.for_index(@index).sanitizer
elsif !@account.nil?
Apollo.accounts.for_account(@account).sanitizer(
type: type,
document: document,
sanitizer: self)
else
Apollo.indices.for_index(:default).sanitizer
end
Expand All @@ -129,14 +134,20 @@ def override
end

def run_sanitizer(type:, document:)
if !@account.nil?
if !@index.nil?
Apollo.indices.for_index(@index).run_sanitizer(
type: type,
document: document,
sanitizer: self
)
elsif !@account.nil?
Apollo.accounts.for_account(@account).run_sanitizer(
type: type,
document: document,
sanitizer: self
)
else
raise 'missing account'
raise 'missing account or index'
end
end
end
Expand Down

0 comments on commit f3e8f2d

Please sign in to comment.