labclient 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a516961c1eaeef85e9ee1d1de52980e03aae212122fd8d1bc49a05e9d4328ac
4
- data.tar.gz: 384c408eb1320f1d31e661fe153edaacad187f02a6971775d7b1afd918eaf88c
3
+ metadata.gz: 866bed156a753e7148f538c380d453899259cae098cca155fba3ed81517d71c7
4
+ data.tar.gz: 2f52c954789f226ead00127e029428f2bc32f85757112211082d0a204ecd1c53
5
5
  SHA512:
6
- metadata.gz: e3b2453fa6d325e570360ca1b956261e5841901c528d8df3af44b28db7bf20081b0bd49c490e58c71055524b1ceff090ba63fb8205d6f379f0547161bfd80aec
7
- data.tar.gz: 942ce7e24982e01141d664b0f4038dd4f8207ccb9f849cd74a058125aecf672c51af03e198f9e2ce7dd7f9bd35976f7e9a35fe1fe7b088240a636edd376d6d6c
6
+ metadata.gz: 13c0c5f1201b8a4a4d77ad09b7496a6ea1c14af360e7d19cce1877467a6b6a70acb018025a36c2746532ffed98e258e6960b03436ebb24bc717d6c895f35af25
7
+ data.tar.gz: b1b10db7e1ab7a4ed4a428330d5fac26fead66f09c220b4147e236aa380066d40a439cb6beb60ab0afd321f4620ffe654250af6121114481d935756cc671a901
@@ -54,6 +54,7 @@ module LabClient
54
54
  pipelines: Pipelines,
55
55
  project_runners: ProjectRunners,
56
56
  projects: Projects,
57
+ terraform: Terraform,
57
58
  protected_branches: ProtectedBranches,
58
59
  protected_environments: ProtectedEnvironments,
59
60
  protected_tags: ProtectedTags,
@@ -84,13 +84,17 @@ module LabClient
84
84
  when LabStruct
85
85
  klass ? klass.new(resp.data, resp, self) : resp.data
86
86
  when Array
87
- if @klass.nil?
87
+ if klass.nil?
88
88
  resp.data
89
89
  else
90
- PaginatedResponse.new(@klass, resp, self)
90
+ PaginatedResponse.new(klass, resp, self)
91
91
  end
92
+ # Return Response/Status Object if there is no output otherwise
93
+ when NilClass
94
+ resp
95
+ # Default handler / if klass defined store plain response in data
92
96
  else
93
- resp.data
97
+ klass ? klass.new({ data: resp.data, response: resp }, resp, self) : resp
94
98
  end
95
99
  end
96
100
  end
@@ -0,0 +1,11 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # General File Wrapper
4
+ class LabFile < Klass
5
+ include ClassHelpers
6
+
7
+ def inspect
8
+ "#<LabFile size: #{data&.size}>"
9
+ end
10
+ end
11
+ end
@@ -45,7 +45,7 @@ module LabClient
45
45
  # Path Name Encoding
46
46
  file_path = CGI.escape(file_path)
47
47
 
48
- client.request(:get, "projects/#{project_id}/repository/files/#{file_path}#{kind}", nil, ref: ref)
48
+ client.request(:get, "projects/#{project_id}/repository/files/#{file_path}#{kind}", LabFile, ref: ref)
49
49
  end
50
50
  end
51
51
  end
@@ -18,7 +18,6 @@ module LabClient
18
18
  end
19
19
 
20
20
  def sync(group_id)
21
- # POST /groups/:id/ldap_sync
22
21
  group_id = format_id(group_id)
23
22
 
24
23
  client.request(:post, "groups/#{group_id}/ldap_sync")
@@ -82,15 +82,25 @@ module Typhoeus
82
82
  self
83
83
  end
84
84
 
85
+ # Check if response body can be parsed
86
+ def json_body?
87
+ content_type = headers['content-type']
88
+
89
+ return false unless content_type
90
+ return true if content_type.include? 'application/json'
91
+
92
+ false
93
+ end
94
+
85
95
  def process_body
86
- if body.empty?
87
- nil
88
- elsif headers['content-type']&.include? 'text/plain'
89
- body
90
- else
96
+ return nil if body.empty?
97
+
98
+ if json_body?
91
99
  result = Oj.load(body, mode: :compat, symbol_keys: true, object_class: LabClient::LabStruct)
