oso-cloud 1.8.0 → 1.9.1

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: aa3ca5a542cd09609eab342416030091943a7e777e6fdccd8b6caf1b1b6a5a99
4
- data.tar.gz: 34c40e85594b08ef91ead85505c1488d42fc1291bcf1f3583dacce49abb47446
3
+ metadata.gz: 971ae28cc897b2bb71f88e0129fedb100bccc8edf285b49c7c62b045bdf360cc
4
+ data.tar.gz: 75e108ed7c4090b207ff9f2860d67c80e5b2e0e257ba4e6ee12f7b89148228f6
5
5
  SHA512:
6
- metadata.gz: e950c324bbb312688fe5b2e119d761fb5e7189ac087386ef232d632b1179d7ad2db0a3f7c63ea468088fd3a4d1b4953d4837f8462b6582bb3f09f4c0ed93eb9e
7
- data.tar.gz: 24bed9cfb7b77c0fa77867166188e55e2811e63c5ed0fedb111d013338b8a8fdd59c0edf084169ad58d11c1988f4fb53a0e14d882aa8d827a195afc12f1129e7
6
+ metadata.gz: ad4bcfe3809d95409113caf477b43fdf3dd18b24a8d4d5fc2479cdae0207fc187a16121406bc63a573c8c160d41e4a37e8aa56f761a0cd8195552238df68882e
7
+ data.tar.gz: e7dc543034f9175b7a533569e780166caf07fa836a614881a482e295d66cfdce82e691a5c46a4b23603e25c256458c5dc50fb1f4eb305649fdadc2e610a7a6e3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- oso-cloud (1.8.0)
4
+ oso-cloud (1.9.1)
5
5
  faraday (~> 2.5.2)
6
6
  faraday-net_http_persistent (~> 2.0)
7
7
  faraday-retry (~> 2.0.0)
data/README.md CHANGED
@@ -32,7 +32,7 @@ architecture, check out the
32
32
  - To get up and running with Oso Cloud, try the
