labclient 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/lib/labclient.rb +19 -3
  3. data/lib/labclient/access_levels.rb +24 -30
  4. data/lib/labclient/client.rb +54 -7
  5. data/lib/labclient/commits/project_helpers.rb +4 -0
  6. data/lib/labclient/commits/show.rb +11 -2
  7. data/lib/labclient/common.rb +15 -6
  8. data/lib/labclient/docs.rb +9 -5
  9. data/lib/labclient/files/update.rb +1 -1
  10. data/lib/labclient/generator/generator.rb +7 -7
  11. data/lib/labclient/generator/template_helper.rb +0 -1
  12. data/lib/labclient/generator/wizard.rb +6 -2
  13. data/lib/labclient/groups/clusters/add.rb +46 -0
  14. data/lib/labclient/groups/clusters/client.rb +17 -0
  15. data/lib/labclient/groups/clusters/delete.rb +36 -0
  16. data/lib/labclient/groups/clusters/group_cluster.rb +37 -0
  17. data/lib/labclient/groups/clusters/list.rb +28 -0
  18. data/lib/labclient/groups/clusters/show.rb +29 -0
  19. data/lib/labclient/groups/clusters/update.rb +44 -0
  20. data/lib/labclient/groups/group.rb +14 -1
  21. data/lib/labclient/http.rb +1 -1
  22. data/lib/labclient/issues/issue.rb +17 -0
  23. data/lib/labclient/issues/update.rb +20 -2
  24. data/lib/labclient/jobs/delete.rb +1 -1
  25. data/lib/labclient/jobs/keep.rb +1 -1
  26. data/lib/labclient/jobs/play.rb +1 -1
  27. data/lib/labclient/jobs/trace.rb +2 -2
  28. data/lib/labclient/klass.rb +6 -6
  29. data/lib/labclient/lab_struct.rb +4 -0
  30. data/lib/labclient/members/member.rb +1 -0
  31. data/lib/labclient/notes/epics/create.rb +8 -0
  32. data/lib/labclient/notes/issues/create.rb +8 -0
  33. data/lib/labclient/notes/merge_requests/create.rb +8 -0
  34. data/lib/labclient/overview.rb +104 -12
  35. data/lib/labclient/paginated_response.rb +2 -0
  36. data/lib/labclient/projects/clusters/add.rb +1 -1
  37. data/lib/labclient/projects/clusters/delete.rb +5 -6
  38. data/lib/labclient/projects/clusters/show.rb +2 -2
  39. data/lib/labclient/projects/clusters/update.rb +13 -5
  40. data/lib/labclient/projects/environments/project_environment.rb +10 -0
  41. data/lib/labclient/projects/forks/fork.rb +0 -2
  42. data/lib/labclient/projects/methods.rb +23 -0
  43. data/lib/labclient/projects/reference.rb +7 -0
  44. data/lib/labclient/projects/stars/starrers.rb +0 -2
  45. data/lib/labclient/protected_branches/protect.rb +6 -5
  46. data/lib/labclient/protected_environments/list.rb +29 -0
  47. data/lib/labclient/protected_environments/protect.rb +53 -0
  48. data/lib/labclient/protected_environments/protected_environment.rb +22 -0
  49. data/lib/labclient/protected_environments/show.rb +24 -0
  50. data/lib/labclient/protected_environments/unprotect.rb +31 -0
  51. data/lib/labclient/users/membership.rb +62 -0
  52. data/lib/labclient/users/memberships.rb +8 -3
  53. data/lib/labclient/users/user.rb +1 -1
  54. data/lib/labclient/version.rb +1 -1
  55. metadata +19 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab2d7a4a0dcf9e876c42f3d92537ad03f6cc9d00391bf574188de36fa5dde3a6