92
100
  result.instance_variable_set(:@response, self) if result.instance_of?(LabClient::LabStruct)
93
101
  result
102
+ else
103
+ body
94
104
  end
95
105
  end
96
106
 
@@ -3,10 +3,10 @@ module LabClient
3
3
  # Specifics
4
4
  class Issues < Common
5
5
  doc 'Delete' do
6
- desc 'Updates an existing project issue. This call is also used to mark an issue as closed. [Project ID, Issue IID]'
6
+ desc 'Only for administrators and project owners. Deletes an issue. [Project ID, Issue IID]'
7
7
  example 'client.issues.delete(5, 1)'
8
8
  result <<~DOC
9
- => #<Issue id: 1, title: Moar Fancy!, state: opened>
9
+ => #<TyphoeusResponse code: 204>
10
10
  DOC
11
11
  end
12
12
 
@@ -3,11 +3,15 @@ module LabClient
3
3
  # Specifics
4
4
  class Jobs < Common
5
5
  doc 'Artifacts' do
6
- desc 'Get the job’s artifacts zipped archive of a project. [Project ID, Job ID, File Path, Job Token]'
6
+ desc 'Get the job’s artifacts zipped archive of a project. [Project ID, Job ID, Job Token, File Path]'
7
7
  example 'client.jobs.artifacts(264, 1)'
8
8
 
9
9
  markdown <<~DOC
10
- File Output will default to the current directory + job id + file extension. 14.zip
10
+ ---
11
+
12
+ Two methods are available. `download_artifacts` will download and write to the local directory (or file path) and `artifacts`/`show_artifacts` which will return a `LabFile` with the key of `data` for the response result.
13
+
14
+ File Output will default to the current directory + job id + file extension. 14.zip (Still returning `LabFile`)
11
15
 
12
16
  Job Token: To be used with triggers for multi-project pipelines. It should be invoked only inside `.gitlab-ci.yml`. Its value is always `$CI_JOB_TOKEN`.
13
17
  DOC
@@ -16,7 +20,7 @@ module LabClient
16
20
  doc 'Artifacts' do
17
21
  desc 'Specific output location'
18
22
  example <<~DOC
19
- client.jobs.artifacts(264, 1, '/tmp/output.zip')
23
+ client.jobs.download_artifacts(264, 1, '/tmp/output.zip')
20
24
  DOC
21
25
  end
22
26
 
@@ -24,6 +28,7 @@ module LabClient
24
28
  desc 'via Project'
25
29
  example <<~DOC
26
30
  project = client.projects.show(264)
31
+ project.job_download_artifacts(7)
27
32
  project.job_artifacts(7)
28
33
  DOC
29
34
  end
@@ -32,18 +37,29 @@ module LabClient
32
37
  desc 'via Job'
33
38
  example <<~DOC
34
39
  job = client.jobs.show(264, 7)
35
- job.artifacts
40
+ job.download_artifacts
41
+ job.show_artifacts
36
42
  DOC
37
43
  end
38
44
 
39
- def artifacts(project_id, job_id, file_path = nil, job_token = nil)
45
+ def artifacts(project_id, job_id, job_token = nil)
40
46
  job_id = format_id(job_id)
41
47
  project_id = format_id(project_id)
42
- file_path ||= "#{Dir.pwd}/#{job_id}.zip"
43
48
  query = { job_token: job_token } if job_token
44
- output = client.request(:get, "projects/#{project_id}/jobs/#{job_id}/artifacts", nil, query)
45
49
 
46
- File.write(file_path, output)
50
+ # Don't try to process output
51
+ client.request(:get, "projects/#{project_id}/jobs/#{job_id}/artifacts", LabFile, query)
52
+ end
53
+
54
+ # Helper to write immediately to a file
55
+ def download_artifacts(project_id, job_id, file_path = nil, job_token = nil)
56
+ file_path ||= "#{Dir.pwd}/#{job_id}.zip"
57
+ output = artifacts(project_id, job_id, job_token)
58
+
59
+ File.write(file_path, output.data) if output.success?
60
+
61
+ # Return LabFile
62
+ output
47
63
  end
