Public/Receive-IBFile.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function Receive-IBFile {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory=$True)]
        [Alias('name')]
        [string]$FunctionName,
        [Parameter(Mandatory=$True)]
        [string]$OutFile,
        [Alias('args')]
        [hashtable]$FunctionArgs,
        [Alias('type')]
        [string]$ObjectType = 'fileop',
        [ValidateScript({Test-NonEmptyString $_ -ThrowOnFail})]
        [Alias('host')]
        [string]$WAPIHost,
        [ValidateScript({Test-VersionString $_ -ThrowOnFail})]
        [Alias('version')]
        [string]$WAPIVersion,
        [PSCredential]$Credential,
        [switch]$SkipCertificateCheck
    )

    Begin {
        # grab the variables we'll be using for our REST calls
        $opts = Initialize-CallVars @PSBoundParameters
    }

    Process {

        # requestion the download token and url
        $response = Invoke-IBFunction -ObjectType $ObjectType `
            -FunctionName $FunctionName -FunctionArgs $FunctionArgs @opts -EA Stop
        $dlUrl = $response.url

        # try to download the file
        try {
            $dlOpts = @{
                Credential = $opts.Credential
                SkipCertificateCheck = $true
                ContentType = 'application/force-download'
            }
            Invoke-IBWAPI -Uri $dlUrl -OutFile $OutFile @dlOpts -EA Stop
        }
        finally {
            # inform Infoblox that the download is complete
            if ($response.token) {
                $null = Invoke-IBFunction -ObjectType 'fileop' `
                    -FunctionName 'downloadcomplete' -FunctionArgs @{token=$response.token} @opts
            }
        }

    }




    <#
    .SYNOPSIS
        Download a file from a fileop function
 
    .DESCRIPTION
        This is a wrapper around the various fileop functions that allow data export from Infoblox.
 
    .PARAMETER FunctionName
        The name of the fileop download function to call.
 
    .PARAMETER OutFile
        Specifies the output file that this cmdlet saves the response body. Enter a path and file name. If you omit the path, the default is the current location.
 
    .PARAMETER FunctionArgs
        A hashtable with the required parameters for the function. NOTE: 'token' parameters are handled automatically and can be ignored.
 
    .PARAMETER ObjectType
        Object type string. (e.g. network, record:host, range)
 
    .PARAMETER WAPIHost
        The fully qualified DNS name or IP address of the Infoblox WAPI endpoint (usually the grid master). This parameter is required if not already set using Set-IBConfig.
 
    .PARAMETER WAPIVersion
        The version of the Infoblox WAPI to make calls against (e.g. '2.2').
 
    .PARAMETER Credential
        Username and password for the Infoblox appliance. This parameter is required unless it was already set using Set-IBConfig.
 
    .PARAMETER SkipCertificateCheck
        If set, SSL/TLS certificate validation will be disabled. Overrides value stored with Set-IBConfig.
 
    .EXAMPLE
        Receive-IBFile getgriddata .\backup.tar.gz -args @{type='BACKUP'}
 
        Download a grid backup file using the 'getgriddata' fileop function.
 
    .EXAMPLE
        Receive-IBFile csv_export .\host-records.csv -args @{_object='record:host'}
 
        Download a CSV export of all host records using the 'csv_export' fileop function.
 
    .LINK
        Project: https://github.com/rmbolger/Posh-IBWAPI
 
    .LINK
        Invoke-IBFunction
 
    #>

}