Class: TrustedSandbox::Cli
- Inherits:
-
Thor
- Object
- Thor
- TrustedSandbox::Cli
- Defined in:
- lib/trusted_sandbox/cli.rb
Instance Method Summary collapse
- #generate_image(image_name = 'ruby-2.1.2') ⇒ Object
- #generate_images ⇒ Object
- #install ⇒ Object
- #reset_uid_pool(uid = nil) ⇒ Object
- #set_quotas(quota_kb) ⇒ Object
- #ssh(uid = nil) ⇒ Object
- #test ⇒ Object
Instance Method Details
#generate_image(image_name = 'ruby-2.1.2') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/trusted_sandbox/cli.rb', line 34 def generate_image(image_name = 'ruby-2.1.2') target_dir = 'trusted_sandbox_images' target_image_path = "#{target_dir}/#{image_name}" gem_image_path = File.("../server_images/#{image_name}", __FILE__) puts "Image #{image_name} does not exist" or return unless Dir.exist?(gem_image_path) puts "Directory #{target_image_path} already exists" or return if Dir.exist?(target_image_path) puts "Copying #{image_name} into #{target_image_path}" FileUtils.mkdir_p target_dir FileUtils.cp_r gem_image_path, target_image_path end |
#generate_images ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/trusted_sandbox/cli.rb', line 48 def generate_images target_dir = 'trusted_sandbox_images' source_dir = File.("../server_images", __FILE__) puts "Directory #{target_dir} already exists" or return if Dir.exist?(target_dir) puts "Copying images into #{target_dir}" FileUtils.cp_r source_dir, target_dir end |
#install ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/trusted_sandbox/cli.rb', line 7 def install curr_dir_file = 'trusted_sandbox.yml' config_dir_file = 'config/trusted_sandbox.yml' puts "#{curr_dir_file} already exists" or return if File.exist?(curr_dir_file) puts "#{config_dir_file} already exists" or return if File.exist?(config_dir_file) target_file = Dir.exist?('config') ? config_dir_file : curr_dir_file puts "Creating #{target_file}" FileUtils.cp File.('../config/trusted_sandbox.yml', __FILE__), target_file end |
#reset_uid_pool(uid = nil) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/trusted_sandbox/cli.rb', line 69 def reset_uid_pool(uid = nil) if uid TrustedSandbox.uid_pool.release uid else TrustedSandbox.uid_pool.release_all end end |
#set_quotas(quota_kb) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/trusted_sandbox/cli.rb', line 59 def set_quotas(quota_kb) from = TrustedSandbox.config.pool_min_uid to = TrustedSandbox.config.pool_max_uid puts "Configuring quota for UIDs [#{from}..#{to}]" (from..to).each do |uid| `sudo setquota -u #{uid} 0 #{quota_kb} 0 0 /` end end |
#ssh(uid = nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/trusted_sandbox/cli.rb', line 27 def ssh(uid) raise 'keep_code_folders must be set to true' unless TrustedSandbox.config.keep_code_folders local_code_dir = File.join TrustedSandbox.config.host_code_root_path, uid `docker run -it -v #{local_code_dir}:/home/sandbox/src --entrypoint="/bin/bash" #{TrustedSandbox.config.docker_image_name} -s` end |
#test ⇒ Object
21 22 23 24 |
# File 'lib/trusted_sandbox/cli.rb', line 21 def test TrustedSandbox.test_connection puts 'Trusted Sandbox seems to be configured correctly!' end |