etna 0.1.45 → 0.1.46
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/lib/etna/clients/magma/formatting/models_csv.rb +14 -4
- data/lib/etna/clients/magma/models.rb +12 -1
- data/lib/etna/clients/magma/workflows/json_validators.rb +5 -1
- data/lib/etna/clients/magma/workflows/model_synchronization_workflow.rb +7 -7
- data/lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb +23 -0
- data/lib/etna/filesystem.rb +2 -0
- data/lib/etna/route.rb +4 -4
- data/lib/etna/server.rb +13 -1
- data/lib/etna/test_auth.rb +4 -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: bf5d46399bfc782d537d246013aeb1cc16bf3b56c8040f84baa92a36c5949fda
|
|
4
|
+
data.tar.gz: 32fabdd9b634b7a0026b8277a55635c16be52e30a60cd7568e8c68938d44d221
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7b48496c8b36afe4aa6f08ef911913bfee6233b3ce50f17e723b38aef03f3aa2b7c9ee6beab94748fa42ff67bfcf68bb73145962ce102d79593055025c439d4
|
|
7
|
+
data.tar.gz: 4f074e556b455f2e6a2e36b30212b781316f198acfa99879059c803d2254ae701bd784adf515e1fb3427734a299546d42a182f08908645ff340ae5a9581dcb91
|
|
@@ -22,6 +22,7 @@ module Etna
|
|
|
22
22
|
:new_attribute_name,
|
|
23
23
|
:attribute_type,
|
|
24
24
|
:link_model_name,
|
|
25
|
+
:link_attribute_name,
|
|
25
26
|
:description,
|
|
26
27
|
:display_name,
|
|
27
28
|
:format_hint,
|
|
@@ -114,7 +115,10 @@ module Etna
|
|
|
114
115
|
if attribute.attribute_type == Etna::Clients::Magma::AttributeType::IDENTIFIER
|
|
115
116
|
# Identifiers for models whose parent link type ends up being a table are non configurable, so we don't
|
|
116
117
|
# want to include them in the CSV.
|
|
117
|
-
if models.find_reciprocal(
|
|
118
|
+
if models.find_reciprocal(
|
|
119
|
+
model: model,
|
|
120
|
+
link_attribute_name: model.name,
|
|
121
|
+
link_model: models.model(model.template.parent))&.attribute_type == Etna::Clients::Magma::AttributeType::TABLE
|
|
118
122
|
return
|
|
119
123
|
end
|
|
120
124
|
else
|
|
@@ -137,6 +141,7 @@ module Etna
|
|
|
137
141
|
attribute_name: attribute.name,
|
|
138
142
|
attribute_type: attribute.attribute_type,
|
|
139
143
|
link_model_name: attribute.link_model_name,
|
|
144
|
+
link_attribute_name: attribute.link_attribute_name,
|
|
140
145
|
reciprocal_link_type: models.find_reciprocal(model: model, attribute: attribute)&.attribute_type,
|
|
141
146
|
description: attribute.description,
|
|
142
147
|
display_name: attribute.display_name,
|
|
@@ -175,7 +180,7 @@ module Etna
|
|
|
175
180
|
# This should line up with the attribute names _on the model itself_.
|
|
176
181
|
ATTRIBUTE_ROW_ENTRIES = [
|
|
177
182
|
:attribute_type,
|
|
178
|
-
:link_model_name, :description,
|
|
183
|
+
:link_model_name, :link_attribute_name, :description,
|
|
179
184
|
:display_name, :format_hint,
|
|
180
185
|
:restricted, :read_only,
|
|
181
186
|
:validation, :attribute_group,
|
|
@@ -223,6 +228,7 @@ module Etna
|
|
|
223
228
|
end
|
|
224
229
|
rescue ImportError => e
|
|
225
230
|
validation_err_block.call(e.message)
|
|
231
|
+
raise e
|
|
226
232
|
end
|
|
227
233
|
|
|
228
234
|
|
|
@@ -255,7 +261,11 @@ module Etna
|
|
|
255
261
|
end
|
|
256
262
|
|
|
257
263
|
row_processor.process(:parent_link_type, :model_name, :parent_model_name) do |parent_link_type, template|
|
|
258
|
-
reciprocal = models.find_reciprocal(
|
|
264
|
+
reciprocal = models.find_reciprocal(
|
|
265
|
+
model_name: template.name,
|
|
266
|
+
link_attribute_name: template.name,
|
|
267
|
+
link_model: models.model(template.parent)
|
|
268
|
+
)
|
|
259
269
|
if reciprocal && reciprocal.attribute_type.to_s != parent_link_type
|
|
260
270
|
raise ImportError.new("Model #{template.name} was provided multiple parent_link_types: #{reciprocal.attribute_type} and #{parent_link_type}")
|
|
261
271
|
end
|
|
@@ -333,7 +343,7 @@ module Etna
|
|
|
333
343
|
att.send(:"#{prop_name}=", value)
|
|
334
344
|
|
|
335
345
|
if att.attribute_type && att.link_model_name
|
|
336
|
-
if att.attribute_type == Etna::Clients::Magma::AttributeType::LINK && models.find_reciprocal(model_name: template.name, attribute: att).nil?
|
|
346
|
+
if att.attribute_type == Etna::Clients::Magma::AttributeType::LINK && models.find_reciprocal(model_name: template.name, attribute: att, link_attribute_name: att.link_attribute_name).nil?
|
|
337
347
|
models.build_model(att.link_model_name).build_template.build_attributes.build_attribute(template.name).tap do |rec_att|
|
|
338
348
|
rec_att.attribute_name = rec_att.name = template.name
|
|
339
349
|
rec_att.display_name = prettify(template.name)
|
|
@@ -239,6 +239,9 @@ module Etna
|
|
|
239
239
|
link_model: self.model(attribute&.link_model_name)
|
|
240
240
|
)
|
|
241
241
|
return nil if model.nil? || model.name.nil?
|
|
242
|
+
|
|
243
|
+
return link_model&.template&.attributes&.all&.find { |a| a.name == link_attribute_name } if link_attribute_name
|
|
244
|
+
|
|
242
245
|
link_model&.template&.attributes&.all&.find { |a| a.link_model_name == model.name }
|
|
243
246
|
end
|
|
244
247
|
|
|
@@ -457,7 +460,7 @@ module Etna
|
|
|
457
460
|
def is_edited?(other)
|
|
458
461
|
# Don't just override == in case need to do a full comparison.
|
|
459
462
|
editable_attribute_names = Attribute::EDITABLE_ATTRIBUTE_ATTRIBUTES.map(&:to_s)
|
|
460
|
-
|
|
463
|
+
|
|
461
464
|
self_editable = raw.slice(*editable_attribute_names)
|
|
462
465
|
other_editable = other.raw.slice(*editable_attribute_names)
|
|
463
466
|
|
|
@@ -505,6 +508,14 @@ module Etna
|
|
|
505
508
|
@raw['attribute_type'] = val
|
|
506
509
|
end
|
|
507
510
|
|
|
511
|
+
def link_attribute_name
|
|
512
|
+
@raw['link_attribute_name']
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
def link_attribute_name=(val)
|
|
516
|
+
@raw['link_attribute_name'] = val
|
|
517
|
+
end
|
|
518
|
+
|
|
508
519
|
def link_model_name
|
|
509
520
|
@raw['link_model_name']
|
|
510
521
|
end
|
|
@@ -113,7 +113,11 @@ module Etna
|
|
|
113
113
|
end
|
|
114
114
|
|
|
115
115
|
def parent_reciprocal_attribute
|
|
116
|
-
@models.find_reciprocal(
|
|
116
|
+
@models.find_reciprocal(
|
|
117
|
+
model: @model,
|
|
118
|
+
link_attribute_name: @model.name,
|
|
119
|
+
link_model: @models.model(@model.template.parent)
|
|
120
|
+
)
|
|
117
121
|
end
|
|
118
122
|
|
|
119
123
|
def name
|
|
@@ -131,7 +131,7 @@ module Etna
|
|
|
131
131
|
unless attribute.attribute_type == AttributeType::PARENT
|
|
132
132
|
if attribute.link_model_name
|
|
133
133
|
ensure_model(attribute.link_model_name)
|
|
134
|
-
ensure_model_link(model_name, attribute.link_model_name, attribute.attribute_name)
|
|
134
|
+
ensure_model_link(model_name, attribute.link_model_name, attribute.attribute_name, attribute.link_attribute_name)
|
|
135
135
|
else
|
|
136
136
|
ensure_model_attribute(model_name, attribute.attribute_name)
|
|
137
137
|
end
|
|
@@ -144,26 +144,26 @@ module Etna
|
|
|
144
144
|
end
|
|
145
145
|
end
|
|
146
146
|
|
|
147
|
-
def ensure_model_link(model_name, link_model_name, attribute_name)
|
|
147
|
+
def ensure_model_link(model_name, link_model_name, attribute_name, link_attribute_name)
|
|
148
148
|
return unless (model = source_models.model(model_name))
|
|
149
149
|
return unless (source_attribute = model.template.attributes.attribute(attribute_name))
|
|
150
150
|
|
|
151
151
|
return unless (link_model = source_models.model(link_model_name))
|
|
152
|
-
|
|
153
|
-
reciprocal = link_model_attributes.all.find do |attr|
|
|
154
|
-
attr.link_model_name == model_name
|
|
155
|
-
end
|
|
152
|
+
return unless (reciprocal = link_model.template.attributes.attribute(link_attribute_name))
|
|
156
153
|
|
|
157
154
|
target_model_name = target_of_source(model_name)
|
|
158
155
|
target_link_model_name = target_of_source(link_model_name)
|
|
159
156
|
|
|
160
157
|
target_attributes = target_models.model(target_model_name).template.attributes
|
|
161
158
|
return if target_attributes.attribute_keys.include?(target_link_model_name)
|
|
159
|
+
return if target_attributes.attribute_keys.include?(reciprocal.attribute_name)
|
|
160
|
+
|
|
161
|
+
# skip non-links for circular references so they don't get added twice
|
|
162
|
+
return if link_model_name == model_name && reciprocal.attribute_type != 'link'
|
|
162
163
|
|
|
163
164
|
add_link = AddLinkAction.new
|
|
164
165
|
add_link.links << AddLinkDefinition.new(model_name: target_model_name, attribute_name: attribute_name, type: source_attribute.attribute_type)
|
|
165
166
|
add_link.links << AddLinkDefinition.new(model_name: target_link_model_name, attribute_name: reciprocal.attribute_name, type: reciprocal.attribute_type)
|
|
166
|
-
|
|
167
167
|
queue_update(add_link)
|
|
168
168
|
end
|
|
169
169
|
|
|
@@ -6,6 +6,8 @@ module Etna
|
|
|
6
6
|
module Clients
|
|
7
7
|
class Metis
|
|
8
8
|
class SyncMetisDataWorkflow < Struct.new(:metis_client, :filesystem, :project_name, :bucket_name, :logger, keyword_init: true)
|
|
9
|
+
DOWNLOAD_REGEX = /^https:\/\/[^\/]*\/(?<project_name>.*)\/download\/(?<bucket_name>.*)\/(?<file_path>[^\?]*).*$/
|
|
10
|
+
|
|
9
11
|
def copy_directory(src, dest, root = dest)
|
|
10
12
|
response = metis_client.list_folder(ListFolderRequest.new(project_name: project_name, bucket_name: bucket_name, folder_path: src))
|
|
11
13
|
|
|
@@ -20,6 +22,27 @@ module Etna
|
|
|
20
22
|
end
|
|
21
23
|
|
|
22
24
|
def copy_file(dest:, url:, stub: false)
|
|
25
|
+
# This does not work due to the magma bucket's restrictions, but if it did work, it'd be super sweet.
|
|
26
|
+
# url_match = DOWNLOAD_REGEX.match(url)
|
|
27
|
+
#
|
|
28
|
+
# if filesystem.instance_of?(Etna::Filesystem::Metis) && !url_match.nil?
|
|
29
|
+
# bucket_name = url_match[:bucket_name]
|
|
30
|
+
# project_name = url_match[:project_name]
|
|
31
|
+
# file_path = url_match[:file_path]
|
|
32
|
+
#
|
|
33
|
+
# metis_client.copy_files(
|
|
34
|
+
# Etna::Clients::Metis::CopyFilesRequest.new(
|
|
35
|
+
# project_name: project_name,
|
|
36
|
+
# revisions: [
|
|
37
|
+
# Etna::Clients::Metis::CopyRevision.new(
|
|
38
|
+
# source: "metis://#{project_name}/#{bucket_name}/#{file_path}",
|
|
39
|
+
# dest: "metis://#{filesystem.project_name}/#{filesystem.bucket_name}#{dest}",
|
|
40
|
+
# )
|
|
41
|
+
# ]
|
|
42
|
+
# )
|
|
43
|
+
# )
|
|
44
|
+
# end
|
|
45
|
+
|
|
23
46
|
metadata = metis_client.file_metadata(url)
|
|
24
47
|
size = metadata[:size]
|
|
25
48
|
|
data/lib/etna/filesystem.rb
CHANGED
|
@@ -251,6 +251,8 @@ module Etna
|
|
|
251
251
|
end
|
|
252
252
|
|
|
253
253
|
class Metis < Filesystem
|
|
254
|
+
attr_reader :project_name, :bucket_name
|
|
255
|
+
|
|
254
256
|
def initialize(metis_client:, project_name:, bucket_name:, root: '/', uuid: SecureRandom.uuid)
|
|
255
257
|
@metis_client = metis_client
|
|
256
258
|
@project_name = project_name
|
data/lib/etna/route.rb
CHANGED
|
@@ -38,11 +38,11 @@ module Etna
|
|
|
38
38
|
|
|
39
39
|
UNSAFE=/[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,]/
|
|
40
40
|
|
|
41
|
-
def self.path(route, params=nil)
|
|
41
|
+
def self.path(route, params=nil, &block)
|
|
42
42
|
if params
|
|
43
43
|
PARAM_TYPES.reduce(route) do |path,pat|
|
|
44
44
|
path.gsub(pat) do
|
|
45
|
-
params[$1.to_sym].split('/').map { |c| URI.encode_www_form_component(c) }.join('/')
|
|
45
|
+
params[$1.to_sym].split('/').map { |c| block_given? ? yield(c) : URI.encode_www_form_component(c) }.join('/')
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
else
|
|
@@ -50,8 +50,8 @@ module Etna
|
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def path(params=nil)
|
|
54
|
-
self.class.path(@route, params)
|
|
53
|
+
def path(params=nil, &block)
|
|
54
|
+
self.class.path(@route, params, &block)
|
|
55
55
|
end
|
|
56
56
|
|
|
57
57
|
def parts
|
data/lib/etna/server.rb
CHANGED
|
@@ -3,7 +3,19 @@ module Etna
|
|
|
3
3
|
class Server
|
|
4
4
|
class << self
|
|
5
5
|
def route(method, path, options={}, &block)
|
|
6
|
-
|
|
6
|
+
# For healthchecks, set up servers
|
|
7
|
+
# with an OPTIONS route on /, with noauth
|
|
8
|
+
@routes ||= [
|
|
9
|
+
Etna::Route.new(
|
|
10
|
+
'OPTIONS',
|
|
11
|
+
'/',
|
|
12
|
+
{
|
|
13
|
+
auth: {
|
|
14
|
+
noauth: true
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
)
|
|
18
|
+
]
|
|
7
19
|
|
|
8
20
|
@routes << Etna::Route.new(
|
|
9
21
|
method,
|
data/lib/etna/test_auth.rb
CHANGED
|
@@ -54,6 +54,9 @@ module Etna
|
|
|
54
54
|
|
|
55
55
|
return false unless token
|
|
56
56
|
|
|
57
|
+
# Useful for testing certain behavior
|
|
58
|
+
params = request.env["rack.request.params"]
|
|
59
|
+
|
|
57
60
|
# Here we simply base64-encode our user hash and pass it through
|
|
58
61
|
# In order to behave more like "real" tokens, we expect the user hash to be
|
|
59
62
|
# in index 1 after splitting by ".".
|
|
@@ -63,7 +66,7 @@ module Etna
|
|
|
63
66
|
request.env['etna.user'] = Etna::User.new(
|
|
64
67
|
update_payload(payload, token, request),
|
|
65
68
|
token
|
|
66
|
-
)
|
|
69
|
+
) unless !!params[:do_not_set_user]
|
|
67
70
|
end
|
|
68
71
|
|
|
69
72
|
def approve_hmac(request)
|
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.
|
|
4
|
+
version: 0.1.46
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Saurabh Asthana
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-08-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|