Class: TrustedSandbox::Config
- Inherits:
-
Object
- Object
- TrustedSandbox::Config
- Defined in:
- lib/trusted_sandbox/config.rb
Overview
Direct Known Subclasses
Instance Attribute Summary collapse
-
#docker_auth_email ⇒ Object
readonly
Returns the value of attribute docker_auth_email.
-
#docker_auth_needed ⇒ Object
readonly
Returns the value of attribute docker_auth_needed.
-
#docker_auth_password ⇒ Object
readonly
Returns the value of attribute docker_auth_password.
-
#docker_auth_user ⇒ Object
readonly
Returns the value of attribute docker_auth_user.
-
#docker_cert_path ⇒ Object
Returns the value of attribute docker_cert_path.
-
#docker_url ⇒ Object
Returns the value of attribute docker_url.
-
#fallback_config ⇒ Object
readonly
Returns the value of attribute fallback_config.
Class Method Summary collapse
-
.attr_accessor_with_fallback(*names) ⇒ Object
Usage: attr_accessor_with_fallback :my_attribute.
-
.attr_reader_with_fallback(*names) ⇒ Object
Usage: attr_reader_with_fallback :my_attribute.
Instance Method Summary collapse
-
#docker_login=(options = {}) ⇒ Object
Set hash used to authenticate with Docker All keys are mandatory.
-
#finished_configuring ⇒ Config
Called to do any necessary setup to allow staged configuration.
-
#host_code_root_path=(path) ⇒ String
The full path that was set.
-
#host_uid_pool_lock_path=(path) ⇒ String
The full path that was set.
-
#initialize(fallback_config, params = {}) ⇒ Config
constructor
A new instance of Config.
-
#override(params = {}) ⇒ Config
A new object with the fallback object set to self.
-
#pool_max_uid ⇒ Integer
The upper boundary of the uid pool based on pool_min_uid and pool_size.
Constructor Details
#initialize(fallback_config, params = {}) ⇒ Config
Returns a new instance of Config.
132 133 134 135 136 137 138 |
# File 'lib/trusted_sandbox/config.rb', line 132 def initialize(fallback_config, params={}) @docker_options_for_cert = {} @fallback_config = fallback_config params.each do |key, value| send "#{key}=", value end end |
Instance Attribute Details
#docker_auth_email ⇒ Object (readonly)
Returns the value of attribute docker_auth_email.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_auth_email @docker_auth_email end |
#docker_auth_needed ⇒ Object (readonly)
Returns the value of attribute docker_auth_needed.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_auth_needed @docker_auth_needed end |
#docker_auth_password ⇒ Object (readonly)
Returns the value of attribute docker_auth_password.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_auth_password @docker_auth_password end |
#docker_auth_user ⇒ Object (readonly)
Returns the value of attribute docker_auth_user.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_auth_user @docker_auth_user end |
#docker_cert_path ⇒ Object
Returns the value of attribute docker_cert_path.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_cert_path @docker_cert_path end |
#docker_url ⇒ Object
Returns the value of attribute docker_url.
57 58 59 |
# File 'lib/trusted_sandbox/config.rb', line 57 def docker_url @docker_url end |
#fallback_config ⇒ Object (readonly)
Returns the value of attribute fallback_config.
9 10 11 |
# File 'lib/trusted_sandbox/config.rb', line 9 def fallback_config @fallback_config end |
Class Method Details
.attr_accessor_with_fallback(*names) ⇒ Object
Usage:
attr_accessor_with_fallback :my_attribute
Equivalent to:
attr_reader_with_fallback :my_attribute
attr_writer :my_attribute
41 42 43 44 45 46 |
# File 'lib/trusted_sandbox/config.rb', line 41 def self.attr_accessor_with_fallback(*names) names.each do |name| attr_reader_with_fallback(name) attr_writer(name) end end |
.attr_reader_with_fallback(*names) ⇒ Object
Usage:
attr_reader_with_fallback :my_attribute
Equivalent to:
def my_attribute
return @my_attribute if @my_attribute
return fallback_config.my_attribute if @my_attribute.nil? and fallback_config.respond_to?(:my_attribute)
nil
end
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/trusted_sandbox/config.rb', line 23 def self.attr_reader_with_fallback(*names) names.each do |name| define_method name do value = instance_variable_get("@#{name}") return value unless value.nil? return fallback_config.send(name) if fallback_config.respond_to?(name) nil end end end |
Instance Method Details
#docker_login=(options = {}) ⇒ Object
Set hash used to authenticate with Docker All keys are mandatory
107 108 109 110 111 112 |
# File 'lib/trusted_sandbox/config.rb', line 107 def docker_login=(={}) @docker_auth_needed = true @docker_auth_user = [:user] || ['user'] @docker_auth_password = [:password] || ['password'] @docker_auth_email = [:email] || ['email'] end |
#finished_configuring ⇒ Config
Called to do any necessary setup to allow staged configuration. These involve:
-
Setting Docker.options based on the cert path
-
Calling Docker.authenticate! with the login parameters, if these were entered
118 119 120 121 122 123 124 125 |
# File 'lib/trusted_sandbox/config.rb', line 118 def finished_configuring Docker. = @docker_options_for_cert.merge() return self unless @docker_auth_needed Docker.authenticate! username: @docker_auth_user, password: @docker_auth_password, email: @docker_auth_email @docker_auth_needed = false self end |
#host_code_root_path=(path) ⇒ String
Returns the full path that was set. E.g.: ‘/home/user/tmp’.
92 93 94 |
# File 'lib/trusted_sandbox/config.rb', line 92 def host_code_root_path=(path) @host_code_root_path = File.(path) end |
#host_uid_pool_lock_path=(path) ⇒ String
Returns the full path that was set.
98 99 100 |
# File 'lib/trusted_sandbox/config.rb', line 98 def host_uid_pool_lock_path=(path) @host_uid_pool_lock_path = File.(path) end |
#override(params = {}) ⇒ Config
Returns a new object with the fallback object set to self.
62 63 64 |
# File 'lib/trusted_sandbox/config.rb', line 62 def override(params={}) Config.send :new, self, params end |
#pool_max_uid ⇒ Integer
Returns the upper boundary of the uid pool based on pool_min_uid and pool_size.
67 68 69 |
# File 'lib/trusted_sandbox/config.rb', line 67 def pool_max_uid pool_min_uid + pool_size - 1 end |