Class: Boxen::Config
- Inherits:
-
Object
- Object
- Boxen::Config
- Defined in:
- lib/boxen/config.rb
Overview
All configuration for Boxen, whether it’s loaded from command-line args, environment variables, config files, or the keychain.
Constant Summary collapse
- KEYCHAIN_SERVICE =
The service name to use when loading/saving config in the Keychain.
"Boxen"
Instance Attribute Summary collapse
-
#color ⇒ Object
writeonly
Sets the attribute color.
-
#debug ⇒ Object
writeonly
Sets the attribute debug.
-
#email ⇒ Object
A GitHub user’s public email.
-
#fde ⇒ Object
writeonly
Sets the attribute fde.
-
#homedir ⇒ Object
Boxen’s home directory.
-
#logfile ⇒ Object
Boxen’s log file.
-
#login ⇒ Object
A GitHub user login.
-
#name ⇒ Object
A GitHub user’s profile name.
-
#password ⇒ Object
A GitHub user password.
-
#pretend ⇒ Object
writeonly
Sets the attribute pretend.
-
#profile ⇒ Object
writeonly
Sets the attribute profile.
-
#puppetdir ⇒ Object
The directory where Puppet expects configuration (which we don’t use) and runtime information (which we generally don’t care about).
-
#repodir ⇒ Object
The directory of the custom Boxen repo for an org.
-
#reponame ⇒ Object
The repo on GitHub to use for error reports and automatic updates, in ‘owner/repo` format.
-
#srcdir ⇒ Object
The directory where repos live.
-
#stealth ⇒ Object
writeonly
Sets the attribute stealth.
-
#token ⇒ Object
A GitHub OAuth token.
-
#user ⇒ Object
A local user login.
Class Method Summary collapse
-
.load(&block) ⇒ Object
Load config.
-
.save(config) ⇒ Object
Save ‘config`.
Instance Method Summary collapse
-
#api ⇒ Object
Create an API instance using the current user creds.
- #color? ⇒ Boolean
-
#debug? ⇒ Boolean
Spew a bunch of debug logging? Default is ‘false`.
-
#envfile ⇒ Object
The shell script that loads Boxen’s environment.
-
#fde? ⇒ Boolean
Is full disk encryption required? Default is ‘true`.
-
#initialize {|_self| ... } ⇒ Config
constructor
Create a new instance.
-
#pretend? ⇒ Boolean
Just go through the motions? Default is ‘false`.
-
#profile? ⇒ Boolean
Run a profiler on Puppet? Default is ‘false`.
-
#projects ⇒ Object
An Array of Boxen::Project entries, one for each project Boxen knows how to manage.
-
#stealth? ⇒ Boolean
Don’t auto-create issues on failure? Default is ‘false`.
Constructor Details
#initialize {|_self| ... } ⇒ Config
Create a new instance. Yields ‘self` if `block` is given.
82 83 84 85 86 87 |
# File 'lib/boxen/config.rb', line 82 def initialize(&block) @fde = true @pull = true yield self if block_given? end |
Instance Attribute Details
#color=(value) ⇒ Object (writeonly)
Sets the attribute color
265 266 267 |
# File 'lib/boxen/config.rb', line 265 def color=(value) @color = value end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
102 103 104 |
# File 'lib/boxen/config.rb', line 102 def debug=(value) @debug = value end |
#email ⇒ Object
A GitHub user’s public email.
106 107 108 |
# File 'lib/boxen/config.rb', line 106 def email @email end |
#fde=(value) ⇒ Object (writeonly)
Sets the attribute fde
121 122 123 |
# File 'lib/boxen/config.rb', line 121 def fde=(value) @fde = value end |
#homedir ⇒ Object
Boxen’s home directory. Default is ‘“/opt/boxen”`. Respects the `BOXEN_HOME` environment variable.
126 127 128 |
# File 'lib/boxen/config.rb', line 126 def homedir @homedir || ENV["BOXEN_HOME"] || "/opt/boxen" end |
#logfile ⇒ Object
Boxen’s log file. Default is ‘“##repodir/log/boxen.log”`. Respects the `BOXEN_LOG_FILE` environment variable. The log is overwritten on every run.
136 137 138 |
# File 'lib/boxen/config.rb', line 136 def logfile @logfile || ENV["BOXEN_LOG_FILE"] || "#{repodir}/log/boxen.log" end |
#login ⇒ Object
A GitHub user login. Default is ‘nil`.
144 145 146 |
# File 'lib/boxen/config.rb', line 144 def login @login end |
#name ⇒ Object
A GitHub user’s profile name.
153 154 155 |
# File 'lib/boxen/config.rb', line 153 def name @name end |
#password ⇒ Object
A GitHub user password. Default is ‘nil`.
157 158 159 |
# File 'lib/boxen/config.rb', line 157 def password @password end |
#pretend=(value) ⇒ Object (writeonly)
Sets the attribute pretend
170 171 172 |
# File 'lib/boxen/config.rb', line 170 def pretend=(value) @pretend = value end |
#profile=(value) ⇒ Object (writeonly)
Sets the attribute profile
178 179 180 |
# File 'lib/boxen/config.rb', line 178 def profile=(value) @profile = value end |
#puppetdir ⇒ Object
The directory where Puppet expects configuration (which we don’t use) and runtime information (which we generally don’t care about). Default is ‘/tmp/boxen/puppet`. Respects the `BOXEN_PUPPET_DIR` environment variable.
202 203 204 |
# File 'lib/boxen/config.rb', line 202 def puppetdir @puppetdir || ENV["BOXEN_PUPPET_DIR"] || "/tmp/boxen/puppet" end |
#repodir ⇒ Object
The directory of the custom Boxen repo for an org. Default is ‘Dir.pwd`. Respects the `BOXEN_REPO_DIR` environment variable.
211 212 213 |
# File 'lib/boxen/config.rb', line 211 def repodir @repodir || ENV["BOXEN_REPO_DIR"] || Dir.pwd end |
#reponame ⇒ Object
The repo on GitHub to use for error reports and automatic updates, in ‘owner/repo` format. Default is the `origin` of a Git repo in `repodir`, if it exists and points at GitHub. Respects the `BOXEN_REPO_NAME` environment variable.
222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/boxen/config.rb', line 222 def reponame override = @reponame || ENV["BOXEN_REPO_NAME"] return override unless override.nil? if File.directory? repodir url = Dir.chdir(repodir) { `git config remote.origin.url`.strip } if $?.success? && %r|github\.com[/:]([^/]+/[^/]+)| =~ url @reponame = $1.sub /\.git$/, "" end end end |
#srcdir ⇒ Object
The directory where repos live. Default is ‘“/Users/##user/src”`.
240 241 242 |
# File 'lib/boxen/config.rb', line 240 def srcdir @srcdir || "/Users/#{user}/src" end |
#stealth=(value) ⇒ Object (writeonly)
Sets the attribute stealth
253 254 255 |
# File 'lib/boxen/config.rb', line 253 def stealth=(value) @stealth = value end |
#token ⇒ Object
A GitHub OAuth token. Default is ‘nil`.
257 258 259 |
# File 'lib/boxen/config.rb', line 257 def token @token end |
#user ⇒ Object
A local user login. Default is the ‘USER` environment variable.
261 262 263 |
# File 'lib/boxen/config.rb', line 261 def user @user || ENV["USER"] end |
Class Method Details
.load(&block) ⇒ Object
Load config. Yields config if ‘block` is given.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/boxen/config.rb', line 19 def self.load(&block) new do |config| file = "#{config.homedir}/config/boxen/defaults.json" if File.file? file attrs = JSON.parse File.read file attrs.each do |key, value| if value && config.respond_to?(selector = "#{key}=") config.send selector, value end end end cmd = "/usr/bin/security find-generic-password " + "-a #{config.user} -s '#{KEYCHAIN_SERVICE}' -w 2>/dev/null" password = `#{cmd}`.strip password = nil unless $?.success? config.password = password yield config if block_given? end end |
.save(config) ⇒ Object
Save ‘config`. Returns `config`. Note that this only saves data, not flags. For example, `login` will be saved, but `stealth?` won’t.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/boxen/config.rb', line 49 def self.save(config) attrs = { :email => config.email, :homedir => config.homedir, :login => config.login, :name => config.name, :puppetdir => config.puppetdir, :repodir => config.repodir, :reponame => config.reponame, :srcdir => config.srcdir, :token => config.token, :user => config.user } file = "#{config.homedir}/config/boxen/defaults.json" FileUtils.mkdir_p File.dirname file File.open file, "wb" do |f| f.write JSON.generate Hash[attrs.reject { |k, v| v.nil? }] end cmd = ["security", "add-generic-password", "-a", config.user, "-s", KEYCHAIN_SERVICE, "-U", "-w", config.password] unless system *cmd raise Boxen::Error, "Can't save config in the Keychain." end config end |
Instance Method Details
#api ⇒ Object
Create an API instance using the current user creds. A new instance is created any time ‘login` or `password` change.
92 93 94 |
# File 'lib/boxen/config.rb', line 92 def api @api ||= Octokit::Client.new :login => login, :password => password end |
#color? ⇒ Boolean
267 268 269 |
# File 'lib/boxen/config.rb', line 267 def color? @color end |
#debug? ⇒ Boolean
Spew a bunch of debug logging? Default is ‘false`.
98 99 100 |
# File 'lib/boxen/config.rb', line 98 def debug? !!@debug end |
#envfile ⇒ Object
The shell script that loads Boxen’s environment.
110 111 112 |
# File 'lib/boxen/config.rb', line 110 def envfile "#{homedir}/env.sh" end |
#fde? ⇒ Boolean
Is full disk encryption required? Default is ‘true`. Respects the `BOXEN_NO_FDE` environment variable.
117 118 119 |
# File 'lib/boxen/config.rb', line 117 def fde? !ENV["BOXEN_NO_FDE"] && @fde end |
#pretend? ⇒ Boolean
Just go through the motions? Default is ‘false`.
166 167 168 |
# File 'lib/boxen/config.rb', line 166 def pretend? !!@pretend end |
#profile? ⇒ Boolean
Run a profiler on Puppet? Default is ‘false`.
174 175 176 |
# File 'lib/boxen/config.rb', line 174 def profile? !!@profile end |
#projects ⇒ Object
An Array of Boxen::Project entries, one for each project Boxen knows how to manage.
FIX: Revisit this once we restructure template projects. It’s broken for several reasons: It assumes paths that won’t be right, and it assumes projects live in the same repo as this file.
188 189 190 191 192 193 194 195 |
# File 'lib/boxen/config.rb', line 188 def projects files = Dir["#{repodir}/modules/projects/manifests/*.pp"] names = files.map { |m| File.basename m, ".pp" }.sort names.map do |name| Boxen::Project.new "#{srcdir}/#{name}" end end |
#stealth? ⇒ Boolean
Don’t auto-create issues on failure? Default is ‘false`. Respects the `BOXEN_NO_ISSUE` environment variable.
249 250 251 |
# File 'lib/boxen/config.rb', line 249 def stealth? !!ENV["BOXEN_NO_ISSUE"] || @stealth end |