gitlab-invite.ps1 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. param(
  2. [string]$token=$env:GL_TOKEN,
  3. [string]$server="https://gitlab.corp.wabtec.com",
  4. [string]$group="annax/teams/developers",
  5. [string]$access_level="30",
  6. [switch]$delete,
  7. [Parameter(Mandatory=$true,ValueFromPipeline = $true)]
  8. [string[]]$input
  9. )
  10. Add-Type -AssemblyName System.Web
  11. if (-not (Get-Module Powershell-Yaml)){
  12. Install-Module -Name Powershell-Yaml -Scope CurrentUser -Force
  13. }
  14. Import-Module Powershell-Yaml
  15. $groupid = [System.Web.HttpUtility]::UrlEncode($group)
  16. $uri = ($server + "/api/v4/groups/" + $groupid + "/invitations")
  17. $headers = @{ 'PRIVATE-TOKEN'=$token }
  18. $input | ForEach-Object {
  19. if (-not $delete){
  20. $mail = $_.ToLower()
  21. "Inviting: " + $mail
  22. $body = "email=$mail&access_level=$access_level"
  23. Invoke-RestMethod -Headers $headers -Uri $uri -Method post -Body $body |convertto-yaml
  24. } else {
  25. $mail = $_
  26. "Uninviting: " + $mail
  27. $uri_user = $uri + "/" + $mail
  28. Invoke-RestMethod -Headers $headers -Uri $uri_user -Method delete |convertto-yaml
  29. }
  30. }