change structure

This commit is contained in:
Stephen Maunder 2017-11-19 20:57:27 +00:00
parent 4dface3fa7
commit c860da790f
20 changed files with 409 additions and 249 deletions

View file

@ -1,177 +0,0 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Assets
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..."
.EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" }
#>
function Get-Asset()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$result = Invoke-Method -URi "$url/api/v1/hardware" `
-Method GET `
-Token $apiKey
$result
}
function New-Asset()
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$Name,
[parameter(mandatory=$true)]
[string]$Status_id,
[parameter(mandatory=$true)]
[string]$Model_id,
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey,
[hashtable] $customfields
)
$Values = @{
"name" = $Name
"status_id" = $status_id
"model_id" = $model_id
}
$Values += $customfields
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware"
Method = 'Post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result
}
function Set-Asset()
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[int]$id,
[parameter(mandatory=$true)]
[string]$Name,
[parameter(mandatory=$true)]
[string]$Status_id,
[parameter(mandatory=$true)]
[string]$Model_id,
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey,
[hashtable] $customfields
)
$Values = @{
"name" = $Name
"status_id" = $status_id
"model_id" = $model_id
}
$Values += $customfields
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result
}
function Set-AssetOwner()
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[int]$id,
[parameter(mandatory=$true)]
[int]$user_id,
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$Values = @{
"user_id" = $user_id
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
return $result
}

View file

@ -0,0 +1,40 @@
<#
.SYNOPSIS
# Gets a list of Snipe-it Assets
.PARAMETER url
URL of Snipeit system, can be set using Set-Info command
.PARAMETER apiKey
Users API Key for Snipeit, can be set using Set-Info command
.EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..."
.EXAMPLE
Get-Asset -url "https://assets.dip.co.uk" -token "token..." | Where-Object {$_.name -eq "SUPPORT23" }
#>
function Get-Asset()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$result = Invoke-Method -URi "$url/api/v1/hardware" `
-Method GET `
-Token $apiKey
$result
}

View file

@ -0,0 +1,16 @@
function Get-Model()
{
Param(
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$result = Invoke-Method -URi "$url/api/v1/models" `
-Method GET `
-Token $apiKey
$result
}

View file

@ -1,68 +0,0 @@
function Get-Model()
{
Param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$result = Invoke-Method -URi "$url/api/v1/models" `
-Method GET `
-Token $apiKey
$result
}
function New-Model()
{
[CmdletBinding(
SupportsShouldProcess=$true,
ConfirmImpact="High"
)]
Param(
[parameter(mandatory=$true)]
[string]$name,
[parameter(mandatory=$true)]
[int]$category_id,
[parameter(mandatory=$true)]
[int]$manufacturer_id,
[parameter(mandatory=$true)]
[int]$fieldset_id,
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[string]$apiKey
)
$Values = @{
name = $name
category_id = $category_id
manufacturer_id = $manufacturer_id
fieldset_id = $fieldset_id
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/models"
Method = 'post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess()) {
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,50 @@
function New-Asset()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[string]$Name,
[parameter(mandatory = $true)]
[string]$Status_id,
[parameter(mandatory = $true)]
[string]$Model_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey,
[hashtable] $customfields
)
$Values = @{
"name" = $Name
"status_id" = $status_id
"model_id" = $model_id
}
$Values += $customfields
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware"
Method = 'Post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,76 @@
<#
.SYNOPSIS
Short description
.DESCRIPTION
Long description
.PARAMETER name
Parameter description
.PARAMETER category_id
Parameter description
.PARAMETER qty
Parameter description
.PARAMETER url
Parameter description
.PARAMETER apiKey
Parameter description
.EXAMPLE
An example
.NOTES
General notes
#>
function New-Component()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[parameter(mandatory = $true)]
[string]$category_id,
[parameter(mandatory = $true)]
[string]$qty,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"name" = $name
"category_id" = $category_id
"qty" = $qty
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/components"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,40 @@
function New-Manufacturer()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[string]$Name,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"name" = $Name
}
#Convert Values to JSON format
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/manufacturers"
Method = 'post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,50 @@
function New-Model()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[string]$name,
[parameter(mandatory = $true)]
[int]$category_id,
[parameter(mandatory = $true)]
[int]$manufacturer_id,
[parameter(mandatory = $true)]
[int]$fieldset_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
name = $name
category_id = $category_id
manufacturer_id = $manufacturer_id
fieldset_id = $fieldset_id
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/models"
Method = 'post'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,52 @@
function Set-Asset()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true)]
[string]$Name,
[parameter(mandatory = $true)]
[string]$Status_id,
[parameter(mandatory = $true)]
[string]$Model_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey,
[hashtable] $customfields
)
$Values = @{
"name" = $Name
"status_id" = $status_id
"model_id" = $model_id
}
$Values += $customfields
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id"
Method = 'Put'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -0,0 +1,41 @@
function Set-AssetOwner()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[int]$id,
[parameter(mandatory = $true)]
[int]$user_id,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"user_id" = $user_id
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/hardware/$id/checkout"
Method = 'POST'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
return $result
}

View file

@ -0,0 +1,41 @@
function Set-Component()
{
[CmdletBinding(
SupportsShouldProcess = $true,
ConfirmImpact = "High"
)]
Param(
[parameter(mandatory = $true)]
[string]$id,
[parameter(mandatory = $true)]
[string]$qty,
[parameter(mandatory = $true)]
[string]$url,
[parameter(mandatory = $true)]
[string]$apiKey
)
$Values = @{
"qty" = $qty
}
$Body = $Values | ConvertTo-Json;
$Parameters = @{
Uri = "$url/api/v1/components/$component_id"
Method = 'Patch'
Body = $Body
Token = $apiKey
}
If ($PSCmdlet.ShouldProcess())
{
$result = Invoke-Method @Parameters
}
$result
}

View file

@ -1,11 +1,11 @@
$scriptRoot = $PSScriptRoot + '\public'
Get-ChildItem $scriptRoot *.psm1 | ForEach-Object {
Get-ChildItem $scriptRoot *.psd1 | ForEach-Object {
Import-Module $_.FullName
}
$scriptRoot = $PSScriptRoot + '\private'
Get-ChildItem $scriptRoot *.psm1 | ForEach-Object {
Get-ChildItem $scriptRoot *.psd1 | ForEach-Object {
Import-Module $_.FullName
}
}

View file

@ -8,7 +8,6 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1"
$changelogFile = "$projectRoot\CHANGELOG.md"
$appveyorFile = "$projectRoot\appveyor.yml"
$publicFunctions = "$moduleRoot\Public"
$internalFunctions = "$moduleRoot\Internal"
Describe "SnipeitPS" {
Context "All required tests are present" {