class Boxen::Config

All configuration for Boxen, whether it's loaded from command-line args, environment variables, config files, or the keychain.

Attributes

color[W]
debug[W]
email[RW]

A GitHub user's public email.

fde[W]
future_parser[W]
ghurl[W]
graph[W]
homedir[W]
logfile[W]
login[RW]

A GitHub user login. Default is `nil`.

name[RW]

A GitHub user's profile name.

pretend[W]
profile[W]
puppetdir[W]
repodir[W]
reponame[W]
report[W]
repotemplate[W]
s3bucket[W]
s3host[W]
srcdir[W]
stealth[W]
token[R]

A GitHub OAuth token. Default is `nil`.

user[W]

Public Class Methods

load() { |config| ... } click to toggle source
# 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
new() { |self| ... } click to toggle source

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) click to toggle source

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

api() click to toggle source

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
color?() click to toggle source
# File lib/boxen/config.rb, line 313
def color?
  @color
end
debug?() click to toggle source

Spew a bunch of debug logging? Default is `false`.

# File lib/boxen/config.rb, line 103
def debug?
  !!@debug
end
enterprise?() click to toggle source

Does this Boxen use a GitHub Enterprise instance?

# File lib/boxen/config.rb, line 274
def enterprise?
  ghurl != "https://github.com"
end
envfile() click to toggle source

The shell script that loads Boxen's environment.

# File lib/boxen/config.rb, line 115
def envfile
  "#{homedir}/env.sh"
end
fde?() click to toggle source

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
future_parser?() click to toggle source

Enable the Puppet future parser? Default is `false`.

# File lib/boxen/config.rb, line 173
def future_parser?
  !!@future_parser
end
ghurl() click to toggle source

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
graph?() click to toggle source

Enable generation of dependency graphs.

# File lib/boxen/config.rb, line 189
def graph?
  !!@graph
end
homedir() click to toggle source

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
logfile() click to toggle source

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
pretend?() click to toggle source

Just go through the motions? Default is `false`.

# File lib/boxen/config.rb, line 157
def pretend?
  !!@pretend
end
profile?() click to toggle source

Run a profiler on Puppet? Default is `false`.

# File lib/boxen/config.rb, line 165
def profile?
  !!@profile
end
projects() click to toggle source

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
puppetdir() click to toggle source

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
repodir() click to toggle source

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
reponame() click to toggle source

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
report?() click to toggle source

Enable puppet reports ? Default is `false`.

# File lib/boxen/config.rb, line 181
def report?
  !!@report
end
repotemplate() click to toggle source

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
s3bucket() click to toggle source

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
s3host() click to toggle source

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
srcdir() click to toggle source

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
stealth?() click to toggle source

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
token=(token) click to toggle source
# File lib/boxen/config.rb, line 300
def token=(token)
  @token = token
  @api = nil
end
user() click to toggle source

A local user login. Default is the `USER` environment variable.

# File lib/boxen/config.rb, line 307
def user
  @user || ENV["USER"]
end