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

puppet-lint stops validating when finding a blank line following a line with only spaces and a single quote #134

Open
rnelson0 opened this issue Jul 11, 2023 · 2 comments
Labels
bug Something isn't working community

Comments

@rnelson0
Copy link

rnelson0 commented Jul 11, 2023

Running pdk validate -a against a controlrepo generates the following error. When this occurs, it stops and does not validate other files. Remove the blank line at the end resolves the error with this file, and it is validated properly. However, an issue is encountered on the next file that has that blank line issue as well, stopping again.

Thus I see two problems here:

  • When puppet-lint cannot parse a file, it stops parsing ALL files. This should be overrideable behavior (perhaps it is, but I do not find a documented flag for it)
  • When encountering a file that has a single quote followed by a blank line followed by a curly brace, it cannot validate that file. Removing the blank line prevents the issue. The conditions for this may be more complicated but can be replicated with this pattern at the end of the file, where at least the indentation does not seem to matter:
      }
    '

  }
}

puppet-lint version: 3.4.0
ruby version: 3.2.2-p53
platform: x64-mingw32
file path: site/profile/manifests/faxing/faxpocfs.pp
file contents:

# This profile contains resources required for RightFax File servers
class profile::faxing::faxpocfs {
  $credential_network_access = vault_lookup('fax-companynamedev')
  $ftpfeatures = ['web-ftp-server','web-ftp-service','web-ftp-ext','web-mgmt-console','web-server','web-webserver']
  $folders = ['E:\\ClaimAttach','E:\\ClaimLinkage','E:\\Clinicals','E:\\RightFax']
  $additionalfolders = ['E:\\Claimattach\\inbound','E:\\Clinicals\\Inbound','E:\\ClaimLinkage\\Images','E:\\ClaimLinkage\\Inbound','E:\\ClaimLinkage\\Resources','E:\\ClaimLinkage\\Responses','E:\\ClaimLinkage\\ResponsesArchive','E:\\ClaimLinkage\\XMLFiles','E:\\Clinicals\\Images','E:\\Clinicals\\Inbound\\Unable_To_Pickup','E:\\Clinicals\\Resources','E:\\Clinicals\\Responses','E:\\Clinicals\\ResponsesArchive','E:\\Clinicals\\XMLFiles','E:\\RightFax\\BFT','E:\\RightFax\\CMDDATA','E:\\RightFax\\FCS','E:\\RightFax\\IMAGE','E:\\RightFax\\OUTGOING','E:\\RightFax\\PAPERS','E:\\RightFax\\SIG']

  # Install FTP Features
    windowsfeature { $ftpfeatures:
      ensure => present
    }

  # Create companynamedev local account
    dsc { 'companynamedev_user':
      resource_name => 'User',
      module        => 'PSDscResources',
      properties    => {
        ensure                 => present,
        username               => 'companynamedev',
        description            => 'Account used by aNet team for uploading claims',
        passwordchangerequired => false,
        passwordneverexpires   => true,
        password               => {
          'dsc_type'       => 'MSFT_Credential',
          'dsc_properties' => {
            'user'     => $credential_network_access[username],
            'password' => Sensitive($credential_network_access[password]),
          },
        },
      },
      before        => File[ $folders ]
    }

  # Create folders
    file { $folders :
      ensure => directory,
      before => File[ $additionalfolders ]
    }

    file { $additionalfolders :
      ensure => directory,
      before => Exec[ 'configure_ftp_server' ]
    }

