Skip to content

Commit

Permalink
Merge pull request #253 from TheJumpCloud/JumpCloudModule_1.18.0
Browse files Browse the repository at this point in the history
Jump cloud module 1.18.0
  • Loading branch information
jworkmanjc authored Aug 14, 2020
2 parents 0fea914 + b7e5bb1 commit b350ad3
Show file tree
Hide file tree
Showing 21 changed files with 718 additions and 1,933 deletions.
77 changes: 36 additions & 41 deletions PowerShell/Deploy/Build-WikiPages.ps1
Original file line number Diff line number Diff line change
@@ -1,44 +1,39 @@
. ($PSScriptRoot + '/' + 'Get-Config.ps1')
###########################################################################
$CurrentLocation = Get-Location
Set-Location -Path:($StagingDirectory)
Invoke-GitClone -Repo:($GitSourceRepoWiki)

### Add step check out support wiki
# $PathToSupportWikiRepo = ''
# $SupportRepoDocs = $PSScriptRoot + '/Docs'
# $SupportWiki = $PathToSupportWikiRepo + '/support.wiki'
# $Docs = Get-ChildItem -Path:($SupportRepoDocs + '/*.md') -Recurse
# ForEach ($Doc In $Docs)
# {
# $DocName = $Doc.Name
# $DocFullName = $Doc.FullName
# $SupportWikiDocFullName = $SupportWiki + '/' + $DocName
# $DocContent = Get-Content -Path:($DocFullName)
# If (Test-Path -Path:($SupportWikiDocFullName))
# {
# $SupportWikiDocContent = Get-Content -Path:($SupportWikiDocFullName)
# $Diffs = Compare-Object -ReferenceObject:($DocContent) -DifferenceObject:($SupportWikiDocContent)
# If ($Diffs)
# {
# Write-Warning -Message:('Diffs found in: ' + $DocName)
# # are you sure you want to continue?
# }
# }
# Else
# {
# Write-Warning -Message:('Creating new file: ' + $DocName)
# }
# $NewDocContent = If (($DocContent | Select-Object -First 1) -eq '---')
# {
# $DocContent | Select-Object -Skip:(7)
# }
# Else
# {
# $DocContent
# }
# Set-Content -Path:($SupportWikiDocFullName) -Value:($NewDocContent) -Force
# }
# ### Add step check in changes to support wiki

Set-Location -Path:($CurrentLocation)
$SupportRepoDocs = "$FolderPath_Module/Docs"
$SupportWiki = "$ScriptRoot/support.wiki"
If (!(Test-Path -Path:($SupportWiki))) { New-Item -Path:($SupportWiki) -ItemType:('Directory') }
Set-Location -Path:($SupportWiki)
$Docs = Get-ChildItem -Path:($SupportRepoDocs + '/*.md') -Recurse
ForEach ($Doc In $Docs)
{
$DocName = $Doc.Name
$DocFullName = $Doc.FullName
$SupportWikiDocFullName = $SupportWiki + '/' + $DocName
$DocContent = Get-Content -Path:($DocFullName)
$NewDocContent = If (($DocContent | Select-Object -First 1) -eq '---')
{
$DocContent | Select-Object -Skip:(7)
}
Else
{
$DocContent
}
If (Test-Path -Path:($SupportWikiDocFullName))
{
$SupportWikiDocContent = Get-Content -Path:($SupportWikiDocFullName)
$Diffs = Compare-Object -ReferenceObject:($NewDocContent) -DifferenceObject:($SupportWikiDocContent)
If (-not [string]::IsNullOrEmpty($Diffs))
{
Write-Warning -Message:('Diffs found in: ' + $DocName)
}
}
Else
{
Write-Warning -Message:('Creating new file: ' + $DocName)
}
Set-Content -Path:($SupportWikiDocFullName) -Value:($NewDocContent) -Force
}
# Check in changes to support wiki
Invoke-GitCommit -BranchName:($GitSourceRepoWiki)
162 changes: 162 additions & 0 deletions PowerShell/Deploy/BuildNuspecFromPsd1.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
. ($PSScriptRoot + '/' + 'Get-Config.ps1')
$nuspecFiles = @{ src = 'en-Us/**;Private/**;Public/**;JumpCloud.psd1;JumpCloud.psm1;LICENSE'; }
# Addapted from PowerShell Get
# https://github.com/PowerShell/PowerShellGetv2/blob/7de99ee0c38611556e5c583ffaca98bb1922a0d4/src/PowerShellGet/private/functions/New-NuspecFile.ps1
function New-NuspecFile
{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$OutputPath,

[Parameter(Mandatory = $true)]
[string]$Id,

[Parameter(Mandatory = $true)]
[string]$Version,

[Parameter(Mandatory = $true)]
[string]$Description,

[Parameter(Mandatory = $true)]
[string[]]$Authors,

[Parameter()]
[string[]]$Owners,

[Parameter()]
[string]$ReleaseNotes,

[Parameter()]
[bool]$RequireLicenseAcceptance,

[Parameter()]
[string]$Copyright,

[Parameter()]
[string[]]$Tags,

[Parameter()]
[string]$LicenseUrl,

[Parameter()]
[string]$ProjectUrl,

[Parameter()]
[string]$IconUrl,

[Parameter()]
[PSObject[]]$Dependencies,

[Parameter()]
[PSObject[]]$Files

)
Set-StrictMode -Off

