Skip to content

Commit

Permalink
Merge pull request #621 from TheJumpCloud/CUT-4324_PolicyGroupTemplate
Browse files Browse the repository at this point in the history
Cut 4324 policy group template
  • Loading branch information
jworkmanjc authored Nov 19, 2024
2 parents a69f610 + 65343fc commit 048483c
Show file tree
Hide file tree
Showing 108 changed files with 4,447 additions and 930 deletions.
97 changes: 81 additions & 16 deletions PowerShell/Deploy/SdkSync/jcapiToSupportSync.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,32 @@ $JumpCloudModulePrefix = 'JC'
$IndentChar = ' '
$MSCopyrightHeader = "`n<#`n.Synopsis`n"
$Divider = "`n[SPLIT]`n<#`n.Synopsis`n"
$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}}"
$FunctionTemplate = @"
{0}
Function {1} {
{2}
Param(
{3}
)
Begin {
{
{4}
}
}
Process {
{
{5}
}
}
End {
{
{6}
}
}
}
"@
# $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 $FilePath_psd1).Directory.FullName
$PSD1_Module = Test-ModuleManifest -Path:("$FilePath_psd1")
Expand Down Expand Up @@ -110,32 +135,72 @@ If (-not [System.String]::IsNullOrEmpty($Modules)) {
$PSScriptInfo = ($FunctionContent | Select-String -Pattern:([regex]'(?s)(<#)(.*?)(#>)')).Matches.Value
$Params = $FunctionContent | Select-String -Pattern:([regex]'(?s)( \[Parameter)(.*?)(\})') -AllMatches
$ParameterContent = ($Params.Matches.Value | Where-Object { $_ -notlike '*DontShow*' -and $_ -notlike '${Limit}' -and $_ -notlike '*${Skip}*' })

for ($i = 0; $i -lt $ParameterContent.Count; $i++) {
if ($i -ne ($ParameterContent.Count - 1 )) {
$ParameterContent[$i] = $($ParameterContent[$i].Replace('}', '},'))
$ParameterContent[$i] += "`n"
} else {
$ParameterContent[$i] = $ParameterContent[$i]
}
}
# declare param here string
$paramString = @"
"@
ForEach ($line in $($ParameterContent -split "`n")) {
# for the last item don't add a new line:
if ($line -eq $($ParameterContent -split "`n")[-1] ) {
$line = $line -replace '(^\s+|\s+$)', ''
$paramString += @"
$line
"@
} else {
# otherwise add a new line after each row
$line = $line -replace '(^\s+|\s+$)', ''
$paramString += @"
$line`n
"@
}
}
$OutputType = (($FunctionContent | Select-String -Pattern:([regex]'(\[OutputType)(.*?)(\]\s+)')).Matches.Value).TrimEnd()
$CmdletBinding = (($FunctionContent | Select-String -Pattern:([regex]'(\[CmdletBinding)(.*?)(\]\s+)')).Matches.Value).TrimEnd()
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 = @()
# $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")
# $NewScript = $FunctionTemplate -f $PSScriptInfo, $NewCommandName, $CmdletBinding, $ParameterContent, $BeginContent, $ProcessContent, $EndContent
$NewScript = @"
$PSScriptInfo
Function $NewCommandName {
$($OutputType)
$($CmdletBinding)
Param(
$paramString
)
Begin {
Connect-JCOnline -force | Out-Null
`$Results = @()
}
Process {
`$Results = $($ModuleName)\$($CommandName) @PSBoundParameters
}
End {
Return `$Results
}
}
"@
# $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()
# $NewScript = $NewScript.Replace("`r`n", "`n").Trim()
# Export the function
Write-Host ("[STATUS] Writing File: $OutputPath/$NewCommandName") -BackgroundColor:('Black') -ForegroundColor:('Magenta')
$OutputFilePath = "$OutputPath/$NewCommandName.ps1"
Expand Down
99 changes: 99 additions & 0 deletions PowerShell/JumpCloud Module/Docs/Get-JCConfiguredTemplatePolicy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
external help file: JumpCloud-help.xml
Module Name: JumpCloud
online version: https://github.com/TheJumpCloud/support/wiki/
schema: 2.0.0
---

# Get-JCConfiguredTemplatePolicy

## SYNOPSIS

Retrieves a Configured Policy Templates

## SYNTAX

### ReturnAll (Default)
```
Get-JCConfiguredTemplatePolicy [<CommonParameters>]
```

### ById
```
Get-JCConfiguredTemplatePolicy -ConfiguredTemplatePolicyID <String>
[<CommonParameters>]
```

### ByName
```
Get-JCConfiguredTemplatePolicy -Name <String> [<CommonParameters>]
```

## DESCRIPTION

Get-JCConfiguredTemplatePolicy returns the configured values for a defined policy member of a MTP Policy Template.

## EXAMPLES

### Example 1

```powershell
PS C:\> Get-JCConfiguredTemplatePolicy -ConfiguredTemplatePolicyID "671958685191450001cc5f2b"
```

Retrieves a Configured Policy Template for this provider with id: 671958685191450001cc5f2b

### Example 1

```powershell
PS C:\> Get-JCConfiguredTemplatePolicy -Name "ConfiguredPolicyName"
```

Retrieves a Configured Policy Template for this provider with name: ConfiguredPolicyName

## PARAMETERS

### -ConfiguredTemplatePolicyID

Retrieves a Configured Policy Templates by Id

```yaml
Type: System.String
Parameter Sets: ById
Aliases: _id, id

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
Retrieves a Configured Policy Templates by Name
```yaml
Type: System.String
Parameter Sets: ByName
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### None
## OUTPUTS
### System.Object
## NOTES
## RELATED LINKS
106 changes: 106 additions & 0 deletions PowerShell/JumpCloud Module/Docs/Get-JCPolicyGroup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
---
external help file: JumpCloud-help.xml
Module Name: JumpCloud
online version: https://github.com/TheJumpCloud/support/wiki/
schema: 2.0.0
---

# Get-JCPolicyGroup

## SYNOPSIS

Returns all policy groups, policy groups by name or id.

## SYNTAX

### ReturnAll (Default)
```
Get-JCPolicyGroup [<CommonParameters>]
```

### ByName
```
Get-JCPolicyGroup -Name <String> [<CommonParameters>]
```

### ById
```
Get-JCPolicyGroup -PolicyGroupID <String> [<CommonParameters>]
```

## DESCRIPTION

Get-JCPolicyGroup will return all policy groups for a given organization by default. If either the 'name' or 'PolicyGroupId' parameters are specified, the function will attempt to find policy groups by name or id.

## EXAMPLES

### Example 1

```powershell
PS C:\> Get-JCPolicyGroup
```

Returns all JumpCloud policy groups

### Example 2

```powershell
PS C:\> Get-JCPolicyGroup -Name "PolicyGroupName"
```

Returns the policy group with name 'PolicyGroupName'

### Example 3

```powershell
PS C:\> Get-JCPolicyGroup -PolicyGroupId "66c3a774294f1e9071f080c9"
```

Returns the policy group with id '66c3a774294f1e9071f080c9'

## PARAMETERS

### -Name

The Name of the JumpCloud policy group you wish to query.

```yaml
Type: System.String
Parameter Sets: ByName
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -PolicyGroupID
The ID of the JumpCloud policy group you wish to query
```yaml
Type: System.String
Parameter Sets: ById
Aliases: _id, id

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
### None
## OUTPUTS
### System.Object
## NOTES
## RELATED LINKS
Loading

0 comments on commit 048483c

Please sign in to comment.