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

Commit 4f655c5

Browse files
authored
Merge pull request #126 from OpenCSPM/build
Build
2 parents 2aa123c + 7b638a1 commit 4f655c5

File tree

7 files changed

+40
-7
lines changed

7 files changed

+40
-7
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ docker/log
66
.viminfo
77
.bash_history
88
*.swp
9+
.env
10+
.idea
911

1012
# Ruby / RMV
1113
.ruby-version

docker/.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# See https://docs.rubocop.org/rubocop/configuration
1111
Layout/LineLength:
12-
Max: 100
12+
Max: 120
1313
Style/FrozenStringLiteralComment:
1414
EnforcedStyle: always_true
1515
Safe: true

docker/app/controllers/api/sources_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
# frozen_string_literal: true
2+
13
class Api::SourcesController < ApplicationController
24
before_action :set_source, only: %i[show update destroy]
35

46
# GET /sources
57
def index
8+
# re-read config.yml sources
9+
Source.new.refresh
10+
611
@sources = Source.all.order(id: :asc)
712

813
render json: @sources

docker/app/jobs/loader_job.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
class LoaderJob < ApplicationJob
99
queue_as :default
10+
CONFIG_FILE = 'load_config/config.yaml'
1011

1112
TYPE = :load
1213

@@ -26,7 +27,7 @@ def perform(args)
2627
logger.info 'Loading data'
2728

2829
begin
29-
BatchImporter.new('load_config/config.yaml').import
30+
BatchImporter.new(CONFIG_FILE).import
3031
job.complete!
3132
puts "Loader job finished - #{guid}"
3233
rescue StandardError => e

docker/app/models/source.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class Source < ApplicationRecord
24
enum status: {
35
disabled: 0,
@@ -9,4 +11,23 @@ class Source < ApplicationRecord
911
def schedule_worker
1012
RunnerJob.perform_later if scan_requested?
1113
end
14+
15+
def refresh
16+
# read config file, find or create a source for each source listed
17+
config_sources = JSON.parse(YAML.load_file(LoaderJob::CONFIG_FILE).to_json, object_class: OpenStruct)
18+
19+
return unless config_sources&.local_dirs&.length&.positive?
20+
21+
config_sources.local_dirs.each do |dir|
22+
puts "Config file local dir source=#{dir}"
23+
source = Source.find_or_create_by(name: dir)
24+
source.active!
25+
end
26+
27+
# loop through all existing sources, disable if not in config file
28+
Source.all.each do |source|
29+
puts "Config file system source=#{source.name} status=#{source.status}"
30+
source.disabled! unless config_sources.local_dirs.include?(source.name)
31+
end
32+
end
1233
end

docker/app/models/user.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
class User < ApplicationRecord
24
has_secure_password
35
rolify
@@ -72,22 +74,22 @@ def get_nav_paths
7274
{
7375
path: '/campaigns',
7476
name: 'Campaigns',
75-
num: Campaign.all.count
77+
num: Campaign.all.count.to_s
7678
},
7779
{
7880
path: '/profiles',
7981
name: 'Profiles',
80-
num: Profile.all.count
82+
num: Profile.all.count.to_s
8183
},
8284
{
8385
path: '/controls',
8486
name: 'Controls',
85-
num: Control.all.count
87+
num: Control.all.count.to_s
8688
},
8789
{
8890
path: '/sources',
8991
name: 'Sources',
90-
num: Source.all.count
92+
num: Source.all.count.to_s
9193
}
9294
]
9395

docker/lib/tasks/batch_import.rake

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
# frozen_string_literal: true
2+
13
$:.unshift('/app/app/jobs/lib')
24
require 'batch_importer'
35
require 'pry'
46

57
namespace :batch do
68
desc 'Loads All Data from Import'
79
task import: :environment do
8-
BatchImporter.new("load_config/config.yaml").import
10+
BatchImporter.new(LoaderJob::CONFIG_FILE).import
911
end
1012
end

0 commit comments

Comments
 (0)