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
/
New-GitLabUser.ps1
267 lines (245 loc) · 7 KB
/
New-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
267
function New-GitLabUser
{
<#
.SYNOPSIS
Creates a new user. Note only administrators can create new users.
.DESCRIPTION
The New-GitlabUser function a new user. Note only administrators can create new users.
returns new user when -PassThru is specified
.EXAMPLE
New-GitLabUser -Email 'John.Johnson@contoso.com' -Password 'randompassword' -UserName 'john.johnson' -Name 'John Johnson'
---------------------------------------------------------------
Creates a useraccount for john johnson with appropriate parameters
.EXAMPLE
NNew-GitLabUser -Email 'John.Johnson@contoso.com' -Password 'randompassword' -UserName 'john.johnson' -Name 'John Johnson' -PassThru
---------------------------------------------------------------
Creates a useraccount for john johnson with appropriate parameters
returns the newly created user
.EXAMPLE
New-GitLabProject -Name 'GitLab-API' -container_registry_enabled $true
---------------------------------------------------------------
Creates a new project named 'Gitlab-API' with container Registry enabled.
#>
[CmdletBinding()]
[Alias()]
[OutputType()]
Param
(
#Email of the new user
[Parameter(HelpMessage = 'new users email',
Mandatory = $true)]
[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 new user
[Parameter(HelpMessage = 'new users password',
Mandatory = $true)]
[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 new user
[Parameter(HelpMessage = 'new users username',
Mandatory = $true)]
[string]$UserName,
#Name of the new user
[Parameter(HelpMessage = 'new users name',
Mandatory = $true)]
[string]$Name,
#Skype ID of the new user
[Parameter(HelpMessage = 'new users Skype ID',
Mandatory = $false)]
[string]$Skype,
#LinkedIn of the new user
[Parameter(HelpMessage = 'new users LinkedIn ID',
Mandatory = $false)]
[string]$LinkedIn,
#Twitter Accountof the new user
[Parameter(HelpMessage = 'new users Twitter Account',
Mandatory = $false)]
[string]$Twitter,
#Website URL of the new user
[Parameter(HelpMessage = 'new users Website URL',
Mandatory = $false)]
[string]$WebsiteURL,
#Organisation of the new user
[Parameter(HelpMessage = 'new 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 new user
[Parameter(HelpMessage = 'new users External UID',
Mandatory = $false)]
[string]$ExternUID,
#external providers name of the new user
[Parameter(HelpMessage = 'new users external provider name',
Mandatory = $false)]
[string]$Provider,
#User's biography
[Parameter(HelpMessage = "User's biography",
Mandatory = $false)]
[string]$Bio,
#Location of the new user
[Parameter(HelpMessage = 'new 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,
#Require confirmation
[Parameter(HelpMessage = 'Require confirmation',
Mandatory = $false)]
[Boolean]$Confirm,
#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 = 'post'
$apiurl = 'users'
$parameters = @{}
#email (required) - Email
$parameters.email = $Email
#password (required) - Password
$parameters.password = $Password
#username (required) - Username
$parameters.username = $UserName
#name (required) - 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($Bio)
{
$parameters.'bio' = $Bio
}
#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'
}
}
#confirm (optional) - Require confirmation
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'Confirm')
{
if($Confirm)
{
$parameters.'confirm' = 'true'
}
else
{
$parameters.'confirm' = 'false'
}
}
#external (optional) - Flags the user as external
if($PSCmdlet.MyInvocation.BoundParameters.keys -contains 'External')
{
if($External)
{
$parameters.'external' = 'true'
}
else
{
$parameters.'external' = 'false'
}
}
$newusr = $GitlabConnect.callapi($apiurl,$httpmethod,$parameters)
if($PassThru)
{
return $newusr
}
}