bigsister 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 801cec260afc76e68534a6eb2a927af3ded0e4a3127b87288cc7129ca11fb643
4
- data.tar.gz: ee112f0f35496f9c96271e57774c9cbb814a704d2d97f5bba7f59b156fbf99b3
3
+ metadata.gz: e856359282c49195b70bf99957e8a51b15829dd04db3e60585cfeff07e07f7bd
4
+ data.tar.gz: 2a0a5e21088f29e54bb2677c13d05a75d43a155d244072cf5a6d3ff667006eb5
5
5
  SHA512:
6
- metadata.gz: cab071a5a1faf95f92221df55e7bcef07b75ee8220d241572a4fc624a2b150d2260882802ed2d1e8032e0ac54974ee72d18bd4f188968080b5d70d3b8f7699c0
7
- data.tar.gz: 82720dfdfcb3d29abbd233f8ad0c2a51a6b2e0e3b12b289d485366c3a206baf6bc9712f01cdbb632fb747f1eabb88f8d5852aab25d0c73b214228ab39b2ae0f4
6
+ metadata.gz: 78f223af17f62af998f0ce1589472a6d642ca8eb87e22e92ebc44c6f129063e4cfaa8d932cb2e59dad0beba01d0f8f813abd70f8b3c6b507b08e80bd03cf7f8f
7
+ data.tar.gz: 920e554d8c4796f8113f80e688a6ea21e6461f07eda99bda0e12995cbc4e7ada5b8e9b425f3d8ff45895fe92757fb6f5735f349144f1a284c51541f1e84809b3
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  Gemfile.lock
14
+ .bigsister.yml
data/GHANGELOG.md CHANGED
@@ -4,10 +4,16 @@ All notable changes to BigSister will be documented in this file.
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.1.2] - Nov 11, 2019
8
+ ### Added
9
+ * CSV reporter
10
+ * Complete monitoring and report generation
11
+
7
12
  ## [0.1.1] - Nov 8, 2019
8
13
  ### Added
9
14
  * Basic Application object
10
15
  * CLI tool
11
16
 
12
- [Unreleased]: https://github.com/paulholden2/bigsister/compare/0.1.1...HEAD
17
+ [Unreleased]: https://github.com/paulholden2/bigsister/compare/0.1.2...HEAD
13
18
  [0.1.1]: https://github.com/paulholden2/bigsister/releases/tag/0.1.1
19
+ [0.1.2]: https://github.com/paulholden2/bigsister/releases/tag/0.1.2
data/README.md CHANGED
@@ -34,12 +34,8 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
34
34
 
35
35
  ## Contributing
36
36
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bigsister. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/paulholden2/bigsister. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
38
38
 
39
39
  ## License
40
40
 
41
41
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
42
-
43
- ## Code of Conduct
44
-
45
- Everyone interacting in the BigSister project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/bigsister/blob/master/CODE_OF_CONDUCT.md).
data/bigsister.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_dependency "springcm-sdk", "~> 0.3"
30
+ spec.add_dependency "springcm-sdk", "~> 0.3.2"
31
31
  spec.add_dependency "os", "~> 1.0"
32
32
 
33
33
  spec.add_development_dependency "bundler", "~> 2.0"
data/exe/bigsister CHANGED
File without changes
data/lib/bigsister.rb CHANGED
@@ -20,4 +20,7 @@ module BigSister
20
20
  super("No configuration files found. Looked in: #{checked_paths.join(', ')}")
21
21
  end
22
22
  end
23
+
24
+ class InvalidConfiguration < Error
25
+ end
23
26
  end
@@ -15,6 +15,21 @@ module BigSister
15
15
  end
16
16
 
17
17
  def run
18
+ config.reporters.each { |reporter|
19
+ config.monitors.each { |monitor|
20
+ if reporter.log_files?
21
+ monitor.files.each { |file|
22
+ reporter.log_file(file)
23
+ }
24
+ end
25
+ if reporter.log_directories?
26
+ monitor.directories.each { |directory|
27
+ reporter.log_directory(directory)
28
+ }
29
+ end
30
+ }
31
+ reporter.render
32
+ }
18
33
  end
19
34
 
20
35
  private
@@ -1,17 +1,21 @@
1
1
  require "bigsister/monitors/local"
2
2
  require "bigsister/monitors/springcm"
3
+ require "bigsister/reporters/csv_reporter"
3
4
 
4
5
  module BigSister
5
6
  class Configuration
6
7
  MONITOR_TYPES = %w(local springcm).freeze
8
+ REPORTER_TYPES = %w(csv).freeze
7
9
 
8
- attr_reader :monitors
10
+ attr_reader :monitors, :reporters
9
11
 
10
12
  def initialize(data)
11
13
  @monitors = []
