Class: StackCar::Proxy

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/stack_car/proxy.rb

Instance Method Summary collapse

Instance Method Details

#certObject



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
# File 'lib/stack_car/proxy.rb', line 24

def cert
  say("Downloading certificate package...")

  IO.copy_stream(URI.open(download_url), output_file)
  say("Download complete.")
  unzip_file

  if Os.macos?
    run("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain #{proxy_dir}/localhost.direct.SS.crt")
  elsif Os.ubuntu?
    run("sudo cp #{proxy_dir}/localhost.direct.SS.crt /usr/local/share/ca-certificates/localhost.direct.SS.crt")
    run("sudo update-ca-certificates")
  elsif Os.wsl?
    say("\n\n\nFor WSL, you need to add the certificate to Windows certificate store:\n")
    say("1. Copy the certificate to a Windows-accessible location:\n")
    run("cp #{proxy_dir}/localhost.direct.SS.crt /mnt/c/temp/localhost.direct.SS.crt")
    say("\n2. Now run this Windows command to import the certificate (requires admin rights):\n")
    run("powershell.exe -Command \"Start-Process powershell -Verb RunAs -ArgumentList '-Command Import-Certificate -FilePath C:\\temp\\localhost.direct.SS.crt -CertStoreLocation Cert:\\LocalMachine\\Root'\"")
    say("\n3. Then restart your browser to apply the changes\n\n")
  else
    say("\n\n\nPlease figure out how to add a certificate to your system, then open a PR for your OS/Distro")
    say("Files are located #{ENV['PWD']}/proxy/localhost.direct.SS.crt and #{ENV['PWD']}/proxy/localhost.direct.SS.key\n\n\n")
    exit(1)
  end
end

#downObject



18
19
20
21
# File 'lib/stack_car/proxy.rb', line 18

def down
  set_proxy_env
  run("docker compose -f #{HammerOfTheGods.gem_root}/proxy/compose.yaml down")
end

#upObject



11
12
13
14
15
# File 'lib/stack_car/proxy.rb', line 11

def up
  #find the socket
  set_proxy_env
  run("docker compose -f #{HammerOfTheGods.gem_root}/proxy/compose.yaml up -d")
end