class PoiseGit::Resources::PoiseGit::Provider
The default provider for the `poise_git` resource.
@see Resource
Public Class Methods
@api private
# File lib/poise_git/resources/poise_git.rb, line 131 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
Public Instance Methods
Like {#load_current_resource}, make sure git is installed since we might need it depending on the version of Chef.
@api private
# File lib/poise_git/resources/poise_git.rb, line 151 def define_resource_requirements create_deploy_key if new_resource.deploy_key super end
Hack our special login in before load_current_resource
runs because that needs access to the git remote.
@api private
# File lib/poise_git/resources/poise_git.rb, line 142 def load_current_resource create_deploy_key if new_resource.deploy_key super end
Private Instance Methods
Install git and set up the deploy key if needed. Safe to call multiple times if needed.
@api private @return [void]
# File lib/poise_git/resources/poise_git.rb, line 163 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
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
# File lib/poise_git/resources/poise_git.rb, line 217 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
# File lib/poise_git/resources/poise_git.rb, line 225 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
Copy the deploy key to a file if needed.
@api private @return [void]
# File lib/poise_git/resources/poise_git.rb, line 186 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]
# File lib/poise_git/resources/poise_git.rb, line 202 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