14
+ @reporters = []
12
15
  @config_errors = []
13
16
 
14
17
  load_monitoring(data)
18
+ load_reporting(data)
15
19
  end
16
20
 
17
21
  def valid?
@@ -22,9 +26,6 @@ module BigSister
22
26
 
23
27
  def load_monitoring(data)
24
28
  @monitoring = data.fetch("monitor", [])
25
- if @monitoring.empty?
26
- config_error("No monitoring locations configured")
27
- end
28
29
  @monitoring.each_with_index { |location, i|
29
30
  # Validate monitoring type
30
31
  type = location.fetch("type", nil)
@@ -46,6 +47,27 @@ module BigSister
46
47
  end
47
48
  end
48
49
 
50
+ def load_reporting(data)
51
+ @reporting = data.fetch("report", [])
52
+ @reporting.each_with_index { |reporter, i|
53
+ # Validate reporting type
54
+ type = reporter.fetch("type", nil)
55
+ if type.nil?
56
+ config_error("No report type specified for reporter #{i}")
57
+ elsif !REPORTER_TYPES.include?(type)
58
+ config_error("Invalid report type specifeid for reporter #{i}")
59
+ end
60
+ @reporters.push(load_reporter(type, reporter, i))
61
+ @reporters = @reporters.reject(&:nil?)
62
+ }
63
+ end
64
+
65
+ def load_reporter(type, reporter, i)
66
+ if type == "csv"
67
+ BigSister::CsvReporter.new(reporter, i)
68
+ end
69
+ end
70
+
49
71
  def config_error(message)
50
72
  @config_errors.push(message)
51
73
  end
@@ -0,0 +1,19 @@
1
+ module BigSister
2
+ class DirectoryInfo
3
+ PROPERTIES = %w(name file_count directory_count).map(&:to_sym).freeze
4
+
5
+ PROPERTIES.each { |prop|
6
+ attr_reader prop
7
+ }
8
+
9
+ def initialize(data = {})
10
+ @name = data[:name]
11
+ @file_count = data[:file_count]
12
+ @directory_count = data[:directory_count]
13
+ end
14
+
15
+ def type
16
+ "directory"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module BigSister
2
+ class FileInfo
3
+ PROPERTIES = %w(name file_size).map(&:to_sym).freeze
4
+
5
+ PROPERTIES.each { |prop|
6
+ attr_reader prop
7
+ }
8
+
9
+ def initialize(data = {})
10
+ @name = data[:name]
11
+ @file_size = data[:file_size]
12
+ end
13
+
14
+ def type
15
+ "file"
16
+ end
17
+ end
18
+ end
@@ -4,11 +4,5 @@ module BigSister
4
4
  @location = location
5
5
  @id = id
6
6
  end
7
-
8
- def summary
9
- end
10
-
11
- def detail
12
- end
13
7
  end
14
8
  end
@@ -1,6 +1,45 @@
1
1
  require "bigsister/monitor"
2
+ require "bigsister/file_info"
3
+ require "bigsister/directory_info"
2
4
 
3
5
  module BigSister
4
6
  class LocalMonitor < BigSister::Monitor
7
+ def initialize(config, i)
8
+ @config = config
9
+ @id = i
10
+ @path = config.fetch("path", nil)
11
+ super(config, i)
12
+ end
13
+
14
+ def files
15
+ res = Dir.entries(@path).reject { |file|
16
+ File.directory?(File.join(@path, file))
17
+ }.map { |file|
18
+ file_path = File.join(@path, file)
19
+ FileInfo.new(
20
+ name: file,
21
+ path: file_path,
22
+ file_size: File.size(file_path)
23
+ )
24
+ }
25
+ res
26
+ end
27
+
28
+ def directories
29
+ res = Dir.entries(@path).select { |file|
30
+ File.directory?(File.join(@path, file))
31
+ }.map { |dir|
32
+ dir_path = File.join(@path, dir)
33
+ file_count = Dir.entries(dir_path).reject { |file| File.directory?(File.join(dir_path, file)) }.size
34
+ directory_count = Dir.entries(dir_path).select { |file| File.directory?(File.join(dir_path, file)) }.size
35
+ DirectoryInfo.new(
36
+ name: dir,
37
+ path: dir_path,
38
+ file_count: file_count,
39
+ directory_count: directory_count
40
+ )
41
+ }
42
+ res
43
+ end
5
44
  end
6
45
  end
@@ -1,6 +1,70 @@
1
1
  require "bigsister/monitor"
2
+ require "bigsister/file_info"
3
+ require "bigsister/directory_info"
4
+ require "springcm-sdk"
2
5
 
3
6
  module BigSister
4
7
  class SpringcmMonitor < BigSister::Monitor
8
+ def initialize(config, i)
9
+ @client_id = config.fetch("client_id", nil)
10
+ @client_secret = config.fetch("client_secret", nil)
11
+ @data_center = config.fetch("data_center", nil)
12
+ @path = config.fetch("path", nil)
13
+ validate_config!
14
+ @client = Springcm::Client.new(@data_center, @client_id, @client_secret)
15
+ @client.connect!
16
+ @folder = @client.folder(path: @path)
17
+ super(config, i)
18
+ end
19
+
20
+ def files
21
+ docs = []
22
+ list = @folder.documents(offset: 0, limit: 20)
23
+ while !list.nil?
24
+ docs = docs + list.items
25
+ list = list.next
26
+ end
27
+ res = docs.map { |document|
28
+ FileInfo.new(
29
+ name: document.name,
30
+ file_size: document.native_file_size
31
+ )
32
+ }
33
+ res
34
+ end
35
+
36
+ def directories
37
+ dirs = []
38
+ list = @folder.folders(offset: 0, limit: 20)
39
+ while !list.nil?
40
+ dirs = dirs + list.items
41
+ list = list.next
42
+ end
43
+ res = dirs.map { |dir|
44
+ DirectoryInfo.new(
45
+ name: dir.name,
46
+ file_count: dir.documents.total,
47
+ directory_count: dir.folders.total
48
+ )
49
+ }
50
+ res
51
+ end
52
+
53
+ private
54
+
55
+ def validate_config!
56
+ if @client_id.nil?
57
+ raise BigSister::InvalidConfiguration.new("SpringCM client_id required.")
58
+ end
59
+ if @client_secret.nil?
60
+ raise BigSister::InvalidConfiguration.new("SpringCM client_secret is required.")
61
+ end
62
+ if @client_secret.nil?
63
+ raise BigSister::InvalidConfiguration.new("SpringCM data_center is required.")
64
+ end
65
+ if @path.nil?
66
+ raise BigSister::InvalidConfiguration.new("SpringCM path is required.")
67
+ end
68
+ end
5
69
  end
6
70
  end
@@ -0,0 +1,136 @@
1
+ module BigSister
2
+ class Reporter
3
+ def initialize(schema, id)
4
+ @id = id
5
+ @schema = schema
6
+ @files = []
7
+ @directories = []
8
+ if !@schema.key?("format")
9
+ raise BigSister::InvalidConfiguration.new("Reporter format is required")
10
+ elsif !%w(summary detail).include?(@schema.fetch("format"))
11
+ raise BigSister::InvalidConfiguration.new("Reporter format must be one of: summary, detail")
12
+ else
13
+ @format = @schema.fetch("format")
14
+ end
15
+ @columns = schema.fetch("columns", [])
16
+ @columns.each { |column|
17
+ validate_column!(column)
18
+ }
19
+ end
20
+
21
+ def log_file(path)
22
+ @files.push(path)
23
+ end
24
+
25
+ def log_directory(path)
26
+ @directories.push(path)
27
+ end
28
+
29
+ def summary?
30
+ return @format == "summary"
31
+ end
32
+
33
+ def detail?
34
+ return !summary?
35
+ end
36
+
37
+ def log_files?
38
+ return @schema.fetch("include", []).include?("files")
39
+ end
40
+
41
+ def log_directories?
42
+ return @schema.fetch("include", []).include?("directories")
43
+ end
44
+
45
+ protected
46
+
47
+ def validate_column!(column)
48
+ if !column.key?("type")
49
+ raise BigSister::InvalidConfiguration.new("Column type is required.")
50
+ end
51
+ allowed_types = %w(timestamp literal file_count directory_count)
52
+ if detail?
53
+ allowed_types += %w(file_size type name)
54
+ end
55
+ type = column.fetch("type")
56
+ if !allowed_types.include?(type)
57
+ list = allowed_types.join(", ")
58
+ raise BigSister::InvalidConfiguration.new("Column type for #{@format} must be one of: #{list}")
59
+ end
60
+ end
61
+
62
+ def transform_file(file, column)
63
+ type = column["type"]
64
+ if type == "timestamp"
65
+ DateTime.now.strftime("%FT%T%:z")
66
+ elsif type == "name"
67
+ file.name
68
+ elsif type == "type"
69
+ file.type
70
+ elsif type == "file_size"
71
+ file.file_size
72
+ elsif type == "literal"
73
+ @schema.fetch("value", nil)
74
+ end
75
+ end
76
+
77
+ def transform_directory(directory, column)
78
+ type = column["type"]
79
+ if type == "timestamp"
80
+ current_timestamp
81
+ elsif type == "name"
82
+ directory.name
83
+ elsif type == "type"
84
+ directory.type
85
+ elsif type == "file_count"
86
+ directory.file_count
87
+ elsif type == "directory_count"
88
+ directory.directory_count
89
+ elsif type == "literal"
90
+ @schema.fetch("value", nil)
91
+ end
92
+ end
93
+
94
+ def file_rows
95
+ @files.map { |file|
96
+ @columns.map { |column|
97
+ transform_file(file, column)
98
+ }
99
+ }
100
+ end
101
+
102
+ def directory_rows
103
+ @directories.map { |dir|
104
+ @columns.map { |column|
105
+ transform_directory(dir, column)
106
+ }
107
+ }
108
+ end
109
+
110
+ def current_timestamp
111
+ DateTime.now.strftime("%FT%T%:z")
112
+ end
113
+
114
+ def detail
115
+ rows = []
116
+ rows += file_rows if log_files?
117
+ rows += directory_rows if log_directories?
118
+ rows
119
+ end
120
+
121
+ def summary
122
+ file_count = file_rows.size
123
+ directory_count = directory_rows.size
124
+ @columns.map { |column|
125
+ type = column["type"]
126
+ if type == "timestamp"
127
+ current_timestamp
128
+ elsif type == "file_count"
129
+ file_count
130
+ elsif type == "directory_count"
131
+ directory_count
132
+ end
133
+ }
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,44 @@
1
+ require "bigsister/reporter"
2
+ require "csv"
3
+
4
+ module BigSister
5
+ class CsvReporter < BigSister::Reporter
6
+ def initialize(schema, i)
7
+ super(schema, i)
8
+ if !schema.key?("path")
9
+ raise BigSister::InvalidConfiguration.new("CSV Reporter path is required.")
10
+ else
11
+ @outfile_path = schema.fetch("path")
12
+ end
13
+ end
14
+
15
+ def csv
16
+ if summary?
17
+ summary
18
+ else
19
+ detail
20
+ end
21
+ end
22
+
23
+ def render
24
+ File.open(@outfile_path, "w") { |file|
25
+ file.write(csv)
26
+ }
27
+ end
28
+
29
+ protected
30
+
31
+ def headers
32
+ @columns.map { |column| column["title"] }.to_csv(row_sep: nil)
33
+ end
34
+
35
+ def detail
36
+ rows = super.map { |row| row.to_csv(row_sep: nil) }
37
+ ([headers] + rows).join("\n")
38
+ end
39
+
40
+ def summary
41
+ [headers, super.to_csv(row_sep: nil)].join("\n")
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module BigSister
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigsister
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Holden
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2019-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: springcm-sdk
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.3'
19
+ version: 0.3.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.3'
26
+ version: 0.3.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: os
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +102,6 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
- - ".bigsister.yml"
106
105
  - ".gitignore"
107
106
  - ".rspec"
108
107
  - ".travis.yml"
@@ -118,9 +117,13 @@ files:
118
117
  - lib/bigsister.rb
119
118
  - lib/bigsister/application.rb
120
119
  - lib/bigsister/configuration.rb
120
+ - lib/bigsister/directory_info.rb
121
+ - lib/bigsister/file_info.rb
121
122
  - lib/bigsister/monitor.rb
122
123
  - lib/bigsister/monitors/local.rb
123
124
  - lib/bigsister/monitors/springcm.rb
125
+ - lib/bigsister/reporter.rb
126
+ - lib/bigsister/reporters/csv_reporter.rb
124
127
  - lib/bigsister/version.rb
125
128
  homepage: https://github.com/paulholden2/bigsister
126
129
  licenses:
data/.bigsister.yml DELETED
@@ -1,49 +0,0 @@
1
- monitor:
2
- - type: local
3
- path: /Users/paul
4
- - type: springcm
5
- path: /Human Resources Records
6
- credentials:
7
- client_id: client_id
8
- client_secret: client_secret
9
- data_center: data_center
10
- generate:
11
- - type: csv
12
- path: ./detail.csv
13
- format: detail
14
- mode: write
15
- include:
16
- - directories
17
- - files
18
- columns:
19
- - title: Timestamp
20
- type: timestamp
21
- - title: Path
22
- type: path
23
- - title: File Size
24
- type: size
25
- - title: File Type
26
- type: type
27
- - title: Created
28
- type: created_at
29
- - title: Modified
30
- type: modified_at
31
- - title: Customer
32
- type: literal
33
- value: KHSD
34
- - type: csv
35
- path: ./summary.csv
36
- format: summary
37
- mode: append
38
- include:
39
- - directories
40
- - files
41
- columns:
42
- - title: Timestamp
43
- type: timestamp
44
- - title: File Count
45
- type: file_count
46
- - title: Directory Count
47
- type: directory_count
48
- - title: File Size
49
- type: file_size