Write-Verbose "Calling New-NuspecFile"

$nameSpaceUri = "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"
[xml]$xml = New-Object System.Xml.XmlDocument

$xmlDeclaration = $xml.CreateXmlDeclaration("1.0", "utf-8", $null)
$xml.AppendChild($xmlDeclaration) | Out-Null

#create top-level elements
$packageElement = $xml.CreateElement("package", $nameSpaceUri)
$metaDataElement = $xml.CreateElement("metadata", $nameSpaceUri)

# warn we're over 4000 characters for standard nuget servers
$tagsString = $Tags -Join " "
if ($tagsString.Length -gt 4000)
{
Write-Warning -Message "Tag list exceeded 4000 characters and may not be accepted by some Nuget feeds."
}

$metaDataElementsHash = [ordered]@{
id = $Id
version = $Version
description = $Description
authors = $Authors -Join ","
owners = $Owners -Join ","
releaseNotes = $ReleaseNotes
requireLicenseAcceptance = $RequireLicenseAcceptance.ToString().ToLower()
copyright = $Copyright
tags = $tagsString
}

if ($LicenseUrl) { $metaDataElementsHash.Add("licenseUrl", $LicenseUrl) }
if ($ProjectUrl) { $metaDataElementsHash.Add("projectUrl", $ProjectUrl) }
if ($IconUrl) { $metaDataElementsHash.Add("iconUrl", $IconUrl) }

foreach ($key in $metaDataElementsHash.Keys)
{
$element = $xml.CreateElement($key, $nameSpaceUri)
$elementInnerText = $metaDataElementsHash.item($key)
$element.InnerText = $elementInnerText

$metaDataElement.AppendChild($element) | Out-Null
}


if ($Dependencies)
{
$dependenciesElement = $xml.CreateElement("dependencies", $nameSpaceUri)

foreach ($dependency in $Dependencies)
{
$element = $xml.CreateElement("dependency", $nameSpaceUri)
# $element.
$element.SetAttribute("id", $dependency)
if ($dependency.version) { $element.SetAttribute("version", $dependency.version) }

$dependenciesElement.AppendChild($element) | Out-Null
}
$metaDataElement.AppendChild($dependenciesElement) | Out-Null
}