4
- data.tar.gz: 9bba10386c15059b97c79a0e6f0ed322af7614736b78e55fd968f362e767dd8e
3
+ metadata.gz: a747d261d131d7f0a228cb02753e21798c951393941247d0d4252a9c253c5650
4
+ data.tar.gz: 228a9181e7345f607e8d4ab6617d729f9b4b44ab7e1fdcd295db4ed3332a257d
5
5
  SHA512:
6
- metadata.gz: 8998430e5b8d07584da6fe906d465238fd7725fa0773b9bb11a7b47dc755ce5fcb80d0cbb22055b16327665d70cbd034a24a63d310fabd11bd560c0ebd994f95
7
- data.tar.gz: 3e61e5c568a93cfad5955198f6524349a89a06d729ead2d8f98c1d05c78e885edfb9fbb069fee2226731b26a1ab8c0404b857883f745d99c7564280e8f855b4d
6
+ metadata.gz: 2d66d602d12ccd265ae6b1e5aa28c0cdeabbbcc0ee678c5be80a30c42ef342e7b9308acf0a075da04cd4bbb76c744ce32d52122e0f4b87c36c9a9faf09b7834a
7
+ data.tar.gz: c3eaf2cb6c83effec491f071bf0e5de9f2638f68d0af5656ae146915245eb00b091d7a566ef6c28c88db562a9b71cf8b773798fd7890693b098fbc66bdfd9adb
@@ -1,6 +1,5 @@
1
1
  # Public Gems
2
2
  require 'oj'
3
- require 'pry'
4
3
  require 'typhoeus'
5
4
  require 'active_support/all'
6
5
  require 'amazing_print'
@@ -36,7 +35,6 @@ require 'labclient/users/current'
36
35
  require 'labclient/users/status'
37
36
  require 'labclient/users/counts'
38
37
  require 'labclient/users/activity'
39
- require 'labclient/users/memberships'
40
38
  require 'labclient/users/search'
41
39
  require 'labclient/users/create'
42
40
  require 'labclient/users/update'
@@ -47,6 +45,8 @@ require 'labclient/users/activate'
47
45
  require 'labclient/users/deactivate'
48
46
  require 'labclient/users/delete'
49
47
  require 'labclient/users/delete_identity'
48
+ require 'labclient/users/memberships'
49
+ require 'labclient/users/membership'
50
50
  require 'labclient/users/user'
51
51
 
52
52
  # ===============================================
@@ -149,6 +149,13 @@ require 'labclient/projects/environments/delete'
149
149
  require 'labclient/projects/environments/stop'
150
150
  require 'labclient/projects/environments/project_environment'
151
151
 
152
+ # Protected Environments
153
+ require 'labclient/protected_environments/list'
154
+ require 'labclient/protected_environments/show'
155
+ require 'labclient/protected_environments/protect'
156
+ require 'labclient/protected_environments/unprotect'
157
+ require 'labclient/protected_environments/protected_environment'
158
+
152
159
  # Project Deployments
153
160
  require 'labclient/projects/deployments/client'
154
161
  require 'labclient/projects/deployments/list'
@@ -352,6 +359,15 @@ require 'labclient/groups/badges/update'
352
359
  require 'labclient/groups/badges/delete'
353
360
  require 'labclient/groups/badges/group_badge'
354
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
+
355
371
  require 'labclient/groups/group'
356
372
 
357
373
  # Issues
@@ -852,7 +868,7 @@ require 'labclient/generator/generator'
852
868
  require 'labclient/generator/wizard'
853
869
 
854
870
  # Dynamically Require Templates (Simplify new template creation)
855
- Dir[File.dirname(__FILE__) + '/labclient/generator/templates/*.rb'].sort.each { |file| require file }
871
+ Dir["#{File.dirname(__FILE__)}/labclient/generator/templates/*.rb"].sort.each { |file| require file }
856
872
 
857
873
  # I am Very Last
858
874
  require 'labclient/client'
@@ -2,46 +2,40 @@
2
2
  module LabClient
3
3
  # Shared Methods
4
4
  module AccessLevel
