Vendor the external cookbooks

Knife-Zero doesn't include Berkshelf support, so vendoring everything in
the repo is convenient again
This commit is contained in:
Greg Karékinian
2019-10-13 19:17:42 +02:00
parent f4bfe31ac1
commit a32f34b408
1245 changed files with 100630 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
#
# Copyright 2015-2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseGit
autoload :GitClientProviders, 'poise_git/git_client_providers'
autoload :GitCommandMixin, 'poise_git/git_command_mixin'
autoload :Resources, 'poise_git/resources'
autoload :SafeString, 'poise_git/safe_string'
autoload :VERSION, 'poise_git/version'
end

View File

@@ -0,0 +1,18 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_git/resources'
require 'poise_git/git_client_providers'

View File

@@ -0,0 +1,36 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/platform/provider_priority_map'
require 'poise_git/git_client_providers/dummy'
require 'poise_git/git_client_providers/system'
module PoiseGit
# Inversion providers for the poise_git resource.
#
# @since 1.0.0
module GitClientProviders
autoload :Base, 'poise_git/git_client_providers/base'
# Set up priority maps
Chef::Platform::ProviderPriorityMap.instance.priority(:poise_git_client, [
PoiseGit::GitClientProviders::Dummy,
PoiseGit::GitClientProviders::System,
])
end
end

View File

@@ -0,0 +1,93 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/provider'
require 'poise'
module PoiseGit
module GitClientProviders
# The provider base class for `poise_git_client`.
#
# @see PoiseGit::Resources::PoiseGitClient::Resource
# @provides poise_git_client
class Base < Chef::Provider
include Poise(inversion: :poise_git_client)
provides(:poise_git_client)
# Set default inversion options.
#
# @api private
def self.default_inversion_options(node, new_resource)
super.merge({
version: new_resource.version,
})
end
# The `install` action for the `poise_git_client` resource.
#
# @return [void]
def action_install
notifying_block do
install_git
end
end
# The `uninstall` action for the `poise_git_client` resource.
#
# @return [void]
def action_uninstall
notifying_block do
uninstall_git
end
end
# The path to the `git` binary. This is an output property.
#
# @abstract
# @return [String]
def git_binary
raise NotImplementedError
end
# The environment variables for this Git. This is an output property.
#
# @return [Hash<String, String>]
def git_environment
{}
end
private
# Install git.
#
# @abstract
# @return [void]
def install_git
raise NotImplementedError
end
# Uninstall git.
#
# @abstract
# @return [void]
def uninstall_git
raise NotImplementedError
end
end
end
end

View File

@@ -0,0 +1,79 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_git/git_client_providers/base'
module PoiseGit
module GitClientProviders
# Inversion provider for the `poise_git_client` resource to use a fake Git,
# for use in unit tests.
#
# @since 1.0.0
# @see PoiseGit::Resources::PoiseGitClient::Resource
# @provides poise_git_client
class Dummy < Base
provides(:dummy)
# Enable by default on ChefSpec.
#
# @api private
def self.provides_auto?(node, _resource)
node.platform?('chefspec')
end
# Manual overrides for dummy data.
#
# @api private
def self.default_inversion_options(node, resource)
super.merge({
git_binary: '/git',
git_environment: nil,
})
end
# The `install` action for the `poise_git_client` resource.
#
# @return [void]
def action_install
# This space left intentionally blank.
end
# The `uninstall` action for the `poise_git_client` resource.
#
# @return [void]
def action_uninstall
# This space left intentionally blank.
end
# Path to the non-existent Git.
#
# @return [String]
def git_binary
options['git_binary']
end
# Environment for the non-existent Git.
#
# @return [String]
def git_environment
options['git_environment'] || super
end
end
end
end

View File

@@ -0,0 +1,73 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_languages'
require 'poise_git/git_client_providers/base'
module PoiseGit
module GitClientProviders
# A provider for `poise_git_client` to install from distro packages.
#
# @since 1.0.0
# @see PoiseGit::Resources::PoiseGitClient::Resource
# @provides poise_git_client
class System < Base
include PoiseLanguages::System::Mixin
provides(:system)
packages('git', {
omnios: {default: %w{developer/versioning/git}},
smartos: {default: %w{scmgit}},
})
# Output value for the Git binary we are installing.
def git_binary
# What should this be for OmniOS and SmartOS?
"/usr/bin/git"
end
private
# Install git from system packages.
#
# @return [void]
def install_git
install_system_packages do
# Unlike language-ish packages, we don't need a headers package.
dev_package false
end
end
# Remove git from system packages.
#
# @return [void]
def uninstall_git
uninstall_system_packages do
# Unlike language-ish packages, we don't need a headers package.
dev_package false
end
end
def system_package_candidates(version)
# This is kind of silly, could use a refactor in the mixin but just
# moving on for right now.
node.value_for_platform(self.class.packages) || %w{git}
end
end
end
end

