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,65 @@
#
# Copyright 2015-2016, 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 Poise
module Utils
# A mixin to dispatch other mixins with resource and provider
# implementations. The module this is included in must have Resource and
# Provider sub-modules.
#
# @since 2.0.0
# @example
# module MyHelper
# include Poise::Utils::ResourceProviderMixin
# module Resource
# # ...
# end
#
# module Provider
# # ...
# end
# end
module ResourceProviderMixin
def self.included(klass)
# Warning here be dragons.
# Create a new anonymous module, klass will be the module that
# actually included ResourceProviderMixin. We want to keep a reference
# to that locked down so that we can close over it and use it in the
# "real" .included defined below to find the original relative consts.
mod = Module.new do
# Use define_method instead of def so we can close over klass and mod.
define_method(:included) do |inner_klass|
# Has to be explicit because super inside define_method.
super(inner_klass)
# Cargo this .included to things which include us.
inner_klass.extend(mod)
# Dispatch to submodules, inner_klass is the most recent includer.
if inner_klass < Chef::Resource || inner_klass.name.to_s.end_with?('::Resource')
# Use klass::Resource to look up relative to the original module.
inner_klass.class_exec { include klass::Resource }
elsif inner_klass < Chef::Provider || inner_klass.name.to_s.end_with?('::Provider')
# As above, klass::Provider.
inner_klass.class_exec { include klass::Provider }
end
end
end
# Add our .included to the original includer.
klass.extend(mod)
end
end
end
end

View File

@@ -0,0 +1,90 @@
#
# Copyright 2015-2016, 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 'etc'
require 'chef/mixin/shell_out'
module Poise
module Utils
# A mixin to provider a better shell_out.
#
# @since 2.5.0
# @example
# Poise::Utils::ShellOut.poise_shell_out('ruby myapp.rb', user: 'myuser')
module ShellOut
extend self
include Chef::Mixin::ShellOut
# An enhanced version of Chef's `shell_out` which sets some default
# parameters. If possible it will set $HOME, $USER, $LOGNAME, and the
# group to run as.
#
# @param command_args [Array] Command arguments to be passed to `shell_out`.
# @param options [Hash<Symbol, Object>] Options to be passed to `shell_out`,
# with modifications.
# @return [Mixlib::ShellOut]
def poise_shell_out(*command_args, **options)
# Allow the env option shorthand.
options[:environment] ||= {}
if options[:env]
options[:environment].update(options[:env])
options.delete(:env)
end
# Convert environment keys to strings to be safe.
options[:environment] = options[:environment].inject({}) do |memo, (key, value)|
memo[key.to_s] = value.to_s
memo
end
# Populate some standard environment variables.
ent = begin
if options[:user].is_a?(Integer)
Etc.getpwuid(options[:user])
elsif options[:user]
Etc.getpwnam(options[:user])
end
rescue ArgumentError
nil
end
username = ent ? ent.name : options[:name]
if username
options[:environment]['HOME'] ||= Dir.home(username)
options[:environment]['USER'] ||= username
# On the off chance they set one manually but not the other.
options[:environment]['LOGNAME'] ||= options[:environment]['USER']
end
# Set the default group on Unix.
options[:group] ||= ent.gid if ent
# Mixlib-ShellOut doesn't support array commands on Windows and has
# super wonky escaping for cmd.exe.
if respond_to?(:node) && node.platform_family?('windows')
command_args = [Poise::Utils::Win32.reparse_command(*command_args)]
end
# Call Chef's shell_out wrapper.
shell_out(*command_args, **options)
end
# The `error!` version of {#poise_shell_out}.
#
# @see #poise_shell_out
# @return [Mixlib::ShellOut]
def poise_shell_out!(*command_args)
poise_shell_out(*command_args).tap(&:error!)
end
end
end
end

View File

@@ -0,0 +1,127 @@
#
# Copyright 2016, 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'
module Poise
module Utils
# Utilities for working with Windows.
#
# @since 2.7.0
module Win32
extend self
# Code borrowed from https://github.com/chef-cookbooks/chef-client/blob/master/libraries/helpers.rb
# Used under the terms of the Apache v2 license.
# Copyright 2012-2016, John Dewey
# Run a WMI query and extracts a property. This assumes Chef has already
# loaded the win32 libraries.
#
# @api private
# @param wmi_property [Symbol] Property to extract.
# @param wmi_query [String] Query to run.
# @return [String]
def wmi_property_from_query(wmi_property, wmi_query)
@wmi = ::WIN32OLE.connect('winmgmts://')
result = @wmi.ExecQuery(wmi_query)
return nil unless result.each.count > 0
result.each.next.send(wmi_property)
end
# Find the name of the Administrator user, give or take localization.
#
# @return [String]
def admin_user
if defined?(::WIN32OLE)
wmi_property_from_query(:name, "select * from Win32_UserAccount where sid like 'S-1-5-21-%-500' and LocalAccount=True")
else
# Warn except under ChefSpec because it will just annoy people.
Chef::Log.warn('[Poise::Utils::Win32] Unable to query admin user, WIN32OLE not available') unless defined?(ChefSpec)
'Administrator'
end
end
# Escaping that is compatible with CommandLineToArgvW. Based on
# https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
#
# @api private
# @param string [String] String to escape.
# @return [String]
def argv_quote(string, force_quote: false)
if !force_quote && !string.empty? && string !~ /[ \t\n\v"]/
# Nothing fancy, no escaping needed.
string
else
command_line = '"'
i = 0
while true
number_backslashes = 0
while i != string.size && string[i] == '\\'
i += 1
number_backslashes += 1
end
if i == string.size
# Escape all backslashes, but let the terminating
# double quotation mark we add below be interpreted
# as a metacharacter.
command_line << '\\' * (number_backslashes * 2)
break
elsif string[i] == '"'
# Escape all backslashes and the following
# double quotation mark.
command_line << '\\' * ((number_backslashes * 2) + 1)
command_line << '"'
else
# Backslashes aren't special here.
command_line << '\\' * number_backslashes
command_line << string[i]
end
i += 1
end
command_line << '"'
command_line
end
end
# Take a string or array command in the format used by shell_out et al and
# create something we can use on Windows.
#
# @
def reparse_command(*args)
array_mode = !(args.length == 1 && args.first.is_a?(String))
# At some point when mixlib-shellout groks array commands on Windows,
# we should support that here.
parsed_args = array_mode ? args.flatten : Shellwords.split(args.first)
cmd = parsed_args.map {|s| argv_quote(s) }.join(' ')
if array_mode
# This fails on non-Windows because of win32/process.
require 'mixlib/shellout/windows'
if Mixlib::ShellOut::Windows::Utils.should_run_under_cmd?(cmd)
# If we are in array mode, try to make cmd.exe keep its grubby paws
# off our metacharacters.
cmd = cmd.each_char.map {|c| '^'+c }.join('')
end
end
cmd
end
end
end
end