5
+ HUMAN_ACCESS_LEVELS = {
6
+ 0 => :none,
7
+ 10 => :guest,
8
+ 20 => :reporter,
9
+ 30 => :developer,
10
+ 40 => :maintainer,
11
+ 50 => :owner,
12
+ 60 => :admin
13
+ }.freeze
14
+
15
+ MACHINE_ACCESS_LEVELS = {
16
+ none: 0,
17
+ guest: 10,
18
+ reporter: 20,
19
+ developer: 30,
20
+ maintainer: 40,
21
+ owner: 50,
22
+ admin: 60
23
+ }.freeze
24
+
5
25
  def human_access_level(level = 10)
6
- case level
7
- when 0 then :none
8
- when 10 then :guest
9
- when 20 then :reporter
10
- when 30 then :developer
11
- when 40 then :maintainer
12
- when 50 then :owner
13
- when 60 then :admin
14
- end
26
+ HUMAN_ACCESS_LEVELS[level]
15
27
  end
16
28
 
17
29
  def machine_access_level(level = :developer)
18
- case level
19
- when :none then 0
20
- when :guest then 10
21
- when :reporter then 20
22
- when :developer then 30
23
- when :maintainer then 40
24
- when :owner then 50
25
- when :admin then 60
26
- end
30
+ MACHINE_ACCESS_LEVELS[level]
27
31
  end
28
32
 
29
33
  def machine_protected_access_level(level = :developer)
30
- case level
31
- when :none then 0
32
- when :developer then 30
33
- when :maintainer then 40
34
- when :admin then 60
35
- end
34
+ MACHINE_ACCESS_LEVELS[level]
36
35
  end
37
36
 
38
37
  def human_protected_access_level(level = 10)
39
- case level
40
- when 0 then :none
41
- when 30 then :developer
42
- when 40 then :maintainer
43
- when 60 then :admin
44
- end
38
+ HUMAN_ACCESS_LEVELS[level]
45
39
  end
46
40
  end
47
41
  end
@@ -1,6 +1,7 @@
1
1
  # Top Namespace
2
2
  module LabClient
3
3
  # API Specifics
4
+ # rubocop:disable Metrics/ClassLength
4
5
  class Client
5
6
  # include HTTParty
6
7
  attr_accessor :settings, :resp, :klass, :link, :http
@@ -55,6 +56,7 @@ module LabClient
55
56
  project_runners: ProjectRunners,
56
57
  projects: Projects,
57
58
  protected_branches: ProtectedBranches,
59
+ protected_environments: ProtectedEnvironments,
58
60
  protected_tags: ProtectedTags,
59
61
  registry: Registry,
60
62
  repo: Repositories,
@@ -80,9 +82,16 @@ module LabClient
80
82
  subclasses.keys.sort
81
83
  end
82
84
 
83
- def help
85
+ def help(help_filter = nil)
84
86
  puts 'Available Methods'
85
- 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"
86
95
  puts "See help for each specific sub-category\n"
87
96
  puts "- client.users.help\n"
88
97
  puts "- client.users.api_methods\n"
@@ -91,27 +100,64 @@ module LabClient
91
100
  end
92
101
 
93
102
  # Default setup, pull in settings
94
- def initialize(settings = nil)
95
- @settings = settings
103
+ def initialize(user_settings = nil)
104
+ @settings = user_settings
105
+ setup_profile if user_settings&.key?(:profile) || ENV['LABCLIENT_PROFILE']
96
106
  @settings ||= fill_configuration
97
107
 
98
108
  # Set Unspecified Defaults
99
109
  unspecified_defaults
100
110
 
101
- raise 'LabClient Error - Missing URL!' if @settings[:url].nil?
111
+ prompt_for_url if @settings[:url].blank?
112
+
113
+ # Only prompt if explicitly set to nil
114
+ prompt_for_token if @settings[:token].nil?
102
115
 
103
116
  self.http = HTTP.new(@settings)
104
117
  end
