labclient 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4c0988633436f9872d93e241ceb4c85e5b780b5f419a08054231138d8448dc5
4
- data.tar.gz: '06268afb4c985bd5dbffebf72c610aa0c4fe1083af0b86d30d5624a69e25f52e'
3
+ metadata.gz: a747d261d131d7f0a228cb02753e21798c951393941247d0d4252a9c253c5650
4
+ data.tar.gz: 228a9181e7345f607e8d4ab6617d729f9b4b44ab7e1fdcd295db4ed3332a257d
5
5
  SHA512:
6
- metadata.gz: c558d37e33b7efdad2b9e0621c3a0d437e2345cc987403af2c15bed6e1d0a04c926de86442e1595a7fbfb6b0aae63af8583430f4046782edea2362a0ebf946f7
7
- data.tar.gz: 211e88abab828ddc51c7b6a8965a962ec34f95fb4f7e3106611f3af5b5d72e6c75431c3eabedb618a838f29b3b64e4301ed173d38120c9ef4bb0e5b0d45a8e69
6
+ metadata.gz: 2d66d602d12ccd265ae6b1e5aa28c0cdeabbbcc0ee678c5be80a30c42ef342e7b9308acf0a075da04cd4bbb76c744ce32d52122e0f4b87c36c9a9faf09b7834a
7
+ data.tar.gz: c3eaf2cb6c83effec491f071bf0e5de9f2638f68d0af5656ae146915245eb00b091d7a566ef6c28c88db562a9b71cf8b773798fd7890693b098fbc66bdfd9adb
@@ -359,6 +359,15 @@ require 'labclient/groups/badges/update'
359
359
  require 'labclient/groups/badges/delete'
360
360
  require 'labclient/groups/badges/group_badge'
361
361
 
362
+ # Group Clusters
363
+ require 'labclient/groups/clusters/client'
364
+ require 'labclient/groups/clusters/list'
365
+ require 'labclient/groups/clusters/show'
366
+ require 'labclient/groups/clusters/add'
367
+ require 'labclient/groups/clusters/update'
368
+ require 'labclient/groups/clusters/delete'
369
+ require 'labclient/groups/clusters/group_cluster'
370
+
362
371
  require 'labclient/groups/group'
363
372
 
364
373
  # Issues
@@ -82,9 +82,16 @@ module LabClient
82
82
  subclasses.keys.sort
83
83
  end
84
84
 
85
- def help
85
+ def help(help_filter = nil)
86
86
  puts 'Available Methods'
