vtk 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 469019fb5bc0695ac68a0deab5ff68305f62852cbe38207bbb199cfee99f805b
4
- data.tar.gz: e81be7f9896a0f057bf4c0c5fb55e904ffecd1fbd56951a84ac8fe9d334e9e0e
3
+ metadata.gz: 5330833427f91a051537c3289baa3dff860f28a03fe3b47508d34e2eaeaffe3d
4
+ data.tar.gz: 00bf91a02ad6e3640c6a70cd1ab58581e70e8b73d04f29c8b8711ae526b3b8a8
5
5
  SHA512:
6
- metadata.gz: '01898cc5e93c4db7ff791b222f087d64f80730f20388ed35c8fdce2ad4adaec71e4fc417d515876baba10ddf64d38ac9978d1759e10e2418d44f71731f5b616f'
7
- data.tar.gz: eddd67f1661dd3a0b7eefe49ab8e531ce1c3b26f4bd534cae9583dfee00c4cf721ae64179bbf42de31bf85c3b961b839c85700852401ef21eb8d54e37eb4afc7
6
+ metadata.gz: 60b2d9deaa896280656e6ccc25af0d200f020e82bf0a3f2a70244d1b3eed7d0288615049fe4ac1d2153f917475c5b5c48b3f51e9febb945b34bc5325e5ec2e99
7
+ data.tar.gz: e7a97e25802f2e2c16075b5033e74fe1d79a6878fd6bcad748bbf1272c617f4b1878c75e71996b9326c5a7a6ff85c39c4804ac3a8a1df7f884cc00d7839eaab6
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2021-07-29 22:40:06 UTC using RuboCop version 1.8.1.
3
+ # on 2021-08-06 20:18:41 UTC using RuboCop version 1.8.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -9,4 +9,4 @@
9
9
  # Offense count: 1
10
10
  # Configuration parameters: CountComments, CountAsOne.
11
11
  Metrics/ClassLength:
12
- Max: 351
12
+ Max: 405
data/CHANGELOG.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## [Unreleased](https://github.com/department-of-veterans-affairs/vtk/tree/HEAD)
3
+ ## [v0.9.0](https://github.com/department-of-veterans-affairs/vtk/tree/v0.9.0) (2021-08-02)
4
4
 
