eworld 1.2.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core/aws_profile.rb +41 -0
- data/lib/eworld.rb +11 -33
- data/lib/routes/generate.rb +127 -0
- data/lib/routes/scan.rb +42 -6
- data/lib/rules/js/rule_js_parameters.rb +1 -2
- data/lib/scanners/controller_scanner.rb +137 -0
- data/lib/scanners/entity_scanner.rb +15 -0
- data/lib/scanners/permission_scanner.rb +15 -0
- data/lib/scanners/queue_scanner.rb +15 -0
- data/lib/scanners/route_scanner.rb +239 -0
- data/lib/version.rb +1 -1
- data/lib/writers/api_docs_writer.rb +32 -0
- data/lib/writers/base_writer.rb +21 -0
- data/lib/writers/controller_writer.rb +115 -0
- data/lib/writers/entity_writer.rb +15 -0
- data/lib/writers/js_docs_writer.rb +32 -0
- data/lib/writers/permission_writer.rb +15 -0
- data/lib/writers/queue_writer.rb +14 -0
- data/lib/writers/route_writer.rb +56 -0
- data/lib/writers/service_writer.rb +106 -0
- data/opt/config/schema.yml +7 -0
- data/opt/schema/controllers.yml +32 -0
- data/opt/schema/database.yml +0 -0
- data/opt/schema/routes.yml +77 -0
- metadata +24 -7
- data/lib/routes/generate_api_entities.rb +0 -35
- data/lib/routes/generate_ui_routes.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '078008fd3dd291e33389b27aa315baf2e685e058'
|
4
|
+
data.tar.gz: c60c14e788eead8fce813927566c3d3fbb6e698d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94582312d862b1604f9b34ec7cc6a82691ff22bf610ddb008d5f323adad8ff750fdf304cbdbba9b6b542986195db1fe3dfd9fc4a87ff052582287ee5505b652
|
7
|
+
data.tar.gz: 6923c41a9ab7945198a4b93eab25b9db09e6269df1c5f776427fef85ea5b521134e3eba4ae968c95b9fd1b97a931b3ed039ef5c0d69b604f754e9030937e7d3d
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class AWSProfile
|
4
|
+
|
5
|
+
@@profile = nil
|
6
|
+
@@credentials = nil
|
7
|
+
|
8
|
+
# Reads the config data and attempts to extract the profile.
|
9
|
+
# @return void
|
10
|
+
def self.init(config_data)
|
11
|
+
|
12
|
+
errors = []
|
13
|
+
|
14
|
+
# Get the profile out of the config YML.
|
15
|
+
@@profile = config_data['AWS']['Profile'] if config_data.has_key?('AWS')
|
16
|
+
|
17
|
+
# Check the credentials exist.
|
18
|
+
@@credentials, more_errors = Blufin::AWS::get_aws_credentials(@@profile)
|
19
|
+
errors.concat(more_errors)
|
20
|
+
|
21
|
+
# If anything is wrong, output error(s).
|
22
|
+
Blufin::Config::invalid_configuration(App::GEM_NAME, errors) if errors.any?
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the AWS profile. Returns either the profile (or nil).
|
27
|
+
# @return string
|
28
|
+
def self.get
|
29
|
+
@@profile
|
30
|
+
end
|
31
|
+
|
32
|
+
# Convenience method to just get the profile name.
|
33
|
+
# @return string
|
34
|
+
def self.get_profile_name
|
35
|
+
return nil if @@credentials.nil?
|
36
|
+
@@profile[PROFILE]
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/lib/eworld.rb
CHANGED
@@ -2,11 +2,16 @@ require 'blufin-lib'
|
|
2
2
|
require 'columnist'
|
3
3
|
require 'convoy'
|
4
4
|
require 'yaml'
|
5
|
+
require 'json'
|
6
|
+
|
5
7
|
require_relative 'version'
|
8
|
+
require 'writers/base_writer'
|
6
9
|
|
7
10
|
Dir["#{File.dirname(__FILE__)}/core/**/*.rb"].each { |file| load(file) }
|
8
11
|
Dir["#{File.dirname(__FILE__)}/routes/**/*.rb"].each { |file| load(file) }
|
9
12
|
Dir["#{File.dirname(__FILE__)}/rules/**/*.rb"].each { |file| load(file) }
|
13
|
+
Dir["#{File.dirname(__FILE__)}/scanners/**/*.rb"].each { |file| load(file) }
|
14
|
+
Dir["#{File.dirname(__FILE__)}/writers/**/*.rb"].each { |file| load(file) unless file =~ /\/(base_writer)\.rb\z/ }
|
10
15
|
|
11
16
|
module App
|
12
17
|
|
@@ -22,7 +27,8 @@ module App
|
|
22
27
|
|
23
28
|
unless ARGV[0] == 'config' || ARGV[0] == 'x'
|
24
29
|
Blufin::Config::init(SCHEMA_FILE, TEMPLATE_FILE, CONFIG_FILE, GEM_NAME)
|
25
|
-
|
30
|
+
App::AWSProfile::init(Blufin::Config::get)
|
31
|
+
Blufin::Projects.new(Blufin::Config::get['Projects'], App::AWSProfile::get)
|
26
32
|
end
|
27
33
|
|
28
34
|
Convoy::App.create do |app|
|
@@ -43,39 +49,11 @@ TEMPLATE
|
|
43
49
|
if is_albert_mac
|
44
50
|
app.command :generate, :aliases => [:g] do |generate|
|
45
51
|
generate.summary 'Generate boiler-plate code'
|
46
|
-
|
47
|
-
|
48
|
-
generate_api.summary 'Generate API code'
|
49
|
-
# e - GENERATE API ENTITIES
|
50
|
-
generate_api.command :api_entities, :aliases => [:e] do |generate_api_entities|
|
51
|
-
generate_api_entities.summary 'Generate boiler-plate entity code'
|
52
|
-
generate_api_entities.action do |opts, args|
|
53
|
-
AppCommand::GenerateApiEntities.new(opts, args).execute
|
54
|
-
end
|
55
|
-
end
|
56
|
-
# GENERATE API (Default)
|
57
|
-
generate_api.action do
|
58
|
-
system("#{App::GEM_NAME} g a -h")
|
59
|
-
end
|
60
|
-
end
|
61
|
-
# generate - GENERATE UI
|
62
|
-
generate.command :ui, :aliases => [:u] do |generate_ui|
|
63
|
-
generate_ui.summary 'Generate UI code'
|
64
|
-
# r - GENERATE UI ROUTES
|
65
|
-
generate_ui.command :ui_routes, :aliases => [:r] do |generate_ui_routes|
|
66
|
-
generate_ui_routes.summary 'Generate routes.js (and blank routes if not exists)'
|
67
|
-
generate_ui_routes.action do |opts, args|
|
68
|
-
AppCommand::GenerateUiRoutes.new(opts, args).execute
|
69
|
-
end
|
70
|
-
end
|
71
|
-
# GENERATE UI (Default)
|
72
|
-
generate_ui.action do
|
73
|
-
system("#{App::GEM_NAME} g u -h")
|
74
|
-
end
|
52
|
+
generate.options do |opts|
|
53
|
+
opts.opt :silent, 'Run in silent mode', :short => '-s', :long => '--silent', :type => :boolean
|
75
54
|
end
|
76
|
-
|
77
|
-
|
78
|
-
system("#{App::GEM_NAME} g -h")
|
55
|
+
generate.action do |opts, args|
|
56
|
+
AppCommand::Generate.new(opts, args).execute
|
79
57
|
end
|
80
58
|
end
|
81
59
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module AppCommand
|
2
|
+
|
3
|
+
class Generate < ::Convoy::ActionCommand::Base
|
4
|
+
|
5
|
+
def execute
|
6
|
+
|
7
|
+
begin
|
8
|
+
|
9
|
+
@opts = command_options
|
10
|
+
@args = arguments
|
11
|
+
|
12
|
+
@verbose = !@opts[:silent]
|
13
|
+
|
14
|
+
@errors = []
|
15
|
+
@generated = []
|
16
|
+
@overwritten = []
|
17
|
+
|
18
|
+
opts_validate
|
19
|
+
opts_routing
|
20
|
+
|
21
|
+
rescue => e
|
22
|
+
|
23
|
+
Blufin::Terminal::print_exception(e)
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def opts_validate
|
30
|
+
|
31
|
+
# TODO - This cannot be hard-coded forever!
|
32
|
+
group = 'fmm'
|
33
|
+
|
34
|
+
# Get API Project.
|
35
|
+
api_projects = Blufin::Projects.get_projects_as_array(group: group, types: [Blufin::Projects::TYPE_API_SIMPLE])
|
36
|
+
@api_project = Blufin::Projects.show_project_prompt(api_projects)
|
37
|
+
|
38
|
+
# Get Quasar Project.
|
39
|
+
ui_projects = Blufin::Projects.get_projects_as_array(group: group, types: [Blufin::Projects::TYPE_QUASAR])
|
40
|
+
@ui_project = Blufin::Projects.show_project_prompt(ui_projects)
|
41
|
+
|
42
|
+
# Get project path(s).
|
43
|
+
@project_path = Blufin::Projects::get_project_path(@api_project[Blufin::Projects::PROJECT_ID])
|
44
|
+
@project_path_ui = Blufin::Projects::get_project_path(@ui_project[Blufin::Projects::PROJECT_ID], true)
|
45
|
+
|
46
|
+
puts if @verbose
|
47
|
+
|
48
|
+
td = @ui_project[Blufin::Projects::TRANSIENT_DATA]
|
49
|
+
root = Blufin::Strings::remove_surrounding_slashes(td[Blufin::Projects::CG_QUASAR_ROOT])
|
50
|
+
js = Blufin::Strings::remove_surrounding_slashes(td[Blufin::Projects::CG_QUASAR_JS])
|
51
|
+
|
52
|
+
Blufin::Terminal::execute_proc("Scanning: #{Blufin::Terminal::format_highlight('Javascript')}", Proc.new {
|
53
|
+
eb = @errors.length
|
54
|
+
@js, je = Blufin::ScannerJs::scan("#{@project_path}/#{root}/#{js}")
|
55
|
+
@errors.concat(je)
|
56
|
+
eb == @errors.length
|
57
|
+
}, verbose: @verbose)
|
58
|
+
|
59
|
+
Blufin::Terminal::execute_proc("Scanning: #{Blufin::Terminal::format_highlight('Routes')}", Proc.new {
|
60
|
+
eb = @errors.length
|
61
|
+
@routes_to_write, re = EWorld::RouteScanner::scan(@ui_project)
|
62
|
+
@errors.concat(re)
|
63
|
+
eb == @errors.length
|
64
|
+
}, verbose: @verbose)
|
65
|
+
|
66
|
+
Blufin::Terminal::execute_proc("Scanning: #{Blufin::Terminal::format_highlight('Controllers')}", Proc.new {
|
67
|
+
eb = @errors.length
|
68
|
+
@controllers, ce = EWorld::ControllerScanner::scan(@api_project)
|
69
|
+
@errors.concat(ce)
|
70
|
+
eb == @errors.length
|
71
|
+
}, verbose: @verbose)
|
72
|
+
|
73
|
+
puts if @errors.any? && @verbose
|
74
|
+
|
75
|
+
Blufin::ScannerError::output_cli(@errors, false) if @errors.any?
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
def opts_routing
|
80
|
+
|
81
|
+
Blufin::Terminal::execute_proc("Processing: #{Blufin::Terminal::format_highlight('Routes')}", Proc.new {
|
82
|
+
rg, ro = EWorld::RouteWriter::write(@ui_project, @routes_to_write)
|
83
|
+
@generated.concat(rg)
|
84
|
+
@overwritten.concat(ro)
|
85
|
+
}, verbose: @verbose)
|
86
|
+
|
87
|
+
Blufin::Terminal::execute_proc("Processing: #{Blufin::Terminal::format_highlight('Controllers')}", Proc.new {
|
88
|
+
cg, co = EWorld::ControllerWriter::write(@api_project, @ui_project, @controllers)
|
89
|
+
@generated.concat(cg)
|
90
|
+
@overwritten.concat(co)
|
91
|
+
|
92
|
+
}, verbose: @verbose)
|
93
|
+
|
94
|
+
Blufin::Terminal::execute_proc("Processing: #{Blufin::Terminal::format_highlight('Services')}", Proc.new {
|
95
|
+
sg, so = EWorld::ServiceWriter::write(@api_project, @ui_project, @controllers)
|
96
|
+
@generated.concat(sg)
|
97
|
+
@overwritten.concat(so)
|
98
|
+
}, verbose: @verbose)
|
99
|
+
|
100
|
+
Blufin::Terminal::execute_proc("Processing: #{Blufin::Terminal::format_highlight('API Docs (JSON)')}", Proc.new {
|
101
|
+
ag, ao = EWorld::ApiDocsWriter::write(@api_project, @ui_project, @controllers)
|
102
|
+
@generated.concat(ag)
|
103
|
+
@overwritten.concat(ao)
|
104
|
+
}, verbose: @verbose)
|
105
|
+
|
106
|
+
Blufin::Terminal::execute_proc("Processing: #{Blufin::Terminal::format_highlight('JS Docs (JSON)')}", Proc.new {
|
107
|
+
jg, jo = EWorld::JsDocsWriter::write(@api_project, @ui_project, @js)
|
108
|
+
@generated.concat(jg)
|
109
|
+
@overwritten.concat(jo)
|
110
|
+
}, verbose: @verbose)
|
111
|
+
|
112
|
+
# Reformat front-end.
|
113
|
+
Blufin::Terminal::execute_proc('Re-formatting UI codebase', Proc.new {
|
114
|
+
Blufin::Terminal::execute('git add .', @project_path_ui, verbose: false)
|
115
|
+
Blufin::Terminal::execute('yarn format', @project_path_ui, verbose: false)
|
116
|
+
}, verbose: @verbose)
|
117
|
+
|
118
|
+
puts if @verbose && !@generated.any? && !@overwritten.any?
|
119
|
+
|
120
|
+
Blufin::Terminal::custom('Generated', 22, 'The following files were generated:', @generated) if @generated.any?
|
121
|
+
Blufin::Terminal::custom('Overwritten', 55, 'The following files were overwritten:', @overwritten) if @overwritten.any?
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
data/lib/routes/scan.rb
CHANGED
@@ -27,15 +27,51 @@ module AppCommand
|
|
27
27
|
def opts_routing
|
28
28
|
|
29
29
|
# TODO - This cannot be hard-coded forever!
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
@
|
30
|
+
group = 'fmm'
|
31
|
+
|
32
|
+
@errors = []
|
33
|
+
@js = nil
|
34
|
+
@java = nil
|
35
|
+
|
36
|
+
Blufin::Projects::get_projects_as_array.each do |project|
|
37
|
+
if project[Blufin::Projects::PROJECT] == group
|
38
|
+
project_id = project[Blufin::Projects::PROJECT_ID]
|
39
|
+
project_type = project[Blufin::Projects::TYPE]
|
40
|
+
project_path = Blufin::Projects::get_project_path(project_id)
|
41
|
+
project_path_inner = Blufin::Projects::get_project_path(project_id, true)
|
42
|
+
case project_type
|
43
|
+
when Blufin::Projects::TYPE_API_SIMPLE
|
44
|
+
raise RuntimeError, "Project with type: #{Blufin::Projects::TYPE_API_SIMPLE} already scanned." unless @java.nil?
|
45
|
+
@java, errors_java = Blufin::ScannerJava::scan("#{project_path_inner}")
|
46
|
+
@errors.concat(errors_java)
|
47
|
+
when Blufin::Projects::TYPE_QUASAR
|
48
|
+
raise RuntimeError, "Project with type: #{Blufin::Projects::TYPE_QUASAR} already scanned." unless @s.nil?
|
49
|
+
# Scan the routes.
|
50
|
+
@routes, errors_routes = EWorld::RouteScanner::scan(project)
|
51
|
+
@errors.concat(errors_routes)
|
52
|
+
# Extract JS data.
|
53
|
+
td = project[Blufin::Projects::TRANSIENT_DATA]
|
54
|
+
root = Blufin::Strings::remove_surrounding_slashes(td[Blufin::Projects::CG_QUASAR_ROOT])
|
55
|
+
js = Blufin::Strings::remove_surrounding_slashes(td[Blufin::Projects::CG_QUASAR_JS])
|
56
|
+
jst = Blufin::Strings::remove_surrounding_slashes(td[Blufin::Projects::CG_QUASAR_TESTS])
|
57
|
+
if project.has_key?(Blufin::Projects::TRANSIENT_DATA) && td.has_key?(Blufin::Projects::CG_QUASAR_JS)
|
58
|
+
@js, errors_js = Blufin::ScannerJs::scan("#{project_path}/#{root}/#{js}")
|
59
|
+
@js_tests, errors_js_tests = Blufin::ScannerJsTests::scan("#{project_path}/#{root}/#{jst}")
|
60
|
+
@vue, errors_vue = Blufin::ScannerVue::scan("#{project_path}/#{root}")
|
61
|
+
@errors.concat(errors_js)
|
62
|
+
@errors.concat(errors_js_tests)
|
63
|
+
@errors.concat(errors_vue)
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise RuntimeError, "Unsupported project type: #{project_type}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
34
70
|
|
35
|
-
run_js_rules(@
|
71
|
+
run_js_rules(@js) unless @js.nil?
|
36
72
|
|
37
73
|
# Output Errors (if any).
|
38
|
-
Blufin::ScannerError::output_cli(@errors)
|
74
|
+
Blufin::ScannerError::output_cli(@errors)
|
39
75
|
|
40
76
|
end
|
41
77
|
|
@@ -2,7 +2,6 @@ module EWorld
|
|
2
2
|
|
3
3
|
class RuleJsParameters
|
4
4
|
|
5
|
-
|
6
5
|
# This rule validate JS method parameters.
|
7
6
|
# It checks that the parameters match the actual methods and that we have a description/return type.
|
8
7
|
# @return Array (of errors)
|
@@ -34,7 +33,7 @@ module EWorld
|
|
34
33
|
actual = method_data[:docs][:params].keys
|
35
34
|
|
36
35
|
# Throw error if params don't match comments.
|
37
|
-
raise RuntimeError, "
|
36
|
+
raise RuntimeError, "#{method_name} \xe2\x80\x94 Param docs are missing, corrupted or incorrect." if expected.to_s != actual.to_s
|
38
37
|
|
39
38
|
# Make sure we have all the comment doc stuff we need.
|
40
39
|
if method_data[:docs].is_a?(Hash)
|
@@ -0,0 +1,137 @@
|
|
1
|
+
module EWorld
|
2
|
+
|
3
|
+
class ControllerScanner
|
4
|
+
|
5
|
+
SCHEMA_FILE = "#{EWorld::Opt::get_base_path}#{EWorld::Opt::OPT_PATH}/schema/controllers.yml"
|
6
|
+
|
7
|
+
# Responsible for scanning the .codegen/controllers/[MULTIPLE].yml file(s).
|
8
|
+
# @return Array
|
9
|
+
def self.scan(api_project)
|
10
|
+
|
11
|
+
# TODO - Need to inject permissions.
|
12
|
+
# TODO - Need to inject entities.
|
13
|
+
|
14
|
+
raise RuntimeError, "Expected project type to be: #{Blufin::Projects::TYPE_API_SIMPLE}, instead got: #{api_project[Blufin::Projects::TYPE]}" unless api_project[Blufin::Projects::TYPE] == Blufin::Projects::TYPE_API_SIMPLE
|
15
|
+
@errors = []
|
16
|
+
@controllers = {}
|
17
|
+
@classes_seen = []
|
18
|
+
@paths_seen = []
|
19
|
+
begin
|
20
|
+
@project_path = Blufin::Projects::get_project_path(api_project[Blufin::Projects::PROJECT_ID])
|
21
|
+
@project_path_api = Blufin::Projects::get_project_path(api_project[Blufin::Projects::PROJECT_ID], true)
|
22
|
+
@project_transient_api = api_project[Blufin::Projects::TRANSIENT_DATA]
|
23
|
+
@controller_path = "#{EWorld::BaseWriter::get_java_path_for(@project_path, @project_transient_api['ControllerPath'])}/#{EWorld::ControllerWriter::PACKAGE_NAME}"
|
24
|
+
@service_path = "#{EWorld::BaseWriter::get_java_path_for(@project_path, @project_transient_api['ServicePath'])}/#{EWorld::ServiceWriter::PACKAGE_NAME}"
|
25
|
+
controller_yml_path = "#{@project_path}/.#{Blufin::Projects::CODEGEN}/controllers"
|
26
|
+
# If path not found, bomb-out immediately.
|
27
|
+
unless Blufin::Files::path_exists(controller_yml_path)
|
28
|
+
@errors << Blufin::ScannerError::add_error(nil, "YML Controller path not found: #{controller_yml_path}")
|
29
|
+
return @errors, {}
|
30
|
+
end
|
31
|
+
# If the parent path where controllers/services should live doesn't exists -- bomb-out!
|
32
|
+
[@controller_path, @service_path].each do |path|
|
33
|
+
unless Blufin::Files::path_exists(path)
|
34
|
+
@errors << Blufin::ScannerError::add_error(nil, "Path not found: #{path}")
|
35
|
+
return {}, @errors
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# Loop all the YML files. Each file = 1 controller.
|
39
|
+
Blufin::Files::get_files_in_dir(controller_yml_path).each do |controller_file|
|
40
|
+
@file = controller_file
|
41
|
+
# Get extension + controller root path.
|
42
|
+
fs = @file.split('.')
|
43
|
+
@root_path = fs[fs.length - 2].split('/')
|
44
|
+
@root_path = @root_path[@root_path.length - 1]
|
45
|
+
@class_name = "#{Blufin::Strings::snake_case_to_camel_case(@root_path.gsub('-', '_'))}"
|
46
|
+
ext = fs[fs.length - 1]
|
47
|
+
# Make sure we don't have duplicate class names.
|
48
|
+
@errors << Blufin::ScannerError::add_error(@file, "Duplicate class: #{@class_name}") if @classes_seen.include?(@class_name.upcase)
|
49
|
+
@classes_seen << @class_name.upcase
|
50
|
+
# Make sure we have validly named YML file(s).
|
51
|
+
@errors << Blufin::ScannerError::add_error(@file, "Expected extension to be lowercase 'yml', instead got: #{ext}") if ext.downcase != 'yml'
|
52
|
+
unless ext.downcase == 'yml'
|
53
|
+
@errors << Blufin::ScannerError::add_error(@file, "Expected extension to be 'yml', instead got: #{ext}")
|
54
|
+
next
|
55
|
+
end
|
56
|
+
controller_yml = Blufin::Yml::read_file(@file, SCHEMA_FILE)
|
57
|
+
# Validate file. If errors, go to next file.
|
58
|
+
next unless validate_file(controller_yml)
|
59
|
+
controller_yml['RootPath'] = Blufin::Strings::remove_surrounding_slashes(@root_path)
|
60
|
+
@controllers[@class_name] = controller_yml
|
61
|
+
end
|
62
|
+
rescue => e
|
63
|
+
Blufin::Terminal::print_exception(e)
|
64
|
+
end
|
65
|
+
return @controllers, @errors
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
# Put all validation here. If any errors get added, this method returns FALSE and the loop at the top skips processing.
|
71
|
+
# @return bool
|
72
|
+
def self.validate_file(data)
|
73
|
+
error_count_before = @errors.length
|
74
|
+
if data.has_key?('EndPoints') && data['EndPoints'].is_a?(Array)
|
75
|
+
data['EndPoints'].each do |resource|
|
76
|
+
path = resource['Path']
|
77
|
+
path_full = "/#{Blufin::Strings::remove_surrounding_slashes(@root_path)}/#{Blufin::Strings::remove_surrounding_slashes(resource['Path'])}"
|
78
|
+
path_downcase = path_full.downcase
|
79
|
+
method = resource['Method']
|
80
|
+
path_method = "#{method} #{path_downcase}"
|
81
|
+
prefix = "#{path_full} \xe2\x80\x94 "
|
82
|
+
# Make sure path does not have trailing/preceding slashes.
|
83
|
+
@errors << Blufin::ScannerError::add_error(@file, "#{prefix}Path should not have trailing/preceding slash(es): #{path}") if path =~ /^\// || path =~ /\/$/
|
84
|
+
# Make sure paths are always lowercase.
|
85
|
+
@errors << Blufin::ScannerError::add_error(@file, "#{prefix}Path(s) must be lowercase, found: #{path_full}") if path_full != path_downcase
|
86
|
+
path_full.downcase!
|
87
|
+
# Make sure there are no duplicate permissions.
|
88
|
+
if resource.has_key?('Permissions')
|
89
|
+
perms = []
|
90
|
+
resource['Permissions'].each do |perm|
|
91
|
+
if perms.include?(perm)
|
92
|
+
@errors << Blufin::ScannerError::add_error(@file, "#{prefix}Duplicate permission(s): #{perm}")
|
93
|
+
next
|
94
|
+
end
|
95
|
+
perms << perm
|
96
|
+
end
|
97
|
+
end
|
98
|
+
# Make sure we don't have duplicate paths.
|
99
|
+
@errors << Blufin::ScannerError::add_error(@file, "Duplicate end-point: #{path_method}") if @paths_seen.include?(path_method)
|
100
|
+
@paths_seen << path_method
|
101
|
+
|
102
|
+
if %w(POST PUT).include?(method)
|
103
|
+
|
104
|
+
# TODO NOW - Validate POST/PUT stuff.
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
# TODO NOW - Validate Service/Method exists.
|
109
|
+
# TODO NOW - Validate Request Params match service method.
|
110
|
+
# TODO NOW - What about abstract controller calls for entities?
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
service_file = "#{@service_path}/#{@class_name}Service.java"
|
116
|
+
if Blufin::Files::file_exists(service_file)
|
117
|
+
|
118
|
+
# TODO - Must scan file here ...
|
119
|
+
|
120
|
+
java_data, errors = Blufin::ScannerJava::scan_file(service_file)
|
121
|
+
|
122
|
+
# TODO - REMOVE
|
123
|
+
# puts
|
124
|
+
# puts java_data.to_yaml
|
125
|
+
# puts errors.to_yaml
|
126
|
+
|
127
|
+
@errors.concat(errors)
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
# If errors have been added, return FALSE.
|
132
|
+
@errors.length == error_count_before
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|