105
118
 
119
+ def prompt_for_url
120
+ print 'Enter GitLab URL (e.g. https://gitlab.com): '
121
+ @settings[:url] = $stdin.gets.chomp
122
+ raise 'LabClient Error - Missing URL!' if @settings[:url].blank?
123
+ end
124
+
125
+ def prompt_for_token
126
+ print 'Enter Personal Access Token: '
127
+ @settings[:token] = $stdin.gets.chomp
128
+ end
129
+
106
130
  def unspecified_defaults
107
131
  @settings[:paginate] = true if @settings[:paginate].nil?
108
132
  @settings[:ssl_verify] = true if @settings[:ssl_verify].nil?
133
+ @settings[:quiet] = false if @settings[:quiet].nil?
109
134
  end
110
135
 
111
136
  def home_file
112
- ENV['HOME'] + '/.gitlab-labclient'
137
+ "#{ENV['HOME']}/.gitlab-labclient"
138
+ end
139
+
140
+ # Easier Profile Name Access
141
+ def profile
142
+ if settings&.key? :profile
143
+ settings[:profile].to_sym
144
+ else
145
+ ENV['LABCLIENT_PROFILE'].to_sym
146
+ end
147
+ end
148
+
149
+ # Support for Named Profiles
150
+ def setup_profile
151
+ return false unless File.exist? home_file
152
+
153
+ config = Oj.load_file(home_file, { symbol_keys: true })
154
+ return false unless config.key? profile
155
+
156
+ self.settings ||= {}
157
+ settings.merge! config[profile]
113
158
  end
114
159
 
160
+ # Load default profile
115
161
  def fill_configuration
116
162
  if File.exist? home_file
117
163
  Oj.load_file(home_file, { symbol_keys: true })
@@ -135,7 +181,7 @@ module LabClient
135
181
 
136
182
  process resp
137
183
  rescue LabClient::Error => e
138
- puts e.message
184
+ puts e.message unless settings[:quiet]
139
185
  resp
140
186
  end
141
187
 
@@ -155,4 +201,5 @@ module LabClient
155
201
  end
156
202
  end
157
203
  end
204
+ # rubocop:enable Metrics/ClassLength
158
205
  end
@@ -6,6 +6,10 @@ module LabClient
6
6
  client.commits.list(id, query)
7
7
  end
8
8
 
9
+ def commit(commit_id, query = {})
10
+ client.commits.show(id, commit_id, query)
11
+ end
12
+
9
13
  def commit_create(query = {})
10
14
  client.commits.create(id, query)
11
15
  end
@@ -16,10 +16,19 @@ module LabClient
16
16
  DOC
17
17
  end
18
18
 
19
+ doc 'Show' do
20
+ desc 'Via Project'
21
+ example <<~DOC
22
+ project = client.projects.show(16)
23
+ project.commit("b539e5d3")
24
+ DOC
25
+ end
26
+
19
27
  # Show
20
- def show(project_id, commit_id)
28
+ def show(project_id, commit_id, query = {})
21
29
  project_id = format_id(project_id)
22
- client.request(:get, "projects/#{project_id}/repository/commits/#{commit_id}", Commit)
30
+
31
+ client.request(:get, "projects/#{project_id}/repository/commits/#{commit_id}", Commit, query)
23
32
  end
24
33
  end
25
34
  end
@@ -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
@@ -26,11 +26,11 @@ module LabClient
26
26
  # ---------------------------------
27
27
 
28
28
  # Klass Helper
29
- def help
29
+ def help(&block)
30
30
  # require 'active_support/inflector'
31
31
  @group_name ||= group_name.pluralize
32
32
  doc 'Reference' do
33
- yield
33
+ block.call
34
34
  end
35
35
  end
36
36
 
@@ -50,10 +50,14 @@ module LabClient
50
50
  end
51
51
 
52
52
  def desc(value)
53
- # @result[:desc] = simple_format value
54
53
  @result[:desc] = value
