This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSet-GitLabUser.ps1
266 lines (244 loc) · 6.22 KB
/
Set-GitLabUser.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
function Set-GitLabUser
{
<#
.SYNOPSIS
Set properties on specified user.
.DESCRIPTION
The Set-GitlabUser function sets properties on the specified user.
returns modified user when -PassThru is specified
.EXAMPLE
Set-GitLabUser -id 1 -bio 'awesome root acocunt'
---------------------------------------------------------------
Sets the bio of user with id 1 to awesome root account
.EXAMPLE
#>
[CmdletBinding()]
[Alias()]
[OutputType()]
Param
(
#ID of yhe user
[Parameter(HelpMessage = 'User ID',
Mandatory = $true)]
[Alias('ID')]
[int]$UserID,
#Email of the user
[Parameter(HelpMessage = 'Email for user')]
[ValidateScript({
if($_ -match "^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])$")
{
$true
}
else
{
Throw "$_ is not a valid email address"
}
})]
[string]$Email,
#Password of the user
[Parameter(HelpMessage = 'password user')]
[ValidatePattern('(?# Error: Password Must Contain at least 8 characters).{8,}')]
[ValidateScript({
if($_ -match "^.{8,}$")
{
$true
}
else
{
Throw 'Password Must Contain at least 8 characters'
}
})]
[string]$Password,
#Username of the user
[Parameter(HelpMessage = 'users username')]
[string]$UserName,
#Name of the user
[Parameter(HelpMessage = 'users name')]
[string]$Name,
#Skype ID of the user
[Parameter(HelpMessage = 'users Skype ID',
Mandatory = $false)]
[string]$Skype,
#LinkedIn of the user
[Parameter(HelpMessage = 'users LinkedIn ID',
Mandatory = $false)]
[string]$LinkedIn,
#Twitter Accountof the user
[Parameter(HelpMessage = 'users Twitter Account',
Mandatory = $false)]
[string]$Twitter,
#Website URL of the user
[Parameter(HelpMessage = 'users Website URL',
Mandatory = $false)]
[string]$WebsiteURL,
#Organisation of the user
[Parameter(HelpMessage = 'users Organisation',
Mandatory = $false)]
[string]$Organization,
#Number of projects user can create
[Parameter(HelpMessage = 'Number of projects user can create',
Mandatory = $false)]
[int]$ProjectsLimit,
#External UID of the user
[Parameter(HelpMessage = 'users External UID',
Mandatory = $false)]
[string]$ExternUID,
#external providers name of the user
[Parameter(HelpMessage = 'users external provider name',
Mandatory = $false)]
[string]$Provider,
#User's biography
[Parameter(HelpMessage = "User's biography",
Mandatory = $false)]
[ValidateScript({
if($_ -match "^.{0,250}$")
{
$true
}
else
{
Throw 'Bio must contain at most 250 characters'
}
})]
[string]$Bio,
#Location of the user
[Parameter(HelpMessage = 'users Location',
Mandatory = $false)]
[String]$Location,
#User is admin
[Parameter(HelpMessage = 'User is admin',
Mandatory = $false)]
[Boolean]$Admin,
#User can create groups
[Parameter(HelpMessage = 'can create groups',
Mandatory = $false)]
[Boolean]$CanCreateGroup,
#Flags the user as external
[Parameter(HelpMessage = 'Flags the user as external',
Mandatory = $false)]
[Boolean]$External,
# Existing GitlabConnector Object, can be retrieved with Get-GitlabConnect
[Parameter(HelpMessage = 'Specify Existing GitlabConnector',
Mandatory = $false,
DontShow = $true)]
[psobject]$GitlabConnect = (Get-GitLabConnect),
# Passthru the created project
[Parameter(HelpMessage = 'Passthru the created project',
Mandatory = $false)]
[switch]$PassThru
)
$httpmethod = 'put'
$apiurl = "users/$UserID"
$parameters = @{}
#email - Email
if($Email)
{
$parameters.email = $Email
}
#password - Password
if($Password)
{
$parameters.password = $Password
}
#username - Username
if($UserName)
{
$parameters.username = $UserName
}
#name - Name
if($Name)
{
$parameters.name = $Name
}
#skype (optional) - Skype ID
if($Skype)
{
$parameters.'skype' = $Skype
}
#linkedin (optional) - LinkedIn
if($LinkedIn)
{
$parameters.'linkedin' = $LinkedIn
}
#twitter (optional) - Twitter account
if($Twitter)
{
$parameters.'twitter' = $Twitter
}
#website_url (optional) - Website URL
if($WebsiteURL)
{
$parameters.'website_url' = $WebsiteURL
}
#organization (optional) - Organization name
if($Organization)
{
$parameters.'organisation' = $Organization
}
#projects_limit (optional) - Number of projects user can create
if($ProjectsLimit)
{
$parameters.'projects_limit' = $ProjectsLimit
}
#extern_uid (optional) - External UID
if($ExternUID)
{
$parameters.'extern_uid' = $ExternUID
}
#provider (optional) - External provider name
if($Provider)
{
$parameters.'provider' = $Provider
}
#bio (optional) - User's biography
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Bio')
{
$parameters.'bio' = $Bio.ToString()
}
#location (optional) - User's location
if($Location)
{
$parameters.'location' = $Location
}
#admin (optional) - User is admin
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Admin')
{
if($Admin)
{
$parameters.admin = 'true'
}
else
{
$parameters.admin = 'false'
}
}
#can_create_group (optional) - User can create groups
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'CanCreateGroup')
{
if($CanCreateGroup)
{
$parameters.'can_create_group' = 'true'
}
else
{
$parameters.'can_create_group' = 'false'
}
}
#external (optional) - Flags the user as external
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'External')
{
if($External)
{
$parameters.'external' = 'true'
}
else
{
$parameters.'external' = 'false'
}
}
$modusr = $GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
if($PassThru)
{
return $modusr
}
}