forked from DivanteLtd/anonymizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
180 lines (155 loc) · 4.71 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# frozen_string_literal: true
require './init.rb'
LoggerHelper.file('rake')
task :default do
puts ''
end
namespace 'project' do
desc 'Anonymize project'
task :anonymize, [:project_name] do |_t, args|
project_name = args[:project_name]
LoggerHelper.file(project_name)
Rake.application.invoke_task("project:copy_dump_from_remote[#{project_name}]")
Rake.application.invoke_task("project:remove_database[#{project_name}]")
Rake.application.invoke_task("project:restore_database[#{project_name}]")
Rake.application.invoke_task("project:anonymize_database[#{project_name}]")
Rake.application.invoke_task("project:dump_database[#{project_name}]")
Rake.application.invoke_task("project:upload_to_web[#{project_name}]")
Rake.application.invoke_task("project:remove_database[#{project_name}]")
Rake.application.invoke_task("project:remove_dump_from_tmp[#{project_name}]")
end
task :restore_database, [:project_name] do |_t, args|
project_name = args[:project_name]
database = {
host: CONFIG['database']['host'],
user: CONFIG['database']['user'],
pass: CONFIG['database']['pass']
}
system(
ShellHelper.create_database(
project_name,
database
)
)
system(
ShellHelper.restore_database(
project_name,
database,
CONFIG['tmp_path']
)
)
end
task :anonymize_database, [:project_name] do |_t, args|
project_name = args[:project_name]
anonymizer = Anonymizer.new project_name
db = Database.new anonymizer.config
db.anonymize
end
task :dump_database, [:project_name] do |_t, args|
project_name = args[:project_name]
anonymizer = Anonymizer.new project_name
database = {
host: CONFIG['database']['host'],
user: CONFIG['database']['user'],
pass: CONFIG['database']['pass'],
random_string: anonymizer.config['random_string']
}
system(
ShellHelper.dump_database(
project_name,
database,
CONFIG['tmp_path']
)
)
end
task :remove_database, [:project_name] do |_t, args|
project_name = args[:project_name]
database = {
host: CONFIG['database']['host'],
user: CONFIG['database']['user'],
pass: CONFIG['database']['pass']
}
system(
ShellHelper.drop_database(
project_name,
database
)
)
end
task :copy_dump_from_remote, [:project_name] do |_t, args|
project_name = args[:project_name]
anonymizer = Anonymizer.new project_name
system(
ShellHelper.download_dump(
project_name,
{
host: anonymizer.config['dump_server']['host'],
port: anonymizer.config['dump_server']['port'],
user: anonymizer.config['dump_server']['user'],
dump_dir: anonymizer.config['dump_server']['path']
},
CONFIG['tmp_path'],
anonymizer.config['dump_server']['rsync_options']
)
)
end
task :upload_to_web, [:project_name] do |_t, args|
project_name = args[:project_name]
anonymizer = Anonymizer.new project_name
database = {
host: CONFIG['database']['host'],
user: CONFIG['database']['user'],
pass: CONFIG['database']['pass'],
random_string: anonymizer.config['random_string']
}
system(
ShellHelper.upload_to_web(
project_name,
database,
{
host: anonymizer.config['web_server']['host'],
port: anonymizer.config['web_server']['port'],
user: anonymizer.config['web_server']['user'],
path: anonymizer.config['web_server']['path']
},
CONFIG['tmp_path'],
anonymizer.config['web_server']['rsync_options']
)
)
end
task :remove_dump_from_tmp, [:project_name] do |_t, args|
project_name = args[:project_name]
anonymizer = Anonymizer.new project_name
system(
ShellHelper.remove_dump(
project_name,
CONFIG['tmp_path']
)
)
system(
ShellHelper.remove_anonymized_dump(
project_name,
anonymizer.config['random_string'],
CONFIG['tmp_path']
)
)
end
end
namespace 'config' do
desc 'Validate all projects configuration file'
task :validate_all_projects do |_t|
projects = Dir[ROOT_DIR + '/config/project/*']
projects.each do |file|
filename = File.basename file
project_name = filename.gsub('.json', '')
task_validate_project = Rake::Task['config:validate_project']
task_validate_project.invoke(project_name)
task_validate_project.reenable
end
end
desc 'Validate single project configuration file'
task :validate_project, [:project_name] do |_t, args|
project_name = args[:project_name]
Anonymizer.new project_name
end
end