33
33
  [Quickstart guide](https://www.osohq.com/docs/get-started/quickstart).
34
34
  - For method-level documentation, see the
35
- [Ruby Client API documentation](https://www.osohq.com/docs/reference/client-apis/ruby).
35
+ [Ruby Client API documentation](https://www.osohq.com/docs/app-integration/client-apis/ruby).
36
36
  - Full documentation is available at
37
37
  [osohq.com/docs](https://www.osohq.com/docs).
38
38
  - To learn about authorization best practices (not specific to Oso), read the
data/lib/oso/api.rb CHANGED
@@ -511,6 +511,9 @@ module OsoCloud
511
511
  req.params = params unless params.nil?
512
512
  req.headers = headers
513
513
  end
514
+
515
+ create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
516
+
514
517
  response.body
515
518
  rescue Faraday::BadRequestError, Faraday::ServerError, Faraday::ConnectionFailed, Faraday::TimeoutError,
516
519
  Faraday::SSLError => e
@@ -520,6 +523,9 @@ module OsoCloud
520
523
  req.params = params unless params.nil?
521
524
  req.headers = headers
522
525
  end
526
+
527
+ create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
528
+
523
529
  response.body
524
530
  end
525
531
  rescue Faraday::Error => e
@@ -542,6 +548,8 @@ module OsoCloud
542
548
  req.headers = headers
543
549
  end
544
550
 
551
+ create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
552
+
545
553
  @last_offset = response.headers[:OsoOffset] if isMutation
546
554
  response.body
547
555
  # only attempt fallback on 5xx, and connection failure conditions
@@ -554,6 +562,7 @@ module OsoCloud
554
562
  req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
555
563
  req.headers = headers
556
564
  end
565
+ create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
557
566
  response.body
558
567
  end
559
568
  rescue Faraday::Error => e
@@ -573,6 +582,9 @@ module OsoCloud
573
582
  req.headers = headers
574
583
  req.body = OsoCloud::Helpers.to_hash(body) unless body.nil?
575
584
  end
585
+
586
+ create_api_error(response, "Unexpected status #{response.status}") if response.status >= 300 || response.status < 200
587
+
576
588
  response.body
577
589
  rescue Faraday::Error => e
578
590
  handle_faraday_error e
@@ -580,14 +592,18 @@ module OsoCloud
580
592
 
581
593
  def handle_faraday_error(error)
582
594
  resp = error.response
595
+ create_api_error(resp, error.message)
596
+ end
597
+
598
+ def create_api_error(resp, message)
583
599
  formatted_request_id = if resp.nil? || resp[:headers].nil? || resp[:headers]['X-Request-ID'].nil?
584
600
  ''
585
601
  else
586
602
  ' (Request ID: ' + resp[:headers]['X-Request-ID'] + ')'
587
603
  end
588
604
 
589
- err = if resp.nil? || resp[:body].nil? || resp[:body][:message].nil?
590
- error.message
605
+ err = if resp.nil? || resp[:body].nil? || !resp[:body].is_a?(Hash) || resp[:body][:message].nil?
606
+ message
591
607
  else
592
608
  resp[:body][:message]
593
609
  end
data/lib/oso/oso.rb CHANGED
@@ -8,7 +8,7 @@ require 'oso/helpers'
8
8
 
9
9
  ##
10
10
  # For more detailed documentation, see
11
- # https://www.osohq.com/docs/reference/client-apis/ruby
11
+ # https://www.osohq.com/docs/app-integration/client-apis/ruby
12
12
  module OsoCloud
13
13
  # Represents an object in your application, with a type and id.
14
14
  # Both "type" and "id" should be strings.
@@ -41,8 +41,9 @@ module OsoCloud
41
41
  # @param actor [OsoCloud::Value]
42
42
  # @param action [String]
43
43
  # @param resource [OsoCloud::Value]
44
+ # @param context_facts [Array<fact>]
44
45
  # @return [String]
45
- def authorize_local(actor, action, resource)
46
+ def authorize_local(actor, action, resource, context_facts = [])
46
47
  actor_typed_id = actor.to_api_value
47
48
  resource_typed_id = resource.to_api_value
48
49
  result = @api.post_authorize_query(
@@ -52,7 +53,7 @@ module OsoCloud
52
53
  action: action,
53
54
  resource_type: resource_typed_id.type,
54
55
  resource_id: resource_typed_id.id,
55
- context_facts: []
56
+ context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
56
57
  )
57
58
  )
58
59
  result.sql
@@ -67,8 +68,9 @@ module OsoCloud
67
68
  # @param action [String]
68
69
  # @param resource_type [String]
69
70
  # @param column [String]
71
+ # @param context_facts [Array<fact>]
70
72
  # @return [String]
71
- def list_local(actor, action, resource_type, column)
73
+ def list_local(actor, action, resource_type, column, context_facts = [])
72
74
  actor_typed_id = actor.to_api_value
73
75
  result = @api.post_list_query(
74
76
  query: OsoCloud::Core::ListQuery.new(
@@ -76,7 +78,7 @@ module OsoCloud
76
78
  actor_id: actor_typed_id.id,
77
79
  action: action,
78
80
  resource_type: resource_type,
79
- context_facts: []
81
+ context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
80
82
  ),
81
83
  column: column
82
84
  )
@@ -90,8 +92,9 @@ module OsoCloud
90
92
  #
91
93
  # @param actor [OsoCloud::Value]
92
94
  # @param resource [OsoCloud::Value]
95
+ # @param context_facts [Array<fact>]
93
96
  # @return [String]
94
- def actions_local(actor, resource)
97
+ def actions_local(actor, resource, context_facts = [])
95
98
  actor_typed_id = actor.to_api_value
96
99
  resource_typed_id = resource.to_api_value
97
100
  result = @api.post_actions_query(
@@ -100,7 +103,7 @@ module OsoCloud
100
103
  actor_id: actor_typed_id.id,
101
104
  resource_type: resource_typed_id.type,
102
105
  resource_id: resource_typed_id.id,
103
- context_facts: []
106
+ context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
104
107
  )
105
108
  )
106
109
  result.sql
data/lib/oso/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module OsoCloud
2
- VERSION = '1.8.0'.freeze
2
+ VERSION = '1.9.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oso-cloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oso Security, Inc.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-10-28 00:00:00.000000000 Z
11
+ date: 2025-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -94,7 +94,7 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '7.0'
97
- description:
97
+ description:
98
98
  email:
99
99
  - support@osohq.com
100
100
  executables: []
@@ -119,7 +119,7 @@ homepage: https://www.osohq.com/
119
119
  licenses:
120
120
  - Apache-2.0
121
121
  metadata: {}
122
- post_install_message:
122
+ post_install_message:
123
123
  rdoc_options: []
124
124
  require_paths:
125
125
  - lib
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubygems_version: 3.2.33
138
- signing_key:
138
+ signing_key:
139
139
  specification_version: 4
140
140
  summary: Oso Cloud Ruby client
141
141
  test_files: []