Last active
October 31, 2019 02:57
-
-
Save glennsarti/e97f55ac6a679615a543341c3b36dc94 to your computer and use it in GitHub Desktop.
Audit modules for litmus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module powershell-yaml | |
$repos = @('puppetlabs-accounts', | |
'puppetlabs-acl', | |
'puppetlabs-apache', | |
'puppetlabs-apt', | |
'puppetlabs-azure', | |
'puppetlabs-bootstrap', | |
'puppetlabs-chocolatey', | |
'puppetlabs-concat', | |
'puppetlabs-docker', | |
'puppetlabs-dsc', | |
'puppetlabs-dsc_lite', | |
'puppetlabs-exec', | |
'puppetlabs-facter_task', | |
'puppetlabs-firewall', | |
'puppetlabs-haproxy', | |
'puppetlabs-helm', | |
'puppetlabs-ibm_installation_manager', | |
'puppetlabs-iis', | |
'puppetlabs-inifile', | |
'puppetlabs-java', | |
'puppetlabs-java_ks', | |
'puppetlabs-kubernetes', | |
'puppetlabs-motd', | |
'puppetlabs-mysql', | |
'puppetlabs-ntp', | |
'puppetlabs-package', | |
'puppetlabs-postgresql', | |
'puppetlabs-powershell', | |
'puppetlabs-puppet_conf', | |
'puppetlabs-reboot', | |
'puppetlabs-registry', | |
'puppetlabs-resource', | |
'puppetlabs-rook', | |
'puppetlabs-satellite_pe_tools', | |
'puppetlabs-scheduled_task', | |
'puppetlabs-service', | |
'puppetlabs-sqlserver', | |
'puppetlabs-stdlib', | |
'puppetlabs-tagmail', | |
'puppetlabs-tomcat', | |
'puppetlabs-translate', | |
'puppetlabs-vcsrepo', | |
'puppetlabs-websphere_application_server', | |
'puppetlabs-windows', | |
'puppetlabs-wsus_client', | |
'cisco_ios', | |
'device_manager', | |
'puppetlabs-panos', | |
'puppetlabs-resource_api', | |
'puppetlabs-testing', | |
'puppetlabs-testing1', | |
'puppetlabs-testing2') | |
Function Contains-Litmus($Uri) { | |
$result = $false | |
try { | |
$response = Invoke-WebRequest -Uri $uri -UseBasicParsing -ErrorAction Stop | |
$result = $response.Content -like "*litmus*" | |
} catch { | |
} | |
Write-Output $result | |
} | |
Function Uri-Exists($Uri) { | |
$result = $false | |
try { | |
Invoke-WebRequest -Uri $uri -UseBasicParsing -ErrorAction Stop | Out-Null | |
$result = $true | |
} catch { | |
} | |
Write-Output $result | |
} | |
$index = 0 | |
Function Get-UnmanagedFiles($Uri) { | |
$content = '' | |
try { | |
$response = Invoke-WebRequest -Uri $uri -UseBasicParsing -ErrorAction Stop | |
$content = $response.Content | |
} catch { | |
} | |
if ($content -eq '') { return } | |
$syncyml = ConvertFrom-Yaml $content | |
foreach($key in $syncyml.Keys) { | |
if ($syncyml[$key]['unmanaged'] -eq $true) { | |
Write-Output $key | |
} | |
} | |
} | |
$litmusResult = $repos | ForEach-Object { | |
$RepoName = $_ | |
Write-Progress -Activity "Checking ${RepoName}" -PercentComplete ($index / $repos.Count * 100) | |
$UnmanagedFiles = Get-UnmanagedFiles -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/.sync.yml" | |
$LitmusInTravis = Contains-Litmus -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/.travis.yml" | |
$LitmusInAppveyor = Contains-Litmus -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/appveyor.yml" | |
$LitmusInSpecHelper = Contains-Litmus -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/spec/spec_helper_acceptance.rb" | |
$HasProvisionYaml = Uri-Exists -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/provision.yaml" | |
$Litmusified = "No" | |
if ($LitmusInTravis -or $LitmusInAppveyor -or $HasProvisionYaml -or $LitmusInSpecHelper) { $Litmusified = 'Yes' } | |
If (-not (Uri-Exists -Uri "https://raw.githubusercontent.com/puppetlabs/${RepoName}/master/metadata.json")) { | |
$Litmusified = "Unknown" | |
} | |
$LitmusInTravisSuffix = '' | |
$LitmusInAppveyorSuffix = '' | |
if (($UnmanagedFiles -notcontains '.travis.yml') -and ($LitmusInTravis)) { | |
$LitmusInTravisSuffix += ' (Managed)' | |
} | |
if (($UnmanagedFiles -notcontains 'appveyor.yml') -and ($LitmusInAppveyor)) { | |
$LitmusInAppveyorSuffix += ' (Managed)' | |
} | |
$prop = [ordered]@{ | |
'Repo' = $RepoName | |
'In Travis' = $LitmusInTravis.ToString() + $LitmusInTravisSuffix | |
'In Appveyor' = $LitmusInAppveyor.ToString() + $LitmusInAppveyorSuffix | |
'In Spec Helper' = $LitmusInSpecHelper | |
'ProvisionYaml' = $HasProvisionYaml | |
'Litmusified' = $Litmusified | |
} | |
Write-Output (New-Object -TypeName PSCustomObject -Property $prop) | |
$index++ | |
} | |
$litmusResult | ft | |
$litmusResult | Export-Csv -Path '.\LitmusResult.csv' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment