brightpearl-cli 1.1.0 → 1.2.0
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 +4 -4
- data/README.md +4 -2
- data/lib/brightpearl_cli.rb +151 -76
- data/lib/core/config.rb +67 -17
- data/lib/core/encrypter.rb +55 -0
- data/lib/core/enums.rb +2 -0
- data/lib/core/git.rb +82 -37
- data/lib/core/mysql.rb +34 -8
- data/lib/core/terminal.rb +74 -165
- data/lib/core/tools.rb +33 -13
- data/lib/routes/build.rb +92 -19
- data/lib/routes/git_checkout.rb +13 -19
- data/lib/routes/git_delete.rb +18 -33
- data/lib/routes/git_merge.rb +148 -70
- data/lib/routes/git_pull.rb +40 -4
- data/lib/routes/git_push.rb +40 -4
- data/lib/routes/git_stash.rb +19 -2
- data/lib/routes/git_update.rb +13 -73
- data/lib/routes/jira.rb +1 -0
- data/lib/routes/production_logs.rb +356 -0
- data/lib/routes/review.rb +30 -4
- data/lib/routes/scripts_api_docs.rb +41 -0
- data/lib/routes/scripts_branch_cleaner.rb +196 -0
- data/lib/routes/scripts_pom_fixer.rb +94 -0
- data/lib/routes/setup.rb +11 -3
- data/lib/routes/tail.rb +46 -0
- metadata +15 -10
- data/lib/routes/less.rb +0 -37
- /data/lib/routes/{tests.rb → test.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da7eebac2caf1baa02083c78c51c17a0a2a17467
|
4
|
+
data.tar.gz: b672ae93fccbb7546e4b53bf86a1a60f107bce76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0b8d69d7314f3ee26df37522d0ad4535a085f7e926bf17051f62204d29931911bab9e19669ce6d8c2cb62067038ed50385c18770b8dd0db475f2b00dd3153ee
|
7
|
+
data.tar.gz: bb880740f1dbc34bb1917ef991fcbbf14ee9b5885281f16c2d7d62579eb00fb9af2993cc8f04b16f8bcd183b39ba6b6b02a4a72fdc770a7bc3c7c53057e1b95f
|
data/README.md
CHANGED
data/lib/brightpearl_cli.rb
CHANGED
@@ -3,6 +3,7 @@ require 'yaml'
|
|
3
3
|
|
4
4
|
require 'core/api'
|
5
5
|
require 'core/config'
|
6
|
+
require 'core/encrypter'
|
6
7
|
require 'core/enums'
|
7
8
|
require 'core/git'
|
8
9
|
require 'core/jira'
|
@@ -21,14 +22,18 @@ require 'routes/git_push'
|
|
21
22
|
require 'routes/git_stash'
|
22
23
|
require 'routes/git_update'
|
23
24
|
require 'routes/jira'
|
24
|
-
require 'routes/
|
25
|
+
require 'routes/production_logs'
|
25
26
|
require 'routes/reset'
|
26
27
|
require 'routes/review'
|
27
|
-
require 'routes/
|
28
|
+
require 'routes/scripts_api_docs'
|
29
|
+
require 'routes/scripts_branch_cleaner'
|
28
30
|
require 'routes/scripts_code_sniffer'
|
31
|
+
require 'routes/scripts_color'
|
32
|
+
require 'routes/scripts_pom_fixer'
|
29
33
|
require 'routes/setup'
|
30
34
|
require 'routes/update'
|
31
|
-
require 'routes/
|
35
|
+
require 'routes/tail'
|
36
|
+
require 'routes/test'
|
32
37
|
|
33
38
|
module Brightpearl
|
34
39
|
|
@@ -48,7 +53,7 @@ module Brightpearl
|
|
48
53
|
# TRUE/FALSE DEPENDING ON WHETHER USER IN ON BETA OR NOT.
|
49
54
|
beta_only = Brightpearl::Config.param(Brightpearl::Config::BETA) == 'true' ? true : false
|
50
55
|
|
51
|
-
brightpearl.version '1.
|
56
|
+
brightpearl.version '1.2.0'
|
52
57
|
brightpearl.summary "\x1B[38;5;166mBRIGHTPEARL-CLI\x1B[0m \x1B[38;5;240m\xe2\x80\x94 BETA\x1B[0m"
|
53
58
|
brightpearl.description "\x1B[38;5;#{title_color}mA command line utility for Brightpearl developers and QAs.\nUsed for automating daily work flows & completing repetitive tasks quicker with less errors.\nDesigned to work from anywhere on your workstation.\n\nUse #{Brightpearl::Terminal::format_command('brightpearl')}\x1B[38;5;#{title_color}m or #{Brightpearl::Terminal::format_command('bp')}\x1B[38;5;#{title_color}m to run.\x1B[0m"
|
54
59
|
|
@@ -57,6 +62,12 @@ module Brightpearl
|
|
57
62
|
# BUILD
|
58
63
|
brightpearl.command :build, :aliases => [:b] do |build|
|
59
64
|
build.summary 'Build (and deploy) Java services'
|
65
|
+
build.options do |opts|
|
66
|
+
opts.opt :serviceOnly, 'Build service only (default)', :short => '-s', :long => '--service-only', :type => :boolean
|
67
|
+
opts.opt :apiOnly, 'Build API only', :short => '-a', :long => '--api-only', :type => :boolean
|
68
|
+
opts.opt :both, 'Build both', :short => '-b', :long => '--both', :type => :boolean
|
69
|
+
opts.opt :deploy, 'Deploy to SkyFactory', :short => '-d', :long => '--deploy', :type => :boolean
|
70
|
+
end
|
60
71
|
build.action do |opts, args|
|
61
72
|
BrightpearlCommand::Build.new(opts, args).execute
|
62
73
|
end
|
@@ -113,7 +124,7 @@ module Brightpearl
|
|
113
124
|
end
|
114
125
|
|
115
126
|
# GIT CHECKOUT
|
116
|
-
git.command :checkout, :aliases => [:c
|
127
|
+
git.command :checkout, :aliases => [:c] do |git_checkout|
|
117
128
|
git_checkout.summary 'Create & checkout branches'
|
118
129
|
git_checkout.options do |opts|
|
119
130
|
opts.opt :branch, 'Create a branch locally', :short => '-b', :long => '--branch', :type => :boolean
|
@@ -147,63 +158,62 @@ module Brightpearl
|
|
147
158
|
d << "\n"
|
148
159
|
d << "\nIf no secondary argument is given, target branch will be #{Brightpearl::Terminal::format_branch('current-branch')}"
|
149
160
|
d << "\n"
|
150
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
151
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
161
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m source_branch')} \x1B[0m"
|
162
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m source_branch target_branch')} \x1B[0m"
|
152
163
|
d << "\n"
|
153
|
-
d << "\nTo merge multiple branches
|
164
|
+
d << "\nTo merge multiple branches use a comma-separated string (without spaces):"
|
154
165
|
d << "\n"
|
155
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
156
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
166
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m sb1,sb2,sb3')}"
|
167
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m sb1,sb2,sb3 target_branch')}"
|
157
168
|
d << "\n"
|
158
|
-
d << "\nAlternatively, use the #{Brightpearl::Terminal::format_flag('
|
169
|
+
d << "\nAlternatively, use the #{Brightpearl::Terminal::format_flag('o', false)} and #{Brightpearl::Terminal::format_flag('f', false)} flags to specify your source branches using a temporary file:"
|
159
170
|
d << "\n"
|
160
|
-
d << "\n
|
161
|
-
d << "\n
|
171
|
+
d << "\n #{Brightpearl::Terminal::format_flag('o', false)} opens #{Brightpearl::Terminal::format_directory(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE)}"
|
172
|
+
d << "\n #{Brightpearl::Terminal::format_flag('f', false)} parses the contents of #{Brightpearl::Terminal::format_directory(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE)} as source branches (one branch per line)"
|
162
173
|
d << "\n"
|
163
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
164
|
-
d << "\n #{Brightpearl::Terminal::format_command('bp g m
|
174
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m -o')} \x1B[0m"
|
175
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m -f')} \x1B[0m"
|
176
|
+
d << "\n #{Brightpearl::Terminal::format_command('bp g m -f target_branch')} \x1B[0m"
|
165
177
|
git_merge.description d
|
166
178
|
git_merge.options do |opts|
|
167
|
-
opts.opt :
|
179
|
+
opts.opt :open_file, "Creates (and opens) #{Brightpearl::Terminal::format_directory(Brightpearl::Enum::GIT_MERGE_DEFAULT_FILE)}", :short => '-o', :long => '--open-file', :type => :boolean
|
180
|
+
opts.opt :from_file, 'Get branch names from file (1 branch per line)', :short => '-f', :long => '--from-file', :type => :boolean
|
181
|
+
opts.opt :delete_source_branches_local, 'Delete all source branches (locally).', :short => '-d', :long => '--delete-local', :type => :boolean
|
182
|
+
opts.opt :delete_source_branches_remote, 'Delete all source branches (remotely).', :short => '-D', :long => '--delete-remote', :type => :boolean
|
168
183
|
end
|
169
184
|
git_merge.action do |opts, args|
|
170
185
|
BrightpearlCommand::GitMerge.new(opts, args).execute
|
171
186
|
end
|
172
187
|
end
|
173
188
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
git_pull.action do |opts, args|
|
180
|
-
BrightpearlCommand::GitPull.new(opts, args).execute
|
181
|
-
end
|
189
|
+
# GIT PULL
|
190
|
+
git.command :pull, :aliases => [:p] do |git_pull|
|
191
|
+
git_pull.summary 'Pull from origin'
|
192
|
+
git_pull.action do |opts, args|
|
193
|
+
BrightpearlCommand::GitPull.new(opts, args).execute
|
182
194
|
end
|
195
|
+
end
|
183
196
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
end
|
197
|
+
# GIT PUSH
|
198
|
+
git.command :push, :aliases => [:P] do |git_push|
|
199
|
+
git_push.summary 'Push to origin'
|
200
|
+
git_push.action do |opts, args|
|
201
|
+
BrightpearlCommand::GitPush.new(opts, args).execute
|
190
202
|
end
|
203
|
+
end
|
191
204
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
end
|
205
|
+
# GIT STASH
|
206
|
+
git.command :stash, :aliases => [:S] do |git_stash|
|
207
|
+
git_stash.summary 'Show your current stashes'
|
208
|
+
git_stash.action do |opts, args|
|
209
|
+
BrightpearlCommand::GitStash.new(opts, args).execute
|
198
210
|
end
|
199
|
-
|
200
211
|
end
|
201
212
|
|
202
213
|
# GIT UPDATE
|
203
214
|
git.command :update, :aliases => [:u] do |git_update|
|
204
215
|
git_update.summary 'Update branch(es)'
|
205
216
|
git_update.options do |opts|
|
206
|
-
opts.opt :all, 'Update all local branches', :short => '-a', :long => '--all', :type => :boolean
|
207
217
|
opts.opt :push, 'Push updates to origin', :short => '-P', :long => '--push', :type => :boolean
|
208
218
|
end
|
209
219
|
git_update.action do |opts, args|
|
@@ -240,17 +250,6 @@ module Brightpearl
|
|
240
250
|
|
241
251
|
end
|
242
252
|
|
243
|
-
# LESS
|
244
|
-
brightpearl.command :less, :aliases => [:l] do |less|
|
245
|
-
less.summary "Compile #{Brightpearl::Terminal::format_directory('screen.less')} file"
|
246
|
-
less.options do |opts|
|
247
|
-
opts.opt :skipConfirm, 'Skips confirmation. Will compile less file immediately', :short => '-K', :long => '--skip-confirmation', :type => :boolean
|
248
|
-
end
|
249
|
-
less.action do |opts, args|
|
250
|
-
BrightpearlCommand::Less.new(opts, args).execute
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
253
|
if beta_only
|
255
254
|
|
256
255
|
# RESET
|
@@ -266,12 +265,43 @@ module Brightpearl
|
|
266
265
|
|
267
266
|
end
|
268
267
|
|
269
|
-
#
|
270
|
-
brightpearl.command :
|
271
|
-
|
272
|
-
|
273
|
-
|
268
|
+
# PRODUCTION
|
269
|
+
brightpearl.command :production, :aliases => [:p] do |production|
|
270
|
+
|
271
|
+
production.summary 'Everything to do with production servers'
|
272
|
+
|
273
|
+
# PRODUCTION LOGS
|
274
|
+
production.command :logs, :aliases => [:l] do |production_logs|
|
275
|
+
production_logs.summary 'Scan production logs'
|
276
|
+
production_logs.options do |opts|
|
277
|
+
opts.opt :watchPHP, 'Watch PHP logs (default)', :short => '-p', :long => '--watch-php-logs', :type => :boolean
|
278
|
+
opts.opt :watchJava, 'Watch Java logs', :short => '-j', :long => '--watch-java-logs', :type => :boolean
|
279
|
+
opts.opt :skipFetch, 'Skip fetching of new logs (quicker)', :short => '-s', :long => '--skip-fetch', :type => :boolean
|
280
|
+
opts.opt :compare, 'Compare logs between 2 versions (requires 2 parameters -- source & target version)', :short => '-c', :long => '--compare', :type => :boolean
|
281
|
+
end
|
282
|
+
production_logs.action do |opts, args|
|
283
|
+
BrightpearlCommand::ProductionLogs.new(opts, args).execute
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
# PRODUCTION (DEFAULT)
|
288
|
+
production.action do
|
289
|
+
system('bp p -h')
|
274
290
|
end
|
291
|
+
|
292
|
+
|
293
|
+
end
|
294
|
+
|
295
|
+
if beta_only
|
296
|
+
|
297
|
+
# REVIEW
|
298
|
+
brightpearl.command :review, :aliases => [:r] do |review|
|
299
|
+
review.summary 'Perform a quick code review'
|
300
|
+
review.action do |opts, args|
|
301
|
+
BrightpearlCommand::Review.new(opts, args).execute
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
275
305
|
end
|
276
306
|
|
277
307
|
# SCRIPTS
|
@@ -279,19 +309,52 @@ module Brightpearl
|
|
279
309
|
|
280
310
|
scripts.summary 'Quick & dirty scripts'
|
281
311
|
|
312
|
+
if beta_only
|
313
|
+
|
314
|
+
# SCRIPTS API DOCS
|
315
|
+
scripts.command :api_docs, :aliases => [:a] do |scripts_api_docs|
|
316
|
+
scripts_api_docs.summary 'Build API docs'
|
317
|
+
scripts_api_docs.action do |opts, args|
|
318
|
+
BrightpearlCommand::ScriptsApiDocs.new(opts, args).execute
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
322
|
+
# SCRIPTS BRANCH CLEANER
|
323
|
+
scripts.command :branch_cleaner, :aliases => [:b] do |scripts_branch_cleaner|
|
324
|
+
scripts_branch_cleaner.summary 'Identify (and remove) old branches'
|
325
|
+
scripts_branch_cleaner.options do |opts|
|
326
|
+
opts.opt :scanLocal, 'Find local branches to remove', :short => '-l', :long => '--scan-local', :type => :boolean
|
327
|
+
opts.opt :scanRemote, 'Find remote branches to remove', :short => '-r', :long => '--scan-remote', :type => :boolean
|
328
|
+
opts.opt :anyName, "Find branches with any last committer, not just: #{Brightpearl::Config.param(Brightpearl::Config::GIT_USERNAME)}", :short => '-a', :long => '--any-name', :type => :boolean
|
329
|
+
end
|
330
|
+
scripts_branch_cleaner.action do |opts, args|
|
331
|
+
BrightpearlCommand::ScriptsBranchCleaner.new(opts, args).execute
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
# SCRIPTS PHP CODE-SNIFFER
|
336
|
+
scripts.command :code_sniffer, :aliases => [:c] do |scripts_code_sniffer|
|
337
|
+
scripts_code_sniffer.summary 'Run PHP CodeSniffer'
|
338
|
+
scripts_code_sniffer.action do |opts, args|
|
339
|
+
BrightpearlCommand::ScriptsCodeSniffer.new(opts, args).execute
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
end
|
344
|
+
|
282
345
|
# SCRIPTS COLOR
|
283
|
-
scripts.command :color, :aliases => [:
|
346
|
+
scripts.command :color, :aliases => [:C] do |scripts_color|
|
284
347
|
scripts_color.summary 'Shows a list of bash/ruby color codes (256-bit)'
|
285
348
|
scripts_color.action do |opts, args|
|
286
349
|
BrightpearlCommand::ScriptsColor.new(opts, args).execute
|
287
350
|
end
|
288
351
|
end
|
289
352
|
|
290
|
-
# SCRIPTS
|
291
|
-
scripts.command :
|
292
|
-
|
293
|
-
|
294
|
-
BrightpearlCommand::
|
353
|
+
# SCRIPTS POM-FIXER
|
354
|
+
scripts.command :pom_fixer, :aliases => [:p] do |scripts_pom_fixer|
|
355
|
+
scripts_pom_fixer.summary 'Finds and fixes feature-tagged POM files.'
|
356
|
+
scripts_pom_fixer.action do |opts, args|
|
357
|
+
BrightpearlCommand::ScriptsPomFixer.new(opts, args).execute
|
295
358
|
end
|
296
359
|
end
|
297
360
|
|
@@ -302,26 +365,38 @@ module Brightpearl
|
|
302
365
|
|
303
366
|
end
|
304
367
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
368
|
+
if beta_only
|
369
|
+
|
370
|
+
# TAIL
|
371
|
+
brightpearl.command :tail, :aliases => [:T] do |tail|
|
372
|
+
tail.summary 'Tail various logs (all catalina.out by default)'
|
373
|
+
tail.action do |opts, args|
|
374
|
+
BrightpearlCommand::Tail.new(opts, args).execute
|
375
|
+
end
|
313
376
|
end
|
314
|
-
|
315
|
-
|
377
|
+
|
378
|
+
# TEST
|
379
|
+
brightpearl.command :tests, :aliases => [:t] do |test|
|
380
|
+
test.summary 'Run various tests (PHPUnit by default)'
|
381
|
+
test.options do |opts|
|
382
|
+
opts.opt :cucumber, 'Run Cucumber tests', :short => '-c', :long => '--cucumber', :type => :boolean
|
383
|
+
opts.opt :fitnesse, 'Run FitNesse tests', :short => '-f', :long => '--fitnesse', :type => :boolean
|
384
|
+
opts.opt :php, 'Run PHPUnit tests (default)', :short => '-p', :long => '--php-unit', :type => :boolean
|
385
|
+
opts.opt :ruby, 'Run Ruby UI tests', :short => '-r', :long => '--ruby-ui', :type => :boolean
|
386
|
+
end
|
387
|
+
test.action do |opts, args|
|
388
|
+
BrightpearlCommand::Test.new(opts, args).execute
|
389
|
+
end
|
316
390
|
end
|
317
|
-
end
|
318
391
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
392
|
+
# UPDATE
|
393
|
+
brightpearl.command :update, :aliases => [:u] do |update|
|
394
|
+
update.summary 'Check for updates'
|
395
|
+
update.action do |opts, args|
|
396
|
+
BrightpearlCommand::Update.new(opts, args).execute
|
397
|
+
end
|
324
398
|
end
|
399
|
+
|
325
400
|
end
|
326
401
|
|
327
402
|
# X - SETUP
|
data/lib/core/config.rb
CHANGED
@@ -7,7 +7,6 @@ module Brightpearl
|
|
7
7
|
|
8
8
|
CONFIG_FILE = '~/.brightpearlrc'
|
9
9
|
|
10
|
-
BETA = 'beta'
|
11
10
|
MAC = 'mac'
|
12
11
|
LINUX = 'linux'
|
13
12
|
|
@@ -23,11 +22,21 @@ module Brightpearl
|
|
23
22
|
VM_MYSQL_USER = 'vm_mysql_user'
|
24
23
|
VM_MYSQL_PASSWORD = 'vm_mysql_password'
|
25
24
|
|
25
|
+
BETA = 'beta'
|
26
|
+
PREFERRED_TEXT_EDITOR = 'preferred_text_editor'
|
27
|
+
GIT_USERNAME = 'git_username'
|
28
|
+
|
29
|
+
CRYPT_KEY = 'crypt_key'
|
30
|
+
CRYPT_HEX = 'crypt_hex'
|
31
|
+
EC2_HOST = 'ec2_host'
|
32
|
+
EC2_USER = 'ec2_user'
|
33
|
+
EC2_PASS = 'ec2_pass'
|
34
|
+
|
26
35
|
@params = {}
|
27
36
|
|
28
37
|
def self.param(param_name)
|
29
|
-
unless
|
30
|
-
|
38
|
+
unless all_available_config_keys.include?(param_name)
|
39
|
+
Brightpearl::Terminal::error("#{Brightpearl::Terminal::format_highlight(param_name)} is not a valid config parameter", true)
|
31
40
|
end
|
32
41
|
@params[param_name]
|
33
42
|
end
|
@@ -41,7 +50,7 @@ module Brightpearl
|
|
41
50
|
end
|
42
51
|
|
43
52
|
def self.config_file_exists?
|
44
|
-
unless File.exists?
|
53
|
+
unless File.exists?(File.expand_path(CONFIG_FILE))
|
45
54
|
return false
|
46
55
|
end
|
47
56
|
true
|
@@ -62,20 +71,22 @@ module Brightpearl
|
|
62
71
|
|
63
72
|
def self.first_journey_message
|
64
73
|
puts
|
65
|
-
puts "Thank you for installing the
|
74
|
+
puts "Thank you for installing the #{Brightpearl::Terminal::format_highlight('brightpearl-cli')} ruby gem."
|
66
75
|
puts "CLI stands for 'Command Line Interface'."
|
67
76
|
puts
|
68
|
-
puts
|
69
|
-
puts "
|
77
|
+
puts "The first thing you'll need to do is setup your configuration file."
|
78
|
+
puts "The file is located at: #{Brightpearl::Terminal::format_directory('~/.brightpearlrc')}"
|
70
79
|
puts
|
71
|
-
puts "You probably won't have this file
|
72
|
-
puts
|
73
|
-
Brightpearl::Terminal::
|
80
|
+
puts "You probably won't have this file so the program will create it for you."
|
81
|
+
puts "\n"
|
82
|
+
unless Brightpearl::Terminal::prompt_yes_no('Create configuration file?')
|
83
|
+
Brightpearl::Terminal::abort
|
84
|
+
end
|
74
85
|
end
|
75
86
|
|
76
87
|
def self.config_file_create
|
77
88
|
File.open("#{File.expand_path(CONFIG_FILE)}", 'w') { |file|
|
78
|
-
file.write("# CONFIGURATION FILE --
|
89
|
+
file.write("# CONFIGURATION FILE -- Use this file to configure brightpearl-cli\n")
|
79
90
|
file.write("\n")
|
80
91
|
file.write("#{WORKSTATION_IP}=172.27.X.X\n")
|
81
92
|
file.write("#{WORKSTATION_OS}=linux\n")
|
@@ -89,6 +100,21 @@ module Brightpearl
|
|
89
100
|
file.write("#{VM_ROOT_PASSWORD}=peXXXXXXXre\n")
|
90
101
|
file.write("#{VM_MYSQL_USER}=root\n")
|
91
102
|
file.write("#{VM_MYSQL_PASSWORD}=peXXXXXXXre\n")
|
103
|
+
file.write("\n")
|
104
|
+
file.write("# Usually vi, vim or nano\n")
|
105
|
+
file.write("#{PREFERRED_TEXT_EDITOR}=\n")
|
106
|
+
file.write("\n")
|
107
|
+
file.write("# Found by running $ git config user.name\n")
|
108
|
+
file.write("#{GIT_USERNAME}=\n")
|
109
|
+
file.write("\n")
|
110
|
+
file.write("#{CRYPT_KEY}=\n")
|
111
|
+
file.write("#{CRYPT_HEX}=\n")
|
112
|
+
file.write("#{EC2_HOST}=\n")
|
113
|
+
file.write("#{EC2_USER}=\n")
|
114
|
+
file.write("#{EC2_PASS}=\n")
|
115
|
+
file.write("\n")
|
116
|
+
file.write("# BETA FEATURES -- Set to TRUE to enable beta features -- NOT RECOMMENDED!\n")
|
117
|
+
file.write("#{BETA}=false\n")
|
92
118
|
}
|
93
119
|
end
|
94
120
|
|
@@ -119,15 +145,13 @@ module Brightpearl
|
|
119
145
|
end
|
120
146
|
error_text = "#{error_text}\x1B[38;5;196mThe value for \x1B[38;5;240m#{WORKSTATION_OS}\x1B[38;5;196m must be either: \x1B[38;5;84m#{MAC}\x1B[38;5;196m or \x1B[38;5;84m#{LINUX}\x1B[38;5;196m\x1B[0m\n"
|
121
147
|
end
|
122
|
-
unless error_text == ''
|
123
|
-
show_error_message(error_text)
|
124
|
-
end
|
125
148
|
code_repo = Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_CODE)
|
149
|
+
db_repo = Brightpearl::Config.param(Brightpearl::Config::WORKSTATION_PATH_TO_BP_DB)
|
126
150
|
unless File.directory?(code_repo)
|
127
151
|
error_text = "#{error_text}The following is NOT a valid directory: \x1B[0m#{code_repo}\x1B[90m\n"
|
128
152
|
end
|
129
|
-
unless File.directory?(
|
130
|
-
error_text = "#{error_text}The following is NOT a valid directory: \x1B[0m#{
|
153
|
+
unless File.directory?(db_repo)
|
154
|
+
error_text = "#{error_text}The following is NOT a valid directory: \x1B[0m#{db_repo}\x1B[90m\n"
|
131
155
|
end
|
132
156
|
unless error_text == ''
|
133
157
|
show_error_message(error_text)
|
@@ -165,7 +189,33 @@ module Brightpearl
|
|
165
189
|
VM_ROOT,
|
166
190
|
VM_ROOT_PASSWORD,
|
167
191
|
VM_MYSQL_USER,
|
168
|
-
VM_MYSQL_PASSWORD
|
192
|
+
VM_MYSQL_PASSWORD,
|
193
|
+
PREFERRED_TEXT_EDITOR,
|
194
|
+
GIT_USERNAME
|
195
|
+
]
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.all_available_config_keys
|
199
|
+
[
|
200
|
+
WORKSTATION_IP,
|
201
|
+
WORKSTATION_OS,
|
202
|
+
WORKSTATION_PATH_TO_BP_CODE,
|
203
|
+
WORKSTATION_PATH_TO_BP_DB,
|
204
|
+
VM_IP,
|
205
|
+
VM_USER,
|
206
|
+
VM_USER_PASSWORD,
|
207
|
+
VM_ROOT,
|
208
|
+
VM_ROOT_PASSWORD,
|
209
|
+
VM_MYSQL_USER,
|
210
|
+
VM_MYSQL_PASSWORD,
|
211
|
+
PREFERRED_TEXT_EDITOR,
|
212
|
+
GIT_USERNAME,
|
213
|
+
BETA,
|
214
|
+
CRYPT_KEY,
|
215
|
+
CRYPT_HEX,
|
216
|
+
EC2_HOST,
|
217
|
+
EC2_USER,
|
218
|
+
EC2_PASS
|
169
219
|
]
|
170
220
|
end
|
171
221
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'openssl'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
module Brightpearl
|
5
|
+
|
6
|
+
class Encrypter
|
7
|
+
|
8
|
+
@key = nil
|
9
|
+
@hex = nil
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
|
13
|
+
@key = Brightpearl::Config.param(Brightpearl::Config::CRYPT_KEY)
|
14
|
+
@hex = Brightpearl::Config.param(Brightpearl::Config::CRYPT_HEX)
|
15
|
+
|
16
|
+
if @key.nil? || @hex.nil?
|
17
|
+
Brightpearl::Terminal::error('Encryption keys not found', ["The command you're trying to run probably requires access to an EC2 database (or some other advanced feature).", "In order for this to work you will need valid #{Brightpearl::Terminal::format_highlight('encryption keys')}.", "Please speak to #{Brightpearl::Terminal::format_highlight('Albert')} (or team Raptor) for more info."], true)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def encrypt(string)
|
23
|
+
|
24
|
+
c = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
25
|
+
c.encrypt
|
26
|
+
c.key = @key = Digest::SHA1.hexdigest(@hex)
|
27
|
+
begin
|
28
|
+
e = c.update(string)
|
29
|
+
e << c.final
|
30
|
+
return Base64.encode64(e)
|
31
|
+
rescue
|
32
|
+
Brightpearl::Terminal::error('Encryption failed', "Could not encrypt string #{string == '' ? '[blank]' : Brightpearl::Terminal::format_highlight(string)} using crypt_key #{Brightpearl::Terminal::format_highlight(Brightpearl::Config.param(Brightpearl::Config::CRYPT_KEY) == '' ? '[blank]' : Brightpearl::Config.param(Brightpearl::Config::CRYPT_KEY))} and crypt_hex #{Brightpearl::Terminal::format_highlight(Brightpearl::Config.param(Brightpearl::Config::CRYPT_HEX) == '' ? '[blank]' : Brightpearl::Config.param(Brightpearl::Config::CRYPT_HEX))}")
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def decrypt(string)
|
38
|
+
|
39
|
+
string_decoded = Base64.decode64(string)
|
40
|
+
c = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
41
|
+
c.decrypt
|
42
|
+
c.key = @key = Digest::SHA1.hexdigest(@hex)
|
43
|
+
begin
|
44
|
+
d = c.update(string_decoded)
|
45
|
+
d << c.final
|
46
|
+
return d
|
47
|
+
rescue
|
48
|
+
Brightpearl::Terminal::error('Decryption failed', "Could not decrypt string #{string == '' ? '[blank]' : Brightpearl::Terminal::format_highlight(string)} using crypt_key #{Brightpearl::Terminal::format_highlight(Brightpearl::Config.param(Brightpearl::Config::CRYPT_KEY) == '' ? '[blank]' : Brightpearl::Config.param(Brightpearl::Config::CRYPT_KEY))} and crypt_hex #{Brightpearl::Terminal::format_highlight(Brightpearl::Config.param(Brightpearl::Config::CRYPT_HEX) == '' ? '[blank]' : Brightpearl::Config.param(Brightpearl::Config::CRYPT_HEX))}")
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|