5
- [Full Changelog](https://github.com/department-of-veterans-affairs/vtk/compare/v0.8.0...HEAD)
5
+ [Full Changelog](https://github.com/department-of-veterans-affairs/vtk/compare/v0.8.0...v0.9.0)
6
6
 
7
7
  **Merged pull requests:**
8
8
 
9
+ - SOCKS Setup Command [\#11](https://github.com/department-of-veterans-affairs/vtk/pull/11) ([ericboehs](https://github.com/ericboehs))
9
10
  - Command Analytics [\#8](https://github.com/department-of-veterans-affairs/vtk/pull/8) ([ericboehs](https://github.com/ericboehs))
10
11
 
11
12
  ## [v0.8.0](https://github.com/department-of-veterans-affairs/vtk/tree/v0.8.0) (2021-03-01)
@@ -37,10 +38,6 @@
37
38
 
38
39
  [Full Changelog](https://github.com/department-of-veterans-affairs/vtk/compare/v0.2.6...v0.3.0)
39
40
 
40
- **Merged pull requests:**
41
-
42
- - SOCKS On/Off Commands [\#9](https://github.com/department-of-veterans-affairs/vtk/pull/9) ([ericboehs](https://github.com/ericboehs))
43
-
44
41
  ## [v0.2.6](https://github.com/department-of-veterans-affairs/vtk/tree/v0.2.6) (2021-02-03)
45
42
 
46
43
  [Full Changelog](https://github.com/department-of-veterans-affairs/vtk/compare/v0.2.5...v0.2.6)
@@ -61,6 +58,7 @@
61
58
  **Merged pull requests:**
62
59
 
63
60
  - added Docker instructions to the README [\#10](https://github.com/department-of-veterans-affairs/vtk/pull/10) ([thilton-oddball](https://github.com/thilton-oddball))
61
+ - SOCKS On/Off Commands [\#9](https://github.com/department-of-veterans-affairs/vtk/pull/9) ([ericboehs](https://github.com/ericboehs))
64
62
  - use system command [\#7](https://github.com/department-of-veterans-affairs/vtk/pull/7) ([LindseySaari](https://github.com/LindseySaari))
65
63
  - Add additional module subcommands [\#6](https://github.com/department-of-veterans-affairs/vtk/pull/6) ([LindseySaari](https://github.com/LindseySaari))
66
64
  - Check for Rails dependency [\#5](https://github.com/department-of-veterans-affairs/vtk/pull/5) ([LindseySaari](https://github.com/LindseySaari))
@@ -80,7 +78,6 @@
80
78
  **Merged pull requests:**
81
79
 
82
80
  - fixing markdown in README … [\#3](https://github.com/department-of-veterans-affairs/vtk/pull/3) ([thilton-oddball](https://github.com/thilton-oddball))
83
- - Open Jenkins [\#1](https://github.com/department-of-veterans-affairs/vtk/pull/1) ([cvalarida](https://github.com/cvalarida))
84
81
 
85
82
  ## [v0.1.0](https://github.com/department-of-veterans-affairs/vtk/tree/v0.1.0) (2021-01-04)
86
83
 
@@ -94,6 +91,10 @@
94
91
 
95
92
  [Full Changelog](https://github.com/department-of-veterans-affairs/vtk/compare/79143038509757799edb2bb9be2f925b7d985221...oclif)
96
93
 
94
+ **Merged pull requests:**
95
+
96
+ - Open Jenkins [\#1](https://github.com/department-of-veterans-affairs/vtk/pull/1) ([cvalarida](https://github.com/cvalarida))
97
+
97
98
 
98
99
 
99
100
  \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
@@ -28,35 +28,49 @@ module Vtk
28
28
  end
29
29
 
30
30
  def execute(input: $stdin, output: $stdout)
31
- @input = input
32
- @output = output
31
+ define_stdin_out_vars input: input, output: output
33
32
 
34
33
  setup_ssh_config
35
34
  check_ssh_key
36
35
  ssh_agent_add
37
36
 
38
- test_ssh_connection unless skip_test
39
-
40
- configure_system_boot
41
- configure_system_proxy
42
-
43
- test_http_connection unless skip_test
37
+ unless @ssh_key_created
38
+ test_ssh_connection unless skip_test
39
+ configure_system_boot
40
+ configure_system_proxy
41
+ end
44
42
 
45
- log 'SOCKS setup complete.'
43
+ log "SOCKS setup complete. #{'Re-run `vtk socks setup` after your key is approved.' if @ssh_key_created}"
46
44
  end
47
45
 
48
46
  private
49
47
 
48
+ def define_stdin_out_vars(input:, output:)
49
+ @input = input
50
+ @output = output
51
+ end
52
+
50
53
  def check_ssh_key
51
- return true if key_exists?
54
+ return true if key_exists? && private_and_public_keys_match?
52
55
 
53
- generate_key_and_open_key_access_request
56
+ @ssh_key_created = generate_key_and_open_key_access_request
54
57
  end
55
58
 
56
59
  def key_exists?
57
60
  File.exist? ssh_key_path
58
61
  end
59
62
 
63
+ def private_and_public_keys_match?
64
+ return true unless public_key_exists?
65
+
66
+ pub_key_from_private = `ssh-keygen -y -e -f #{ssh_key_path}`
67
+ pub_key_from_public = `ssh-keygen -y -e -f #{ssh_key_path}.pub`
68
+ return true if pub_key_from_private == pub_key_from_public
69
+
70
+ log "❌ ERROR: #{ssh_key_path}.pub is not the public key for #{ssh_key_path}."
71
+ exit 1
72
+ end
73
+
60
74
  def public_key_exists?
61
75
  File.exist? "#{ssh_key_path}.pub"
62
76
  end
@@ -67,29 +81,46 @@ module Vtk
67
81
 
68
82
  if prompt.yes?(copy_and_open_gh)
69
83
  copy_key_to_clipboard
70
- `#{'xdg-' unless macos?}open "#{access_request_template_url}" 2> /dev/null`
84
+ open_command access_request_template_url
71
85
  else
72
- log "You'll need to submit ~/.ssh/id_rsa_vagov.pub for approval to: #{access_request_template_url}."
86
+ key_contents = File.read "#{ssh_key_path}.pub"
87
+ log "Copy this key & submit into the access request form (#{access_request_template_url}):\n#{key_contents}"
73
88
  end
74
89
  end
75
90
 
76
91
  def copy_key_to_clipboard
77
92
  ssh_key_contents = File.read "#{ssh_key_path}.pub"
78
93
 
94
+ if copy_command
95
+ IO.popen(copy_command, 'w') { |f| f << ssh_key_contents }
96
+ elsif wsl?
97
+ system %(powershell.exe Set-Clipboard -Value "'#{ssh_key_contents}'")
98
+ end
99
+ end
100
+
101
+ def copy_command
79
102
  if macos?
80
- copy_command = 'pbcopy'
81
- elsif ubuntu_like?
103
+ 'pbcopy'
104
+ elsif ubuntu_like? && !wsl?
82
105
  system 'sudo apt-get install -y xsel' if `which xsel`.empty?
83
- copy_command = 'xsel --clipboard'
106
+ 'xsel --clipboard'
84
107
  end
108
+ end
85
109
 
86
- IO.popen(copy_command, 'w') { |f| f << ssh_key_contents }
110
+ def open_command(url)
111
+ if macos?
112
+ `open "#{url}"`
113
+ elsif wsl?
114
+ `powershell.exe Start '"#{url}"'`
115
+ elsif ubuntu_like?
116
+ `xdg-open "#{url}"`
117
+ end
87
118
  end
88
119
 
89
120
  def access_request_template_url
90
121
  'https://github.com/department-of-veterans-affairs/va.gov-team/issues/new?' \
91
- 'assignees=&labels=external-request%2C+operations&template=Environment-Access-Request-Template.md&' \
92
- 'title=Access+for+%5Bindividual%5D'
122
+ 'assignees=&labels=external-request%2C+operations%2C+ops-access-request&' \
123
+ 'template=Environment-Access-Request-Template.md&title=Access+for+%5Bindividual%5D'
93
124
  end
94
125
 
95
126
  def copy_and_open_gh
@@ -138,6 +169,8 @@ module Vtk
138
169
  ssh_config_clean_up
139
170
 
140
171
  ssh_agent_add
172
+ system 'git config --global credential.helper > /dev/null || ' \
173
+ "git config --global credential.helper 'cache --timeout=600'"
141
174
  cloned = system(
142
175
  "git clone --quiet#{' --depth 1' if macos?} --no-checkout --filter=blob:none #{repo_url} '/tmp/dova-devops'"
143
176
  )
@@ -250,16 +283,18 @@ module Vtk
250
283
 
251
284
  add_ip_to_known_hosts
252
285
 
253
- ssh_output = `ssh -i #{ssh_key_path} -F #{ssh_config_path} -o ConnectTimeout=5 -q socks -D #{port} exit 2>&1`
254
-
255
- if ssh_output.include? 'This account is currently not available.'
256
- output.puts ' ✅'
286
+ if proxy_running? || ssh_output.include?('This account is currently not available.')
287
+ output.puts ' ✅ DONE'
257
288
  else
258
289
  check_ssh_error ssh_output
259
290
  exit 1
260
291
  end
261
292
  end
262
293
 
294
+ def ssh_output
295
+ `ssh -i #{ssh_key_path} -F #{ssh_config_path} -o ConnectTimeout=5 -q socks -D #{port} exit 2>&1`
296
+ end
297
+
263
298
  def add_ip_to_known_hosts
264
299
  jump_box_ip = `grep -A 2 'Host socks' ~/.ssh/config | grep ProxyCommand | awk '{print $6}'`.chomp
265
300
  socks_ip = `grep -A 2 'Host socks' ~/.ssh/config | grep HostName | awk '{print $2}'`.chomp
@@ -272,8 +307,8 @@ module Vtk
272
307
 
273
308
  def check_ssh_error(ssh_output)
274
309
  if ssh_output.include? 'Permission denied (publickey)'
275
- @skip_test = true
276
310
  output.puts '⚠️ WARN: SSH key is not approved yet. Once it is, re-run `vtk socks setup`.'
311
+ copy_key_to_clipboard if prompt.yes? 'Would you like to copy your VA public key to your clipboard again?'
277
312
  else
278
313
  ssh_command = "ssh -i #{ssh_key_path} -F #{ssh_config_path} -o ConnectTimeout=5 -vvv socks -D #{port} -N"
279
314
  output.puts ' ❌ ERROR: SSH Connection to SOCKS server unsuccessful. Error message:'
@@ -284,10 +319,39 @@ module Vtk
284
319
 
285
320
  def configure_system_boot
286
321
  log 'Configuring SOCKS tunnel to run on system boot...' do
287
- install_autossh && (install_launch_agent || install_systemd_service)
322
+ if wsl?
323
+ wsl_configure_system_boot && wsl_start_socks_proxy
324
+ else
325
+ install_autossh && (install_launch_agent || install_systemd_service)
326
+ end
288
327
  end
289
328
  end
290
329
 
330
+ def wsl_configure_system_boot
331
+ return true if File.exist? socks_bat
332
+
333
+ IO.write socks_bat, 'wsl nohup bash -c "/usr/bin/ssh socks -N &" < nul > nul 2>&1', mode: 'a'
334
+ end
335
+
336
+ def socks_bat
337
+ "#{socks_bat_dir}/gov.va.socks.bat"
338
+ end
339
+
340
+ def socks_bat_dir
341
+ profile_path = `wslpath "$(wslvar USERPROFILE)"`.chomp
342
+ "#{profile_path}/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"
343
+ end
344
+
345
+ def wsl_start_socks_proxy
346
+ return true if proxy_running?
347
+
348
+ system "cd '#{socks_bat_dir}'; cmd.exe /c gov.va.socks.bat > /dev/null"
349
+ end
350
+
351
+ def proxy_running?
352
+ system("lsof -i:#{port}", out: '/dev/null') || system('lsof -nP | grep ssh | grep -q sock')
353
+ end
354
+
291
355
  def launch_agent_label
292
356
  @launch_agent_label ||= begin
293
357
  launch_agent_label = 'gov.va.socks'
@@ -374,6 +438,8 @@ module Vtk
374
438
 
375
439
  if macos?
376
440
  mac_configure_system_proxy
441
+ elsif wsl?
442
+ wsl_configure_system_proxy
377
443
  elsif ubuntu_like?
378
444
  ubuntu_configure_system_proxy
379
445
  end
@@ -398,6 +464,13 @@ module Vtk
398
464
  end
399
465
  end
400
466
 
467
+ def wsl_configure_system_proxy
468
+ log 'Configuring system proxy to use SOCKS tunnel...' do
469
+ reg_key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings'
470
+ `powershell.exe Set-ItemProperty -path "'#{reg_key}'" AutoConfigURL -Value "'#{PROXY_URL}'"`
471
+ end
472
+ end
473
+
401
474
  def mac_system_proxy_already_configured?
402
475
  network_interfaces.map do |network_interface|
403
476
  output = `networksetup -getautoproxyurl "#{network_interface}"`
@@ -413,25 +486,14 @@ module Vtk
413
486
  end
414
487
  end
415
488
 
416
- def test_http_connection
417
- output.print '----> Testing SOCKS HTTP connection...'
418
-
419
- success = 5.times.map do
420
- sleep 1
421
- not_connected = system "nscurl http://grafana.vfs.va.gov 2>&1 | grep -q 'hostname could not be found'"
422
-
423
- break [true] unless not_connected
424
- end.all?
425
-
426
- output.puts success ? ' ✅' : ' ❌ ERROR: SOCKS connection failed HTTP test. Try running setup again.'
427
-
428
- exit 1 unless success
429
- end
430
-
431
489
  def macos?
432
490
  RUBY_PLATFORM.include? 'darwin'
433
491
  end
434
492
 
493
+ def wsl?
494
+ @wsl ||= File.exist?('/proc/version') && File.open('/proc/version').grep(/Microsoft/).size.positive?
495
+ end
496
+
435
497
  def ubuntu_like?
436
498
  return false if `which apt-get`.empty? && `which gsettings`.empty?
437
499
 
@@ -456,7 +518,7 @@ module Vtk
456
518
 
457
519
  return_value = yield
458
520
 
459
- output.puts return_value ? ' ✅' : ' ❌'
521
+ output.puts return_value ? ' ✅ DONE' : ' ❌ FAIL'
460
522
 
461
523
  return_value
462
524
  else
data/lib/vtk/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vtk
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vtk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Boehs
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-08-02 00:00:00.000000000 Z
13
+ date: 2021-08-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor