Skip to content

Commit

Permalink
Merge pull request #247 from TheJumpCloud/JumpCloudModule_1.17.5
Browse files Browse the repository at this point in the history
Jump cloud module 1.17.5
  • Loading branch information
jworkmanjc authored Jul 20, 2020
2 parents 7d1ad8a + a06da22 commit 5a9a6c4
Show file tree
Hide file tree
Showing 16 changed files with 1,074 additions and 330 deletions.
9 changes: 7 additions & 2 deletions PowerShell/Deploy/Functions/Get-PSGalleryModuleVersion.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Function Get-PSGalleryModuleVersion
{
Param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)][ValidateNotNullOrEmpty()][string]$Name,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][ValidateSet('Major', 'Minor', 'Patch')][string]$RELEASETYPE
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)][ValidateNotNullOrEmpty()][ValidateSet('Major', 'Minor', 'Patch', 'Manual')][string]$RELEASETYPE
)
# Check to see if module already exists to set version number
$PowerShellGalleryModule = Find-Module -Name:($Name) -ErrorAction:('Ignore')
Expand Down Expand Up @@ -48,7 +48,12 @@ Function Get-PSGalleryModuleVersion
}

}
$NextVersion = ($ModuleVersion.Major, $ModuleVersion.Minor, $ModuleVersion.Patch) -join '.'
if ($RELEASETYPE -eq 'Manual'){
$NextVersion = ($Psd1).ModuleVersion
}
else {
$NextVersion = ($ModuleVersion.Major, $ModuleVersion.Minor, $ModuleVersion.Patch) -join '.'
}
Add-Member -InputObject:($ModuleVersion) -MemberType:('NoteProperty') -Name:('NextVersion') -Value:($NextVersion)
Return $ModuleVersion
}
3 changes: 3 additions & 0 deletions PowerShell/Deploy/Get-Config.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ $RequiredFiles | ForEach-Object {
# Get module function names
$Functions_Public = If (Test-Path -Path:($FolderPath_Public)) { Get-ChildItem -Path:($FolderPath_Public + '/' + '*.ps1') -Recurse }
$Functions_Private = If (Test-Path -Path:($FolderPath_Private)) { Get-ChildItem -Path:($FolderPath_Private + '/' + '*.ps1') -Recurse }
# Get psd1 contents
$Psd1 = Import-PowerShellDataFile -Path:($FilePath_psd1)
$RequiredModules = $Psd1.RequiredModules
# Load deploy functions
$DeployFunctions = @(Get-ChildItem -Path:($PSScriptRoot + '/Functions/*.ps1') -Recurse)
Foreach ($DeployFunction In $DeployFunctions)
Expand Down
108 changes: 108 additions & 0 deletions PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
. ((Get-Item -Path:($PSScriptRoot)).Parent.FullName + '/' + 'Get-Config.ps1')
###########################################################################
Install-Module -Name:('PSScriptAnalyzer') -Force
$ApprovedFunctions = [Ordered]@{
'JumpCloud.SDK.DirectoryInsights' = @(
[PSCustomObject]@{
Destination = '/Public/DirectoryInsights'
Name = 'Get-JcSdkEvent'
},
[PSCustomObject]@{
Destination = '/Public/DirectoryInsights'
Name = 'Get-JcSdkEventCount'
}
)
}
$SdkPrefix = 'JcSdk'
$JumpCloudModulePrefix = 'JC'
$IndentChar = ' '
$MSCopyrightHeader = "`n# ----------------------------------------------------------------------------------`n#`n# Copyright Microsoft Corporation`n# Licensed under the Apache License, Version 2.0 (the ""License"");`n# you may not use this file except in compliance with the License.`n# You may obtain a copy of the License at`n# http://www.apache.org/licenses/LICENSE-2.0`n# Unless required by applicable law or agreed to in writing, software`n# distributed under the License is distributed on an ""AS IS"" BASIS,`n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.`n# See the License for the specific language governing permissions and`n# limitations under the License.`n# ----------------------------------------------------------------------------------`n"
$Divider = '|#|#|#|#|#|#|#|#|#|#|#|#|#|#|#|'
$FunctionTemplate = "{0}`nFunction {1}`n{{`n$($IndentChar){2}`n$($IndentChar)Param(`n{3}`n$($IndentChar))`n$($IndentChar)Begin`n$($IndentChar){{`n{4}`n$($IndentChar)}}`n$($IndentChar)Process`n$($IndentChar){{`n{5}`n$($IndentChar)}}`n$($IndentChar)End`n$($IndentChar){{`n{6}`n$($IndentChar)}}`n}}"
$ScriptAnalyzerResults = @()
$JumpCloudModulePath = (Get-Item -Path:($PSScriptRoot)).Parent.Parent.FullName + '/JumpCloud Module'
Import-Module -Name:($RequiredModules)
Get-Module -Refresh -ListAvailable -All | Out-Null
$Modules = Get-Module -Name:($RequiredModules | Where-Object { $_ -in $ApprovedFunctions.Keys })
If (-not [System.String]::IsNullOrEmpty($Modules))
{
ForEach ($Module In $Modules)
{
$ModuleName = $Module.Name
ForEach ($Function In $ApprovedFunctions.$ModuleName)
{
$FunctionName = $Function.Name
$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')
{
<# 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)
{
$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)
}
}
}
Else
{
Write-Error ('No modules found!')
}
18 changes: 18 additions & 0 deletions PowerShell/Deploy/Setup-Dependencies.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
. ($PSScriptRoot + '/' + 'Get-Config.ps1')
###########################################################################
ForEach ($RequiredModule In $RequiredModules)
{
Write-Host("Setting up dependency '$RequiredModule'")
# Check to see if the module is installed
If ([System.String]::IsNullOrEmpty((Get-InstalledModule).Where( { $_.Name -eq $RequiredModule })))
{
Write-Host("Installing '$RequiredModule'")
Install-Module -Name:($RequiredModule) -Force
}
# Get-Module -Refresh -ListAvailable
If ([System.String]::IsNullOrEmpty((Get-Module).Where( { $_.Name -eq $RequiredModule })))
{
Write-Host("Importing '$RequiredModule'")
Import-Module -Name:($RequiredModule) -Force
}
}
84 changes: 27 additions & 57 deletions PowerShell/JumpCloud Module/Docs/Get-JCEvent.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Query the API for Directory Insights events

### GetExpanded (Default)
```
Get-JCEvent [-EndTime <DateTime>] [-Fields <String[]>] [-Limit <Int64>] [-SearchAfter <String[]>]
[-SearchTermAnd <Hashtable>] [-SearchTermOr <Hashtable>] [-Service <String[]>] [-Sort <String>]
[-StartTime <DateTime>] [-Paginate <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-JCEvent -Service <String[]> -StartTime <DateTime> [-EndTime <DateTime>] [-Fields <String[]>]
[-SearchAfter <String[]>] [-SearchTermAnd <Hashtable>] [-SearchTermOr <Hashtable>] [-Sort <String>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

### Get
```
Get-JCEvent -EventQueryBody <IEventQuery> [-Paginate <Boolean>] [-WhatIf] [-Confirm] [<CommonParameters>]
Get-JCEvent -Body <IEventQuery> [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -87,42 +87,42 @@ Get all events filtered by organization_update term between a date range

## PARAMETERS

### -EventQueryBody
EventQuery is the users' command to search our auth logs
To construct, see NOTES section for EVENTQUERYBODY properties and create a hash table.
### -Service
service name to query.
Known services: systems,radius,sso,directory,ldap,all

```yaml
Type: JumpCloud.SDK.DirectoryInsights.Models.IEventQuery
Parameter Sets: Get
Type: System.String[]
Parameter Sets: GetExpanded
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept pipeline input: False
Accept wildcard characters: False
```
### -EndTime
optional query end time, UTC in RFC3339 format
### -StartTime
query start time, UTC in RFC3339 format
```yaml
Type: System.DateTime
Parameter Sets: GetExpanded
Aliases:

Required: False
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Fields
optional list of fields to return from query
### -EndTime
optional query end time, UTC in RFC3339 format
```yaml
Type: System.String[]
Type: System.DateTime
Parameter Sets: GetExpanded
Aliases:

Expand All @@ -133,17 +133,17 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Limit
Max number of rows to return
### -Fields
optional list of fields to return from query
```yaml
Type: System.Int64
Type: System.String[]
Parameter Sets: GetExpanded
Aliases:

Required: False
Position: Named
Default value: 0
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
Expand Down Expand Up @@ -195,22 +195,6 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Service
service name to query.
Known services: systems,radius,sso,directory,ldap,all
```yaml
Type: System.String[]
Parameter Sets: GetExpanded
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Sort
ASC or DESC order for timestamp
Expand All @@ -226,33 +210,19 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -StartTime
query start time, UTC in RFC3339 format
### -Body
EventQuery is the users' command to search our auth logs
To construct, see NOTES section for BODY properties and create a hash table.
```yaml
Type: System.DateTime
Parameter Sets: GetExpanded
Type: JumpCloud.SDK.DirectoryInsights.Models.IEventQuery
Parameter Sets: Get
Aliases:

Required: False
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Paginate
Set to $true to return all results.
```yaml
Type: System.Boolean
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: True
Accept pipeline input: False
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
Expand Down
Loading

0 comments on commit 5a9a6c4

Please sign in to comment.