oso-cloud 1.5.2 → 1.7.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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/oso/api.rb +17 -0
- data/lib/oso/helpers.rb +2 -1
- data/lib/oso/oso.rb +90 -74
- data/lib/oso/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 747cf1fda61eae9e9a96076e782a503e3c440a3aa7049a6b8f74ce8d0c697273
|
4
|
+
data.tar.gz: 5a3fcbb8574c21416fa81dbf8e1054dfef59337da6c72ff686c06304b3c27711
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f0a4732c2f76b499f1dc962a0ee806fd6d2c17abdb734d2a1ce448c35eff4781dafce6aec90f39ede78e06fac44bcdbbb11033949867d562007c3f15a3fcee7
|
7
|
+
data.tar.gz: 41b95a2e852e431e1e1598277abeaad8b76bb174ea562d52a6e9c1d9c644f12a5799e1cde75063bf1d6757eb4cd62be0463c369192f8644353bb791a69391e43
|
data/Gemfile.lock
CHANGED
data/lib/oso/api.rb
CHANGED
@@ -260,6 +260,16 @@ module OsoCloud
|
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
|
+
# @!visibility private
|
264
|
+
class LocalActionsQuery
|
265
|
+
attr_reader :query, :data_bindings
|
266
|
+
|
267
|
+
def initialize(query:, data_bindings:)
|
268
|
+
@query = query
|
269
|
+
@data_bindings = data_bindings
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
263
273
|
# @!visibility private
|
264
274
|
class LocalQueryResult
|
265
275
|
attr_reader :sql
|
@@ -436,6 +446,13 @@ module OsoCloud
|
|
436
446
|
LocalQueryResult.new(**result)
|
437
447
|
end
|
438
448
|
|
449
|
+
def post_actions_query(query)
|
450
|
+
url = '/actions_query'
|
451
|
+
data = LocalActionsQuery.new(query: query, data_bindings: @data_bindings)
|
452
|
+
result = POST(url, nil, data, false)
|
453
|
+
LocalQueryResult.new(**result)
|
454
|
+
end
|
455
|
+
|
439
456
|
def clear_data
|
440
457
|
url = '/clear_data'
|
441
458
|
result = POST(url, nil, nil, true)
|
data/lib/oso/helpers.rb
CHANGED
@@ -4,8 +4,9 @@ module OsoCloud
|
|
4
4
|
# @!visibility private
|
5
5
|
def self.extract_value(x)
|
6
6
|
return OsoCloud::Core::Value.new(type: 'String', id: x) if x.is_a? String
|
7
|
-
|
8
7
|
return OsoCloud::Core::Value.new(type: nil, id: nil) if x.nil?
|
8
|
+
return OsoCloud::Core::Value.new(type: 'Boolean', id: x.to_s) if [true, false].include? x
|
9
|
+
return OsoCloud::Core::Value.new(type: 'Integer', id: x.to_s) if x.is_a? Integer
|
9
10
|
|
10
11
|
type = (x.type.nil? ? nil : x.type.to_s)
|
11
12
|
id = (x.id.nil? ? nil : x.id.to_s)
|
data/lib/oso/oso.rb
CHANGED
@@ -28,67 +28,82 @@ module OsoCloud
|
|
28
28
|
# Any other elements in the array, which together represent the fact's arguments,
|
29
29
|
# can be "OsoCloud::Value" objects or strings.
|
30
30
|
class Oso
|
31
|
-
attr_reader :experimental
|
32
|
-
|
33
31
|
def initialize(url: 'https://cloud.osohq.com', api_key: nil, fallback_url: nil, data_bindings: nil)
|
34
|
-
@api = OsoCloud::Core::Api.new(url: url, api_key: api_key, data_bindings: data_bindings,
|
35
|
-
|
32
|
+
@api = OsoCloud::Core::Api.new(url: url, api_key: api_key, data_bindings: data_bindings,
|
33
|
+
options: { fallback_url: fallback_url })
|
36
34
|
end
|
37
35
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
actor_type: actor_typed_id.type,
|
59
|
-
actor_id: actor_typed_id.id,
|
60
|
-
action: action,
|
61
|
-
resource_type: resource_typed_id.type,
|
62
|
-
resource_id: resource_typed_id.id,
|
63
|
-
context_facts: []
|
64
|
-
)
|
36
|
+
##
|
37
|
+
# Check a permission depending on data both in Oso Cloud and stored in a local database
|
38
|
+
#
|
39
|
+
# Returns a SQL query to run against the local database
|
40
|
+
#
|
41
|
+
# @param actor [OsoCloud::Value]
|
42
|
+
# @param action [String]
|
43
|
+
# @param resource [OsoCloud::Value]
|
44
|
+
# @return [String]
|
45
|
+
def authorize_local(actor, action, resource)
|
46
|
+
actor_typed_id = actor.to_api_value
|
47
|
+
resource_typed_id = resource.to_api_value
|
48
|
+
result = @api.post_authorize_query(
|
49
|
+
OsoCloud::Core::AuthorizeQuery.new(
|
50
|
+
actor_type: actor_typed_id.type,
|
51
|
+
actor_id: actor_typed_id.id,
|
52
|
+
action: action,
|
53
|
+
resource_type: resource_typed_id.type,
|
54
|
+
resource_id: resource_typed_id.id,
|
55
|
+
context_facts: []
|
65
56
|
)
|
66
|
-
|
67
|
-
|
57
|
+
)
|
58
|
+
result.sql
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# List authorized resources depending on data both in Oso Cloud and stored in a local database
|
63
|
+
#
|
64
|
+
# Returns a SQL query to run against the local database
|
65
|
+
#
|
66
|
+
# @param actor [OsoCloud::Value]
|
67
|
+
# @param action [String]
|
68
|
+
# @param resource_type [String]
|
69
|
+
# @param column [String]
|
70
|
+
# @return [String]
|
71
|
+
def list_local(actor, action, resource_type, column)
|
72
|
+
actor_typed_id = actor.to_api_value
|
73
|
+
result = @api.post_list_query(
|
74
|
+
query: OsoCloud::Core::ListQuery.new(
|
75
|
+
actor_type: actor_typed_id.type,
|
76
|
+
actor_id: actor_typed_id.id,
|
77
|
+
action: action,
|
78
|
+
resource_type: resource_type,
|
79
|
+
context_facts: []
|
80
|
+
),
|
81
|
+
column: column
|
82
|
+
)
|
83
|
+
result.sql
|
84
|
+
end
|
68
85
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
),
|
88
|
-
column: column
|
86
|
+
##
|
87
|
+
# Fetches a query that can be run against your database to fetch the actions an actor can perform on a resource.
|
88
|
+
#
|
89
|
+
# Returns a SQL query to run against the local database
|
90
|
+
#
|
91
|
+
# @param actor [OsoCloud::Value]
|
92
|
+
# @param resource [OsoCloud::Value]
|
93
|
+
# @return [String]
|
94
|
+
def actions_local(actor, resource)
|
95
|
+
actor_typed_id = actor.to_api_value
|
96
|
+
resource_typed_id = resource.to_api_value
|
97
|
+
result = @api.post_actions_query(
|
98
|
+
OsoCloud::Core::ActionsQuery.new(
|
99
|
+
actor_type: actor_typed_id.type,
|
100
|
+
actor_id: actor_typed_id.id,
|
101
|
+
resource_type: resource_typed_id.type,
|
102
|
+
resource_id: resource_typed_id.id,
|
103
|
+
context_facts: []
|
89
104
|
)
|
90
|
-
|
91
|
-
|
105
|
+
)
|
106
|
+
result.sql
|
92
107
|
end
|
93
108
|
|
94
109
|
##
|
@@ -335,6 +350,7 @@ module OsoCloud
|
|
335
350
|
context_facts: OsoCloud::Helpers.params_to_facts(context_facts)))
|
336
351
|
OsoCloud::Helpers.facts_to_params(result.results)
|
337
352
|
end
|
353
|
+
|
338
354
|
##
|
339
355
|
# List authorized actions for a batch of queries
|
340
356
|
#
|
@@ -345,26 +361,26 @@ module OsoCloud
|
|
345
361
|
# @return [Array<Array<String>>]
|
346
362
|
# @see Oso for more information about facts
|
347
363
|
def bulk_actions(actor, queries:)
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
364
|
+
actor_typed_id = actor.to_api_value
|
365
|
+
data = queries.map do |q|
|
366
|
+
context_facts = []
|
367
|
+
resource = nil
|
368
|
+
if q.is_a?(Array)
|
369
|
+
resource = q[0]
|
370
|
+
context_facts = q[1]
|
371
|
+
else
|
372
|
+
resource = q
|
373
|
+
end
|
374
|
+
resource_typed_id = resource.to_api_value
|
375
|
+
OsoCloud::Core::ActionsQuery.new(
|
376
|
+
actor_type: actor_typed_id.type,
|
377
|
+
actor_id: actor_typed_id.id,
|
378
|
+
resource_type: resource_typed_id.type,
|
379
|
+
resource_id: resource_typed_id.id,
|
380
|
+
context_facts: OsoCloud::Helpers.params_to_facts(context_facts)
|
381
|
+
)
|
366
382
|
end
|
367
|
-
@api.post_bulk_actions(data).map
|
383
|
+
@api.post_bulk_actions(data).map(&:results)
|
368
384
|
end
|
369
385
|
end
|
370
386
|
end
|
data/lib/oso/version.rb
CHANGED
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.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oso Security, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|