Merge pull request #53 from snazy2000/develop

New Release
This commit is contained in:
Stephen 2020-06-17 09:39:02 +01:00 committed by GitHub
commit 8214d8db99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 134 additions and 22 deletions

View file

@ -0,0 +1,64 @@
<#
.SYNOPSIS
Add a new Audit to Snipe-it asset system
.DESCRIPTION
Long description
.PARAMETER Tag
The asset tag of the asset you wish to audit
.PARAMETER Location_id
ID of the location you want to associate with the audit
.EXAMPLE
New-Audit -tag 1 -location_id "Location of Audit"
#>
function New-Audit()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$tag,
[int]$location_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"location_id" = $location_id
}
if ($PSBoundParameters.ContainsKey('tag'))
{
$Values += @{"asset_tag" = $tag}
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/audit"
Method = 'Post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -0,0 +1,48 @@
<#
.SYNOPSIS
Removes Asset to Snipe-it asset system
.DESCRIPTION
Long description
.PARAMETER ID
Unique ID For Asset to be removed
.EXAMPLE
Remove-Asset -ID 44 -url $url -apiKey $secret -Verbose
#>
function Remove-Asset ()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "Low"
)]
Param(
[parameter(mandatory = $true)]
[string]$ID,
[parameter(mandatory = $true)]
[string]$URL,
[parameter(mandatory = $true)]
[string]$APIKey
)
$Values = @{
"ID" = $Name
}
$Body = $Values | ConvertTo-Json
$Parameters = @{
Uri = "$url/api/v1/hardware/$ID"
Method = 'Delete'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess("ShouldProcess?"))
{
$result = Invoke-SnipeitMethod @Parameters
}
$result
}

View file

@ -31,7 +31,7 @@ function Set-Model() {
[string]$apiKey [string]$apiKey
) )
$Values = Copy-Parameters -InputObject $PSBoundParameters $Values = . Get-ParameterValue
$Body = $Values | ConvertTo-Json; $Body = $Values | ConvertTo-Json;

View file

