Skip to content

Commit

Permalink
Merge pull request #431 from TheJumpCloud/SA-2866-Set-JCCommand-Inclu…
Browse files Browse the repository at this point in the history
…de-CommandType

Sa 2866 set jc command include command type
  • Loading branch information
kmaranionjc authored Oct 13, 2022
2 parents fcadf62 + fd203a5 commit 69f9196
Show file tree
Hide file tree
Showing 132 changed files with 1,687 additions and 2,982 deletions.
4 changes: 2 additions & 2 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ parameters:
description: "Release Type. Accepted values [ Major, Minor, Patch ]"
type: enum
enum: ["Major", "Minor", "Patch"]
default: "Major"
default: "Patch"
RequiredModulesRepo:
description: "PowerShell Repository for JumpCloud SDKs"
type: enum
Expand All @@ -49,7 +49,7 @@ parameters:
PublishToPSGallery:
description: "When `true` and when run against Master branch, this workflow will publish the latest code to PSGallery"
type: boolean
default: false
default: true
ManualModuleVersion:
description: "When `true` the pipeline will use the Module Version specified in JumpCloud Module JumpCloud.psd1 file"
type: boolean
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
.vscode
.vscode/launch.json
# Ignore Test Results Directory
*test_results
# Ignore support.wiki
Expand Down
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"spellright.language": ["en"],
"spellright.documentTypes": ["markdown", "latex", "plaintext"],
"editor.formatOnSave": true,
"powershell.codeFormatting.preset": "OTBS",
"powershell.scriptAnalysis.enable": true,
"files.trimTrailingWhitespace": true,
"powershell.scriptAnalysis.settingsPath": "PowerShell/JumpCloud Module/Tests/ModuleValidation/PSScriptAnalyzerSettings.psd1"
}
8 changes: 4 additions & 4 deletions Azure/Serverless/Function_Example.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ $result = Invoke-Expression $command
$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."

