Skip to content

Commit

Permalink
Fix Bug in Import-Type for SHiPS compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
fvanroie committed Sep 29, 2018
1 parent 0cfcdd6 commit 61d11ea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
17 changes: 10 additions & 7 deletions OPNsensePSDrive.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ using namespace Microsoft.PowerShell.SHiPS
class OPNsenseDrive : SHiPSDirectory {

static [PSCredential] $Credential
static [String] $Url
static [String] $Url = 'http://opnsense.localdomain'
static [Boolean] $SkipCertificateCheck = $true

OPNsenseDrive([string]$name): base($name) {
Write-Verbose $([OPNsenseDrive]::credential).username
Write-Verbose $([OPNsenseDrive]::Url)

$apiCred = [OPNsenseDrive]::Credential

if (!$apiCred -Or !$apiCred.Username) {
Throw "Please specify the api credentials."
}


try {
$context = Connect-OPNsense -Url $([OPNsenseDrive]::Url) -Credential $([OPNsenseDrive]::Credential) -SkipCertificateCheck:$([OPNsenseDrive]::SkipCertificateCheck) -WarningAction 'SilentlyContinue'
$context = Connect-OPNsense -Url $([OPNsenseDrive]::Url) -Credential $([OPNsenseDrive]::Credential) -SkipCertificateCheck:$([OPNsenseDrive]::SkipCertificateCheck) -WarningAction 'SilentlyContinue' -erroraction Stop
} catch {
throw ("Unable to Connect to OPNsense server '{0}' using api key '{1}'" -f $([OPNsenseDrive]::Url), $([OPNsenseDrive]::credential).username)
}

$context = Get-OPNsense
Write-Verbose $context.product_name
if (IsNullOrEmpty($context)) {
if ([String]::IsNullOrEmpty($context)) {
throw "Unable to get the OPNsense status info"
}
}
Expand All @@ -28,7 +32,6 @@ class OPNsenseDrive : SHiPSDirectory {
$obj = @()

$context = Get-OPNsensePackage -Plugin -Installed
Write-Verbose $context.count
foreach ($pkg in $context) {

$obj += $pkg
Expand Down
7 changes: 5 additions & 2 deletions PS_OPNsense.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ ForEach ($Folder in 'Classes', 'Core', 'Plugins', 'Private', 'Public') {
}

ForEach ($Folder in 'Classes') {
$FullPath = ("{0}/{1}/" -f $PSScriptRoot, $Folder)
$Files = Get-ChildItem -Recurse -Filter '*.cs' -Path $FullPath | Where-Object { $_.Name -notlike '*.Tests.ps1' }
$FullPath = Join-Path -Path $PSScriptRoot -ChildPath $Folder

$Files = Get-ChildItem -Recurse -Filter '*.cs' -Path $FullPath |
Where-Object { $_.Name -notlike '*.Tests.ps1' }

ForEach ($File in $Files) {
if ($debug) {
Write-Host -ForegroundColor Gray "Loading class file $file"
Expand Down
3 changes: 2 additions & 1 deletion Private/Import-Type.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ Function Import-Type {

# Check Module Debug Variable
if (-not $Debug) {
# BUG: this debuf tests does not work in SHiPS
try {
# In production, check if the TypeName already exists. Only Add TypeDefinition when needed
New-Object $Path.basename | Out-Null
# New-Object $Path.basename | Out-Null
# Object creation succeeded, no need to add the Type again
return
} catch {
Expand Down

0 comments on commit 61d11ea

Please sign in to comment.