Skip to content
This repository has been archived by the owner on Feb 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #177 from OpenCSPM/build
Browse files Browse the repository at this point in the history
better handling of malformed JSON import files. #176
  • Loading branch information
joshlarsen authored May 28, 2021
2 parents 1545ef1 + f7e1ae1 commit 6af7338
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ assignees: ''
**Describe the bug**
A clear and concise description of what the bug is.

**OpenCSPM version**
What version of the OpenCSPM Docker image are you using? (e.g. 0.1.22)

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
Expand Down
8 changes: 8 additions & 0 deletions docker/app/jobs/lib/loader/asset/asset_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

# Comment
class AssetRouter
INVALID_JSON = 'Expected NDJSON import file, found JSON import file.'

def initialize(asset, import_id, db)
@asset = asset
@import_id = import_id
Expand All @@ -25,6 +27,12 @@ def initialize(asset, import_id, db)
end

def route
# raise exception if not NDJSON
if @asset.is_a?(Array)
puts "[asset_router] Error: #{INVALID_JSON}"
raise INVALID_JSON
end

# Load an AWS resource
return aws_load if (%w[account service region resource] - @asset.keys).empty?

Expand Down
11 changes: 8 additions & 3 deletions docker/app/jobs/lib/loader/file_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ def loop_over_asset_lines(file_name)
file.each_slice(batch_size) do |lines|
line_count += lines.length
Parallel.each(lines, in_processes: 8) do |line|
asset_json = FastJsonparser.parse(line, symbolize_keys: false)
AssetRouter.new(asset_json, @import_id, @db)
line_count += 1
begin
asset_json = FastJsonparser.parse(line, symbolize_keys: false)
AssetRouter.new(asset_json, @import_id, @db)
line_count += 1
rescue FastJsonparser::ParseError => e
puts "[file_loader] Error: JSON can't be parsed. Ensure you are loading NDJSON files."
raise e
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ x-app: &app
RAILS_ENV: ${RAILS_ENV:-production}
RAILS_SERVE_STATIC_FILES: 1
RAILS_LOG_TO_STDOUT: 1
image: gcr.io/opencspm/engine:0.1.22
image: gcr.io/opencspm/engine:0.1.23
tmpfs:
- /tmp

Expand Down

0 comments on commit 6af7338

Please sign in to comment.