if ($Files)
{
$filesElement = $xml.CreateElement("files", $nameSpaceUri)

foreach ($file in $Files)
{
$element = $xml.CreateElement("file", $nameSpaceUri)
$element.SetAttribute("src", $file.src)
if ($file.target) { $element.SetAttribute("target", $file.target) }
if ($file.exclude) { $element.SetAttribute("exclude", $file.exclude) }

$filesElement.AppendChild($element) | Out-Null
}
}

$packageElement.AppendChild($metaDataElement) | Out-Null
if ($filesElement) { $packageElement.AppendChild($filesElement) | Out-Null }

$xml.AppendChild($packageElement) | Out-Null

$nuspecFullName = Join-Path -Path $OutputPath -ChildPath "$Id.nuspec"
$xml.save($nuspecFullName)

Write-Output $nuspecFullName
}
# Set Variables for New-NuspecFile
$Psd1 = Import-PowerShellDataFile -Path:($FilePath_psd1)
$params = @{
OutputPath = $FolderPath_Module
Id = $(Get-Item ($FilePath_psd1)).BaseName
Version = $Psd1.ModuleVersion
Authors = $Psd1.Author
Owners = $Psd1.CompanyName
Description = $Psd1.Description
ReleaseNotes = $Psd1.PrivateData.PSData.ReleaseNotes
# RequireLicenseAcceptance = ($requireLicenseAcceptance -eq $true)
Copyright = $Psd1.Copyright
Tags = $Psd1.PrivateData.PSData.Tags
LicenseUrl = $Psd1.PrivateData.PSData.LicenseUri
ProjectUrl = $Psd1.PrivateData.PSData.ProjectUri
IconUrl = $Psd1.PrivateData.PSData.IconUri
Dependencies = $Psd1.RequiredModules
Files = $nuspecFiles
}
New-NuspecFile @params
123 changes: 63 additions & 60 deletions PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,73 @@ If (-not [System.String]::IsNullOrEmpty($Modules))
$FunctionDestination = $Function.Destination
$OutputPath = "$JumpCloudModulePath/$FunctionDestination"
$Command = Get-Command -Name:($FunctionName)
$CommandName = $Command.Name
$NewCommandName = $CommandName.Replace($SdkPrefix, $JumpCloudModulePrefix)
Write-Host ("[STATUS] Building: $NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta')
# Get content from sdk function
$CommandFilePath = $Command.ScriptBlock.File
$CommandFilePathContent = Get-Content -Path:($CommandFilePath) -Raw
$FunctionContent = If ($CommandFilePath -like '*ProxyCmdletDefinitions.ps1')
foreach ($individualCommand in $Command)
{
<# When the autorest generated module has been installed and imported from the PSGallery all the
cmdlets will exist in a single ProxyCmdletDefinitions.ps1 file. We need to parse
out the specific function in order to gather the parts we need to copy over. #>
$CommandFilePathContent.Replace($MSCopyrightHeader, $Divider).Split($Divider).Where( { $_ -like ('*' + "function $CommandName {" + '*') })
}
Else
{
<# When the autorest generated module has been imported from a local psd1 module the function will
remain in their individual files. #>
$CommandFilePathContent
}
$PSScriptInfo = ($FunctionContent | Select-String -Pattern:('(?s)(<#)(.*?)(#>)')).Matches.Value
$Params = $FunctionContent | Select-String -Pattern:('(?s)( \[Parameter)(.*?)(\})') -AllMatches
$ParameterContent = ($Params.Matches.Value | Where-Object { $_ -notlike '*DontShow*' -and $_ -notlike '*Limit*' -and $_ -notlike '*Skip*' })
$OutputType = ($FunctionContent | Select-String -Pattern:('(\[OutputType)(.*?)(\]\r)')).Matches.Value
$CmdletBinding = ($FunctionContent | Select-String -Pattern:('(\[CmdletBinding)(.*?)(\]\r)')).Matches.Value
If (-not [System.String]::IsNullOrEmpty($PSScriptInfo))
{
$PSScriptInfo = $PSScriptInfo.Replace($SdkPrefix, $JumpCloudModulePrefix)
$PSScriptInfo = $PSScriptInfo.Replace("$NewCommandName.md", "$FunctionName.md")
}
# Build CmdletBinding
If (-not [System.String]::IsNullOrEmpty($OutputType)) { $CmdletBinding = "$($OutputType)`n$($IndentChar)$($CmdletBinding)" }
# Build $BeginContent, $ProcessContent, and $EndContent
$BeginContent = @()
$ProcessContent = @()
$EndContent = @()
# Build "Begin" block
$BeginContent += "$($IndentChar)$($IndentChar)Connect-JCOnline -force | Out-Null"
$BeginContent += "$($IndentChar)$($IndentChar)`$Results = @()"
# Build "Process" block
$ProcessContent += "$($IndentChar)$($IndentChar)`$Results = $($ModuleName)\$($CommandName) @PSBoundParameters"
# Build "End" block
$EndContent += "$($IndentChar)$($IndentChar)Return `$Results"
If (-not [System.String]::IsNullOrEmpty($BeginContent) -and -not [System.String]::IsNullOrEmpty($ProcessContent) -and -not [System.String]::IsNullOrEmpty($EndContent))
{
# Build "Function"
$NewScript = $FunctionTemplate -f $PSScriptInfo, $NewCommandName, $CmdletBinding, ($ParameterContent -join ",`n`n"), ($BeginContent -join "`n"), ($ProcessContent -join "`n"), ($EndContent -join "`n")
# Fix line endings
$NewScript = $NewScript.Replace("`r`n", "`n").Trim()
# Export the function
$OutputFilePath = "$OutputPath/$NewCommandName.ps1"
New-FolderRecursive -Path:($OutputFilePath) -Force
$NewScript | Out-File -FilePath:($OutputFilePath) -Force
# Validate script syntax
$ScriptAnalyzerResult = Invoke-ScriptAnalyzer -Path:($OutputFilePath) -Recurse -ExcludeRule PSShouldProcess, PSAvoidTrailingWhitespace, PSAvoidUsingWMICmdlet, PSAvoidUsingPlainTextForPassword, PSAvoidUsingUsernameAndPasswordParams, PSAvoidUsingInvokeExpression, PSUseDeclaredVarsMoreThanAssignments, PSUseSingularNouns, PSAvoidGlobalVars, PSUseShouldProcessForStateChangingFunctions, PSAvoidUsingWriteHost, PSAvoidUsingPositionalParameters
If ($ScriptAnalyzerResult)
$CommandName = $individualCommand.Name
$NewCommandName = $CommandName.Replace($SdkPrefix, $JumpCloudModulePrefix)
Write-Host ("[STATUS] Building: $NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta')
# Get content from sdk function
$CommandFilePath = $individualCommand.ScriptBlock.File
$CommandFilePathContent = Get-Content -Path:($CommandFilePath) -Raw
$FunctionContent = If ($CommandFilePath -like '*ProxyCmdletDefinitions.ps1')
{
<# When the autorest generated module has been installed and imported from the PSGallery all the
cmdlets will exist in a single ProxyCmdletDefinitions.ps1 file. We need to parse
out the specific function in order to gather the parts we need to copy over. #>
$CommandFilePathContent.Replace($MSCopyrightHeader, $Divider).Split($Divider).Where( { $_ -like ('*' + "function $CommandName {" + '*') })
}
Else
{
<# When the autorest generated module has been imported from a local psd1 module the function will
remain in their individual files. #>
$CommandFilePathContent
}
$PSScriptInfo = ($FunctionContent | Select-String -Pattern:('(?s)(<#)(.*?)(#>)')).Matches.Value
$Params = $FunctionContent | Select-String -Pattern:('(?s)( \[Parameter)(.*?)(\})') -AllMatches
$ParameterContent = ($Params.Matches.Value | Where-Object { $_ -notlike '*DontShow*' -and $_ -notlike '*Limit*' -and $_ -notlike '*Skip*' })
$OutputType = ($FunctionContent | Select-String -Pattern:('(\[OutputType)(.*?)(\]\r)')).Matches.Value
$CmdletBinding = ($FunctionContent | Select-String -Pattern:('(\[CmdletBinding)(.*?)(\]\r)')).Matches.Value
If (-not [System.String]::IsNullOrEmpty($PSScriptInfo))
{
$PSScriptInfo = $PSScriptInfo.Replace($SdkPrefix, $JumpCloudModulePrefix)
$PSScriptInfo = $PSScriptInfo.Replace("$NewCommandName.md", "$FunctionName.md")
}
# Build CmdletBinding
If (-not [System.String]::IsNullOrEmpty($OutputType)) { $CmdletBinding = "$($OutputType)`n$($IndentChar)$($CmdletBinding)" }
# Build $BeginContent, $ProcessContent, and $EndContent
$BeginContent = @()
$ProcessContent = @()
$EndContent = @()
# Build "Begin" block
$BeginContent += "$($IndentChar)$($IndentChar)Connect-JCOnline -force | Out-Null"
$BeginContent += "$($IndentChar)$($IndentChar)`$Results = @()"
# Build "Process" block
$ProcessContent += "$($IndentChar)$($IndentChar)`$Results = $($ModuleName)\$($CommandName) @PSBoundParameters"
# Build "End" block
$EndContent += "$($IndentChar)$($IndentChar)Return `$Results"
If (-not [System.String]::IsNullOrEmpty($BeginContent) -and -not [System.String]::IsNullOrEmpty($ProcessContent) -and -not [System.String]::IsNullOrEmpty($EndContent))
{
$ScriptAnalyzerResults += $ScriptAnalyzerResult
# Build "Function"
$NewScript = $FunctionTemplate -f $PSScriptInfo, $NewCommandName, $CmdletBinding, ($ParameterContent -join ",`n`n"), ($BeginContent -join "`n"), ($ProcessContent -join "`n"), ($EndContent -join "`n")
# Fix line endings
$NewScript = $NewScript.Replace("`r`n", "`n").Trim()
# Export the function
$OutputFilePath = "$OutputPath/$NewCommandName.ps1"
New-FolderRecursive -Path:($OutputFilePath) -Force
$NewScript | Out-File -FilePath:($OutputFilePath) -Force
# Validate script syntax
$ScriptAnalyzerResult = Invoke-ScriptAnalyzer -Path:($OutputFilePath) -Recurse -ExcludeRule PSShouldProcess, PSAvoidTrailingWhitespace, PSAvoidUsingWMICmdlet, PSAvoidUsingPlainTextForPassword, PSAvoidUsingUsernameAndPasswordParams, PSAvoidUsingInvokeExpression, PSUseDeclaredVarsMoreThanAssignments, PSUseSingularNouns, PSAvoidGlobalVars, PSUseShouldProcessForStateChangingFunctions, PSAvoidUsingWriteHost, PSAvoidUsingPositionalParameters
If ($ScriptAnalyzerResult)
{
$ScriptAnalyzerResults += $ScriptAnalyzerResult
}
}
# Copy tests?
# Copy-Item -Path:($AutoRest_Tests) -Destination:($JCModule_Tests) -Force
# Update .Psd1 file
$Psd1.FunctionsToExport += $NewCommandName
Update-ModuleManifest -Path:($FilePath_psd1) -FunctionsToExport:($Psd1.FunctionsToExport)
}
# Copy tests?
# Copy-Item -Path:($AutoRest_Tests) -Destination:($JCModule_Tests) -Force
# Update .Psd1 file
$Psd1.FunctionsToExport += $NewCommandName
Update-ModuleManifest -Path:($FilePath_psd1) -FunctionsToExport:($Psd1.FunctionsToExport)
}
}
}
Expand Down
Loading

0 comments on commit b350ad3

Please sign in to comment.