48
64
  end
49
65
  end
@@ -17,9 +17,16 @@ module LabClient
17
17
  Pipeline.new(@table[:pipeline], response, client)
18
18
  end
19
19
 
20
- def artifacts(file_path = nil, job_token = nil)
20
+ # File Write Response
21
+ def download_artifacts(file_path = nil, job_token = nil)
21
22
  project_id = collect_project_id
22
- client.jobs.artifacts(project_id, id, file_path, job_token)
23
+ client.jobs.download_artifacts(project_id, id, job_token, file_path)
24
+ end
25
+
26
+ # LabFile Response
27
+ def show_artifacts(job_token = nil)
28
+ project_id = collect_project_id
29
+ client.jobs.artifacts(project_id, id, job_token)
23
30
  end
24
31
 
25
32
  def artifacts_path(artifacts_path, file_path = nil)
@@ -65,7 +72,7 @@ module LabClient
65
72
  help do
66
73
  @group_name = 'Jobs'
67
74
  subtitle 'Job'
68
- option 'artifacts', 'Download Job artifacts. [File Path, Job Token]'
75
+ option 'download_artifacts', 'Download Job artifacts. [File Path, Job Token]'
69
76
  option 'artifacts_path', 'Download Job artifacts path. [File Path, Output Path]'
70
77
  option 'trace', 'Get Job Output'
71
78
  option 'cancel', 'Cancel Job'
@@ -226,8 +226,12 @@ module LabClient
226
226
  client.jobs.show(id, job_id)
227
227
  end
228
228
 
229
- def job_artifacts(job_id, file_path = nil, job_token = nil)
230
- client.jobs.artifacts(id, job_id, file_path, job_token)
229
+ def job_download_artifacts(job_id, file_path = nil, job_token = nil)
230
+ client.jobs.download_artifacts(id, job_id, file_path, job_token)
231
+ end
232
+
233
+ def job_artifacts(job_id, job_token = nil)
234
+ client.jobs.artifacts(id, job_id, job_token)
231
235
  end
232
236
 
233
237
  def job_artifacts_latest(branch_name, job_name, file_path = nil, job_token = nil)
@@ -17,6 +17,11 @@ module LabClient
17
17
  client.registry.tags(project_id, id)
18
18
  end
19
19
 
20
+ def delete
21
+ project_id = collect_project_id
22
+ client.registry.delete(project_id, id)
23
+ end
24
+
20
25
  help do
21
26
  @group_name = 'Registry'
22
27
  subtitle 'Registry Repository'
@@ -0,0 +1,23 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Terraform < Common
5
+ doc 'Create' do
6
+ desc 'Creates a new State. [Project ID, StateName, LockID, Hash]'
7
+ example 'client.terraform.create(5, {})'
8
+ result '#<TerraformState serial: 4>'
9
+
10
+ markdown <<~DOC
11
+ Attributes for Hash
12
+
13
+ ID,Operation,Info,Who,Version,Created,Path
14
+ DOC
15
+ end
16
+
17
+ def create(project_id, name, xid, body)
18
+ project_id = format_id(project_id)
19
+
20
+ client.request(:post, "projects/#{project_id}/terraform/state/#{name}?ID=#{xid}", nil, body)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Terraform < Common
5
+ doc 'Delete' do
6
+ desc 'Delete Terraform State. [Project ID, StateName]'
7
+ example 'client.terraform.delete(5, :state_name)'
8
+ end
9
+
10
+ def delete(project_id, name)
11
+ project_id = format_id(project_id)
12
+
13
+ client.request(:delete, "projects/#{project_id}/terraform/state/#{name}")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Terraform < Common
5
+ doc 'Lock' do
6
+ desc 'Locks a new State. [Project ID, Hash]'
7
+ example 'client.wikis.Lock(5, content: "Lots of Stuff", title: "Title!")'
8
+ result '#<TerraformState slug: Title!>'
9
+ end
10
+
11
+ def lock(project_id, name, query)
12
+ project_id = format_id(project_id)
13
+
14
+ client.request(:post, "projects/#{project_id}/terraform/state/#{name}/lock", nil, query)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,22 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Terraform < Common
5
+ doc 'Show' do
6
+ desc 'Collect Terraform State Information'
7
+ example 'client.terraform.show(264, "README.md")'
8
+
9
+ markdown <<~DOC
10
+ Ref will default to `main`
11
+
12
+ Kind can be left empty or set to either :raw or :blame
13
+ DOC
14
+ end
15
+
16
+ def show(project_id, name)
17
+ project_id = format_id(project_id)
18
+
19
+ client.request(:get, "projects/#{project_id}/terraform/state/#{name}", TerraformState)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,11 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Inspect Helper
4
+ class TerraformState < Klass
5
+ include ClassHelpers
6
+
7
+ def inspect
8
+ "#<TerraformState serial: #{serial}>"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ # Top namespace
2
+ module LabClient
3
+ # Specifics
4
+ class Terraform < Common
5
+ doc 'Lock' do
6
+ desc 'Unlock State [Project ID, StateName Lock ID]'
7
+ example 'client.terraform.lock(5, :state_name, 123)'
8
+ end
9
+
10
+ def unlock(project_id, name, xid)
11
+ project_id = format_id(project_id)
12
+
13
+ client.request(:delete, "projects/#{project_id}/terraform/state/#{name}/lock?ID=#{xid}")
14
+ end
15
+ end
16
+ end
@@ -1,6 +1,6 @@
1
1
  # Overall version
