Update cookbooks

This commit is contained in:
Greg Karékinian
2016-04-16 00:15:56 +02:00
parent 3854ab7232
commit c50b096c37
127 changed files with 1792 additions and 7431 deletions

View File

@@ -1,65 +0,0 @@
#
# Copyright 2015, 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

@@ -1,85 +0,0 @@
#
# Copyright 2015, 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
# 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