class TrustedSandbox::Cli
Public Instance Methods
generate_image(image_name = 'ruby-2.1.2')
click to toggle source
# 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.expand_path("../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()
click to toggle source
# File lib/trusted_sandbox/cli.rb, line 48 def generate_images target_dir = 'trusted_sandbox_images' source_dir = File.expand_path("../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()
click to toggle source
# 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.expand_path('../config/trusted_sandbox.yml', __FILE__), target_file end
reset_uid_pool(uid = nil)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/trusted_sandbox/cli.rb, line 21 def test TrustedSandbox.test_connection puts 'Trusted Sandbox seems to be configured correctly!' end