View File

@@ -0,0 +1,37 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise/utils'
require 'poise_languages'
module PoiseGit
# Mixin for resources and providers which run Git commands.
#
# @since 1.0.0
module GitCommandMixin
include Poise::Utils::ResourceProviderMixin
# Mixin for resources which run Git commands.
module Resource
include PoiseLanguages::Command::Mixin::Resource(:git, runtime: :poise_git_client)
end
module Provider
include PoiseLanguages::Command::Mixin::Provider(:git)
end
end
end

View File

@@ -0,0 +1,27 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'poise_git/resources/poise_git_client'
require 'poise_git/resources/poise_git'
module PoiseGit
# Chef resources and providers for poise-git.
#
# @since 1.0.0
module Resources
end
end

View File

@@ -0,0 +1,252 @@
#
# Copyright 2015-2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'shellwords'
require 'zlib'
require 'chef/provider/git'
require 'chef/resource/git'
require 'poise'
require 'poise_git/git_command_mixin'
require 'poise_git/safe_string'
module PoiseGit
module Resources
# (see PoiseGit::Resource)
# @since 1.0.0
module PoiseGit
# A `poise_git` resource to manage Python installations using pip.
#
# @provides poise_git
# @action checkout
# @action export
# @action sync
# @example
# poise_git '/srv/myapp' do
# repository 'https://...'
# deploy_key data_bag_item('deploy_keys', 'myapp')['key']
# end
class Resource < Chef::Resource::Git
include Poise
include ::PoiseGit::GitCommandMixin
provides(:poise_git)
# Manually create matchers because #actions is unreliable.
%i{checkout export sync}.each do |action|
Poise::Helpers::ChefspecMatchers.create_matcher(:poise_git, action)
end
# @api private
def initialize(*args)
super
# Because the superclass declares this, we have to as well. Should be
# removable at some point when Chef makes everything use the provider
# resolver system instead.
@resource_name = :poise_git if defined?(@resource_name) && @resource_name
@provider = ::PoiseGit::Resources::PoiseGit::Provider if defined?(@provider) && @provider
end
# @!attribute strict_ssh
# Enable strict SSH host key checking. Defaults to false.
# @return [Boolean]
attribute(:strict_ssh, equal_to: [true, false], default: false)
# @!attribute deploy_key
# SSH deploy key as either a string value or a path to a key file.
# @return [String]
def deploy_key(val=nil)
# Use a SafeString for literal deploy keys so they aren't shown.
val = SafeString.new(val) if val && !deploy_key_is_local?(val)
set_or_return(:deploy_key, val, kind_of: String)
end
# Default SSH wrapper path.
#
# @api private
# @return [String]
def ssh_wrapper_path
@ssh_wrapper_path ||= "#{Chef::Config[:file_cache_path]}/poise_git_wrapper_#{Zlib.crc32(name)}"
end
# Guess if the deploy key is a local path or literal value.
#
# @api private
# @param key [String, nil] Key value to check. Defaults to self.key.
# @return [Boolean]
def deploy_key_is_local?(key=nil)
key ||= deploy_key
# Try to be mindful of Windows-y paths here even though they almost
# certainly won't actually work later on with ssh.
key && key =~ /\A(\/|[a-zA-Z]:)/
end
# Path to deploy key.
#
# @api private
# @return [String]
def deploy_key_path
@deploy_key_path ||= if deploy_key_is_local?
deploy_key
else
"#{Chef::Config[:file_cache_path]}/poise_git_deploy_#{Zlib.crc32(name)}"
end
end
# Hook to force the git install via recipe if needed.
def after_created
if !parent_git && node['poise-git']['default_recipe']
# Use the default recipe to give us a parent the next time we ask.
run_context.include_recipe(node['poise-git']['default_recipe'])
# Force it to re-expand the cache next time.
@parent_git = nil
end
super
end
end
# The default provider for the `poise_git` resource.
#
# @see Resource
class Provider < Chef::Provider::Git
include Poise
include ::PoiseGit::GitCommandMixin
provides(:poise_git)
# @api private
def initialize(*args)
super
# Set the SSH wrapper path in a late-binding kind of way. This better
# supports situations where the user doesn't exist until Chef converges.
new_resource.ssh_wrapper(new_resource.ssh_wrapper_path) if new_resource.deploy_key
end
# Hack our special login in before load_current_resource runs because that
# needs access to the git remote.
#
# @api private
def load_current_resource
create_deploy_key if new_resource.deploy_key
super
end
# Like {#load_current_resource}, make sure git is installed since we might
# need it depending on the version of Chef.
#
# @api private
def define_resource_requirements
create_deploy_key if new_resource.deploy_key
super
end
private
# Install git and set up the deploy key if needed. Safe to call multiple
# times if needed.
#
# @api private
# @return [void]
def create_deploy_key
return if @create_deploy_key
Chef::Log.debug("[#{new_resource}] Creating deploy key")
old_why_run = Chef::Config[:why_run]
begin
# Forcibly disable why run support so these will always run, since
# we need to be able to talk to the git remote even just for the
# whyrun checks.
Chef::Config[:why_run] = false
notifying_block do
write_deploy_key
write_ssh_wrapper
end
ensure
Chef::Config[:why_run] = old_why_run
end
@create_deploy_key = true
end
# Copy the deploy key to a file if needed.
#
# @api private
# @return [void]
def write_deploy_key
# Check if we have a local path or some actual content
return if new_resource.deploy_key_is_local?
file new_resource.deploy_key_path do
owner new_resource.user
group new_resource.group
mode '600'
content new_resource.deploy_key
sensitive true
end
end
# Create the SSH wrapper script.
#
# @api private
# @return [void]
def write_ssh_wrapper
# Write out the GIT_SSH script, it should already be enabled above
file new_resource.ssh_wrapper_path do
owner new_resource.user
group new_resource.group
mode '700'
content %Q{#!/bin/sh\n/usr/bin/env ssh #{'-o "StrictHostKeyChecking=no" ' unless new_resource.strict_ssh}-i "#{new_resource.deploy_key_path}" $@\n}
end
end
# Patch back in the `#git` from the git provider. This otherwise conflicts
# with the `#git` defined by the DSL, which gets included in such a way
# that the DSL takes priority.
#
# @api private
def git(*args, &block)
self.class.superclass.instance_method(:git).bind(self).call(*args, &block)
end
# Trick all shell_out related things in the base class in to using
# my git_shell_out instead.
#
# @api private
def shell_out(*cmd, **options)
if @shell_out_hack_inner
# This is the real call.
super
else
# This ia call we want to intercept and send to our method.
begin
@shell_out_hack_inner = true
# Remove nils and flatten for compat with how core uses this method.
cmd.compact!
cmd.flatten!
# Reparse the command to get a clean array.
cmd = Shellwords.split(cmd.join(' '))
# We'll add the git command back in ourselves.
cmd.shift if cmd.first == 'git'
# Push the yak stack.
git_shell_out(*cmd, **options)
ensure
@shell_out_hack_inner = false
end
end
end
end
end
end
end

View File

@@ -0,0 +1,82 @@
#
# Copyright 2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
require 'chef/resource'
require 'poise'
module PoiseGit
module Resources
# (see PoiseGitClient::Resource)
# @since 1.0.0
module PoiseGitClient
# A `poise_git_client` resource to install a C compiler and build tools.
#
# @provides poise_git_client
# @action install
# @action uninstall
# @example
# poise_git_client 'git'
class Resource < Chef::Resource
include Poise(inversion: true, container: true)
provides(:poise_git_client)
actions(:install, :uninstall)
# @!attribute version
# Version of Git to install. The version is prefix-matched so `'2'`
# will install the most recent Git 2.x, and so on.
# @return [String]
# @example Install any version
# poise_git_client 'any' do
# version ''
# end
# @example Install Git 2
# poise_git_client '2'
attribute(:version, kind_of: String, default: lazy { default_version })
# The path to the `git` binary for this Git installation. This is
# an output property.
#
# @return [String]
# @example
# execute "#{resources('poise_git_client[git]').git_binary} init"
def git_binary
provider_for_action(:git_binary).git_binary
end
# The environment variables for this Git installation. This is an
# output property.
#
# @return [Hash<String, String>]
def git_environment
provider_for_action(:git_environment).git_environment
end
private
# Default value for the version property. Trims an optional `git-` from
# the resource name.
#
# @return [String]
def default_version
name[/^(git-?)?(.*)$/, 2] || ''
end
end
# Providers can be found under git_client_providers/.
end
end
end

View File

@@ -0,0 +1,25 @@
#
# Copyright 2015-2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseGit
# A string that won't be shown in Chef error output
class SafeString < String
def to_text
'"suppressed sensitive value"'
end
end
end

View File

@@ -0,0 +1,20 @@
#
# Copyright 2015-2017, Noah Kantrowitz
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module PoiseGit
VERSION = '1.0.0'
end