Public/RestTimeout.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
#
# Copyright 2018, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
# Copyright 2018, Cédric Moreau <moreaucedric0 at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
#

function Get-ArubaSWRestSessionTimeout {

    <#
        .SYNOPSIS
        Get REST Session Timeout when you connect to a switch
 
        .DESCRIPTION
        Get REST Session Timeout
 
        .EXAMPLE
        Get-ArubaSWRestSessionTimeout
        This function give you idle time (in seconds) before being disconnected
    #>


    Param(
        [Parameter (Mandatory=$False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection=$DefaultArubaSWConnection
    )
    Begin {
    }

    Process {

        $uri = "rest/v4/session-idle-timeout"

        $response = Invoke-ArubaSWWebRequest -method "GET" -uri $uri -connection $connection

        $run = ($response | ConvertFrom-Json).timeout

        $run

    }

    End {
    }
}



function Set-ArubaSWRestSessionTimeout {

    <#
        .SYNOPSIS
        Set REST Session Timeout when you connect to a switch
 
        .DESCRIPTION
        Set REST Session Timeout
 
        .EXAMPLE
        Set-ArubaSWRestSessionTimeout 1200
        This function allow you to set idle time (in seconds) before being disconnected.
 
        .EXAMPLE
        Set-ArubaSWRestSessionTimeout -timeout 120
        This function allow you to set idle time (in seconds) before being disconnected with the parameter timeout.
    #>


    Param(
        [Parameter (Mandatory = $true, Position = 1)]
        [ValidateRange(120, 7200)]
        [int]$timeout,
        [Parameter (Mandatory=$False)]
        [ValidateNotNullOrEmpty()]
        [PSObject]$connection=$DefaultArubaSWConnection
    )

    Begin {
    }

    Process {

        $uri = "rest/v4/session-idle-timeout"

        $time = New-Object -TypeName PSObject

        if ( $PsBoundParameters.ContainsKey('timeout') ) {
            $time | Add-Member -name "timeout" -membertype NoteProperty -Value $timeout
        }

        $response = Invoke-ArubaSWWebRequest -method "PUT" -body $time -uri $uri -connection $connection

        $run = ($response | ConvertFrom-Json).timeout

        $run

    }

    End {
    }
}