etna 0.1.29 → 0.1.30

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: 8d4c9465edd6fd280a9cd91b9c3abbc3ef08114a46e3ffb41e14a20ce612fe7f
4
- data.tar.gz: bfd29114b8db331c92f79be1fe765fa6b64c7b5ee4a8543cd75f6c9fe7c38a84
3
+ metadata.gz: 9118a99396cf2b041083ff982fb680a5d60096802699789962d19bcf3fecf41d
4
+ data.tar.gz: 3145994427f0fa57bf796e68dfe4e69156eb407f144a6afe048bd17454201949
5
5
  SHA512:
6
- metadata.gz: 8ea7b21a563d743cdb6f8a06f92ca15fdeb56ecb291b27ff32a555a8f863cd6ce4400fc6954ae5620a9766bbafbed861609f52309f4de3d407f117d4f9b3f1b1
7
- data.tar.gz: 6a9530ee4beb8e6a6d7940c30a2a2bc7412dc4420492e650cb731eac4e5e958a4ca630a966aede4591706ae79212e3290b1a080b5fafe5549df24cc302cbc82b
6
+ metadata.gz: ec59fd21bcf8bb88848e0c8c628a0185226d7dd7ee1af79525a790ac2117fe2b7d44b9d3e514717e9c23233bd531c9d3c8404981892174adbeee221e62118c33
7
+ data.tar.gz: bf0cc8cea804bb218e7f487ea014c84e394738760dc400de1c716b780da6a668ca5f853a72acfff7a77cd979f4a90004a866cdd16cb26a008a3498c83161fd71
@@ -91,6 +91,10 @@ module Etna::Application
91
91
  (ENV["#{self.class.name.upcase}_ENV"] || :development).to_sym
92
92
  end
93
93
 
94
+ def id
95
+ ENV["APP_NAME"] || self.class.name.snake_case.split(/::/).last
96
+ end
97
+
94
98
  def find_descendents(klass)
95
99
  ObjectSpace.each_object(Class).select do |k|
96
100
  k < klass
data/lib/etna/client.rb CHANGED
@@ -17,6 +17,29 @@ module Etna
17
17
 
18
18
  attr_reader :routes
19
19
 
20
+ def signed_route_path(route, params)
21
+ path = route_path(route,params)
22
+
23
+ signatory = params.delete(:signatory)
24
+
25
+ return path unless signatory
26
+
27
+ hmac = Etna::Hmac.new(
28
+ signatory,
29
+ method: route[:method],
30
+ host: URI(@host).host,
31
+ path: path,
32
+ expiration: (DateTime.now + 10).iso8601,
33
+ id: signatory.id,
34
+ nonce: SecureRandom.hex,
35
+ headers: params.except(*route[:params].map(&:to_sym))
36
+ )
37
+
38
+ url_params = hmac.url_params(route[:method] == 'GET')
39
+
40
+ return url_params[:path] + '?' + url_params[:query]
41
+ end
42
+
20
43
  def route_path(route, params)
21
44
  Etna::Route.path(route[:route], params)
22
45
  end
@@ -60,14 +83,19 @@ module Etna
60
83
  @routes.each do |route|
61
84
  next unless route[:name]
62
85
  self.define_singleton_method(route[:name]) do |params = {}|
63
-
64
86
  missing_params = (route[:params] - params.keys.map(&:to_s))
87
+
65
88
  unless missing_params.empty?
66
89
  raise ArgumentError, "Missing required #{missing_params.size > 1 ?
67
90
  'params' : 'param'} #{missing_params.join(', ')}"
68
91
  end
69
92
 
70
- response = send(route[:method].downcase, route_path(route, params), params)
93
+ response = send(
94
+ route[:method].downcase,
95
+ signed_route_path(route, params),
96
+ params
97
+ )
98
+
71
99
  if block_given?
72
100
  yield response
73
101
  else
@@ -37,8 +37,7 @@ module Etna
37
37
  end
38
38
 
39
39
  def update_attributes