if ($command) {
$body = $result
$body = $result
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $body
})
StatusCode = [HttpStatusCode]::OK
Body = $body
})
41 changes: 13 additions & 28 deletions PowerShell/Deploy/Build-HelpFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ $FolderPath_Docs = "$ModulePath/Docs"
$FolderPath_enUS = "$ModulePath/$Locale"
$FilePath_ModulePagePath = "$FolderPath_Docs/$ModuleName.md"
Write-Host ("[status]Creating/Updating help files")
Try
{
Try {
Write-Host ("[status]Installing module: PlatyPS")
Install-Module -Repository:('PSGallery') -Name:('PlatyPS') -Force
# Import module
Expand All @@ -25,29 +24,23 @@ Try
#########################################################
############### Adding Comment based help ###############
#########################################################
If ($AddCommentBasedHelp)
{
If ($AddCommentBasedHelp) {
$FolderPath_Public = "$ModulePath/Public"
# Move the help contents from docs files to ps1 files
$DocFiles = Get-ChildItem $FolderPath_Docs
$DocFiles | ForEach-Object {
$file = Get-ChildItem $FolderPath_Public -Filter ($_.BaseName + ".ps1") -Recurse
if ($file.FullName)
{
if ($file.FullName) {
$help = Get-Help -Name $_.BaseName
$content = Get-Content $file.FullName -Raw
if ($content -notlike "<#*")
{
if ($content -notlike "<#*") {
$synopsis = ".Synopsis`r`n" + ($help.Synopsis).Trim()
$description = ".Description`r`n" + ($help.description.text).Trim()
$examples = $help.examples.example | ForEach-Object {
$Example = $_
$ExampleCode = If ($Example.code -like '*C:\>*')
{
$ExampleCode = If ($Example.code -like '*C:\>*') {
($Example.code).split(">")[1]
}
Else
{
} Else {
$Example.code
}
(".Example`r`n" + ($ExampleCode).Trim() + "`r`n`r`n" + ($Example.remarks.text).Trim())
Expand All @@ -67,20 +60,16 @@ Try
#########################################################
#########################################################
# If not exist create: .\Docs\about_$ModuleName.md
If (-not (Test-Path -Path:("$($FolderPath_Docs)/about_$($ModuleName).md")))
{
If (-not (Test-Path -Path:("$($FolderPath_Docs)/about_$($ModuleName).md"))) {
Write-Host ("[status]Creating New-MarkdownAboutHelp")
New-MarkdownAboutHelp -OutputFolder:($FolderPath_Docs) -AboutName:($ModuleName)
}
# Creating help files: .\Docs\*.md
Write-Host ("[status]Creating help files: .\Docs\*.md")
Switch ($NewMarkdownHelpParamSet)
{
'FromCommand'
{
Switch ($NewMarkdownHelpParamSet) {
'FromCommand' {
$Psd1.FunctionsToExport | ForEach-Object {
If (-not (Test-Path -Path:("$($FolderPath_Docs)/$($_).md")))
{
If (-not (Test-Path -Path:("$($FolderPath_Docs)/$($_).md"))) {
$parameters = @{
Command = $_
Force = $true
Expand All @@ -98,8 +87,7 @@ Try
}
}
}
'FromModule'
{
'FromModule' {
$parameters = @{
Module = $ModuleName
Force = $true
Expand All @@ -119,8 +107,7 @@ Try
}
New-MarkdownHelp @parameters
}
Default
{
Default {
Write-Error ("Unknown `$NewMarkdownHelpParamSet value: $NewMarkdownHelpParamSet")
}
}
Expand Down Expand Up @@ -153,9 +140,7 @@ Try
# Creating: .\en-Us\$ModuleName-help.xml and .\en-Us\about_$ModuleName.help.txt
Write-Host ("[status]Creating: .\en-Us\$ModuleName-help.xml and .\en-Us\about_$ModuleName.help.txt")
New-ExternalHelp -Path:($FolderPath_Docs) -OutputPath:($FolderPath_enUS) -Force # -ApplicableTag <String> -Encoding <Encoding> -MaxAboutWidth <Int32> -ErrorLogFile <String> -ShowProgress
}
Catch
{
} Catch {
Write-Error ($_)
}

Expand Down
11 changes: 4 additions & 7 deletions PowerShell/Deploy/Build-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ Write-Host ('[status]Check PowerShell Gallery for module version info')
$PSGalleryInfo = Get-PSGalleryModuleVersion -Name:($ModuleName) -ReleaseType:($RELEASETYPE) #('Major', 'Minor', 'Patch')
# Check to see if ManualModuleVersion parameter is set to true
if ($ManualModuleVersion) {
$ManualModuleVersionRetrieval = Get-Content -Path:($FilePath_psd1) | Where-Object {$_ -like '*ModuleVersion*'}
$ManualModuleVersionRetrieval = Get-Content -Path:($FilePath_psd1) | Where-Object { $_ -like '*ModuleVersion*' }
$SemanticRegex = [Regex]"[0-9]+.[0-9]+.[0-9]+"
$SemeanticVersion = Select-String -InputObject $ManualModuleVersionRetrieval -pattern ($SemanticRegex)
$ModuleVersion = $SemeanticVersion[0].Matches.Value
}
else {
} else {
$ModuleVersion = $PSGalleryInfo.NextVersion
}
Write-Host ('[status]PowerShell Gallery Name:' + $PSGalleryInfo.Name + ';CurrentVersion:' + $PSGalleryInfo.Version + '; NextVersion:' + $ModuleVersion )
Expand All @@ -46,17 +45,15 @@ New-JCModuleManifest -Path:($FilePath_psd1) `
Write-Host ('[status]Updating module banner: "' + $FilePath_ModuleBanner + '"')
$ModuleBanner = Get-Content -Path:($FilePath_ModuleBanner)
$NewModuleBannerRecord = New-ModuleBanner -LatestVersion:($ModuleVersion) -BannerCurrent:('{{Fill in the Banner Current}}') -BannerOld:('{{Fill in the Banner Old}}')
If (!(($ModuleBanner | Select-Object -Index 3) -match $ModuleVersion))
{
If (!(($ModuleBanner | Select-Object -Index 3) -match $ModuleVersion)) {
$NewModuleBannerRecord.Trim() | Set-Content -Path:($FilePath_ModuleBanner) -Force
}
# EndRegion Updating module banner
# Region Updating module change log
Write-Host ('[status]Updating module change log: "' + $FilePath_ModuleChangelog + '"')
$ModuleChangelog = Get-Content -Path:($FilePath_ModuleChangelog)
$NewModuleChangelogRecord = New-ModuleChangelog -LatestVersion:($ModuleVersion) -ReleaseNotes:('{{Fill in the Release Notes}}') -Features:('{{Fill in the Features}}') -Improvements:('{{Fill in the Improvements}}') -BugFixes('{{Fill in the Bug Fixes}}')
If (!(($ModuleChangelog | Select-Object -First 1) -match $ModuleVersion))
{
If (!(($ModuleChangelog | Select-Object -First 1) -match $ModuleVersion)) {
($NewModuleChangelogRecord + ($ModuleChangelog | Out-String)).Trim() | Set-Content -Path:($FilePath_ModuleChangelog) -Force
}
# EndRegion Updating module change log
6 changes: 2 additions & 4 deletions PowerShell/Deploy/Build-PesterTestFiles.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@ param (
################################################################################
Write-Host ('[status]Creating files for Pester tests')
$Files = $Functions_Public + $Functions_Private
Foreach ($File in $Files)
{
Foreach ($File in $Files) {
$NewDirectory = ([string]$File.Directory).Replace($ModuleFolderName, $ModuleFolderName + '/' + $FolderName_Tests)
$NewName = $File.BaseName + '.Tests' + $File.Extension
$NewFullName = $NewDirectory + '/' + $NewName
If ( !( Test-Path -Path:($NewFullName) ))
{
If ( !( Test-Path -Path:($NewFullName) )) {
New-FolderRecursive -Path:($NewFullName)
Write-Host ('[status]Create test files for new function')
New-Item -ItemType:('File') -Path:($NewFullName) -Force
Expand Down
20 changes: 6 additions & 14 deletions PowerShell/Deploy/Build-WikiPages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,23 @@ $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)
{
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 '---')
{
$NewDocContent = If (($DocContent | Select-Object -First 1) -eq '---') {
$DocContent | Select-Object -Skip:(7)
}
Else
{
} Else {
$DocContent
}
If (Test-Path -Path:($SupportWikiDocFullName))
{
If (Test-Path -Path:($SupportWikiDocFullName)) {
$SupportWikiDocContent = Get-Content -Path:($SupportWikiDocFullName)
$Diffs = Compare-Object -ReferenceObject:($NewDocContent) -DifferenceObject:($SupportWikiDocContent)
If (-not [string]::IsNullOrEmpty($Diffs))
{
If (-not [string]::IsNullOrEmpty($Diffs)) {
Write-Warning -Message:('Diffs found in: ' + $DocName)
}
}
Else
{
} Else {
Write-Warning -Message:('Creating new file: ' + $DocName)
}
Set-Content -Path:($SupportWikiDocFullName) -Value:($NewDocContent) -Force
Expand Down
52 changes: 16 additions & 36 deletions PowerShell/Deploy/Functions/Create-ModuleManifest.ps1
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
Function Global:New-JCModuleManifest
{
Function Global:New-JCModuleManifest {
[cmdletbinding(SupportsShouldProcess = $True)]
Param()
DynamicParam
{
DynamicParam {
$Params = @()
$NewModuleManifestParameterSets = (Get-Command -Name:('New-ModuleManifest')).ParameterSets
ForEach ($NewModuleManifestParameterSet In $NewModuleManifestParameterSets)
{
ForEach ($NewModuleManifestParam In $NewModuleManifestParameterSet.Parameters)
{
If ($NewModuleManifestParam.Name -notin @([System.Management.Automation.PSCmdlet]::CommonParameters + [System.Management.Automation.PSCmdlet]::OptionalCommonParameters))
{
ForEach ($NewModuleManifestParameterSet In $NewModuleManifestParameterSets) {
ForEach ($NewModuleManifestParam In $NewModuleManifestParameterSet.Parameters) {
If ($NewModuleManifestParam.Name -notin @([System.Management.Automation.PSCmdlet]::CommonParameters + [System.Management.Automation.PSCmdlet]::OptionalCommonParameters)) {
$Params += @{
'ParameterSets' = $NewModuleManifestParameterSet.Name;
'Name' = $NewModuleManifestParam.Name;
Expand Down Expand Up @@ -44,70 +39,55 @@ Function Global:New-JCModuleManifest
New-Object PSObject -Property $_
} | New-DynamicParameter
}
Begin
{
Begin {
# Create new variables for script
$PsBoundParameters.GetEnumerator() | ForEach-Object { Set-Variable -Name:($_.Key) -Value:($_.Value) -Force }
Write-Debug ('[CallFunction]' + $MyInvocation.MyCommand.Name + ' ' + ($PsBoundParameters.GetEnumerator() | Sort-Object Key | ForEach-Object { ('-' + $_.Key + ":('" + ($_.Value -join "','") + "')").Replace("'True'", '$True').Replace("'False'", '$False') }) )
If ($PSCmdlet.ParameterSetName -ne '__AllParameterSets') { Write-Verbose ('[ParameterSet]' + $MyInvocation.MyCommand.Name + ':' + $PSCmdlet.ParameterSetName) }
$CurrentErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
}
Process
{
Process {
# Create hash table to store variables
$FunctionParameters = [ordered]@{ }
If (Test-Path -Path:($Path))
{
If (Test-Path -Path:($Path)) {
$FilePath_psd1 = Get-Item -Path:($Path)
$CurrentModuleManifest = Import-LocalizedData -BaseDirectory:($FilePath_psd1.DirectoryName) -FileName:($FilePath_psd1.BaseName)
# Add input parameters from function in to hash table and filter out unnecessary parameters
$CurrentModuleManifest.GetEnumerator() | ForEach-Object { $FunctionParameters.Add($_.Key, $_.Value) | Out-Null }
$PrivateDataPSData = $CurrentModuleManifest['PrivateData']['PSData']
# New-ModuleManifest parameters that come from previous ModuleManifest PrivateData
$PrivateDataPSData.GetEnumerator() | ForEach-Object {
If ($FunctionParameters.Contains($_.Key))
{
If ($FunctionParameters.Contains($_.Key)) {
$FunctionParameters[$_.Key] = $_.Value
}
Else
{
} Else {
$FunctionParameters.Add($_.Key, $_.Value) | Out-Null
}
}
# Remove previous ModuleManifest PrivateData
$FunctionParameters.Remove('PrivateData') | Out-Null
# Update values with values passed in from function
$PsBoundParameters.GetEnumerator() | ForEach-Object {
If ($FunctionParameters.Contains($_.Key))
{
If ($FunctionParameters.Contains($_.Key)) {
$FunctionParameters[$_.Key] = $_.Value
}
Else
{
} Else {
$FunctionParameters.Add($_.Key, $_.Value) | Out-Null
}
}
}
Else
{
} Else {
Write-Warning ('Creating new module manifest. Please populate empty fields: ' + $Path)
New-ModuleManifest -Path:($Path)
}
Write-Debug ('Splatting Parameters');
If ($DebugPreference -ne 'SilentlyContinue') { $FunctionParameters }
New-ModuleManifest @FunctionParameters
}
End
{
End {
# Validate that the module manifest is valid
$ModuleValid = Test-ModuleManifest -Path:($FilePath_psd1.FullName)
If ($ModuleValid)
{
If ($ModuleValid) {
$ModuleValid
}
Else
{
} Else {
$ModuleValid
Write-Error ('ModuleManifest is invalid!')
}
Expand Down
Loading

0 comments on commit 69f9196

Please sign in to comment.