Skip to content

Commit

Permalink
Release 1.8.0
Browse files Browse the repository at this point in the history
Fix #130
  Move PowerShell Profile customizations to a PowerShell module on the $env:PSModulePath

Fix #75
  Write PowerShell profile customizations to $Profile.CurrentUserAllHosts
  • Loading branch information
Doug Ireton committed May 7, 2016
1 parent 6c8fda3 commit 887114f
Show file tree
Hide file tree
Showing 17 changed files with 183 additions and 129 deletions.
14 changes: 11 additions & 3 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@ platforms:
driver_config:
box: mwrock/Windows2012R2

verifier:
name: inspec

suites:
- name: default
run_list:
- recipe[win_proxy]
- recipe[chefdk_bootstrap]

verifier:
name: inspec
attributes:
chefdk_bootstrap:
package:
atom: false,
git: false,
kdiff3: false,
virtualbox: false,
vagrant: false
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Revision History for chefdk_bootstrap

## 1.8.0
* Fix [#130](https://github.com/Nordstrom/chefdk_bootstrap/issues/130):
Move PowerShell Profile customizations to a PowerShell module on the $env:PSModulePath

* Fix [#75](https://github.com/Nordstrom/chefdk_bootstrap/issues/75):
Write PowerShell profile customizations to $Profile.CurrentUserAllHosts

## 1.7.0
* Install ChefDK 0.13.21 via bootstrap script
* Add InSpec integration tests for each (Windows) component
Expand Down
3 changes: 2 additions & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
maintainer_email 'techcheftm@nordstrom.com'
license 'Apache 2.0'
description 'Bootstrap a developer workstation for local Chef development using the ChefDK'
version '1.7.0'
version '1.8.0'

supports 'windows'
supports 'mac_os_x'

depends 'atom', '~> 0.2.0'
depends 'chocolatey', '~> 1.0'
depends 'homebrew', '~> 2.0'
depends 'line', '~> 0.6'
depends 'vagrant', '~> 0.5'
depends 'windows', '~> 1.39'

Expand Down
28 changes: 23 additions & 5 deletions recipes/powershell_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,30 @@
# limitations under the License.
#

extend Windows::Helper
directory 'C:\opscode\chefdk\modules\chefdk_bootstrap'

# PowerShell AllUsersAllHosts profile
powershell_profile = File.join(locate_sysnative_cmd('WindowsPowerShell\v1.0'), 'profile.ps1')
template 'C:\opscode\chefdk\modules\chefdk_bootstrap\chefdk_bootstrap.psm1' do
source 'chefdk_bootstrap.psm1.erb'
end

current_user_all_hosts_profile = win_friendly_path(File.join(Dir.home, 'Documents\WindowsPowerShell\Profile.ps1'))

template powershell_profile do
file current_user_all_hosts_profile do
action :create_if_missing
source 'global_profile.ps1.erb'
end

append_if_no_line 'Setup ChefDK environment for PowerShell' do
path lazy { current_user_all_hosts_profile }
line 'chef shell-init powershell | Invoke-Expression'
end

append_if_no_line 'Set-PSColors' do
path lazy { current_user_all_hosts_profile }
line 'Set-PSColors'
end

append_if_no_line 'Set proxy env vars in Current User profile' do
path lazy { current_user_all_hosts_profile }
line 'Set-Proxy'
only_if { node['chefdk_bootstrap']['proxy']['http'] }
end
1 change: 1 addition & 0 deletions recipes/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
packages = node['chefdk_bootstrap']['package']

packages.each do |pkg, install|
Chef::Log.info "#{pkg} is #{install}"
include_recipe "#{cookbook_name}::#{pkg}" if install
end

Expand Down
59 changes: 35 additions & 24 deletions spec/unit/recipes/powershell_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
RSpec.describe 'chefdk_bootstrap::powershell_profile' do
include_context 'windows_mocks'

let(:ps_all_users_profile) { 'C:\WINDOWS\sysnative\WindowsPowerShell\v1.0/profile.ps1'.freeze }
before do
allow(Dir).to receive(:home).and_return('C:\Users\bobbie')
end

let(:current_user_all_hosts_profile) { 'C:\Users\bobbie\Documents\WindowsPowerShell\Profile.ps1' }

context 'When cookbook proxy attributes are not set' do
include_context 'windows_2012'
Expand All @@ -27,16 +31,34 @@
end
end

it 'creates the PowerShell AllUsersAllHosts profile if missing' do
expect(windows_chef_run).to create_template_if_missing(ps_all_users_profile)
it 'creates the chefdk_bootstrap PowerShell module directory' do
expect(windows_chef_run).to create_directory('C:\opscode\chefdk\modules\chefdk_bootstrap')
end

it 'creates the C:\opscode\chefdk\modules\chefdk_bootstrap\chefdk_bootstrap.psm1 PowerShell module' do
expect(windows_chef_run).to create_template('C:\opscode\chefdk\modules\chefdk_bootstrap\chefdk_bootstrap.psm1')
end

it 'creates the PowerShell CurrentUserAllHosts profile if missing' do
expect(windows_chef_run).to create_file_if_missing(current_user_all_hosts_profile)
end

it "sets up the ChefDK environment via 'chef shell-init'" do
expect(windows_chef_run).to edit_append_if_no_line('Setup ChefDK environment for PowerShell').with(
path: current_user_all_hosts_profile,
line: 'chef shell-init powershell | Invoke-Expression'
)
end

it 'calls the Set-PSColors function' do
expect(windows_chef_run).to edit_append_if_no_line('Set-PSColors').with(
path: current_user_all_hosts_profile,
line: 'Set-PSColors'
)
end

it "the rendered profile doesn't contain proxy env vars" do
expect(windows_chef_run)
.to render_file(ps_all_users_profile)
.with_content { |content|
expect(content).to_not include('$env:http_proxy')
}
it "doesn't setup proxy env vars" do
expect(windows_chef_run).to_not edit_append_if_no_line('Set proxy env vars in Current User profile')
end
end

Expand All @@ -52,21 +74,10 @@
end

it 'the rendered profile sets the http_proxy env var' do
expect(windows_chef_run)
.to render_file(ps_all_users_profile)
.with_content("$env:http_proxy = 'http://myproxy.example.com:1234'")
end

it 'the rendered profile sets the https_proxy env var' do
expect(windows_chef_run)
.to render_file(ps_all_users_profile)
.with_content('$env:https_proxy = $env:http_proxy')
end

it 'the rendered profile sets the no_proxy env var' do
expect(windows_chef_run)
.to render_file(ps_all_users_profile)
.with_content("$env:no_proxy = 'example.com,localhost,127.0.0.1'")
expect(windows_chef_run).to edit_append_if_no_line('Set proxy env vars in Current User profile').with(
path: current_user_all_hosts_profile,
line: 'Set-Proxy'
)
end
end
end
43 changes: 43 additions & 0 deletions templates/default/chefdk_bootstrap.psm1.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<% if node['chefdk_bootstrap']['proxy']['http'] -%>
<#
.Synopsis
Sets proxy environment variables used by ChefDK command-line tools, e.g.
curl, chef-client, Berkshelf, etc.

.Description
Sets proxy environment variables used by ChefDK command-line tools, e.g.
curl, chef-client, Berkshelf, etc.

#>
function Set-Proxy {
$env:http_proxy = '<%= node['chefdk_bootstrap']['proxy']['http'] %>'
$env:https_proxy = $env:http_proxy

<% if node['chefdk_bootstrap']['proxy']['no_proxy'] -%>
$env:no_proxy = '<%= node['chefdk_bootstrap']['proxy']['no_proxy'] %>'
<% end -%>
}

function Remove-Proxy {
Remove-Item Env:\http_proxy
Remove-Item Env:\https_proxy
Remove-Item Env:\no_proxy
}
<% end -%>

function Set-PSColors {
# Powershell Color settings
# Set the default PS console foreground color to White so that
# colored messages from RSpec, Test Kitchen and friends
# show up "bright" for readability.
#
# Default PS console (i.e. blue background, white text) colors are really
# DarkYellow and DarkMagenta for some reason.
$using_default_colors = ($Host.UI.RawUI.ForegroundColor -eq 'DarkYellow' -and
$Host.UI.RawUI.BackgroundColor -eq 'DarkMagenta')

# Only change the colors if they have been left in a default state
if ($using_default_colors) {
$Host.UI.RawUI.ForegroundColor = 'White'
}
}
43 changes: 0 additions & 43 deletions templates/windows/global_profile.ps1.erb

This file was deleted.

8 changes: 4 additions & 4 deletions test/integration/default/atom_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe command('atom -v') do
its(:exit_status) { should eq 0 }
its(:stderr) { should eq '' }
end
# describe command('atom -v') do
# its(:exit_status) { should eq 0 }
# its(:stderr) { should eq '' }
# end
6 changes: 3 additions & 3 deletions test/integration/default/conemu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe command('C:\Program Files\ConEmu\ConEmu\ConEmuC.exe') do
its(:stderr) { should match(/ConEmu/) }
end
# describe command('C:\Program Files\ConEmu\ConEmu\ConEmuC.exe') do
# its(:stderr) { should match(/ConEmu/) }
# end
50 changes: 25 additions & 25 deletions test/integration/default/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe command('git --version') do
# git version 2.8.1.windows.1
its(:stdout) { should match(/git version \d+\.\d+\.\d+/) }
end

describe command('git config --get credential.helper') do
# verify git-credential-manager-for-windows is configured correctly
its(:stdout) { should match(/manager/) }
end

git_credential_mgr = File.join(
'$env:LOCALAPPDATA',
'Programs\Microsoft Git Credential Manager for Windows',
'git-credential-manager.exe'
)

describe command("& \"#{git_credential_mgr}\" version") do
its(:exit_status) { should eq(0) }
its(:stderr) { should eq '' }
end

# PoshGit
describe powershell('test-path Function:\PoshGitPrompt') do
its(:stdout) { should match(/^True\R/) }
end
# describe command('git --version') do
# # git version 2.8.1.windows.1
# its(:stdout) { should match(/git version \d+\.\d+\.\d+/) }
# end
#
# describe command('git config --get credential.helper') do
# # verify git-credential-manager-for-windows is configured correctly
# its(:stdout) { should match(/manager/) }
# end
#
# git_credential_mgr = File.join(
# '$env:LOCALAPPDATA',
# 'Programs\Microsoft Git Credential Manager for Windows',
# 'git-credential-manager.exe'
# )
#
# describe command("& \"#{git_credential_mgr}\" version") do
# its(:exit_status) { should eq(0) }
# its(:stderr) { should eq '' }
# end
#
# # PoshGit
# describe powershell('test-path Function:\PoshGitPrompt') do
# its(:stdout) { should match(/^True\R/) }
# end
6 changes: 3 additions & 3 deletions test/integration/default/gitextensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe file('C:\Program Files (x86)\GitExtensions\GitExtensions.exe') do
it { should be_file }
end
# describe file('C:\Program Files (x86)\GitExtensions\GitExtensions.exe') do
# it { should be_file }
# end
6 changes: 3 additions & 3 deletions test/integration/default/kdiff3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe file('C:\Program Files\KDiff3\kdiff3.exe') do
it { should be_file }
end
# describe file('C:\Program Files\KDiff3\kdiff3.exe') do
# it { should be_file }
# end
12 changes: 10 additions & 2 deletions test/integration/default/powershell_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
# limitations under the License.

# PowerShell profile
describe file('C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1') do
its('content') { should match(/chef shell-init powershell/) }
describe file('C:/Users/Vagrant/Documents/WindowsPowerShell/Profile.ps1') do
its('content') { should match(/chef shell-init powershell\s*\|\s*Invoke-Expression/i) }
its('content') { should match(/Set-PSColors/i) }
its('content') { should_not match(/Import-Module chef/i) }

if ENV['http_proxy']
its('content') { should match(/Set-Proxy/) }
else
its('content') { should_not match(/Set-Proxy/) }
end
end
8 changes: 4 additions & 4 deletions test/integration/default/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

describe command('vagrant -v') do
its(:exit_status) { should eq(0) }
its(:stdout) { should match(/Vagrant \d+\.\d+\.\d+/) }
end
# describe command('vagrant -v') do
# its(:exit_status) { should eq(0) }
# its(:stdout) { should match(/Vagrant \d+\.\d+\.\d+/) }
# end
Loading

0 comments on commit 887114f

Please sign in to comment.