aikido-ruby-client 0.0.2 → 0.0.3

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: 2195bf014566aa0b80fbbf1412abce1996457bd8a93a126280689e00bdf19d72
4
- data.tar.gz: 2904c3cd13469f36ef32e3d74daf4a1eef837286f5f71047fc3bb53b0c23b400
3
+ metadata.gz: 6692ba6b0f697d0f69b840a95e96cbbca656863ed9c71af7c48fc2634678a659
4
+ data.tar.gz: 9997f0daca4a3e133a3d5e3c041f8ddf66bd6af56521d18d6c8bfbffbc323b40
5
5
  SHA512:
6
- metadata.gz: 3e1e0ced53c59664ba1b3eb53f1711bf82da26e244c4fb8a8b48f05456799639314bb6d625e140802b36dc7f8d13e0e2c23cef34677aacee1ebc443cc09bf40b
7
- data.tar.gz: c5cc2da2ed92067ef28e7c5a5b9fc6af21c8fb96675dd085b219ba26e4aa59a1a165218610104b0fd8d68345987ce7eda7807f072aad74384d9541f310fd8cd4
6
+ metadata.gz: 5597d2ddd0e6a518a078e6fa6d2b55e3c01a022ffadbb018fe76423f761f9c4381a4dc06bc647866b8bea5ea21cdb8230811c0e71cc60f9ef46e78ed2d4057c3
7
+ data.tar.gz: d1659f8a75fe77dbd4e60f8b74884b3354458c520482531b49d7b10e014ca1ccbbc8958743686814a5bc075ecbf03b176bb321055df6bc12145651e6aa5dae40
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.3](https://github.com/anakinj/aikido-ruby-client/tree/v0.0.3) (2024-03-10)
4
+
5
+ **Features:**
6
+
7
+ - Support for even more endpoints
8
+
3
9
  ## [v0.0.2](https://github.com/anakinj/aikido-ruby-client/tree/v0.0.2) (2024-03-10)
4
10
 
5
11
  **Features:**
data/exe/aikido CHANGED
@@ -5,5 +5,10 @@ require 'aikido-ruby-client'
5
5
 
6
6
  client = Aikido::Client.new
7
7
 
8
- puts client.issues
9
- puts client.code_repositories.to_a
8
+ result = client.public_send(ARGV[0], *ARGV[1..-1])
9
+
10
+ if result.is_a?(Aikido::PaginatedResponse)
11
+ puts result.to_a
12
+ else
13
+ puts result
14
+ end
data/lib/aikido/client.rb CHANGED
@@ -30,8 +30,15 @@ module Aikido
30
30
  end
31
31
  end
32
32
 
33
- def issues(params: {})
34
- get('/public/v1/issues/export', params: params).json
33
+ def connect_aws_cloud(role_arn:, name:, environment:)
34
+ handle_response!(authed_http.post('/public/v1/clouds/aws',
35
+ json: { role_arn: role_arn,
36
+ name: name,
37
+ environment: environment })).json
38
+ end
39
+
40
+ def issues(options = {})
41
+ get('/public/v1/issues/export', params: options).json
35
42
  end
36
43
 
37
44
  def issue(id)
@@ -55,7 +62,25 @@ module Aikido
55
62
  end
56
63
 
57
64
  def code_repository_sbom(id, format: 'csv')
58
- get("repositories/code/#{id.to_i}/licenses/export", params: { format: format }).body
65
+ get("/public/v1/repositories/code/#{id.to_i}/licenses/export", params: { format: format }).read
66
+ end
67
+
68
+ def teams
69
+ PaginatedResponse.new do |page|
70
+ get('/public/v1/teams', params: { page: page }).json
71
+ end
72
+ end
73
+
74
+ def create_team(name:)
75
+ handle_response!(authed_http.post('/public/v1/teams', json: { name: name })).json
76
+ end
77
+
78
+ def update_team(id)
79
+ raise NotImplementedError
80
+ end
81
+
82
+ def containers
83
+ get('/public/v1/containers').json
59
84
  end
60
85
 
61
86
  private
@@ -92,6 +117,8 @@ module Aikido
92
117
 
93
118
  def raise_response_error!(response)
94
119
  case response.status
120
+ when 400
121
+ raise Errors::BadRequestError, response
95
122
  when 401
96
123
  raise Errors::UnauthorizedError, response
97
124
  else
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aikido
4
+ # Represents a context for interacting with the Aikido API
5
+ # Context will store data in memory for further processing
6
+ class Context
7
+ def initialize(client: nil)
8
+ @client = client || Aikido::Client.new
9
+ end
10
+
11
+ def issues_for_code_repository(external_repo_id:)
12
+ repo = code_repositories.find { |r| r['external_repo_id'] == external_repo_id }
13
+ return [] unless repo
14
+
15
+ issues.select do |issue|
16
+ issue['code_repo_id'] == repo['id']
17
+ end
18
+ end
19
+
20
+ def code_repositories
21
+ @code_repositories ||= @client.code_repositories
22
+ end
23
+
24
+ def issues
25
+ @issues ||= @client.issues
26
+ end
27
+ end
28
+ end
data/lib/aikido/errors.rb CHANGED
@@ -12,14 +12,19 @@ module Aikido
12
12
  end
13
13
 
14
14
  def message
15
- if @response.json['error_description']
16
- "#{super} - #{@response.json['error_description']}"
15
+ json = @response.json
16
+ if json.key?('error_description')
17
+ "#{super} - #{json['error_description']}"
18
+ elsif json.key?('reason_phrase')
19
+ "#{super} - #{json['reason_phrase']}"
17
20
  else
18
21
  super
19
22
  end
20
23
  end
21
24
  end
25
+
26
+ BadRequestError = Class.new(ApiError)
22
27
  UnauthorizedError = Class.new(ApiError)
23
- NotFoundError = Class.new(ApiError)
28
+ NotFoundError = Class.new(ApiError)
24
29
  end
25
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Aikido
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'aikido/client'
4
+ require 'aikido/context'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aikido-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joakim Antman
@@ -41,6 +41,7 @@ files:
41
41
  - exe/aikido
42
42
  - lib/aikido-ruby-client.rb
43
43
  - lib/aikido/client.rb
44
+ - lib/aikido/context.rb
44
45
  - lib/aikido/errors.rb
45
46
  - lib/aikido/paginated_response.rb
46
47
  - lib/aikido/version.rb
@@ -50,7 +51,7 @@ licenses:
50
51
  metadata:
51
52
  homepage_uri: https://github.com/anakinj/aikido-ruby-client
52
53
  source_code_uri: https://github.com/anakinj
53
- changelog_uri: https://github.com/anakinj/jwk-loader/blob/0.0.2/CHANGELOG.md
54
+ changelog_uri: https://github.com/anakinj/jwk-loader/blob/0.0.3/CHANGELOG.md
54
55
  rubygems_mfa_required: 'true'
55
56
  post_install_message:
56
57
  rdoc_options: []