55
54
  end
56
55
 
56
+ def demo(value)
57
+ @result[:demo_url] = "https://asciinema.org/a/#{value}.js"
58
+ @result[:demo] = "<script id='asciicast-#{value}' src='#{@result[:demo_url]}' data-autoplay='true' data-loop='true' async></script>"
59
+ end
60
+
57
61
  def example(value)
58
62
  @result[:example] = value
59
63
  end
@@ -81,10 +85,10 @@ module LabClient
81
85
  subnav = subgroup.gsub(' ', '_')
82
86
 
83
87
  # Title
84
- subnav += '_' + @result[:title].gsub(' ', '_') if @result.key? :title
88
+ subnav += "_#{@result[:title].gsub(' ', '_')}" if @result.key? :title
85
89
 
86
90
  @result[:nav] = nav
87
- @result[:nav] += '-' + subnav if subnav
91
+ @result[:nav] += "-#{subnav}" if subnav
88
92
  end
89
93
 
90
94
  def doc(subgroup)
@@ -33,7 +33,7 @@ module LabClient
33
33
  desc 'via Project'
34
34
  example <<~DOC
35
35
  project = client.projects.show(264)
36
- project.file_create('other.md',
36
+ project.file_update('other.md',
37
37
  branch: :master,
38
38
  commit_message: "New File!",
39
39
  content: "Content!")
@@ -43,13 +43,13 @@ module LabClient
43
43
 
44
44
  doc 'Wizard' do
45
45
  markdown <<~DOC
46
- | Setting | Type | Description |
47
- | -------- | ------- | ------------------------------------------------------ |
48
- | random | Boolean | Run Populate. Setup random Users, Projects, and Groups |
49
- | count | Hash | Settings for random. User, Project, Group count |
50
- | password | String | Default password for generated Users |
51
- | domain | String | Defaults to client url. Default email domain for users |
52
-
46
+ | Setting | Type | Description |
47
+ | ----------------- | ------- | ------------------------------------------------------ |
48
+ | random | Boolean | Run Populate. Setup random Users, Projects, and Groups |
49
+ | count | Hash | Settings for random. User, Project, Group count |
50
+ | password | String | Default password for generated Users |
51
+ | domain | String | Defaults to client url. Default email domain for users |
52
+ | skip_confirmation | Boolean | Enable/Disable skip_confirmation on new users |
53
53
  DOC
54
54
  end
55
55
 
@@ -74,7 +74,6 @@ module LabClient
74
74
 
75
75
  def generate_group
76
76
  @group = client.groups.create(name: group_name, path: group_path)
77
- # puts "#{@group.name} - #{@group.web_url}"
78
77
  raise 'Unable to Create Group' unless @group.success?
79
78
  end
80
79
  end
@@ -5,7 +5,7 @@ module LabClient
5
5
  class Wizard
6
6
  include Generator::Names # Name Generator
7
7
  attr_reader :client
8
- attr_accessor :count, :random, :password, :templates, :domain
8
+ attr_accessor :count, :random, :password, :templates, :domain, :skip_confirmation
9
9
 
10
10
  def inspect
11
11
  "#<Wizard count=#{count}, random=#{random}, domain=#{domain}> templates=#{templates}"
@@ -26,6 +26,9 @@ module LabClient
26
26
  self.random = true # Populate Random or use only Templates
27
27
  self.count = default_count
28
28
  self.password = SecureRandom.uuid
29
+ puts "Default Password: #{password}"
30
+
31
+ self.skip_confirmation = true
29
32
  self.domain = URI.parse(client.settings[:url]).hostname
30
33
 
31
34
  # Default Templates
@@ -61,7 +64,8 @@ module LabClient
61
64
  name: name,
62
65
  email: email,
63
66
  password: password,
64
- username: username
67
+ username: username,
68
+ skip_confirmation: skip_confirmation
65
69
  )
66
70
  end
67
71
  end
@@ -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