blufin 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/bf +5 -0
- data/bin/blufin +5 -0
- data/lib/blufin.rb +245 -0
- data/lib/core/code_scanners/common/scanner_common.rb +83 -0
- data/lib/core/code_scanners/common/scanner_java.rb +106 -0
- data/lib/core/code_scanners/scanner_java_embedded_objects.rb +386 -0
- data/lib/core/code_scanners/scanner_java_enums.rb +125 -0
- data/lib/core/code_scanners/scanner_java_source.rb +29 -0
- data/lib/core/code_scanners/scanner_java_tests.rb +157 -0
- data/lib/core/error_handling/schema_error.rb +9 -0
- data/lib/core/error_handling/sql_error.rb +21 -0
- data/lib/core/error_handling/sql_error_handler.rb +149 -0
- data/lib/core/error_handling/yml_error.rb +21 -0
- data/lib/core/error_handling/yml_error_handler.rb +437 -0
- data/lib/core/mysql.rb +347 -0
- data/lib/core/opt.rb +21 -0
- data/lib/core/site/site.rb +26 -0
- data/lib/core/site/site_auth.rb +88 -0
- data/lib/core/site/site_embedded.rb +27 -0
- data/lib/core/site/site_ports.rb +9 -0
- data/lib/core/site/site_resolver.rb +276 -0
- data/lib/core/site/site_services.rb +162 -0
- data/lib/core/site/site_ui.rb +16 -0
- data/lib/core/yml/config/yml_config_validator.rb +219 -0
- data/lib/core/yml/maven/yml_maven_validator.rb +1132 -0
- data/lib/core/yml/resource/yml_resource_validator.rb +154 -0
- data/lib/core/yml/schema/yml_schema_flags.rb +9 -0
- data/lib/core/yml/schema/yml_schema_validator.rb +1850 -0
- data/lib/core/yml/yml_cache_handler.rb +115 -0
- data/lib/core/yml/yml_common.rb +487 -0
- data/lib/core/yml/yml_meta_writer_base.rb +300 -0
- data/lib/core/yml/yml_outputter.rb +307 -0
- data/lib/core/yml/yml_validator_base.rb +630 -0
- data/lib/core/yml_writers/yml_configuration_writer.rb +40 -0
- data/lib/core/yml_writers/yml_java_api_resource_writer.rb +348 -0
- data/lib/core/yml_writers/yml_java_cron_type_writer.rb +113 -0
- data/lib/core/yml_writers/yml_java_css_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_dao_writer.rb +364 -0
- data/lib/core/yml_writers/yml_java_dto_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_embedded_object_writer.rb +968 -0
- data/lib/core/yml_writers/yml_java_enum_writer.rb +161 -0
- data/lib/core/yml_writers/yml_java_js_dependency_writer.rb +59 -0
- data/lib/core/yml_writers/yml_java_message_type_writer.rb +106 -0
- data/lib/core/yml_writers/yml_java_meta_writer.rb +173 -0
- data/lib/core/yml_writers/yml_java_model_writer.rb +510 -0
- data/lib/core/yml_writers/yml_java_pom_writer.rb +1050 -0
- data/lib/core/yml_writers/yml_java_resource_data_writer.rb +251 -0
- data/lib/core/yml_writers/yml_java_sdk_writer.rb +732 -0
- data/lib/core/yml_writers/yml_java_validator_writer.rb +280 -0
- data/lib/core/yml_writers/yml_java_worker_writer.rb +81 -0
- data/lib/core/yml_writers/yml_sql_structure_writer.rb +307 -0
- data/lib/core/yml_writers/yml_sql_template_writer.rb +243 -0
- data/lib/core/yml_writers/yml_vue_service_writer.rb +170 -0
- data/lib/core/yml_writers/yml_writer_base.rb +114 -0
- data/lib/routes/api_list.rb +35 -0
- data/lib/routes/api_meta.rb +59 -0
- data/lib/routes/build.rb +46 -0
- data/lib/routes/create/create_api.rb +35 -0
- data/lib/routes/create/create_ui.rb +84 -0
- data/lib/routes/export.rb +56 -0
- data/lib/routes/generate/generate_api.rb +225 -0
- data/lib/routes/generate/generate_img_favicon.rb +56 -0
- data/lib/routes/generate/generate_img_landing.rb +94 -0
- data/lib/routes/generate/generate_lambda.rb +43 -0
- data/lib/routes/lint.rb +35 -0
- data/lib/routes/mysql_reset.rb +43 -0
- data/lib/routes/release_blufin.rb +351 -0
- data/lib/routes/run.rb +35 -0
- data/lib/version.rb +1 -0
- data/opt/README.MD +2 -0
- data/opt/config/schema.yml +73 -0
- data/opt/config/template.yml +25 -0
- data/opt/sql/data/config/data-client.sql +7 -0
- data/opt/sql/data/config/data-db-configuration-property.sql +47 -0
- data/opt/sql/data/config/data-db-configuration.sql +9 -0
- data/opt/sql/data/config/data-db.sql +175 -0
- data/opt/sql/data/config/data-profile-api.sql +47 -0
- data/opt/sql/data/config/data-profile-cron.sql +0 -0
- data/opt/sql/data/config/data-profile-worker.sql +0 -0
- data/opt/sql/data/config/data-profile.sql +87 -0
- data/opt/sql/data/config/data-project.sql +95 -0
- data/opt/sql/structure/blufin-master-structure-fks.sql +65 -0
- data/opt/sql/structure/blufin-master-structure.sql +97 -0
- data/opt/sql/structure/blufin-mock-structure-fks.sql +38 -0
- data/opt/sql/structure/blufin-mock-structure.sql +98 -0
- data/opt/sql/templates/config/template-client.sql +7 -0
- data/opt/sql/templates/config/template-db-configuration-property.sql +11 -0
- data/opt/sql/templates/config/template-db-configuration.sql +9 -0
- data/opt/sql/templates/config/template-db.sql +21 -0
- data/opt/sql/templates/config/template-profile-api.sql +11 -0
- data/opt/sql/templates/config/template-profile-cron.sql +7 -0
- data/opt/sql/templates/config/template-profile-worker.sql +7 -0
- data/opt/sql/templates/config/template-profile.sql +21 -0
- data/opt/sql/templates/config/template-project.sql +23 -0
- data/opt/yml/api/schema/config/client.yml +14 -0
- data/opt/yml/api/schema/config/db.yml +45 -0
- data/opt/yml/api/schema/config/db_configuration.yml +22 -0
- data/opt/yml/api/schema/config/db_configuration_property.yml +22 -0
- data/opt/yml/api/schema/config/profile.yml +53 -0
- data/opt/yml/api/schema/config/profile_api.yml +22 -0
- data/opt/yml/api/schema/config/profile_cron.yml +14 -0
- data/opt/yml/api/schema/config/profile_worker.yml +14 -0
- data/opt/yml/api/schema/config/project.yml +48 -0
- data/opt/yml/api/schema/mock/mock.yml +99 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_if_enum_system.yml +16 -0
- data/opt/yml/api/schema/mock/mock_nested_linked.yml +43 -0
- data/opt/yml/api/schema/mock/mock_nested_multiple.yml +61 -0
- data/opt/yml/api/schema/mock/mock_nested_single.yml +67 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_deep.yml +32 -0
- data/opt/yml/api/schema/mock/mock_nested_single_super_super_deep.yml +17 -0
- metadata +240 -0
data/lib/core/mysql.rb
ADDED
@@ -0,0 +1,347 @@
|
|
1
|
+
require 'mysql2'
|
2
|
+
|
3
|
+
module App
|
4
|
+
|
5
|
+
class MySQL
|
6
|
+
|
7
|
+
CONFIG_SCHEMA = 'blufin-master'
|
8
|
+
CONFIG_FILENAME_STRUCTURE = 'blufin-master-structure.sql'
|
9
|
+
CONFIG_FILENAME_STRUCTURE_FKS = 'blufin-master-structure-fks.sql'
|
10
|
+
|
11
|
+
MOCK_SCHEMA = 'blufin-mock'
|
12
|
+
MOCK_FILENAME_STRUCTURE = 'blufin-mock-structure.sql'
|
13
|
+
MOCK_FILENAME_STRUCTURE_FKS = 'blufin-mock-structure-fks.sql'
|
14
|
+
|
15
|
+
# Reset the DB.
|
16
|
+
# @return void
|
17
|
+
def self.reset_full_mock_data(site, skip_confirm = false, verbose = false)
|
18
|
+
|
19
|
+
begin
|
20
|
+
|
21
|
+
# TODO - 4/13/18 - IMPLEMENT OPTIONAL CONFIG RESET FLAG.
|
22
|
+
Blufin::Terminal::output("Must create flag to make #{CONFIG_SCHEMA} reset optional.", Blufin::Terminal::MSG_TODO)
|
23
|
+
|
24
|
+
@site = Blufin::SiteResolver::validate_site(site)
|
25
|
+
@site_name = Blufin::SiteResolver::get_site_name(@site)
|
26
|
+
|
27
|
+
@error_handler = Blufin::SqlErrorHandler.new(@site)
|
28
|
+
|
29
|
+
@sql_mismatch_errors = []
|
30
|
+
@vsf_max = []
|
31
|
+
@asf_max = []
|
32
|
+
|
33
|
+
@schema_data = Blufin::YmlCacheHandler::get(@site, Blufin::YmlCacheHandler::SCHEMA_DATA)
|
34
|
+
@schema_fks_hash = Blufin::YmlCacheHandler::get(@site, Blufin::YmlCacheHandler::SCHEMA_FKS)
|
35
|
+
|
36
|
+
schemas = Blufin::YmlSchemaValidator::VALID_SCHEMAS_GENERATE
|
37
|
+
warning_message = ['This process cannot be reversed and all current data will be lost in the following schemas:', nil]
|
38
|
+
has_path_to_ruby = !Blufin::Config::get_path('Paths', 'BlufinRuby').nil?
|
39
|
+
|
40
|
+
Blufin::Terminal::output("Path to ruby not found in #{Blufin::Terminal::format_directory(App::CONFIG_FILE)}, #{Blufin::Terminal::format_highlight(App::MySQL::CONFIG_SCHEMA)} table will not be generated.", Blufin::Terminal::MSG_WARNING) unless has_path_to_ruby
|
41
|
+
|
42
|
+
schemas.each do |schema|
|
43
|
+
if schema == Blufin::YmlSchemaValidator::CONFIG
|
44
|
+
warning_message << CONFIG_SCHEMA if has_path_to_ruby
|
45
|
+
elsif schema == Blufin::YmlSchemaValidator::MOCK
|
46
|
+
warning_message << MOCK_SCHEMA if has_path_to_ruby
|
47
|
+
else
|
48
|
+
warning_message << "#{Blufin::SiteResolver::get_site_name(@site)}-#{schema}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
sql_data_files = get_sql_data_files
|
53
|
+
|
54
|
+
# Validates all the data-insert statements.
|
55
|
+
sql_data_files.each { |file| validate_sql_data_file(file) } if sql_data_files.any?
|
56
|
+
|
57
|
+
generate_sql_mismatch_errors if @sql_mismatch_errors.any?
|
58
|
+
|
59
|
+
# If SQL data errors exist, script will not execute past this point.
|
60
|
+
return if @error_handler.display_errors_if_any
|
61
|
+
|
62
|
+
# TODO DB - Need to replace with DBResolver.
|
63
|
+
|
64
|
+
cli_host = Blufin::Config::get['Databases'][0]['Host']
|
65
|
+
cli_user = Blufin::Config::get['Databases'][0]['User']
|
66
|
+
cli_pass = Blufin::Config::get['Databases'][0]['Password']
|
67
|
+
cli_host = cli_host == 'nil' ? '' : " -h #{cli_host}"
|
68
|
+
cli_user = cli_user == 'nil' ? '' : " -u#{cli_user}"
|
69
|
+
cli_pass = cli_pass == 'nil' ? '' : " -p#{cli_pass.gsub('$', '\$')}"
|
70
|
+
cli_verbose = verbose ? '' : ' &>/dev/null';
|
71
|
+
|
72
|
+
if skip_confirm || Blufin::Terminal::prompt_yes_no("Are you sure you want to #{Blufin::Terminal::format_highlight('completely reset')} your database(s)?", warning_message)
|
73
|
+
|
74
|
+
commands_truncate = []
|
75
|
+
commands_build_schema = []
|
76
|
+
commands_build_fks = []
|
77
|
+
commands_insert_data = []
|
78
|
+
|
79
|
+
schemas.each do |schema|
|
80
|
+
|
81
|
+
structure_path = get_structure_path(schema)
|
82
|
+
data_path = get_data_path(schema)
|
83
|
+
|
84
|
+
# Skip if user doesn't have the PATH_TO_RUBY config value.
|
85
|
+
next if structure_path.nil? || data_path.nil?
|
86
|
+
|
87
|
+
site_schema = (schema == Blufin::YmlSchemaValidator::CONFIG) ? CONFIG_SCHEMA : "#{@site_name}-#{schema}"
|
88
|
+
structure_file = "#{structure_path}/" + ((schema == Blufin::YmlSchemaValidator::CONFIG) ? CONFIG_FILENAME_STRUCTURE : "#{@site_name}-#{schema}.sql")
|
89
|
+
foreign_key_file = "#{structure_path}/" + ((schema == Blufin::YmlSchemaValidator::CONFIG) ? CONFIG_FILENAME_STRUCTURE_FKS : "#{@site_name}-fks-#{schema}.sql")
|
90
|
+
|
91
|
+
commands_truncate << "mysql#{cli_host}#{cli_user}#{cli_pass} -e 'set foreign_key_checks = 0; drop database if exists `#{site_schema}`; create database `#{site_schema}`; set foreign_key_checks = 1;'#{cli_verbose}"
|
92
|
+
commands_build_schema << "mysql#{cli_host}#{cli_user}#{cli_pass} #{site_schema} < #{structure_file}#{cli_verbose}" if Blufin::Files::file_exists(structure_file)
|
93
|
+
commands_build_fks << "mysql#{cli_host}#{cli_user}#{cli_pass} #{site_schema} < #{foreign_key_file}#{cli_verbose}" if Blufin::Files::file_exists(foreign_key_file)
|
94
|
+
|
95
|
+
path_vcs = "#{data_path}/#{schema}"
|
96
|
+
|
97
|
+
# Generate path(s) if they don't exist.
|
98
|
+
unless Blufin::Files::path_exists(path_vcs)
|
99
|
+
Blufin::Files::create_directory(path_vcs)
|
100
|
+
Blufin::Terminal::output(Blufin::Terminal::format_directory(path_vcs), Blufin::Terminal::MSG_GENERATED)
|
101
|
+
end
|
102
|
+
|
103
|
+
# Generates all the data-insert commands.
|
104
|
+
Blufin::Files::get_files_in_dir(path_vcs).each { |file| commands_insert_data << "mysql#{cli_host}#{cli_user}#{cli_pass} #{site_schema} < #{file}#{cli_verbose}" if file_exists_and_has_data(file) } if sql_data_files.any?
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
Blufin::Terminal::info("Destroying #{Blufin::Terminal::format_highlight('schema(s)')}")
|
109
|
+
Blufin::Terminal::command(commands_truncate)
|
110
|
+
Blufin::Terminal::info("Creating #{Blufin::Terminal::format_highlight('schema(s)')}")
|
111
|
+
Blufin::Terminal::command(commands_build_schema)
|
112
|
+
Blufin::Terminal::info("Inserting #{Blufin::Terminal::format_highlight('mock data')}")
|
113
|
+
Blufin::Terminal::command(commands_insert_data)
|
114
|
+
Blufin::Terminal::info("Adding #{Blufin::Terminal::format_highlight('foreign key constraints')}")
|
115
|
+
Blufin::Terminal::command(commands_build_fks)
|
116
|
+
Blufin::Terminal::success('Reset of MySQL data done', 'You should now have a clean database.')
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
rescue => e
|
121
|
+
|
122
|
+
Blufin::Terminal::print_exception(e)
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Checks that SQL Data file exists and has data in it.
|
131
|
+
# @return Boolean
|
132
|
+
def self.file_exists_and_has_data(path_and_file)
|
133
|
+
begin
|
134
|
+
Blufin::Files::read_file(path_and_file).length > 0
|
135
|
+
rescue
|
136
|
+
false
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
# Gets an Array of files containing all the SQL data.
|
141
|
+
# @return Array
|
142
|
+
def self.get_sql_data_files
|
143
|
+
sql_data_files = []
|
144
|
+
@schema_data.keys.each do |schema|
|
145
|
+
unless @schema_data[schema].keys.nil?
|
146
|
+
@schema_data[schema].keys.each do |table|
|
147
|
+
path_and_file = "#{get_data_path(schema)}/#{schema}/data-#{table.gsub('_', '-')}.sql"
|
148
|
+
sql_data_files << path_and_file if Blufin::Files::file_exists(path_and_file)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
sql_data_files
|
153
|
+
end
|
154
|
+
|
155
|
+
# Validates that the data contained in the template is still valid.
|
156
|
+
# If not, will add an entry to the @error Array which will prevent MySQL update from happening.
|
157
|
+
# @return void
|
158
|
+
def self.validate_sql_data_file(path_and_file)
|
159
|
+
|
160
|
+
# TODO - Commented this out because it was rubbish!
|
161
|
+
# TODO - Need to write a new parser/validator that STRIPS ALL WHITESPACE/NEW LINES first and then validate from that.
|
162
|
+
return
|
163
|
+
|
164
|
+
line_number = 0
|
165
|
+
data_group = 0
|
166
|
+
data_index = 0
|
167
|
+
data_fields = {}
|
168
|
+
data_values = {}
|
169
|
+
extract_fields = false
|
170
|
+
extract_values = false
|
171
|
+
|
172
|
+
parts = path_and_file.strip.split('/')
|
173
|
+
table = parts[parts.length - 1].gsub(/\Adata-/, '').gsub(/\.sql\z/, '').gsub('-', '_')
|
174
|
+
schema = parts[parts.length - 2]
|
175
|
+
|
176
|
+
Blufin::Files::read_file(path_and_file).each do |line|
|
177
|
+
|
178
|
+
line = line.gsub("\n", '')
|
179
|
+
line_number += 1
|
180
|
+
|
181
|
+
if line =~ /\AINSERT IGNORE INTO\s\S+\s\(\z/
|
182
|
+
@error_handler.add_error(Blufin::SqlErrorHandler::ERROR_SQL_STATEMENT_NOT_EXPECTED, path_and_file, line_number) if extract_fields || extract_values
|
183
|
+
extract_fields = true
|
184
|
+
data_index = 0
|
185
|
+
elsif line =~ /\A `[a-z0-9_]{2,}`,?/
|
186
|
+
data_fields[data_group] = {} if data_fields[data_group].nil?
|
187
|
+
field = line.match(/`[a-z0-9_]{2,}`/)
|
188
|
+
field = field[0].gsub(/\A`/, '').gsub(/`\z/, '')
|
189
|
+
data_fields[data_group][data_index] = [field, line_number]
|
190
|
+
data_index += 1
|
191
|
+
elsif line =~ /\A\)\s+VALUES\s+\(\z/
|
192
|
+
@error_handler.add_error(Blufin::SqlErrorHandler::ERROR_SQL_STATEMENT_NOT_EXPECTED, path_and_file, line_number) unless extract_fields && !extract_values
|
193
|
+
extract_fields = false
|
194
|
+
extract_values = true
|
195
|
+
data_index = 0
|
196
|
+
elsif line =~ /\A '(.)*',?/
|
197
|
+
data_values[data_group] = {} if data_values[data_group].nil?
|
198
|
+
value = line.match(/'(.)*',?/)
|
199
|
+
value = value[0].gsub(/\A'/, '').gsub(/',?\z/, '')
|
200
|
+
data_values[data_group][data_index] = [value, line_number]
|
201
|
+
data_index += 1
|
202
|
+
# TODO - I WROTE THIS THEN DECIDED IT WASN'T NECESSARY.
|
203
|
+
# TODO - WE SHOULD PROBABLY TAKE NULL INTO CONSIDERATION FOR INTEGERS/DECIMALS... LEAVIN THIS HERE JUST SO IT GETS COMMITTED TO GIT.
|
204
|
+
# elsif line =~ /\A ([0-9\-\.]+|NULL),?/
|
205
|
+
# data_values[data_group] = {} if data_values[data_group].nil?
|
206
|
+
# value = line.match(/([0-9\-\.]+|NULL),?/)
|
207
|
+
# value = value[0].gsub(/,?\z/, '')
|
208
|
+
# data_values[data_group][data_index] = [value, line_number]
|
209
|
+
# data_index += 1
|
210
|
+
elsif line =~ /\A NULL,?( -- FK: )?\S*\z/
|
211
|
+
data_values[data_group] = {} if data_values[data_group].nil?
|
212
|
+
data_values[data_group][data_index] = [nil, line_number]
|
213
|
+
data_index += 1
|
214
|
+
elsif line =~ /\A\);\z/
|
215
|
+
@error_handler.add_error(Blufin::SqlErrorHandler::ERROR_SQL_STATEMENT_NOT_EXPECTED, path_and_file, line_number) unless extract_values && !extract_fields
|
216
|
+
extract_values = false
|
217
|
+
data_group += 1
|
218
|
+
elsif line == ''
|
219
|
+
elsif line =~ /\Aset\s+(session|global)\s+sql_mode\s*=\s*'[A-Za-z_]+';\z/i
|
220
|
+
else
|
221
|
+
@error_handler.add_error(Blufin::SqlErrorHandler::ERROR_SQL_REGEX_MISMATCH, path_and_file, line_number)
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
|
226
|
+
# Add error (if exists).
|
227
|
+
add_sql_mismatch_error(data_fields, path_and_file, schema, table)
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
# Adds a SQL MISMATCH error to tmp Array for later processing. To get around the spacing problem.
|
232
|
+
# @return void
|
233
|
+
def self.add_sql_mismatch_error(data_fields, path_and_file, schema, table)
|
234
|
+
|
235
|
+
valid_schema = {}
|
236
|
+
actual_schema = {}
|
237
|
+
error_line = nil
|
238
|
+
error_group = nil
|
239
|
+
idx_counter = 0
|
240
|
+
|
241
|
+
@schema_data[schema][table].keys.each do |key|
|
242
|
+
next if key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\[\]\z/ || key =~ /\A(#{Blufin::YmlSchemaValidator::VALID_SCHEMAS_REGEX})\.[a-z_]+\z/ || key =~/\A[a-z_.]+\[#{Blufin::YmlSchemaValidator::LINK}\]/
|
243
|
+
valid_schema[idx_counter] = key
|
244
|
+
idx_counter += 1
|
245
|
+
end
|
246
|
+
|
247
|
+
data_fields.each_with_index do |data_group, group_idx|
|
248
|
+
actual_schema_group = {}
|
249
|
+
data_group[1].each_with_index do |data, data_idx|
|
250
|
+
actual_schema_group[data_idx] = data[1][0]
|
251
|
+
if error_line.nil? && data[1][0] != valid_schema[data_idx]
|
252
|
+
error_line = data[1][1]
|
253
|
+
error_group = group_idx
|
254
|
+
end
|
255
|
+
end
|
256
|
+
actual_schema[group_idx] = actual_schema_group
|
257
|
+
end
|
258
|
+
|
259
|
+
if actual_schema.keys.length > 0
|
260
|
+
valid_schema.each do |field_idx, field|
|
261
|
+
actual_schema.each do |group_idx, group_data|
|
262
|
+
|
263
|
+
if error_line.nil? && group_data[field_idx] != field
|
264
|
+
|
265
|
+
index_in_group = field_idx + 1
|
266
|
+
valid_group_lines = (valid_schema.keys.length * 2) + 4
|
267
|
+
|
268
|
+
# This 'might' not be 100% accurate.
|
269
|
+
error_line = (valid_group_lines * group_idx) + index_in_group + 1
|
270
|
+
error_group = group_idx
|
271
|
+
|
272
|
+
end
|
273
|
+
|
274
|
+
end
|
275
|
+
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
unless error_line.nil?
|
281
|
+
vsf = []
|
282
|
+
vsc = []
|
283
|
+
asf = []
|
284
|
+
asc = []
|
285
|
+
valid_schema.each { |vs| vsf << vs[1] }
|
286
|
+
actual_schema[error_group].each { |as| asf << as[1] }
|
287
|
+
@vsf_max << vsf.max_by(&:length).length + 5
|
288
|
+
@asf_max << asf.max_by(&:length).length + 5
|
289
|
+
(0..([vsf.length, asf.length].max - 1)).each do |n|
|
290
|
+
vsc << (vsf[n].nil? ? '' : vsf[n])
|
291
|
+
asc << (asf[n].nil? ? '' : asf[n])
|
292
|
+
end
|
293
|
+
@sql_mismatch_errors << [path_and_file, error_line, vsc, asc]
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
# Generates SQL MISMATCH errors with even spacing.
|
298
|
+
# @return void
|
299
|
+
def self.generate_sql_mismatch_errors
|
300
|
+
|
301
|
+
@sql_mismatch_errors.each do |error_array|
|
302
|
+
|
303
|
+
multi_line_content = []
|
304
|
+
vsf = error_array[2]
|
305
|
+
asf = error_array[3]
|
306
|
+
multi_line_content << ''
|
307
|
+
multi_line_content << " \x1B[38;5;246m#{'EXPECTED'.ljust(@vsf_max.max, ' ')}\x1B[0m \x1B[38;5;196m#{'ACTUAL'.ljust(@asf_max.max, ' ')}\x1B[0m"
|
308
|
+
multi_line_content << ''
|
309
|
+
(0..([vsf.length, asf.length].max - 1)).each do |n|
|
310
|
+
valid = vsf[n].nil? ? '' : vsf[n]
|
311
|
+
actual = asf[n].nil? ? '' : asf[n]
|
312
|
+
color = (valid == actual) ? 118 : 196
|
313
|
+
multi_line_content << " \x1B[38;5;240m#{valid.ljust(@vsf_max.max, ' ')}\x1B[0m \x1B[38;5;#{color}m#{actual.ljust(@asf_max.max, ' ')}\x1B[0m"
|
314
|
+
end
|
315
|
+
multi_line_content << ''
|
316
|
+
@error_handler.add_error(Blufin::SqlErrorHandler::ERROR_SQL_SCHEMA_MISMATCH, error_array[0], error_array[1], multi_line_content)
|
317
|
+
|
318
|
+
end
|
319
|
+
|
320
|
+
end
|
321
|
+
|
322
|
+
# @return Array
|
323
|
+
def self.get_data_path(schema)
|
324
|
+
if schema == Blufin::YmlSchemaValidator::CONFIG || schema == Blufin::YmlSchemaValidator::MOCK
|
325
|
+
path_to_blufin_ruby = Blufin::Config::get_path('Paths', 'BlufinRuby')
|
326
|
+
return nil if path_to_blufin_ruby.nil?
|
327
|
+
"#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/data"
|
328
|
+
else
|
329
|
+
"#{Blufin::SiteResolver::get_site_location(@site)}/#{Blufin::Site::PATH_TO_SQL_DATA}"
|
330
|
+
end
|
331
|
+
|
332
|
+
end
|
333
|
+
|
334
|
+
# @return Array
|
335
|
+
def self.get_structure_path(schema)
|
336
|
+
if schema == Blufin::YmlSchemaValidator::CONFIG || schema == Blufin::YmlSchemaValidator::MOCK
|
337
|
+
path_to_blufin_ruby = Blufin::Config::get_path('Paths', 'BlufinRuby')
|
338
|
+
return nil if path_to_blufin_ruby.nil?
|
339
|
+
"#{path_to_blufin_ruby}/#{App::Opt::BLUFIN}#{App::Opt::OPT_PATH_SQL}/structure"
|
340
|
+
else
|
341
|
+
"#{Blufin::SiteResolver::get_site_location(@site)}/#{Blufin::Site::PATH_TO_SQL_STRUCTURE}"
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
end
|
data/lib/core/opt.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module App
|
2
|
+
|
3
|
+
class Opt
|
4
|
+
|
5
|
+
BLUFIN = 'blufin'
|
6
|
+
|
7
|
+
OPT_PATH = '/opt'
|
8
|
+
OPT_PATH_SQL = '/opt/sql'
|
9
|
+
OPT_PATH_YML = '/opt/yml'
|
10
|
+
|
11
|
+
# Get PATH to assets, scripts, etc.
|
12
|
+
# @return String
|
13
|
+
def self.get_base_path
|
14
|
+
base_path = File.dirname(File.expand_path(__FILE__))
|
15
|
+
base_path = base_path.gsub(/\/\w+\/\w+\z/i, '')
|
16
|
+
base_path
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class Site
|
4
|
+
|
5
|
+
APP = 'app'
|
6
|
+
COMMON = 'common'
|
7
|
+
CONFIG = 'config'
|
8
|
+
PATH_TO_SQL = 'sql'
|
9
|
+
PATH_TO_SQL_DATA = 'sql/data'
|
10
|
+
PATH_TO_SQL_STRUCTURE = 'sql/structure'
|
11
|
+
PATH_TO_SQL_TEMPLATES = 'sql/templates'
|
12
|
+
PATH_TO_YML = 'yml'
|
13
|
+
PATH_TO_YML_CONFIG = 'yml/config'
|
14
|
+
PATH_TO_YML_API_SCHEMA = 'yml/api/schema'
|
15
|
+
PATH_TO_BLUFIN_API = '/blufin-api'
|
16
|
+
PATH_TO_BLUFIN_CORE_LIB = '/blufin-core-lib'
|
17
|
+
PATH_TO_BLUFIN_CRON = '/blufin-cron'
|
18
|
+
PATH_TO_BLUFIN_SDK = '/blufin-sdk'
|
19
|
+
PATH_TO_BLUFIN_WORKER = '/blufin-worker'
|
20
|
+
DEFAULT_SITE = 'bf'
|
21
|
+
PATH_APP_INFRASTRUCTURE = 'app-infrastructure'
|
22
|
+
REGEX_APP_DIRS = "#{PATH_APP_INFRASTRUCTURE}"
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Blufin
|
2
|
+
|
3
|
+
class SiteAuth
|
4
|
+
|
5
|
+
INTERNAL = 'INTERNAL'
|
6
|
+
INTERNAL_ACCOUNT = 'INTERNAL_ACCOUNT'
|
7
|
+
INTERNAL_ACCOUNT_USER = 'INTERNAL_ACCOUNT_USER'
|
8
|
+
OAUTH_ACCOUNT = 'OAUTH_ACCOUNT'
|
9
|
+
OAUTH_ACCOUNT_USER = 'OAUTH_ACCOUNT_USER'
|
10
|
+
|
11
|
+
CLIENT = 'client'
|
12
|
+
DB = 'db'
|
13
|
+
DB_CONFIGURATION = 'db_configuration'
|
14
|
+
DB_CONFIGURATION_PROPERTY = 'db_configuration_property'
|
15
|
+
PROFILE = 'profile'
|
16
|
+
PROFILE_API = 'profile_api'
|
17
|
+
PROFILE_CRON = 'profile_cron'
|
18
|
+
PROFILE_WORKER = 'profile_worker'
|
19
|
+
PROJECT = 'project'
|
20
|
+
THIRD_PARTY_DEVELOPER = 'third_party_developer'
|
21
|
+
THIRD_PARTY_APPLICATION = 'third_party_application'
|
22
|
+
THIRD_PARTY_APPLICATION_PRIVILEGES = 'third_party_application_permission'
|
23
|
+
ACCOUNT = 'account'
|
24
|
+
ACCOUNT_PRIVILEGES = 'account_permission'
|
25
|
+
CRON = 'cron'
|
26
|
+
USER = 'user'
|
27
|
+
USER_PRIVILEGES = 'user_permission'
|
28
|
+
|
29
|
+
LEVEL_NONE = 'NONE'
|
30
|
+
LEVEL_ACCOUNT = 'ACCOUNT'
|
31
|
+
LEVEL_ACCOUNT_USER = 'ACCOUNT_USER'
|
32
|
+
|
33
|
+
CONFIG_COMMON = [CLIENT, DB, DB_CONFIGURATION, DB_CONFIGURATION_PROPERTY, PROFILE, PROFILE_API, PROFILE_CRON, PROFILE_WORKER, PROJECT]
|
34
|
+
|
35
|
+
AUTHENTICATION_LEVELS = {
|
36
|
+
INTERNAL => CONFIG_COMMON + [],
|
37
|
+
INTERNAL_ACCOUNT => CONFIG_COMMON + [ACCOUNT, ACCOUNT_PRIVILEGES],
|
38
|
+
INTERNAL_ACCOUNT_USER => CONFIG_COMMON + [ACCOUNT, ACCOUNT_PRIVILEGES, USER, USER_PRIVILEGES],
|
39
|
+
OAUTH_ACCOUNT => CONFIG_COMMON + [THIRD_PARTY_DEVELOPER, THIRD_PARTY_APPLICATION, THIRD_PARTY_APPLICATION_PRIVILEGES, ACCOUNT, ACCOUNT_PRIVILEGES],
|
40
|
+
OAUTH_ACCOUNT_USER => CONFIG_COMMON + [THIRD_PARTY_DEVELOPER, THIRD_PARTY_APPLICATION, THIRD_PARTY_APPLICATION_PRIVILEGES, ACCOUNT, ACCOUNT_PRIVILEGES, USER, USER_PRIVILEGES],
|
41
|
+
}
|
42
|
+
|
43
|
+
@auth_level = nil
|
44
|
+
|
45
|
+
# Handles all the logic revolved around the different Auth Levels.
|
46
|
+
# Only needs to be initialized once.
|
47
|
+
# @return void
|
48
|
+
def self.init(auth_level)
|
49
|
+
@auth_level = auth_level
|
50
|
+
end
|
51
|
+
|
52
|
+
# Gets the Authorization Level.
|
53
|
+
# @return String
|
54
|
+
def self.get_auth_level
|
55
|
+
@auth_level
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns 1 of 3 values -> NONE, ACCOUNT, ACCOUNT_USER.
|
59
|
+
# From this value you should be able to determine what level of Authentication is required depending on the context you're in at that point.
|
60
|
+
# Doesn't need to be aware of what site it's on as this is all hard-coded generator logic.
|
61
|
+
# @return String
|
62
|
+
def self.get_auth_level_for_table(schema, table)
|
63
|
+
|
64
|
+
raise RuntimeError, "Invalid @auth_level: #{@auth_level}" unless AUTHENTICATION_LEVELS.keys.include?(@auth_level)
|
65
|
+
|
66
|
+
case schema
|
67
|
+
when Blufin::YmlSchemaValidator::APP
|
68
|
+
if [USER, USER_PRIVILEGES].include?(table)
|
69
|
+
return LEVEL_ACCOUNT
|
70
|
+
else
|
71
|
+
return [INTERNAL_ACCOUNT_USER, OAUTH_ACCOUNT_USER].include?(@auth_level) ? LEVEL_ACCOUNT_USER : LEVEL_ACCOUNT
|
72
|
+
end
|
73
|
+
when Blufin::YmlSchemaValidator::CONFIG
|
74
|
+
return LEVEL_NONE
|
75
|
+
when Blufin::YmlSchemaValidator::COMMON
|
76
|
+
[ACCOUNT, ACCOUNT_PRIVILEGES, THIRD_PARTY_DEVELOPER, THIRD_PARTY_APPLICATION, THIRD_PARTY_APPLICATION_PRIVILEGES].include?(table) ? LEVEL_NONE : LEVEL_ACCOUNT
|
77
|
+
|
78
|
+
when Blufin::YmlSchemaValidator::MOCK
|
79
|
+
return LEVEL_ACCOUNT_USER
|
80
|
+
else
|
81
|
+
raise RuntimeError, "Unrecognized schema: #{schema}"
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|