2
2
  module LabClient
3
- VERSION = '0.5.1'.freeze
3
+ VERSION = '0.6.0'.freeze
4
4
 
5
5
  # Make it easy to print version
6
6
  def self.version
data/lib/labclient.rb CHANGED
@@ -778,12 +778,6 @@ require 'labclient/repository/compare'
778
778
  require 'labclient/repository/contributors'
779
779
  require 'labclient/repository/merge_base'
780
780
 
781
- # Files
782
- require 'labclient/files/show'
783
- require 'labclient/files/create'
784
- require 'labclient/files/update'
785
- require 'labclient/files/delete'
786
-
787
781
  # Branches
788
782
  require 'labclient/branches/list'
789
783
  require 'labclient/branches/show'
@@ -866,6 +860,21 @@ require 'labclient/feature_flags/delete'
866
860
  require 'labclient/feature_flags/list'
867
861
  require 'labclient/feature_flags/feature_flag'
868
862
 
863
+ # Files
864
+ require 'labclient/files/file'
865
+ require 'labclient/files/show'
866
+ require 'labclient/files/create'
867
+ require 'labclient/files/update'
868
+ require 'labclient/files/delete'
869
+
870
+ # Terraform
871
+ require 'labclient/terraform/create'
872
+ require 'labclient/terraform/lock'
873
+ require 'labclient/terraform/unlock'
874
+ require 'labclient/terraform/delete'
875
+ require 'labclient/terraform/show'
876
+ require 'labclient/terraform/terraform_state'
877
+
869
878
  require 'labclient/resource_labels/resource_label'
870
879
 
871
880
  # Generators
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.5.1
4
+ version: 0.6.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: 2021-12-21 00:00:00.000000000 Z
11
+ date: 2022-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -449,6 +449,7 @@ files:
449
449
  - lib/labclient/feature_flags/list.rb
450
450
  - lib/labclient/files/create.rb
451
451
  - lib/labclient/files/delete.rb
452
+ - lib/labclient/files/file.rb
452
453
  - lib/labclient/files/show.rb
453
454
  - lib/labclient/files/update.rb
454
455
  - lib/labclient/generator/generator.rb
@@ -892,6 +893,12 @@ files:
892
893
  - lib/labclient/tags/show.rb
893
894
  - lib/labclient/tags/tag.rb
894
895
  - lib/labclient/tags/update.rb
896
+ - lib/labclient/terraform/create.rb
897
+ - lib/labclient/terraform/delete.rb
898
+ - lib/labclient/terraform/lock.rb
899
+ - lib/labclient/terraform/show.rb
900
+ - lib/labclient/terraform/terraform_state.rb
901
+ - lib/labclient/terraform/unlock.rb
895
902
  - lib/labclient/todos/list.rb
896
903
  - lib/labclient/todos/mark_all_done.rb
897
904
  - lib/labclient/todos/mark_done.rb