  exec { 'configure_ftp_server' :
    provider => powershell,
    command  => '
                  # Create Share
                  $folders = "ClaimAttach","ClaimLinkage","Clinicals","RightFax"
                  Foreach ($folder in $folders) {
                    $path = (get-item e:\$folder).fullname
                          $accessUser = New-Object System.Security.Principal.NTAccount("$($env:COMPUTERNAME)\companynamedev")
                    $accessRight = [System.Security.AccessControl.FileSystemRights]"FullControl"
                    $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($accessUser,$accessRight,"ContainerInherit,ObjectInherit","None","Allow")
                    $acl = Get-Acl $path
                    $acl.SetAccessRule($accessRule)
                    Set-Acl -path $Path -AclObject $acl
                    New-SmbShare -Path $path -Name $folder -FullAccess "Authenticated Users" -NoAccess "DOMAIN\No Access"
                  }

                  # Remove Default Web Site
                  get-website | remove-website

                  # Create FTP Site
                  New-WebFtpSite -Name "Default FTP Site" -Id 2 -Port 21 -IPAddress * -PhysicalPath "C:\inetpub\ftproot"

                  # Create Virtual Directories
                  New-WebVirtualDirectory -Site "Default FTP Site" -Name Claimattach -PhysicalPath "E:\Claimattach"
                  New-WebVirtualDirectory -Site "Default FTP Site" -Name ClaimLinkage -PhysicalPath "E:\ClaimLinkage"
                  New-WebVirtualDirectory -Site "Default FTP Site" -Name Clinicals -PhysicalPath "E:\Clinicals"

                  # Allow SSL
                  Set-ItemProperty "IIS:\Sites\Default FTP Site" -Name ftpServer.security.ssl.controlChannelPolicy -Value 0
                  Set-ItemProperty "IIS:\Sites\Default FTP Site" -Name ftpServer.security.ssl.dataChannelPolicy -Value 0

                  # Enable Directory Browsing
                  Set-ItemProperty "IIS:\Sites\Default FTP Site" -Name ftpServer.directoryBrowse.showFlags -Value "DisplayVirtualDirectories"

                  # Enable Basic Authentication
                  Set-ItemProperty "IIS:\Sites\Default FTP Site" -Name ftpServer.security.authentication.basicAuthentication.enabled -Value $true

                  # Give All Users read/write on the virtual directories
                  Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read";users="*"} -PSPath IIS:\ -location "Default FTP Site"
                  Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read,Write";users="*"} -PSPath IIS:\ -location "Default FTP Site/Claimattach"
                  Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read,Write";users="*"} -PSPath IIS:\ -location "Default FTP Site/ClaimLinkage"
                  Add-WebConfiguration "/system.ftpServer/security/authorization" -value @{accessType="Allow";roles="";permissions="Read,Write";users="*"} -PSPath IIS:\ -location "Default FTP Site/Clinicals"
                  iisreset /noforce
                ',
    onlyif   => '
                  if(((Test-NetConnection localhost -port 21).tcptestsucceeded) -eq $True)
                  {
                      exit 1
                  }
                '

  }
}

error:

TypeError: no implicit conversion from nil to integer
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `insert'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `fix'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:67:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint.rb:224:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:84:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/bin/puppet-lint:7:in `<top (required)>'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `load'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `<main>'
@rnelson0 rnelson0 added the bug Something isn't working label Jul 11, 2023
@rnelson0
Copy link
Author

Complicating factors:

  • I just upgraded to PDK 3.0.0 from 2.7.0
  • I am still using pdktemplates 2.7.1
  • I updated metadata.json manually (rather than through the pdk) to support puppet < 9.0.0 so that it tests against puppet 8
  • I also had this line commented out in my Gemfile prior to encountering this issue gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false

So it could be related to those plugins, or the upgrade to pdk3.0.0, or both.

@rnelson0
Copy link
Author

I can replicate this on a smaller file as well, definitely seems related to the single quote/empty following line


puppet-lint version: 3.4.0
ruby version: 3.2.2-p53
platform: x64-mingw32
file path: site/profile/manifests/windows/install_gmsa.pp
file contents:

# Profile to add a Group Managed Service Account to a computer. This simply installs the MSA to the computer, you still have to specify
# it in a service.
class profile::windows::install_gmsa (
  String $service_account,
) {
  if (!defined(Windowsfeature['RSAT-AD-PowerShell'])) {
    windowsfeature { 'RSAT-AD-PowerShell':
      ensure => present,
    }
  }

  exec { 'install-gmsa-account':
    provider    => powershell,
    environment => ["gmsa_account=${service_account}"],
    logoutput   => false,
    onlyif      => '
      If (Test-ADServiceAccount -Identity $Env:gmsa_account)
      {
        Exit 1
      }
      Exit 0
    ',
    command     => '
      Try {
        Install-ADServiceAccount -Identity $Env:gmsa_account -ErrorAction Stop
      }
    '

  }
}

error:

TypeError: no implicit conversion from nil to integer
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `insert'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-trailing_comma-check-1.0.0/lib/puppet-lint/plugins/check_trailing_comma.rb:145:in `fix'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:42:in `block in fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checkplugin.rb:38:in `fix_problems'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:67:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/checks.rb:65:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint.rb:224:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:84:in `block in run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `each'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/lib/puppet-lint/bin.rb:80:in `run'
C:/Users/username/AppData/Local/PDK/cache/ruby/3.2.0/gems/puppet-lint-3.4.0/bin/puppet-lint:7:in `<top (required)>'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `load'
C:/Users/username/git/controlrepo/bin/puppet-lint:27:in `<main>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community
Projects
None yet
Development

No branches or pull requests

2 participants