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.
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.
-
#future_parser ⇒ Object
writeonly
Sets the attribute future_parser.
-
#ghurl ⇒ Object
GitHub location (public or GitHub Enterprise).
-
#graph ⇒ Object
writeonly
Sets the attribute graph.
-
#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.
-
#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.
-
#report ⇒ Object
writeonly
Sets the attribute report.
-
#repotemplate ⇒ Object
Repository URL template (required for GitHub Enterprise).
-
#s3bucket ⇒ Object
The S3 bucket name.
-
#s3host ⇒ Object
The S3 host name.
-
#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
-
.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`.
-
#enterprise? ⇒ Boolean
Does this Boxen use a GitHub Enterprise instance?.
-
#envfile ⇒ Object
The shell script that loads Boxen’s environment.
-
#fde? ⇒ Boolean
Is full disk encryption required? Default is ‘true`.
-
#future_parser? ⇒ Boolean
Enable the Puppet future parser? Default is ‘false`.
-
#graph? ⇒ Boolean
Enable generation of dependency graphs.
-
#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.
-
#report? ⇒ Boolean
Enable puppet reports ? Default is ‘false`.
-
#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.
87 88 89 90 91 92 |
# File 'lib/boxen/config.rb', line 87 def initialize(&block) @fde = true @pull = true yield self if block_given? end |
Instance Attribute Details
#color=(value) ⇒ Object (writeonly)
Sets the attribute color
317 318 319 |
# File 'lib/boxen/config.rb', line 317 def color=(value) @color = value end |
#debug=(value) ⇒ Object (writeonly)
Sets the attribute debug
107 108 109 |
# File 'lib/boxen/config.rb', line 107 def debug=(value) @debug = value end |
#email ⇒ Object
A GitHub user’s public email.
111 112 113 |
# File 'lib/boxen/config.rb', line 111 def email @email end |
#fde=(value) ⇒ Object (writeonly)
Sets the attribute fde
126 127 128 |
# File 'lib/boxen/config.rb', line 126 def fde=(value) @fde = value end |
#future_parser=(value) ⇒ Object (writeonly)
Sets the attribute future_parser
177 178 179 |
# File 'lib/boxen/config.rb', line 177 def future_parser=(value) @future_parser = value end |
#ghurl ⇒ Object
GitHub location (public or GitHub Enterprise)
257 258 259 |
# File 'lib/boxen/config.rb', line 257 def ghurl @ghurl || ENV["BOXEN_GITHUB_ENTERPRISE_URL"] || "https://github.com" end |
#graph=(value) ⇒ Object (writeonly)
Sets the attribute graph
193 194 195 |
# File 'lib/boxen/config.rb', line 193 def graph=(value) @graph = value end |
#homedir ⇒ Object
Boxen’s home directory. Default is ‘“/opt/boxen”`. Respects the `BOXEN_HOME` environment variable.
131 132 133 |
# File 'lib/boxen/config.rb', line 131 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.
141 142 143 |
# File 'lib/boxen/config.rb', line 141 def logfile @logfile || ENV["BOXEN_LOG_FILE"] || "#{repodir}/log/boxen.log" end |
#login ⇒ Object
A GitHub user login. Default is ‘nil`.
149 150 151 |
# File 'lib/boxen/config.rb', line 149 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 |
#pretend=(value) ⇒ Object (writeonly)
Sets the attribute pretend
161 162 163 |
# File 'lib/boxen/config.rb', line 161 def pretend=(value) @pretend = value end |
#profile=(value) ⇒ Object (writeonly)
Sets the attribute profile
169 170 171 |
# File 'lib/boxen/config.rb', line 169 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.
217 218 219 |
# File 'lib/boxen/config.rb', line 217 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.
226 227 228 |
# File 'lib/boxen/config.rb', line 226 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.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/boxen/config.rb', line 237 def reponame override = @reponame || ENV["BOXEN_REPO_NAME"] return override unless override.nil? if File.directory? repodir ghuri = URI(ghurl) url = Dir.chdir(repodir) { `git config remote.origin.url`.strip } # find the path and strip off the .git suffix repo_exp = Regexp.new Regexp.escape(ghuri.host) + "[/:]([^/]+/[^/]+)" if $?.success? && repo_exp.match(url) @reponame = $1.sub /\.git$/, "" end end end |
#report=(value) ⇒ Object (writeonly)
Sets the attribute report
185 186 187 |
# File 'lib/boxen/config.rb', line 185 def report=(value) @report = value end |
#repotemplate ⇒ Object
Repository URL template (required for GitHub Enterprise)
265 266 267 268 |
# File 'lib/boxen/config.rb', line 265 def repotemplate default = 'https://github.com/%s' @repotemplate || ENV["BOXEN_REPO_URL_TEMPLATE"] || default end |
#s3bucket ⇒ Object
The S3 bucket name. Default is ‘“boxen-downloads”`. Respects the `BOXEN_S3_BUCKET` environment variable.
331 332 333 |
# File 'lib/boxen/config.rb', line 331 def s3bucket @s3bucket || ENV["BOXEN_S3_BUCKET"] || "boxen-downloads" end |
#s3host ⇒ Object
The S3 host name. Default is ‘“s3.amazonaws.com”`. Respects the `BOXEN_S3_HOST` environment variable.
322 323 324 |
# File 'lib/boxen/config.rb', line 322 def s3host @s3host || ENV["BOXEN_S3_HOST"] || "s3.amazonaws.com" end |
#srcdir ⇒ Object
The directory where repos live. Default is ‘“/Users/##user/src”`.
281 282 283 |
# File 'lib/boxen/config.rb', line 281 def srcdir @srcdir || ENV["BOXEN_SRC_DIR"] || "/Users/#{user}/src" end |
#stealth=(value) ⇒ Object (writeonly)
Sets the attribute stealth
294 295 296 |
# File 'lib/boxen/config.rb', line 294 def stealth=(value) @stealth = value end |
#token ⇒ Object
A GitHub OAuth token. Default is ‘nil`.
298 299 300 |
# File 'lib/boxen/config.rb', line 298 def token @token end |
#user ⇒ Object
A local user login. Default is the ‘USER` environment variable.
307 308 309 |
# File 'lib/boxen/config.rb', line 307 def user @user || ENV["USER"] end |
Class Method Details
.load(&block) ⇒ Object
15 16 17 18 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 44 45 46 |
# File 'lib/boxen/config.rb', line 15 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.nil? && config.respond_to?(selector = "#{key}=") config.send selector, value end end end if Boxen::Util.osx? keychain = Boxen::Keychain.new config.user config.token = keychain.token else config.token = '' end if config.enterprise? # configure to talk to GitHub Enterprise Octokit.configure do |c| c.api_endpoint = "#{config.ghurl}/api/v3" c.web_endpoint = config.ghurl end end 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.
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 79 80 81 82 83 |
# File 'lib/boxen/config.rb', line 52 def self.save(config) attrs = { :email => config.email, :fde => config.fde?, :homedir => config.homedir, :login => config.login, :name => config.name, :puppetdir => config.puppetdir, :repodir => config.repodir, :reponame => config.reponame, :ghurl => config.ghurl, :srcdir => config.srcdir, :user => config.user, :repotemplate => config.repotemplate, :s3host => config.s3host, :s3bucket => config.s3bucket } 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 if Boxen::Util.osx? keychain = Boxen::Keychain.new config.user keychain.token = config.token end config end |
Instance Method Details
#api ⇒ Object
Create an API instance using the current user creds. A new instance is created any time ‘token` changes.
97 98 99 |
# File 'lib/boxen/config.rb', line 97 def api @api ||= Octokit::Client.new :login => token, :password => 'x-oauth-basic' end |
#color? ⇒ Boolean
313 314 315 |
# File 'lib/boxen/config.rb', line 313 def color? @color end |
#debug? ⇒ Boolean
Spew a bunch of debug logging? Default is ‘false`.
103 104 105 |
# File 'lib/boxen/config.rb', line 103 def debug? !!@debug end |
#enterprise? ⇒ Boolean
Does this Boxen use a GitHub Enterprise instance?
274 275 276 |
# File 'lib/boxen/config.rb', line 274 def enterprise? ghurl != "https://github.com" end |
#envfile ⇒ Object
The shell script that loads Boxen’s environment.
115 116 117 |
# File 'lib/boxen/config.rb', line 115 def envfile "#{homedir}/env.sh" end |
#fde? ⇒ Boolean
Is full disk encryption required? Default is ‘true`. Respects the `BOXEN_NO_FDE` environment variable.
122 123 124 |
# File 'lib/boxen/config.rb', line 122 def fde? !ENV["BOXEN_NO_FDE"] && @fde end |
#future_parser? ⇒ Boolean
Enable the Puppet future parser? Default is ‘false`.
173 174 175 |
# File 'lib/boxen/config.rb', line 173 def future_parser? !!@future_parser end |
#graph? ⇒ Boolean
Enable generation of dependency graphs.
189 190 191 |
# File 'lib/boxen/config.rb', line 189 def graph? !!@graph end |
#pretend? ⇒ Boolean
Just go through the motions? Default is ‘false`.
157 158 159 |
# File 'lib/boxen/config.rb', line 157 def pretend? !!@pretend end |
#profile? ⇒ Boolean
Run a profiler on Puppet? Default is ‘false`.
165 166 167 |
# File 'lib/boxen/config.rb', line 165 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.
203 204 205 206 207 208 209 210 |
# File 'lib/boxen/config.rb', line 203 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 |
#report? ⇒ Boolean
Enable puppet reports ? Default is ‘false`.
181 182 183 |
# File 'lib/boxen/config.rb', line 181 def report? !!@report end |
#stealth? ⇒ Boolean
Don’t auto-create issues on failure? Default is ‘false`. Respects the `BOXEN_NO_ISSUE` environment variable.
290 291 292 |
# File 'lib/boxen/config.rb', line 290 def stealth? !!ENV["BOXEN_NO_ISSUE"] || @stealth end |