Functions/Config/Set-SOCatStoreAccess.psm1

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
#region: Set-SOCatStoreAccess
<#
 .Synopsis
 Permits or denys Client access to a StoreOnce Catalyst Store.
 
 .Description
 Permits or denys Client access to a StoreOnce Catalyst Store.
  
 .Parameter Server
    IP Address oder DNS Name of your StoreOnce system like defined via Connect-SOAppliance (check Get-SOConnections).
 
 .Parameter SOCatClientName
 Name for the Client on your StoreOnce system.
 
 .Parameter SOCatStoreName
 Name for the Store on your StoreOnce system.
 
 .Parameter allowAccess
 $True ore $False
 
 .Example
 Set-SOCatStoreAccess -Server 192.168.2.1 -SOCatClientName MyNewClient -SOCatStoreName MyNewStore -allowAccess:$true
 
#Requires PS -Version 4.0
#>

function Set-SOCatStoreAccess {
    [CmdletBinding()]
    param (
        [parameter(Mandatory=$true, Position=0)]
        [ValidateNotNullOrEmpty()]
            [String]$Server,
        [parameter(Mandatory=$true, Position=1)]
        [ValidateNotNullOrEmpty()]
            [String]$SOCatClientName,
        [parameter(Mandatory=$true, Position=2)]
        [ValidateNotNullOrEmpty()]
            [String]$SOCatStoreName,
        [parameter(Mandatory=$true, Position=3)]
        [ValidateNotNullOrEmpty()]
            [Boolean]$allowAccess
            
    )
    Process {
        if (!$Global:SOConnections) {throw "No StoreOnce Appliance(s) connected! Use 'Connect-SOAppliance'"}
        if ($Server.count -gt 1) {throw "This Command only Supports one D2D System."}
        $Connection = $Global:SOConnections | Where {$_.Server -eq $Server}
        if (!$Connection) {throw "No D2D System found, check Get-SOConnections."}
        if ($Connection.count -gt 1) {throw "This Command only Supports one D2D System. Multiple Matches for $Server found..."}

        if (Test-IP -IP $($Connection.Server)) {
            if (!($SOCaStore = (Get-SOCatStores | where {$_.Name -eq $SOCatStoreName -and $_.System -eq $($Connection.Server)}))) {throw "Store $SOCatStoreName does not exists."}
            if (!($SOCatClient = (Get-SOCatClients | where {$_.Name -eq $SOCatClientName -and $_.System -eq $($Connection.Server) -and $_.SSID -eq $($SOCaStore).SSID}))) {throw "Client $SOCatClientName does not exists."}
            
            $SSID = $($SOCaStore).SSID
            $StoreID = $($SOCaStore).ID
            $ClientID = $($SOCatClient).ID
            if ($allowAccess -eq $true) {$Access = "true"} else {$Access = "false"}
            $AccessCall = @{uri = "https://$($Connection.Server)/storeonceservices/cluster/servicesets/$SSID/services/cat/stores/$StoreID/permissions/$ClientID";
                            Method = 'PUT';
                            Headers = @{Authorization = 'Basic ' + $($Connection.EncodedPassword);
                                        Accept = 'text/xml';
                                        'Content-Type' = 'application/x-www-form-urlencoded'
                            }
                            Body = @{allowAccess = $Access                        
                            } 
                        }

            $AccessResponse = Invoke-RestMethod @AccessCall
        }
        Return (Get-SOCatStoreAccess -Server $($Connection.Server) -CatStore $SOCaStore.Name | ft * -AutoSize)
        
    }
}
#endregion