To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

...
 
Commits (3)
$script:IAMCreds = $null
$script:ApiHost = "https://iam.password.ethz.ch/iam-ws-legacy"
$script:ApiHost = "https://vmiam42.ethz.ch:8443/iam-ws-legacy"
$script:DebugMode = $false
$Public = @( Get-ChildItem -Path "$PSScriptRoot\Public" -Include "*.ps1" -Recurse -ErrorAction SilentlyContinue )
......
......@@ -5,20 +5,20 @@ Function Write-RequestToConsole {
[string]$JsonBody
)
Write-Debug "-- || -- || -- || -- || --"
Write-Verbose "-- || -- || -- || -- || --"
Write-Debug "$($Method.toUpper()) $Uri"
Write-Verbose "$($Method.toUpper()) $Uri"
foreach ($h in $Headers.Keys) {
# Do not print basic auth string to console, instead override with some value
if ($h -ne "Authorization") {
Write-Debug "${h}: $($Headers[$h])"
Write-Verbose "${h}: $($Headers[$h])"
}
else {
Write-Debug "${h}: Basic BasicAuthString99999="
Write-Verbose "${h}: Basic BasicAuthString99999="
}
}
Write-Debug "Body: $JsonBody"
Write-Verbose "Body: $JsonBody"
}
......@@ -26,9 +26,9 @@ function Write-ResponseToConsole {
param (
$Response
)
Write-Debug "------ RESPONSE:"
Write-Verbose "------ RESPONSE:"
if ($null -ne $Response) {
Write-Debug (ConvertTo-Json $Response)
Write-Verbose (ConvertTo-Json $Response)
}
}
......
function Test-IsIAMClientInitialized {
if ($null -eq $script:IAMCreds) {
throw "Please initialize the client to use this function"
return $false
Initialize-IAMClient
return $true
}
return $true
......
$script:IAMCreds = $null
$script:ApiHost = "https://iam.password.ethz.ch/iam-ws-legacy"
$script:DebugMode = $false
\ No newline at end of file
$script:DebugMode = $true
\ No newline at end of file
......@@ -57,8 +57,8 @@ Function Invoke-IAMMethod {
PROCESS {
if ($PSCmdlet.ShouldProcess($Url)) {
try {
# only provide the bdoy when needed, as it gives an error when used with GET
if ($Method -eq "Get") {
# only provide the body when needed, as it gives an error when used with GET
if ($Method -eq [Microsoft.PowerShell.Commands.WebRequestMethod]::Get) {
$Response = Invoke-RestMethod -Uri $Uri -Method $Method -Headers $Headers
}
else {
......@@ -80,10 +80,17 @@ Function Invoke-IAMMethod {
}
try {
$errResponse = ConvertFrom-Json $_
try {
$errResponse = ConvertFrom-Json $_
}
catch {
Write-Error -Message $_.Exception.Message -Exception $_
return
}
Write-Error -Message ($errResponse.level + " -> " + $errResponse.message)
return
} catch {
}
catch {
throw "API Request failed. Message: $_"
}
}
......
......@@ -58,8 +58,8 @@ function Find-ETHGroup {
}
Invoke-IAMMethod -Url $url -Method Get -Credentials $script:IAMCreds |
ForEach-Object { $_.pstypenames.Insert(0, "ETHZ.ID.IAMClient.IAMGroupSearchResult"); $_ } |
Sort-Object AdminGroup, type, Name
ForEach-Object { $_.pstypenames.Insert(0, "ETHZ.ID.IAMClient.IAMGroupSearchResult"); $_ } |
Sort-Object AdminGroup, type, Name
}
END {
......
......@@ -58,11 +58,11 @@ function New-ETHGroup {
PROCESS {
$Body = @{
"name" = $Name
"name" = $Name
"description" = $Description
"admingroup" = $AdminGroup
"members" = $Members
"targets" = $Targets
"admingroup" = $AdminGroup
"members" = $Members
"targets" = $Targets
}
Invoke-IAMMethod -Url $url -Method Post -Body $Body -Credentials $script:IAMCreds
......
......@@ -43,5 +43,5 @@ function Remove-ETHGroupMember {
}
}
END {}
END { }
}
\ No newline at end of file
......@@ -60,18 +60,18 @@ function Set-ETHGroup {
$url = "/groupmgr/group/$Identity"
$Body = @{}
$Body = @{ }
if ($NewName){$Body["name"] = $NewName}
if ($Description){$Body["description"] = $Description}
if ($Targets){$Body["targets"] = $Targets}
if ($AdminGroup){$Body["admingroup"] = $AdminGroup}
if ($NewName) { $Body["name"] = $NewName }
if ($Description) { $Body["description"] = $Description }
if ($Targets) { $Body["targets"] = $Targets }
if ($AdminGroup) { $Body["admingroup"] = $AdminGroup }
if ($body.Count -gt 0){
if ($body.Count -gt 0) {
Invoke-IAMMethod -Url $url -Method Put -Body $Body -Credentials $script:IAMCreds -ea Continue
}
$Identity = if ($NewName){$NewName} else {$Identity}
$Identity = if ($NewName) { $NewName } else { $Identity }
Get-ETHGroup $Identity
}
......
......@@ -27,7 +27,7 @@ function Set-ETHGroupMember {
pscustomobject. Returns a custom object with 3 properties Added, Removed and Kept to show what the cmdlet did
#>
[CmdletBinding(SupportsShouldProcess=$true,HelpUri="https://gitlab.ethz.ch/aurels/iam-powershell/tree/master/docs/Set-ETHGroupMember.md")]
[CmdletBinding(SupportsShouldProcess = $true, HelpUri = "https://gitlab.ethz.ch/aurels/iam-powershell/tree/master/docs/Set-ETHGroupMember.md")]
[OutputType([PSCustomObject])]
param(
# Group Name
......@@ -80,9 +80,9 @@ function Set-ETHGroupMember {
}
return @{
Added = $ToBeAdded;
Added = $ToBeAdded;
Removed = $ToBeRemoved;
Kept = $MemberCompare.ToKeep;
Kept = $MemberCompare.ToKeep;
}
}
......
......@@ -41,7 +41,7 @@ function Sync-ETHGroupMember {
#>
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName="ToGroup")]
[CmdletBinding(SupportsShouldProcess = $true, DefaultParameterSetName = "ToGroup")]
[OutputType([System.Collections.HashTable])]
param(
# Group Name
......@@ -114,11 +114,11 @@ function Sync-ETHGroupMember {
$ListsToProcess = @()
$GroupsToProcess = @()
if ($SourceLists.Count -gt 0) {
if ($SourceLists.Count -gt 0) {
$ListsToProcess = @($SourceLists | ForEach-Object { [PSCustomObject]@{Name = $_; Type = "List" } })
}
if ($SourceGroups.Count -gt 0){
if ($SourceGroups.Count -gt 0) {
$GroupsToProcess = @($SourceGroups | ForEach-Object { [PSCustomObject]@{Name = $_; Type = "Group" } })
}
}
......
......@@ -6,7 +6,7 @@ function Get-ETHMaillistMember {
[string]$Identity
)
BEGIN {}
BEGIN { }
PROCESS {
......
......@@ -29,7 +29,7 @@ function Set-ETHMaillistMembers {
# Add members
try {
if ($ToAddMembers.Count -gt 0){
if ($ToAddMembers.Count -gt 0) {
$null = Add-ETHMaillistMember -Identity $Identity -Members $ToAddMembers
Write-Debug "Successfully added $($ToAddMembers.Count) new members to Mailinglist $Identity"
}
......@@ -41,7 +41,7 @@ function Set-ETHMaillistMembers {
# Remove members
try {
if ($ToRemoveMembers.Count -gt 0){
if ($ToRemoveMembers.Count -gt 0) {
$null = Remove-ETHMaillistMember -Identity $Identity -Members $ToRemoveMembers
Write-Debug "Successfully removed $($ToRemoveMembers.Count) members from Mailinglist $Identity"
}
......@@ -52,9 +52,9 @@ function Set-ETHMaillistMembers {
}
return @{
Added = $ToAddMembers;
Added = $ToAddMembers;
Removed = $ToRemoveMembers;
Kept = $MemberCompare.ToKeep;
Kept = $MemberCompare.ToKeep;
}
}
}
\ No newline at end of file
......@@ -39,7 +39,7 @@ function Get-ETHUserGroupMembership {
$groups | Add-Member -MemberType NoteProperty -Value $Identity -Name "User"
# set type for all objects
$groups | ForEach-Object {$_.pstypenames.Insert(0, "ETHZ.ID.IAMClient.IAMGroupMembership")}
$groups | ForEach-Object { $_.pstypenames.Insert(0, "ETHZ.ID.IAMClient.IAMGroupMembership") }
return ($groups | Sort-Object -property Type, Name)
......
......@@ -10,20 +10,14 @@ function Set-ETHUser {
[string]$Service = "Mailbox"
)
BEGIN {
# Check if client is initialized
Test-IsIAMClientInitialized | Out-Null
$sourceUser = Get-ETHUser -Identity $Identity
$changedProperties = Get-ObjectDiffs $sourceUser $User
}
# Check if client is initialized
$null = Test-IsIAMClientInitialized
PROCESS {
$result = Invoke-IAMMethod -Url "/usermgr/user/$Identity/service/$Service" -Method Put -Body $changedProperties -Credentials $script:IAMCreds
}
$sourceUser = Get-ETHUser -Identity $Identity
$changedProperties = Get-ObjectDiffs $sourceUser $User
END {
$result
return (Get-ETHUser -Identity $Identity)
}
Invoke-IAMMethod -Url "/usermgr/user/$Identity/service/$Service" -Method Put -Body $changedProperties -Credentials $script:IAMCreds
}
\ No newline at end of file
......@@ -5,12 +5,13 @@ function Initialize-IAMClient {
[Parameter(Position = 1, Mandatory = 1)]
[pscredential]$Credentials,
[switch]$Force
[switch]$Force,
[switch]$EnableDebugOutput
)
if ($null -ne $script:IAMCreds -and $Force -eq $false) {
Write-Error "The Client is already initialized, use the -Force Switch to override credentials"
return
if ($Force -eq $true) {
Write-Warning "The -Force switch is included for backwards compatibility only, it has no functionality"
}
if (-not (Test-ETHCredentials $Credentials)) {
......@@ -18,12 +19,12 @@ function Initialize-IAMClient {
}
# Enable Debug mode for script
if ($PSBoundParameters.Debug.IsPresent) {
if ($EnableDebugOutput) {
$script:DebugMode = $true
$DebugPreference = "Continue"
$VerbosePreference = "Continue"
}
else {
$DebugPreference = "SilentlyContinue"
$VerbosePreference = "SilentlyContinue"
}
$script:IAMCreds = $Credentials
......