40
- method = json_values ? :update_json : :update
41
- magma_crud.update_records(method: method) do |update_request|
40
+ magma_crud.update_records(method: :update_json) do |update_request|
42
41
  each_revision do |model_name, record_name, revision|
43
42
  update_request.update_revision(model_name, record_name, revision)
44
43
  end
@@ -53,10 +52,18 @@ module Etna
53
52
  end
54
53
 
55
54
  class RowBase
56
- def stripped_value(attribute_value)
55
+ def attribute_is_json?(attribute)
56
+ [Etna::Clients::Magma::AttributeType::FILE,
57
+ Etna::Clients::Magma::AttributeType::FILE_COLLECTION,
58
+ Etna::Clients::Magma::AttributeType::IMAGE].include?(attribute.attribute_type)
59
+ end
60
+
61
+ def stripped_value(attribute, attribute_value)
57
62
  attribute_value = attribute_value&.strip
58
63
 
59
- if attribute_value && @workflow.json_values && attribute_value != @workflow.hole_value
64
+ if attribute_value &&
65
+ ( @workflow.json_values || attribute_is_json?(attribute) ) &&
66
+ attribute_value != @workflow.hole_value
60
67
  attribute_value = JSON.parse(attribute_value)
61
68
  end
62
69
  attribute_value
@@ -123,7 +130,7 @@ module Etna
123
130
  raise "Invalid attribute #{attribute_name} for model #{model_name}."
124
131
  end
125
132
 
126
- stripped = stripped_value(@raw[index + 1])
133
+ stripped = stripped_value(attribute, @raw[index + 1])
127
134
  unless @workflow.hole_value.nil?
128
135
  next if stripped == @workflow.hole_value
129
136
  end
@@ -234,7 +241,7 @@ module Etna
234
241
  attribute_name_clean = attribute_name.strip
235
242
  raise "Invalid attribute \"#{attribute_name_clean}\" for model #{@model_name}." unless attribute = @workflow.find_attribute(@model_name, attribute_name_clean)
236
243
 
237
- attributes[attribute_name_clean] = stripped_value(@raw[attribute_name])
244
+ attributes[attribute_name_clean] = stripped_value(attribute, @raw[attribute_name])
238
245
  end
239
246
  end
240
247
  end
@@ -18,6 +18,35 @@ class DirectedGraph
18
18
  parents[parent] = parent_parents
19
19
  end
20
20
 
21
+ def serialized_path_from(root)
22
+ seen = Set.new
23
+ [].tap do |result|
24
+ result << root
25
+ seen.add(root)
26
+ path_q = paths_from(root)
27
+
28
+ until path_q.empty?
29
+ next_path = path_q.shift
30
+ next if next_path.nil?
31
+
32
+ until next_path.empty?
33
+ next_n = next_path.shift
34
+ next if next_n.nil?
35
+ next if seen.include?(next_n)
36
+
37
+ if @parents[next_n].keys.any? { |p| !seen.include?(p) }
38
+ next_path.unshift(next_n)
39
+ path_q.push(next_path)
40
+ break
41
+ else
42
+ result << next_n
43
+ seen.add(next_n)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+
21
50
  def paths_from(root)
22
51
  [].tap do |result|
23
52
  parents_of_map = descendants(root)
data/lib/etna/hmac.rb CHANGED
@@ -20,14 +20,14 @@ module Etna
20
20
  end
21
21
 
22
22
  # this returns arguments for URI::HTTP.build
23
- def url_params
23
+ def url_params(with_headers=true)
24
24
  params = {
25
25
  signature: signature,
26
26
  expiration: @expiration,
27
27
  nonce: @nonce,
28
28
  id: @id.to_s,
29
29
  headers: @headers.keys.join(','),
30
- }.merge(@headers).map do |name, value|
30
+ }.merge(with_headers ? @headers : {}).map do |name, value|
31
31
  [
32
32
  "X-Etna-#{ name.to_s.split(/_/).map(&:capitalize).join('-') }",
33
33
  value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-23 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack