Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MAINT) Fix powershell_version OS guard #122

Merged
merged 1 commit into from
Aug 21, 2019
Merged

(MAINT) Fix powershell_version OS guard #122

merged 1 commit into from
Aug 21, 2019

Conversation

michaeltlombardi
Copy link
Contributor

Prior to this commit the library code for retrieving the powershell
version on the box had a failing guard which gated the requiring of
win32/registry behind a platform-dependent check, but not the rest
of the logic which relies on that code.

This commit corrects the regression.

Prior to this commit the library code for retrieving the powershell
version on the box had a failing guard which gated the requiring of
win32/registry behind a platform-dependent check, but not the rest
of the logic which relies on that code.

This commit corrects the regression.
Copy link

@kreeuwijk kreeuwijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes it!

Notice: Local environment: 'production' doesn't match server specified node environment 'development', switching agent to 'development'.
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/opt/puppetlabs/puppet/cache/lib/facter/powershell_version.rb]/content: content changed '{md5}dcefec62cfb871bad5590b5fe0b85494' to '{md5}79ab33006cb3c2319193024733f3cf0d'
Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet_x/puppetlabs/dsc_lite/powershell_version.rb]/content:
--- /opt/puppetlabs/puppet/cache/lib/puppet_x/puppetlabs/dsc_lite/powershell_version.rb	2019-08-21 20:29:12.228690900 +0200
+++ /tmp/puppet-file20190821-54497-fa0f3a	2019-08-21 20:51:51.416690900 +0200
@@ -13,61 +13,60 @@

 if Puppet::Util::Platform.windows?
   require 'win32/registry'
-end
+  module PuppetX
+    module PuppetLabs
+      module DscLite
+        # Gets the Powershell version
+        class PowerShellVersion
+          # Access rights used to access registry
+          ACCESS_TYPE = Win32::Registry::KEY_READ | 0x100
+          # Alias for HKEY_LOCAL_MACHINE registry
+          HKLM              = Win32::Registry::HKEY_LOCAL_MACHINE
+          # Registry key for PS 1 engine path
+          PS_ONE_REG_PATH   = 'SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine'.freeze
+          # Registry key for PS 3 engine path
+          PS_THREE_REG_PATH = 'SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine'.freeze
+          # Registry key for current PS version
+          REG_KEY           = 'PowerShellVersion'.freeze

-module PuppetX
-  module PuppetLabs
-    module DscLite
-      # Gets the Powershell version
-      class PowerShellVersion
-        # Access rights used to access registry
-        ACCESS_TYPE = Win32::Registry::KEY_READ | 0x100
-        # Alias for HKEY_LOCAL_MACHINE registry
-        HKLM              = Win32::Registry::HKEY_LOCAL_MACHINE
-        # Registry key for PS 1 engine path
-        PS_ONE_REG_PATH   = 'SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine'.freeze
-        # Registry key for PS 3 engine path
-        PS_THREE_REG_PATH = 'SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine'.freeze
-        # Registry key for current PS version
-        REG_KEY           = 'PowerShellVersion'.freeze
-
-        # Retrieves version of current PS installation. An installation for PS 3 and PS 1 is checked
-        # for, with the version of a PS 3 installation taking precedence over that of a PS 1
-        # installation.
-        #
-        # @return [String] version
-        def self.version
-          powershell_three_version || powershell_one_version
-        end
+          # Retrieves version of current PS installation. An installation for PS 3 and PS 1 is checked
+          # for, with the version of a PS 3 installation taking precedence over that of a PS 1
+          # installation.
+          #
+          # @return [String] version
+          def self.version
+            powershell_three_version || powershell_one_version
+          end

-        # Retrieves version of PS 1 installation
-        #
-        # @return [String] version
-        def self.powershell_one_version
-          version = nil
-          begin
-            HKLM.open(PS_ONE_REG_PATH, ACCESS_TYPE) do |reg|
-              version = reg[REG_KEY]
-            end
-          rescue
+          # Retrieves version of PS 1 installation
+          #
+          # @return [String] version
+          def self.powershell_one_version
             version = nil
+            begin
+              HKLM.open(PS_ONE_REG_PATH, ACCESS_TYPE) do |reg|
+                version = reg[REG_KEY]
+              end
+            rescue
+              version = nil
+            end
+            version
           end
-          version
-        end

-        # Retrieves version of PS 3 installation
-        #
-        # @return [String] version
-        def self.powershell_three_version
-          version = nil
-          begin
-            HKLM.open(PS_THREE_REG_PATH, ACCESS_TYPE) do |reg|
-              version = reg[REG_KEY]
-            end
-          rescue
+          # Retrieves version of PS 3 installation
+          #
+          # @return [String] version
+          def self.powershell_three_version
             version = nil
+            begin
+              HKLM.open(PS_THREE_REG_PATH, ACCESS_TYPE) do |reg|
+                version = reg[REG_KEY]
+              end
+            rescue
+              version = nil
+            end
+            version
           end
-          version
         end
       end
     end

Notice: /File[/opt/puppetlabs/puppet/cache/lib/puppet_x/puppetlabs/dsc_lite/powershell_version.rb]/content: content changed '{md5}ec909a9cb3b87946a7a13fcfe1a1b680' to '{md5}9bbc7ad8919dc67f11bd1af673fc2975'
Info: Retrieving locales
Info: Loading facts
Info: Caching catalog for splunk.dreamworx.nl
Info: Applying configuration version 'puppet-development-63fe40174b8'
Notice: Applied catalog in 2.23 seconds```

@ThoughtCrhyme ThoughtCrhyme merged commit 47f4ffe into puppetlabs:master Aug 21, 2019
@michaeltlombardi michaeltlombardi deleted the maint-fix-facter branch August 22, 2019 01:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants