labclient 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/labclient.rb +19 -3
- data/lib/labclient/access_levels.rb +24 -30
- data/lib/labclient/client.rb +54 -7
- data/lib/labclient/commits/project_helpers.rb +4 -0
- data/lib/labclient/commits/show.rb +11 -2
- data/lib/labclient/common.rb +15 -6
- data/lib/labclient/docs.rb +9 -5
- data/lib/labclient/files/update.rb +1 -1
- data/lib/labclient/generator/generator.rb +7 -7
- data/lib/labclient/generator/template_helper.rb +0 -1
- data/lib/labclient/generator/wizard.rb +6 -2
- data/lib/labclient/groups/clusters/add.rb +46 -0
- data/lib/labclient/groups/clusters/client.rb +17 -0
- data/lib/labclient/groups/clusters/delete.rb +36 -0
- data/lib/labclient/groups/clusters/group_cluster.rb +37 -0
- data/lib/labclient/groups/clusters/list.rb +28 -0
- data/lib/labclient/groups/clusters/show.rb +29 -0
- data/lib/labclient/groups/clusters/update.rb +44 -0
- data/lib/labclient/groups/group.rb +14 -1
- data/lib/labclient/http.rb +1 -1
- data/lib/labclient/issues/issue.rb +17 -0
- data/lib/labclient/issues/update.rb +20 -2
- data/lib/labclient/jobs/delete.rb +1 -1
- data/lib/labclient/jobs/keep.rb +1 -1
- data/lib/labclient/jobs/play.rb +1 -1
- data/lib/labclient/jobs/trace.rb +2 -2
- data/lib/labclient/klass.rb +6 -6
- data/lib/labclient/lab_struct.rb +4 -0
- data/lib/labclient/members/member.rb +1 -0
- data/lib/labclient/notes/epics/create.rb +8 -0
- data/lib/labclient/notes/issues/create.rb +8 -0
- data/lib/labclient/notes/merge_requests/create.rb +8 -0
- data/lib/labclient/overview.rb +104 -12
- data/lib/labclient/paginated_response.rb +2 -0
- data/lib/labclient/projects/clusters/add.rb +1 -1
- data/lib/labclient/projects/clusters/delete.rb +5 -6
- data/lib/labclient/projects/clusters/show.rb +2 -2
- data/lib/labclient/projects/clusters/update.rb +13 -5
- data/lib/labclient/projects/environments/project_environment.rb +10 -0
- data/lib/labclient/projects/forks/fork.rb +0 -2
- data/lib/labclient/projects/methods.rb +23 -0
- data/lib/labclient/projects/reference.rb +7 -0
- data/lib/labclient/projects/stars/starrers.rb +0 -2
- data/lib/labclient/protected_branches/protect.rb +6 -5
- data/lib/labclient/protected_environments/list.rb +29 -0
- data/lib/labclient/protected_environments/protect.rb +53 -0
- data/lib/labclient/protected_environments/protected_environment.rb +22 -0
- data/lib/labclient/protected_environments/show.rb +24 -0
- data/lib/labclient/protected_environments/unprotect.rb +31 -0
- data/lib/labclient/users/membership.rb +62 -0
- data/lib/labclient/users/memberships.rb +8 -3
- data/lib/labclient/users/user.rb +1 -1
- data/lib/labclient/version.rb +1 -1
- metadata +19 -6
@@ -11,6 +11,14 @@ module LabClient
|
|
11
11
|
DOC
|
12
12
|
end
|
13
13
|
|
14
|
+
doc 'Merge Request' do
|
15
|
+
desc 'Via Merge Request'
|
16
|
+
example <<~DOC
|
17
|
+
merge_request = client.merge_requests.show(16, 2)
|
18
|
+
merge_request.note_create(body: 'There!')
|
19
|
+
DOC
|
20
|
+
end
|
21
|
+
|
14
22
|
doc 'Merge Requests' do
|
15
23
|
markdown <<~DOC
|
16
24
|
| Attribute | Type | Required | Description |
|
data/lib/labclient/overview.rb
CHANGED
@@ -7,11 +7,15 @@ module LabClient
|
|
7
7
|
|
8
8
|
doc 'Overview' do
|
9
9
|
title 'About'
|
10
|
-
|
10
|
+
markdown <<~DOC
|
11
11
|
Labclient is another Gitlab API Gem. A focus on ease of use and helpers and snippets.
|
12
12
|
|
13
13
|
<a href="https://github.com/NARKOZ/gitlab">Gitlab</a> is an excellent gem, and is nearly complete in its implementation. While this is still a work in progress and you are looking for general use you should use it.
|
14
|
+
|
15
|
+
Here's a quick whirlwind example of some of the features:
|
14
16
|
DOC
|
17
|
+
|
18
|
+
demo '350689'
|
15
19
|
end
|
16
20
|
|
17
21
|
doc 'Overview' do
|
@@ -44,6 +48,41 @@ module LabClient
|
|
44
48
|
DOC
|
45
49
|
end
|
46
50
|
|
51
|
+
doc 'Authentication' do
|
52
|
+
title 'Named Profiles'
|
53
|
+
markdown 'Within the `~/.gitlab-labclient` you can also specify profile names'
|
54
|
+
example <<~DOC
|
55
|
+
{
|
56
|
+
"prod": {
|
57
|
+
"url": "https://labclient-prod",
|
58
|
+
"token": "super_secure",
|
59
|
+
"paginate": false
|
60
|
+
},
|
61
|
+
"dev": {
|
62
|
+
"url": "https://labclient-dev",
|
63
|
+
"token": "super_secure",
|
64
|
+
"ssl_verify": false,
|
65
|
+
"paginate": true
|
66
|
+
}
|
67
|
+
}
|
68
|
+
DOC
|
69
|
+
end
|
70
|
+
|
71
|
+
doc 'Authentication' do
|
72
|
+
desc 'Manually select a named profile'
|
73
|
+
example <<~DOC
|
74
|
+
client = LabClient::Client.new(profile: 'prod')
|
75
|
+
DOC
|
76
|
+
end
|
77
|
+
|
78
|
+
doc 'Authentication' do
|
79
|
+
desc 'Automatically select via ENV Variables'
|
80
|
+
example <<~DOC
|
81
|
+
ENV['LABCLIENT_PROFILE'] = 'dev'
|
82
|
+
client = LabClient::Client.new
|
83
|
+
DOC
|
84
|
+
end
|
85
|
+
|
47
86
|
doc 'Authentication' do
|
48
87
|
title 'Environment Variables'
|
49
88
|
desc 'If not provided, and credentials file does not exist will attempt to use ENV variables'
|
@@ -167,16 +206,21 @@ module LabClient
|
|
167
206
|
doc 'Other' do
|
168
207
|
title 'Common Helpers'
|
169
208
|
markdown <<~DOC
|
170
|
-
The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples
|
209
|
+
The main api namespaces have a `help` and an `api_methods` methods. These will print out available methods and examples.
|
210
|
+
|
211
|
+
These each accept a filter argument
|
171
212
|
DOC
|
172
213
|
|
173
214
|
result <<~DOC
|
215
|
+
# General Help / Available Methods
|
174
216
|
client.help
|
175
217
|
client.api_methods
|
176
218
|
|
219
|
+
# Show Project specific Methods
|
177
220
|
client.projects.api_methods
|
178
221
|
# => [:show, :list, :create]
|
179
222
|
|
223
|
+
# Show Users specific help
|
180
224
|
client.users.help
|
181
225
|
Users
|
182
226
|
Available Methods
|
@@ -191,6 +235,26 @@ module LabClient
|
|
191
235
|
User
|
192
236
|
- client.users.show(5)
|
193
237
|
- client.users.show(5)
|
238
|
+
|
239
|
+
# General Help Filter
|
240
|
+
client.help :protect
|
241
|
+
Available Methods
|
242
|
+
- protected_branches protected_environments protected_tags
|
243
|
+
|
244
|
+
# Projects Help Filter
|
245
|
+
client.projects.help :cluster
|
246
|
+
Projects
|
247
|
+
Available Methods
|
248
|
+
- clusters
|
249
|
+
|
250
|
+
# Project Object Help
|
251
|
+
project = client.projects.show(16)
|
252
|
+
project.help
|
253
|
+
|
254
|
+
# Project Object Help Filter
|
255
|
+
project.help :member
|
256
|
+
|
257
|
+
|
194
258
|
DOC
|
195
259
|
end
|
196
260
|
|
@@ -209,6 +273,9 @@ module LabClient
|
|
209
273
|
# Awesome Print all details
|
210
274
|
project.valid_group_project_levels
|
211
275
|
# => [:guest, :reporter, :developer, :maintainer, :owner]
|
276
|
+
|
277
|
+
# Select Data from objects with `slice`
|
278
|
+
project.slice(:readme_url, :owner)
|
212
279
|
DOC
|
213
280
|
end
|
214
281
|
|
@@ -253,17 +320,18 @@ module LabClient
|
|
253
320
|
end
|
254
321
|
|
255
322
|
doc 'Other' do
|
256
|
-
title '
|
257
|
-
desc '
|
323
|
+
title 'Quiet'
|
324
|
+
desc 'Error messages by default are printed to STDOUT. This can be supressed via the :quiet setting'
|
258
325
|
|
259
|
-
example
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
326
|
+
example <<~DOC
|
327
|
+
client = LabClient::Client.new(
|
328
|
+
url: 'https://gitlab.labclient',
|
329
|
+
token: 'gitlab api token',
|
330
|
+
quiet: true
|
331
|
+
)
|
332
|
+
|
333
|
+
# Or after the init
|
334
|
+
client.settings[:quiet] = true
|
267
335
|
DOC
|
268
336
|
end
|
269
337
|
|
@@ -291,6 +359,30 @@ module LabClient
|
|
291
359
|
- [API Authentication](https://docs.gitlab.com/ee/api/README.html#authentication)
|
292
360
|
DOC
|
293
361
|
end
|
362
|
+
|
363
|
+
doc 'Docker' do
|
364
|
+
desc 'A docker image is created from master and can be used to execute snippets or load a quick pry session'
|
365
|
+
|
366
|
+
example 'docker run -it registry.gitlab.com/labclient/labclient'
|
367
|
+
|
368
|
+
result <<~DOC
|
369
|
+
# Run Container
|
370
|
+
docker run -it registry.gitlab.com/labclient/labclient
|
371
|
+
# Without settings configured, initial will prompt for credentials
|
372
|
+
|
373
|
+
client.users.list
|
374
|
+
DOC
|
375
|
+
end
|
376
|
+
|
377
|
+
doc 'Docker' do
|
378
|
+
desc 'The docker container configured and execute code snippets'
|
379
|
+
|
380
|
+
example 'docker run -it registry.gitlab.com/labclient/labclient'
|
381
|
+
|
382
|
+
result <<~DOC
|
383
|
+
docker run -it -e LABCLIENT_URL="https://labclient" -e LABCLIENT_TOKEN="secure_token" labclient 'puts client.users.list.count'
|
384
|
+
DOC
|
385
|
+
end
|
294
386
|
end
|
295
387
|
end
|
296
388
|
# rubocop:enable Metrics/ClassLength
|
@@ -40,7 +40,9 @@ module LabClient
|
|
40
40
|
DOC
|
41
41
|
end
|
42
42
|
|
43
|
+
# rubocop:disable Lint/MissingSuper
|
43
44
|
def respond_to_missing?(method_name, include_private = false); end
|
45
|
+
# rubocop:enable Lint/MissingSuper
|
44
46
|
|
45
47
|
def each_page(&block)
|
46
48
|
yield @array # This will eventually be the whole list
|
@@ -27,7 +27,7 @@ module LabClient
|
|
27
27
|
| --------- | ---- | -------- | ----------- |
|
28
28
|
| name | string | yes | The name of the cluster |
|
29
29
|
| domain | string | no | The base domain of the cluster |
|
30
|
-
| management_project_id | integer | no | The ID of the
|
30
|
+
| management_project_id | integer | no | The ID of the management project for the cluster |
|
31
31
|
| enabled | boolean | no | Determines if cluster is active or not, defaults to true |
|
32
32
|
| managed | boolean | no | Determines if GitLab will manage namespaces and service accounts for this cluster, defaults to true |
|
33
33
|
| platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
|
@@ -11,11 +11,10 @@ module LabClient
|
|
11
11
|
|
12
12
|
doc 'Delete' do
|
13
13
|
markdown <<~DOC
|
14
|
-
| Attribute
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| only_protected_branches| Boolean | no | Determines if only protected branches are clustered. |
|
14
|
+
| Attribute | Type | Required | Description |
|
15
|
+
| --------- | ---- | -------- | ----------- |
|
16
|
+
| `id` | integer | yes | The ID of the project owned by the authenticated user |
|
17
|
+
| `cluster_id` | integer | yes | The ID of the cluster |
|
19
18
|
DOC
|
20
19
|
end
|
21
20
|
|
@@ -23,7 +22,7 @@ module LabClient
|
|
23
22
|
desc 'Via ProjectCluster [Params]'
|
24
23
|
example <<~DOC
|
25
24
|
cluster = client.projects.clusters.list(310).first
|
26
|
-
cluster.
|
25
|
+
cluster.delete
|
27
26
|
DOC
|
28
27
|
end
|
29
28
|
|
@@ -11,11 +11,19 @@ module LabClient
|
|
11
11
|
|
12
12
|
doc 'Update' do
|
13
13
|
markdown <<~DOC
|
14
|
-
| Attribute
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
| Attribute | Type | Required | Description |
|
15
|
+
| --------- | ---- | -------- | ----------- |
|
16
|
+
| name | string | yes | The name of the cluster |
|
17
|
+
| domain | string | no | The base domain of the cluster |
|
18
|
+
| management_project_id | integer | no | The ID of the management project for the cluster |
|
19
|
+
| platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
|
20
|
+
| platform_kubernetes_attributes[token] | string | yes | The token to authenticate against Kubernetes |
|
21
|
+
| platform_kubernetes_attributes[ca_cert] | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
|
22
|
+
| platform_kubernetes_attributes[namespace] | string | no | The unique namespace related to the project |
|
23
|
+
| environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
|
24
|
+
|
25
|
+
`name`, `api_url`, `ca_cert` and `token` can only be updated if the cluster was added through the
|
26
|
+
“Add existing Kubernetes cluster” option or through the “Add existing cluster to project” endpoint.
|
19
27
|
DOC
|
20
28
|
end
|
21
29
|
|
@@ -24,6 +24,14 @@ module LabClient
|
|
24
24
|
client.projects.environments.delete(project_id, id)
|
25
25
|
end
|
26
26
|
|
27
|
+
def show
|
28
|
+
project_id = collect_project_id
|
29
|
+
|
30
|
+
update_self client.projects.environments.show(project_id, id)
|
31
|
+
end
|
32
|
+
|
33
|
+
alias reload show
|
34
|
+
|
27
35
|
def stop
|
28
36
|
project_id = collect_project_id
|
29
37
|
|
@@ -35,6 +43,8 @@ module LabClient
|
|
35
43
|
help do
|
36
44
|
subtitle 'ProjectEnvironment'
|
37
45
|
option 'project', 'Show Project'
|
46
|
+
option 'show', 'Collect/reload environment'
|
47
|
+
option 'reload', 'Collect/reload environment'
|
38
48
|
option 'update', 'Update this environment [Hash]'
|
39
49
|
option 'delete', 'Delete this environment'
|
40
50
|
option 'stop', 'Stop this environment'
|
@@ -476,6 +476,8 @@ module LabClient
|
|
476
476
|
client.projects.environments.show(id, environment_id)
|
477
477
|
end
|
478
478
|
|
479
|
+
alias environment environment_show
|
480
|
+
|
479
481
|
def environment_create(query)
|
480
482
|
client.projects.environments.create(id, query)
|
481
483
|
end
|
@@ -492,6 +494,23 @@ module LabClient
|
|
492
494
|
client.projects.environments.stop(id, environment_id)
|
493
495
|
end
|
494
496
|
|
497
|
+
# Protected Environments
|
498
|
+
def protected_environments
|
499
|
+
client.protected_environments.list(id)
|
500
|
+
end
|
501
|
+
|
502
|
+
def protected_environment(environment_id)
|
503
|
+
client.protected_environments.show(id, environment_id)
|
504
|
+
end
|
505
|
+
|
506
|
+
def protect_environment(query)
|
507
|
+
client.protected_environments.protect(id, query)
|
508
|
+
end
|
509
|
+
|
510
|
+
def unprotect_environment(environment_id)
|
511
|
+
client.protected_environments.unprotect(id, environment_id)
|
512
|
+
end
|
513
|
+
|
495
514
|
# Project Triggers
|
496
515
|
def triggers
|
497
516
|
client.projects.triggers.list(id)
|
@@ -690,6 +709,10 @@ module LabClient
|
|
690
709
|
client.projects.clusters.list(id)
|
691
710
|
end
|
692
711
|
|
712
|
+
def cluster(cluster_id)
|
713
|
+
client.projects.clusters.show(id, cluster_id)
|
714
|
+
end
|
715
|
+
|
693
716
|
# Reload
|
694
717
|
def reload
|
695
718
|
update_self client.projects.show(id)
|
@@ -71,6 +71,12 @@ module LabClient
|
|
71
71
|
option 'environment_update', 'Update project environment [Environment ID, Hash]'
|
72
72
|
option 'environment_stop', 'Stop project environment [Environment ID]'
|
73
73
|
|
74
|
+
# Protected Environments
|
75
|
+
option 'protected_environments', 'List protected environments [String]'
|
76
|
+
option 'protected_environment', 'Show single protected environment [String]'
|
77
|
+
option 'protect_environment', 'Protect a single environment [Hash]'
|
78
|
+
option 'unprotect_environment', 'Unprotect environment [Environment]'
|
79
|
+
|
74
80
|
# Deployments
|
75
81
|
option 'deployments', "List this project's deployments"
|
76
82
|
option 'deployment_create', 'Create project deployment [Hash]'
|
@@ -133,6 +139,7 @@ module LabClient
|
|
133
139
|
|
134
140
|
# Commits
|
135
141
|
option 'commits', 'List Commits [Hash]'
|
142
|
+
option 'commit', 'Show Commit [String/Commit Sha]'
|
136
143
|
option 'commit_create', 'Create new commit [Hash]'
|
137
144
|
option 'commit_refs', 'Get all references (from branches or tags) a commit is pushed to. [Commit ID, Scope]'
|
138
145
|
option 'commit_cherry_pick', 'Cherry picks a commit to a target branch. [Commit ID, Branch]'
|
@@ -19,11 +19,12 @@ module LabClient
|
|
19
19
|
| allowed_to_unprotect | array | no | **(STARTER)** Array of access levels allowed to unprotect, with each described by a hash |
|
20
20
|
| code_owner_approval_required | boolean | no | **(PREMIUM)** Prevent pushes to this branch if it matches an item in the CODEOWNERS file (defaults: false) |
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
**Valid access levels**
|
23
|
+
|
24
|
+
- 0, :none => No access
|
25
|
+
- 30, :developer => Developer access
|
26
|
+
- 40, :maintainer => Maintainer access
|
27
|
+
- 60, :admin => Admin access
|
27
28
|
|
28
29
|
DOC
|
29
30
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Top namespace
|
2
|
+
module LabClient
|
3
|
+
# Specifics
|
4
|
+
class ProtectedEnvironments < Common
|
5
|
+
doc 'List' do
|
6
|
+
desc 'Gets a list of protected environmentes from a project. [Project ID, String]'
|
7
|
+
example 'client.protected_environments.list(36)'
|
8
|
+
result '[#<ProtectedEnvironment name: prod>]'
|
9
|
+
|
10
|
+
markdown <<~DOC
|
11
|
+
Search: You can use ^term and term$ to find environmentes that begin and end with term respectively.
|
12
|
+
DOC
|
13
|
+
end
|
14
|
+
|
15
|
+
doc 'List' do
|
16
|
+
desc 'via Project'
|
17
|
+
example <<~DOC
|
18
|
+
project = client.projects.show(264)
|
19
|
+
project.protected_environments
|
20
|
+
DOC
|
21
|
+
end
|
22
|
+
|
23
|
+
def list(project_id)
|
24
|
+
project_id = format_id(project_id)
|
25
|
+
|
26
|
+
client.request(:get, "projects/#{project_id}/protected_environments", ProtectedEnvironment)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Top namespace
|
2
|
+
module LabClient
|
3
|
+
# Specifics
|
4
|
+
class ProtectedEnvironments < Common
|
5
|
+
doc 'Protect' do
|
6
|
+
desc 'Protects a single environment [Project ID, Hash]'
|
7
|
+
example <<~DOC
|
8
|
+
client.protected_environments.protect(36,
|
9
|
+
name: :prod,
|
10
|
+
deploy_access_levels: [
|
11
|
+
{ access_level: :developer }
|
12
|
+
]
|
13
|
+
)
|
14
|
+
DOC
|
15
|
+
result '#<ProtectedEnvironment name: prod>'
|
16
|
+
|
17
|
+
markdown <<~DOC
|
18
|
+
| Attribute | Type | Required | Description |
|
19
|
+
| -------------------- | -------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |
|
20
|
+
| name | string | yes | The name of the environment. |
|
21
|
+
| deploy_access_levels | array | yes | Array of access levels allowed to deploy, with each described by a hash. |
|
22
|
+
|
23
|
+
Elements in the deploy_access_levels array should take the form {user_id: integer}, {group_id: integer} or {access_level: integer}. Each user must have access to the project and each group must have this project shared.
|
24
|
+
|
25
|
+
**Valid access levels**
|
26
|
+
|
27
|
+
| Access Level | Values |
|
28
|
+
| ------------ | --------------- |
|
29
|
+
| Developer | 30, :developer |
|
30
|
+
| Maintainer | 40, :maintainer |
|
31
|
+
| Admin | 60, :admin |
|
32
|
+
|
33
|
+
DOC
|
34
|
+
end
|
35
|
+
|
36
|
+
doc 'Protect' do
|
37
|
+
desc 'via Project'
|
38
|
+
example <<~DOC
|
39
|
+
project = client.projects.show(264)
|
40
|
+
project.protect_environment(name: :other, push_access_level: :admin)
|
41
|
+
DOC
|
42
|
+
end
|
43
|
+
|
44
|
+
def protect(project_id, query)
|
45
|
+
query[:deploy_access_levels].each do |access_level|
|
46
|
+
protected_query_access_level(access_level, :access_level)
|
47
|
+
end
|
48
|
+
|
49
|
+
project_id = format_id(project_id)
|
50
|
+
client.request(:post, "projects/#{project_id}/protected_environments", ProtectedEnvironment, query)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|