Skip to content

Commit

Permalink
Merge pull request #402 from TheJumpCloud/SA-2726-Get-Raw-Command-fro…
Browse files Browse the repository at this point in the history
…m-GH

Sa 2726 get raw command from gh
  • Loading branch information
jworkmanjc authored Jul 29, 2022
2 parents c2ed836 + 56502ee commit 6af7815
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 51 deletions.
3 changes: 2 additions & 1 deletion .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 Expand Up @@ -119,6 +119,7 @@ workflows:
- Build Help and Test Files
- Build Nuspec
- Invoke Git Commit
- Module Validation Tests
context: aws-credentials
- Pester Tests Mac:
requires:
Expand Down
2 changes: 1 addition & 1 deletion PowerShell/JumpCloud Module/Docs/JumpCloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Module Name: JumpCloud
Module Guid: 31c023d1-a901-48c4-90a3-082f91b31646
Download Help Link: https://github.com/TheJumpCloud/support/wiki
Help Version: 1.23.3
Help Version: 1.23.4
Locale: en-US
---

Expand Down
4 changes: 2 additions & 2 deletions PowerShell/JumpCloud Module/JumpCloud.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: JumpCloud Solutions Architect Team
#
# Generated on: 7/21/2022
# Generated on: 7/29/2022
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'JumpCloud.psm1'

# Version number of this module.
ModuleVersion = '1.23.3'
ModuleVersion = '1.23.4'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Function New-JCCommandFromURL
{
Function New-JCCommandFromURL {
[CmdletBinding()]
param (

Expand All @@ -12,51 +11,37 @@ Function New-JCCommandFromURL

)

begin
{
process {

}

process
{

$Command = Invoke-WebRequest -Uri $GitHubURL -UseBasicParsing -UserAgent:(Get-JCUserAgent) | Select-Object RawContent
# Convert GitHub url to raw url
$httpUrl = $GitHubURL | Select-String -Pattern "\bmaster.*$" | % { $_.Matches } | % { $_.Value }
$rawUrl = "https://raw.githubusercontent.com/TheJumpCloud/support/$httpUrl"

$CodeRaw = $Command | Select-String '(?<=\<code(.*?)\>)((.|\n|\r)*?)(?=<\/code>)' # Contain XML escape characters
$rawUrlInvoke = Invoke-WebRequest -Uri $rawUrl -UseBasicParsing -UserAgent:(Get-JCUserAgent)
$content = [Regex]::Matches($rawUrlInvoke.Content, '#### (Name|commandType).*[\r\n]+(.*)|#### Command[\n\r]+.*\n([\s\S]*?)```$', [System.Text.RegularExpressions.RegexOptions]::Multiline)

$Code = ((((($CodeRaw.Matches.Value.Trim() -replace "&amp;", "&") -replace "&lt;", "<") -replace "&gt;", ">") -replace "&quot;", '"') -Replace "&apos;", "'") # Replace XML character references

$Name = (((((($Command -split 'Name</h4>')[1]) -replace "`n", "") -split '</p>')[0]) -replace '(\<p)(.*?)(\>)', '')

$commandType = (((($Command -split 'commandType</h4>')[1] -replace "`n", "") -split '</p>')[0] -replace '(\<p)(.*?)(\>)', "")
# Command Values
$Name = $content[0].Groups[2].Value #Name
$commandType = $content[1].Groups[2].Value #CommandType
$Command = $content[2].Groups[3].Value #Command

$NewCommandParams = @{

name = $Name
commandType = $commandType
command = $code
command = $command
}

Write-Verbose $NewCommandParams

try
{
try {

$NewCommand = New-JCCommand @NewCommandParams

}


catch
{
} catch {

$NewCommand = $_.ErrorDetails

}
}

end
{
end {

Return $NewCommand

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,4 @@ Describe -Tag:('JCCommand') 'Import-JCCommand 1.1' {
Remove-JCCommand -CommandID $Command._id -force

}

It "Imports a JumpCloud command from a short URL" {

$Command = Import-JCCommand -URL 'https://git.io/jccg-Mac-GetLoggedInUsers'

$Command.commandType | Should -Be 'mac'

Remove-JCCommand -CommandID $Command._id -force

}


}
8 changes: 3 additions & 5 deletions PowerShell/ModuleBanner.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#### Latest Version

```
1.23.3
1.23.4
```

#### Banner Current

```
* Get-JCUser -State should accept case insensitive values such as "suspended" "activated" "staged" and validate input```
* New-JCCommandURL converts Import-JCCommand command url (https://github.com/) to raw github content (https://raw.githubusercontent.com/)
```

#### Banner Old

```
- Added search endpoint functionality and parameters to Get-jCCommand
* Get-JCUser -State should accept case insensitive values such as "suspended" "activated" "staged" and validate input```
```
7 changes: 7 additions & 0 deletions PowerShell/ModuleChangelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.23.4

Release Date: July 25, 2022

#### RELEASE NOTES

This release modifies New-JCCommandURL to convert Import-JCCommand url to raw github content to prevent changes to GitHub HTML from breaking Import-JCCommand function
## 1.23.3

Release Date: July 20, 2022
Expand Down

0 comments on commit 6af7815

Please sign in to comment.