class Boxen::Config
All configuration for Boxen
, whether it's loaded from command-line args, environment variables, config files, or the keychain.
Attributes
A GitHub user's public email.
A GitHub user login. Default is `nil`.
A GitHub user's profile name.
A GitHub OAuth token. Default is `nil`.
Public Class Methods
# 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
Create a new instance. Yields `self` if `block` is given.
# File lib/boxen/config.rb, line 87 def initialize(&block) @fde = true @pull = true yield self if block_given? end
Save `config`. Returns `config`. Note that this only saves data, not flags. For example, `login` will be saved, but `stealth?` won't.
# 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
Public Instance Methods
Create an API instance using the current user creds. A new instance is created any time `token` changes.
# File lib/boxen/config.rb, line 97 def api @api ||= Octokit::Client.new :login => token, :password => 'x-oauth-basic' end
# File lib/boxen/config.rb, line 313 def color? @color end
Spew a bunch of debug logging? Default is `false`.
# File lib/boxen/config.rb, line 103 def debug? !!@debug end
Does this Boxen
use a GitHub Enterprise instance?
# File lib/boxen/config.rb, line 274 def enterprise? ghurl != "https://github.com" end
The shell script that loads Boxen's environment.
# File lib/boxen/config.rb, line 115 def envfile "#{homedir}/env.sh" end
Is full disk encryption required? Default is `true`. Respects the `BOXEN_NO_FDE` environment variable.
# File lib/boxen/config.rb, line 122 def fde? !ENV["BOXEN_NO_FDE"] && @fde end
Enable the Puppet future parser? Default is `false`.
# File lib/boxen/config.rb, line 173 def future_parser? !!@future_parser end
GitHub location (public or GitHub Enterprise)
# File lib/boxen/config.rb, line 257 def ghurl @ghurl || ENV["BOXEN_GITHUB_ENTERPRISE_URL"] || "https://github.com" end
Enable generation of dependency graphs.
# File lib/boxen/config.rb, line 189 def graph? !!@graph end
Boxen's home directory. Default is `“/opt/boxen”`. Respects the `BOXEN_HOME` environment variable.
# File lib/boxen/config.rb, line 131 def homedir @homedir || ENV["BOXEN_HOME"] || "/opt/boxen" end
Boxen's log file. Default is `“#{repodir}/log/boxen.log”`. Respects the `BOXEN_LOG_FILE` environment variable. The log is overwritten on every run.
# File lib/boxen/config.rb, line 141 def logfile @logfile || ENV["BOXEN_LOG_FILE"] || "#{repodir}/log/boxen.log" end
Just go through the motions? Default is `false`.
# File lib/boxen/config.rb, line 157 def pretend? !!@pretend end
Run a profiler on Puppet? Default is `false`.
# File lib/boxen/config.rb, line 165 def profile? !!@profile end
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.
# 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
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.
# File lib/boxen/config.rb, line 217 def puppetdir @puppetdir || ENV["BOXEN_PUPPET_DIR"] || "/tmp/boxen/puppet" end
The directory of the custom Boxen
repo for an org. Default is `Dir.pwd`. Respects the `BOXEN_REPO_DIR` environment variable.
# File lib/boxen/config.rb, line 226 def repodir @repodir || ENV["BOXEN_REPO_DIR"] || Dir.pwd end
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.
# 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
Enable puppet reports ? Default is `false`.
# File lib/boxen/config.rb, line 181 def report? !!@report end
Repository URL template (required for GitHub Enterprise)
# File lib/boxen/config.rb, line 265 def repotemplate default = 'https://github.com/%s' @repotemplate || ENV["BOXEN_REPO_URL_TEMPLATE"] || default end
The S3 bucket name. Default is `“boxen-downloads”`. Respects the `BOXEN_S3_BUCKET` environment variable.
# File lib/boxen/config.rb, line 331 def s3bucket @s3bucket || ENV["BOXEN_S3_BUCKET"] || "boxen-downloads" end
The S3 host name. Default is `“s3.amazonaws.com”`. Respects the `BOXEN_S3_HOST` environment variable.
# File lib/boxen/config.rb, line 322 def s3host @s3host || ENV["BOXEN_S3_HOST"] || "s3.amazonaws.com" end
The directory where repos live. Default is `“/Users/#{user}/src”`.
# File lib/boxen/config.rb, line 281 def srcdir @srcdir || ENV["BOXEN_SRC_DIR"] || "/Users/#{user}/src" end
Don't auto-create issues on failure? Default is `false`. Respects the `BOXEN_NO_ISSUE` environment variable.
# File lib/boxen/config.rb, line 290 def stealth? !!ENV["BOXEN_NO_ISSUE"] || @stealth end
# File lib/boxen/config.rb, line 300 def token=(token) @token = token @api = nil end
A local user login. Default is the `USER` environment variable.
# File lib/boxen/config.rb, line 307 def user @user || ENV["USER"] end