Sha256: d04bbbeb00d1ba8a9666db01ecd5cc46752d53e15e1a13287c5d6ff702caf0c1

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

require 'kitchen/provisioner/chef_zero'
require 'kitchen-appbundle-updater/helpers'

module Kitchen
  module Provisioner
    class ChefGithub < Kitchen::Provisioner::ChefZero
      default_config :refname, "master"
      default_config :github_owner, "chef"
      default_config :github_repo, "chef"

      def create_sandbox
        super
        dna = {
          chef_appbundle_updater: {
            github_org: config[:github_owner],
            github_repo: config[:github_repo],
            refname: config[:refname]
          }
        }

        File.open(File.join(sandbox_path, 'dna_updater.json'), "wb") do |f|
          f.write(dna.to_json)
        end
      end

      def latest_chef_appbundle_updater
        url = "https://api.github.com/repos/jdmundrawala/chef-appbundle-updater/releases/latest"
        url += "?access_token=#{config[:github_access_token]}" if config[:github_access_token]

        @cookbook_url ||= open(url) do |r|
          j = JSON.parse(r.read)
          j["assets"][0]["browser_download_url"]
        end
      end

      def prepare_command
        [
          prepare_command_vars,
          KitchenAppbundleUpdater::Helpers.load_file("chef_base_updater", powershell_shell?)
        ].join("\n")
      end

      def prepare_command_vars
        vars = [
          shell_var("cookbook_url", latest_chef_appbundle_updater),
          shell_var("json", File.join(config[:root_path], 'dna_updater.json')),
          shell_var("chef_omnibus_root", config[:chef_omnibus_root]),
        ]

        if powershell_shell?
          vars.join("\n")
        else
          vars.join(";\n")
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kitchen-appbundle-updater-0.0.3 lib/kitchen/provisioner/chef_github.rb