Class: LittleGhost::Sandbox::Limits
- Inherits:
-
Object
- Object
- LittleGhost::Sandbox::Limits
- Defined in:
- lib/little_ghost/sandbox/limits.rb
Overview
Bounded file and process output sizes applied by Sandbox tools.
Constant Summary collapse
- DEFAULTS =
{ read_bytes: 1_000_000, write_bytes: 1_000_000, list_entries: 10_000, output_bytes: 1_000_000 }.freeze
Instance Attribute Summary collapse
-
#list_entries ⇒ Object
readonly
Maximum entries returned by one directory listing.
-
#output_bytes ⇒ Object
readonly
Maximum bytes captured from each child output stream.
-
#read_bytes ⇒ Object
readonly
Maximum bytes returned by one filesystem read.
-
#write_bytes ⇒ Object
readonly
Maximum bytes accepted by one filesystem write.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Returns
valueunchanged or builds limits from a Hash.
Instance Method Summary collapse
-
#initialize(**values) ⇒ Limits
constructor
Builds positive file and process output limits.
Constructor Details
#initialize(**values) ⇒ Limits
Builds positive file and process output limits.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/little_ghost/sandbox/limits.rb', line 23 def initialize(**values) unknown = values.keys - DEFAULTS.keys raise PolicyError, "unknown sandbox limits: #{unknown.join(", ")}" unless unknown.empty? DEFAULTS.merge(values).each do |name, value| value = Integer(value) raise PolicyError, "sandbox #{name} must be positive" unless value.positive? instance_variable_set("@#{name}", value) rescue ArgumentError, TypeError raise PolicyError, "sandbox #{name} must be an integer" end freeze end |
Instance Attribute Details
#list_entries ⇒ Object (readonly)
Maximum entries returned by one directory listing.
43 44 45 |
# File 'lib/little_ghost/sandbox/limits.rb', line 43 def list_entries @list_entries end |
#output_bytes ⇒ Object (readonly)
Maximum bytes captured from each child output stream.
45 46 47 |
# File 'lib/little_ghost/sandbox/limits.rb', line 45 def output_bytes @output_bytes end |
#read_bytes ⇒ Object (readonly)
Maximum bytes returned by one filesystem read.
39 40 41 |
# File 'lib/little_ghost/sandbox/limits.rb', line 39 def read_bytes @read_bytes end |
#write_bytes ⇒ Object (readonly)
Maximum bytes accepted by one filesystem write.
41 42 43 |
# File 'lib/little_ghost/sandbox/limits.rb', line 41 def write_bytes @write_bytes end |
Class Method Details
.coerce(value) ⇒ Object
Returns value unchanged or builds limits from a Hash.
15 16 17 18 19 20 |
# File 'lib/little_ghost/sandbox/limits.rb', line 15 def self.coerce(value) return value if value.is_a?(self) raise PolicyError, "sandbox limits must be a Hash" unless value.respond_to?(:to_h) new(**value.to_h.transform_keys(&:to_sym)) end |