@ -4,7 +4,7 @@ $here = Split-Path -Parent $MyInvocation.MyCommand.Path
$projectRoot = Split-Path -Parent $here $projectRoot = Split-Path -Parent $here
$moduleRoot = "$projectRoot\SnipeitPS" $moduleRoot = "$projectRoot\SnipeitPS"
$script:manifestFile = "$moduleRoot\SnipeitPS.psd1" $manifestFile = "$moduleRoot\SnipeitPS.psd1"
$changelogFile = "$projectRoot\CHANGELOG.md" $changelogFile = "$projectRoot\CHANGELOG.md"
$appveyorFile = "$projectRoot\appveyor.yml" $appveyorFile = "$projectRoot\appveyor.yml"
$publicFunctions = "$moduleRoot\Public" $publicFunctions = "$moduleRoot\Public"
@ -28,7 +28,7 @@ Describe "SnipeitPS" {
# tests goes to Dave Wyatt, the genius behind Pester. I've just adapted them # tests goes to Dave Wyatt, the genius behind Pester. I've just adapted them
# slightly to match SnipeitPS. # slightly to match SnipeitPS.
$script:manifest = $null <#$script:manifest = $null
foreach ($line in (Get-Content $changelogFile)) foreach ($line in (Get-Content $changelogFile))
{ {
@ -53,8 +53,8 @@ Describe "SnipeitPS" {
It "Includes a valid manifest file" { It "Includes a valid manifest file" {
{ {
$script:manifest = Test-ModuleManifest -Path $script:manifestFile -ErrorAction Stop -WarningAction SilentlyContinue $script:manifest = Test-ModuleManifest -Path "$moduleRoot\SnipeitPS.psd1" -ErrorAction Stop -WarningAction SilentlyContinue
} | Should Not Throw } | Should -Not Throw
} }
# There is a bug that prevents Test-ModuleManifest from updating correctly when the manifest file changes. See here: # There is a bug that prevents Test-ModuleManifest from updating correctly when the manifest file changes. See here:
@ -63,49 +63,49 @@ Describe "SnipeitPS" {
# As a temp workaround, we'll just read the manifest as a raw hashtable. # As a temp workaround, we'll just read the manifest as a raw hashtable.
# Credit to this workaround comes from here: # Credit to this workaround comes from here:
# https://psescape.azurewebsites.net/pester-testing-your-module-manifest/ # https://psescape.azurewebsites.net/pester-testing-your-module-manifest/
$script:manifest = Invoke-Expression (Get-Content $script:manifestFile -Raw) $script:manifest = Invoke-Expression (Get-Content "$moduleRoot\SnipeitPS.psd1" -Raw)
It "Manifest file includes the correct root module" { It "Manifest file includes the correct root module" {
$script:manifest.RootModule | Should Be 'SnipeitPS' $script:manifest.RootModule | Should -Be 'SnipeitPS'
} }
It "Manifest file includes the correct guid" { It "Manifest file includes the correct guid" {
$script:manifest.Guid | Should Be 'f86f4db4-1cb1-45c4-b7bf-6762531bfdeb' $script:manifest.Guid | Should -Be 'f86f4db4-1cb1-45c4-b7bf-6762531bfdeb'
} }
It "Manifest file includes a valid version" { It "Manifest file includes a valid version" {
# $script:manifest.Version -as [Version] | Should Not BeNullOrEmpty # $script:manifest.Version -as [Version] | Should Not BeNullOrEmpty
$script:manifest.ModuleVersion -as [Version] | Should Not BeNullOrEmpty $script:manifest.ModuleVersion -as [Version] | Should -Not BeNullOrEmpty
} }
It "Includes a changelog file" { It "Includes a changelog file" {
$changelogFile | Should Exist $changelogFile | Should -Exist
} }
# $changelogVersion = $null # $changelogVersion = $null
It "Changelog includes a valid version number" { It "Changelog includes a valid version number" {
$changelogVersion | Should Not BeNullOrEmpty $changelogVersion | Should -Not BeNullOrEmpty
$changelogVersion -as [Version] | Should Not BeNullOrEmpty $changelogVersion -as [Version] | Should -Not BeNullOrEmpty
} }
It "Changelog version matches manifest version" { It "Changelog version matches manifest version" {
$changelogVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) $changelogVersion -as [Version] | Should -Be ( $script:manifest.ModuleVersion -as [Version] )
} }
# Back to me! Pester doesn't use AppVeyor, as far as I know, and I do. # Back to me! Pester doesn't use AppVeyor, as far as I know, and I do.
It "Includes an appveyor.yml file" { It "Includes an appveyor.yml file" {
$appveyorFile | Should Exist $appveyorFile | Should -Exist
} }
It "Appveyor.yml file includes the module version" { It "Appveyor.yml file includes the module version" {
$appveyorVersion | Should Not BeNullOrEmpty $appveyorVersion | Should -Not BeNullOrEmpty
$appveyorVersion -as [Version] | Should Not BeNullOrEmpty $appveyorVersion -as [Version] | Should -Not BeNullOrEmpty
} }
It "Appveyor version matches manifest version" { It "Appveyor version matches manifest version" {
$appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) $appveyorVersion -as [Version] | Should -Be ( $script:manifest.ModuleVersion -as [Version] )
} }#>
} }
# The CI changes I'm testng now will render this section obsolete, # The CI changes I'm testng now will render this section obsolete,
@ -129,13 +129,13 @@ Describe "SnipeitPS" {
# foreach ($f in $functionFiles) { # foreach ($f in $functionFiles) {
# It "Exports $f" { # It "Exports $f" {
# $exportedFunctions -contains $f | Should Be $true # $exportedFunctions -contains $f | Should -Be $true
# } # }
# } # }
# foreach ($f in $internalFiles) { # foreach ($f in $internalFiles) {
# It "Does not export $f" { # It "Does not export $f" {
# $exportedFunctions -contains $f | Should Be $false # $exportedFunctions -contains $f | Should -Be $false
# } # }
# } # }
# } # }
@ -204,7 +204,7 @@ Describe "SnipeitPS" {
$analysis | $analysis |
Where-Object RuleName -EQ $rule -OutVariable failures | Where-Object RuleName -EQ $rule -OutVariable failures |
Out-Default Out-Default
$failures.Count | Should Be 0 $failures.Count | Should -Be 0
} }
} }
} }

View file

@ -29,7 +29,7 @@ New-Asset -status_id 1 -model_id 1 -name "Machine1"
### -------------------------- EXAMPLE 2 -------------------------- ### -------------------------- EXAMPLE 2 --------------------------
``` ```
New-Asset -status_id 1 -model_id 1 -name "Machine1" -CustomValues = @{ "_snipeit_os_5 = "Windows 10 Pro" } New-Asset -status_id 1 -model_id 1 -name "Machine1" -customfields = @{ "_snipeit_os_5" = "Windows 10 Pro" }
``` ```
## PARAMETERS ## PARAMETERS