87
- puts " - #{subclasses.keys.sort.join(' ')}\n\n"
87
+
88
+ shown_subclasses = if help_filter
89
+ api_methods.grep(/#{help_filter}/)
90
+ else
91
+ api_methods
92
+ end
93
+
94
+ puts " - #{shown_subclasses.join(' ')}\n\n"
88
95
  puts "See help for each specific sub-category\n"
89
96
  puts "- client.users.help\n"
90
97
  puts "- client.users.api_methods\n"
@@ -12,13 +12,15 @@ module LabClient
12
12
  end
13
13
 
14
14
  def api_methods
15
- public_methods(false)
15
+ public_methods(false).sort
16
16
  end
17
17
 
18
- def help
19
- api_methods_help
18
+ def help(help_filter = nil)
19
+ api_methods_help(help_filter)
20
+
21
+ LabClient::Docs.docs[group_name]&.each do |key, group|
22
+ next if help_filter && !key.downcase.include?(help_filter.to_s)
20
23
 
21
- LabClient::Docs.docs[group_name].each do |key, group|
22
24
  puts "\n=====[ #{key} ]====="
23
25
  group.select { |x| x[:example] }.each { |x| puts "#{x[:example]}\n" }
24
26
  end
@@ -26,10 +28,17 @@ module LabClient
26
28
  nil
27
29
  end
28
30
 
29
- def api_methods_help
31
+ def api_methods_help(help_filter = nil)
30
32
  puts group_name
31
33
  puts ' Available Methods'
32
- puts " #{api_methods.sort.join(' ')}\n"
34
+
35
+ shown_subclasses = if help_filter
36
+ api_methods.grep(/#{help_filter}/)
37
+ else
38
+ api_methods
39
+ end
40
+
41
+ puts " #{shown_subclasses.join(' ')}\n"
33
42
  end
34
43
 
35
44
  # Helper to get docs
@@ -0,0 +1,46 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Add' do
6
+ desc 'Adds an existing Kubernetes cluster to the group. [Group ID, Hash]'
7
+ example <<~DOC
8
+ params = {
9
+ name: 'cluster-5',
10
+ platform_kubernetes_attributes: {
11
+ api_url: 'https://35.111.51.20',
12
+ token: '12345',
13
+ ca_cert: "-----BEGIN .....-----END CERTIFICATE-----"
14
+ }
15
+ }
16
+
17
+ client.groups.clusters.add(310, params)
18
+ DOC
19
+
20
+ result '=> #<GroupCluster id: 2, name: cluster-5>'
21
+ end
22
+
23
+ doc 'Add' do
24
+ markdown <<~DOC
25
+ | Attribute | Type | Required | Description |
26
+ | --------- | ---- | -------- | ----------- |
27
+ | name | string | yes | The name of the cluster |
28
+ | domain | string | no | The base domain of the cluster |
29
+ | management_project_id | integer | no | The ID of the management project for the cluster |
30
+ | enabled | boolean | no | Determines if cluster is active or not, defaults to true |
31
+ | managed | boolean | no | Determines if GitLab will manage namespaces and service accounts for this cluster, defaults to true |
32
+ | platform_kubernetes_attributes[api_url] | string | yes | The URL to access the Kubernetes API |
33
+ | platform_kubernetes_attributes[token] | string | yes | The token to authenticate against Kubernetes |
34
+ | platform_kubernetes_attributes[ca_cert] | string | no | TLS certificate. Required if API is using a self-signed TLS certificate. |
35
+ | platform_kubernetes_attributes[authorization_type] | string | no | The cluster authorization type: rbac, abac or unknown_authorization. Defaults to rbac. |
36
+ | environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
37
+ DOC
38
+ end
39
+
40
+ def add(group_id, query)
41
+ group_id = format_id(group_id)
42
+
43
+ client.request(:post, "groups/#{group_id}/clusters/user", GroupCluster, query)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,17 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class GroupClusters < Common
5
+ include ClassHelpers
6
+ end
7
+ end
8
+
9
+ # Top namespace
10
+ module LabClient
11
+ # Specifics
12
+ class Groups < Common
13
+ def clusters
14
+ GroupClusters.new(client)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Delete' do
6
+ desc 'Deletes an existing group cluster. [Project ID, Mirror ID, Params]'
7
+ example 'client.group.clusters.update(310, 3, enabled: true)'
8
+
9
+ result '=> #<GroupCluster id: 3, name: planet bob>'
10
+ end
11
+
12
+ doc 'Delete' do
13
+ markdown <<~DOC
14
+ | Attribute | Type | Required | Description |
15
+ | ---------- | ----- | --------- | ------------ |
16
+ | `id` | integer/string | yes | The ID or URL-encoded path of the group |
17
+ | `cluster_id` | integer | yes | The ID of the cluster |
18
+ DOC
19
+ end
20
+
21
+ doc 'Delete' do
22
+ desc 'Via GroupCluster [Params]'
23
+ example <<~DOC
24
+ cluster = client.groups.clusters.list(310).first
25
+ cluster.delete
26
+ DOC
27
+ end
28
+
29
+ def delete(group_id, cluster_id)
30
+ group_id = format_id(group_id)
31
+ cluster_id = format_id(cluster_id)
32
+
33
+ client.request(:delete, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class GroupCluster < Klass
5
+ include ClassHelpers
6
+ def inspect
7
+ "#<GroupCluster id: #{id}, name: #{name}>"
8
+ end
9
+
10
+ def group
11
+ group_id = collect_group_id
12
+ client.groups.show group_id
13
+ end
14
+
15
+ def update(query)
16
+ group_id = collect_group_id
17
+
18
+ update_self client.groups.clusters.update(group_id, id, query)
19
+ end
20
+
21
+ def delete
22
+ group_id = collect_group_id
23
+
24
+ client.groups.clusters.delete(group_id, id)
25
+ end
26
+
27
+ date_time_attrs %i[created_at]
28
+ user_attrs %i[uster]
29
+
30
+ help do
31
+ subtitle 'GroupCluster'
32
+ option 'group', 'Show Group'
33
+ option 'update', 'Update this Cluster [Hash]'
34
+ option 'delete', 'Delete cluster'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'List' do
6
+ desc 'Returns a list of group clusters. [Group ID]'
7
+ example 'client.groups.clusters.list(16)'
8
+
9
+ result <<~DOC
10
+ => #<GroupCluster id: 1, name: cluster-5>]
11
+ DOC
12
+ end
13
+
14
+ doc 'List' do
15
+ desc 'Via Group'
16
+ example <<~DOC
17
+ group = client.groups.show(16)
18
+ group.clusters
19
+ DOC
20
+ end
21
+
22
+ def list(group_id)
23
+ group_id = format_id(group_id)
24
+
25
+ client.request(:get, "groups/#{group_id}/clusters", GroupCluster)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Show' do
6
+ desc 'Gets a single group cluster. [Group ID, Cluster ID]'
7
+ example 'client.groups.clusters.list(16)'
8
+
9
+ result <<~DOC
10
+ => #<GroupCluster id: 1, name: cluster-5>
11
+ DOC
12
+ end
13
+
14
+ doc 'Show' do
15
+ desc 'Via Group'
16
+ example <<~DOC
17
+ group = client.groups.show(16)
18
+ group.cluster(cluster_id)
19
+ DOC
20
+ end
21
+
22
+ def show(group_id, cluster_id)
23
+ cluster_id = format_id(cluster_id)
24
+ group_id = format_id(group_id)
25
+
26
+ client.request(:get, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,44 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class GroupClusters < Common
5
+ doc 'Update' do
6
+ desc 'Updates an existing group cluster. [Group ID, Cluster ID, Hash]'
7
+ example 'client.groups.clusters.update(310, 3, name: "Sweet")'
8
+
9
+ result '=> #<GroupCluster id: 3, name: Sweet>'
10
+ end
11
+
12
+ doc 'Update' do
13
+ markdown <<~DOC
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
+ | environment_scope | string | no | The associated environment to the cluster. Defaults to * **(PREMIUM)** |
23
+
24
+ `name`, `api_url`, `ca_cert` and `token` can only be updated if the cluster was added through the
25
+ “Add existing Kubernetes cluster” option or through the “Add existing cluster to project” endpoint.
26
+ DOC
27
+ end
28
+
29
+ doc 'Update' do
30
+ desc 'Via GroupCluster [Params]'
31
+ example <<~DOC
32
+ cluster = client.groups.clusters.list(310).first
33
+ cluster.update(name: 'bump')
34
+ DOC
35
+ end
36
+
37
+ def update(group_id, cluster_id, query)
38
+ group_id = format_id(group_id)
39
+ cluster_id = format_id(cluster_id)
40
+
41
+ client.request(:put, "groups/#{group_id}/clusters/#{cluster_id}", GroupCluster, query)
42
+ end
43
+ end
44
+ end
@@ -151,6 +151,15 @@ module LabClient
151
151
  client.groups.badges.delete(id, badge_id)
152
152
  end
153
153
 
154
+ # Group Clusters
155
+ def clusters
156
+ client.groups.clusters.list(id)
157
+ end
158
+
159
+ def cluster(cluster_id)
160
+ client.groups.clusters.show(id, cluster_id)
161
+ end
162
+
154
163
  # Group Epics
155
164
  def epics
156
165
  client.epics.list(id)
@@ -295,6 +304,10 @@ module LabClient
295
304
  option 'badge_show', 'Show specific badge from group [Badge ID]'
296
305
  option 'badge_update', 'Update group badge [Badge ID, Hash]'
297
306
 
307
+ # Clusters
308
+ option 'clusters', "List this group's clusters"
309
+ option 'cluster', 'Show specific cluster from group [Cluster ID]'
310
+
298
311
  # Epics
299
312
  option 'epics', "List this group's epics"
300
313
  option 'epic_create', 'Create group epic [Hash]'
@@ -14,7 +14,7 @@ module LabClient
14
14
 
15
15
  # API Methods here have to be explicitly documented / custom helpers
16
16
  # Assume no methods by default
17
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
17
+ # rubocop:disable Metrics/AbcSize
18
18
  def help(help_filter = nil)
19
19
  docs = LabClient::Docs.docs.dig(group_name, 'Reference')
20
20
  unless docs
@@ -27,9 +27,7 @@ module LabClient
27
27
  next unless doc[:options]
28
28
 
29
29
  doc[:options].each do |opt|
30
- if help_filter
31
- next unless (opt[:name] + opt[:text]).include? help_filter.to_s
32
- end
30
+ next if help_filter && !(opt[:name] + opt[:text]).include?(help_filter.to_s)
33
31
 
34
32
  puts " #{opt[:name]}"
35
33
  puts " #{opt[:text]}\n"
@@ -39,7 +37,7 @@ module LabClient
39
37
  # Ignore Output
40
38
  nil
41
39
  end
42
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
40
+ # rubocop:enable Metrics/AbcSize
43
41
 
44
42
  # Documented API Methods
45
43
  def api_methods
@@ -206,16 +206,21 @@ module LabClient
206
206
  doc 'Other' do
207
207
  title 'Common Helpers'
208
208
  markdown <<~DOC
209
- 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
210
212
  DOC
211
213
 
212
214
  result <<~DOC
215
+ # General Help / Available Methods
213
216
  client.help
214
217
  client.api_methods
215
218
 
219
+ # Show Project specific Methods
216
220
  client.projects.api_methods
217
221
  # => [:show, :list, :create]
218
222
 
223
+ # Show Users specific help
219
224
  client.users.help
220
225
  Users
221
226
  Available Methods
@@ -231,6 +236,25 @@ module LabClient
231
236
  - client.users.show(5)
232
237
  - client.users.show(5)
233
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
+
234
258
  DOC
235
259
  end
236
260
 
@@ -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 [management project](../user/clusters/management_project.md) for the cluster |
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 | Type | Required | Description |
15
- | ---------- | ----- | --------- | ------------ |
16
- | url | String | yes | The URL of the remote repository to be clustered. |
17
- | enabled | Boolean | no | Determines if the cluster is enabled. |
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.update(enabled: false)
25
+ cluster.delete
27
26
  DOC
28
27
  end
29
28
 
@@ -12,10 +12,10 @@ module LabClient
12
12
  end
13
13
 
14
14
  doc 'Show' do
15
- desc 'Via Project'
15
+ desc 'Via Project [Cluster ID]'
16
16
  example <<~DOC
17
17
  project = client.projects.show(16)
18
- project.clusters
18
+ project.cluster(cluster_id)
19
19
  DOC
20
20
  end
21
21
 
@@ -11,11 +11,19 @@ module LabClient
11
11
 
12
12
  doc 'Update' do
13
13
  markdown <<~DOC
14
- | Attribute | Type | Required | Description |
15
- | ---------- | ----- | --------- | ------------ |
16
- | url | String | yes | The URL of the remote repository to be clustered. |
17
- | enabled | Boolean | no | Determines if the cluster is enabled. |
18
- | only_protected_branches| Boolean | no | Determines if only protected branches are clustered. |
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
 
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Project Forks'
6
-
7
5
  doc 'Create' do
8
6
  desc 'Forks a project into the user namespace of the authenticated user or the one provided.'
9
7
  example 'client.projects.fork(299)'
@@ -709,6 +709,10 @@ module LabClient
709
709
  client.projects.clusters.list(id)
710
710
  end
711
711
 
712
+ def cluster(cluster_id)
713
+ client.projects.clusters.show(id, cluster_id)
714
+ end
715
+
712
716
  # Reload
713
717
  def reload
714
718
  update_self client.projects.show(id)
@@ -2,8 +2,6 @@
2
2
  module LabClient
3
3
  # Specifics
4
4
  class Projects < Common
5
- @group_name = 'Project Stars'
6
-
7
5
  doc 'Starrers' do
8
6
  desc 'List the users who starred the specified project. [user id]'
9
7
  example 'client.projects.starrers(5)'
@@ -1,3 +1,3 @@
1
1
  module LabClient
2
- VERSION = '0.2.1'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: labclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Davin Walker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -210,16 +210,16 @@ dependencies:
210
210
  name: rubocop
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
- - - "~>"
213
+ - - "<"
214
214
  - !ruby/object:Gem::Version
215
- version: '0.82'
215
+ version: 0.91.0
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
- - - "~>"
220
+ - - "<"
221
221
  - !ruby/object:Gem::Version
222
- version: '0.82'
222
+ version: 0.91.0
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: simplecov
225
225
  requirement: !ruby/object:Gem::Requirement
@@ -423,6 +423,13 @@ files:
423
423
  - lib/labclient/groups/badges/preview.rb
424
424
  - lib/labclient/groups/badges/show.rb
425
425
  - lib/labclient/groups/badges/update.rb
426
+ - lib/labclient/groups/clusters/add.rb
427
+ - lib/labclient/groups/clusters/client.rb
428
+ - lib/labclient/groups/clusters/delete.rb
429
+ - lib/labclient/groups/clusters/group_cluster.rb
430
+ - lib/labclient/groups/clusters/list.rb
431
+ - lib/labclient/groups/clusters/show.rb
432
+ - lib/labclient/groups/clusters/update.rb
426
433
  - lib/labclient/groups/create.rb
427
434
  - lib/labclient/groups/delete.rb
428
435
  - lib/labclient/groups/group.rb