etna 0.1.51 → 0.2.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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/bin/etna +2 -2
  3. data/etna.completion +75 -50
  4. data/lib/commands.rb +10 -8
  5. data/lib/etna/application.rb +33 -0
  6. data/lib/etna/auth.rb +5 -2
  7. data/lib/etna/client.rb +7 -12
  8. data/lib/etna/clients/base_client.rb +10 -2
  9. data/lib/etna/clients/gnomon/client.rb +20 -0
  10. data/lib/etna/clients/gnomon/models.rb +33 -0
  11. data/lib/etna/clients/gnomon.rb +2 -0
  12. data/lib/etna/clients/janus/client.rb +26 -0
  13. data/lib/etna/clients/janus/models.rb +16 -0
  14. data/lib/etna/clients/janus/workflows/generate_token_workflow.rb +1 -1
  15. data/lib/etna/clients/magma/client.rb +126 -6
  16. data/lib/etna/clients/magma/models.rb +64 -22
  17. data/lib/etna/clients/magma/workflows/model_synchronization_workflow.rb +2 -4
  18. data/lib/etna/clients/metis/client.rb +66 -2
  19. data/lib/etna/clients/metis/models.rb +138 -85
  20. data/lib/etna/clients/metis/workflows/ingest_metis_data_workflow.rb +15 -5
  21. data/lib/etna/clients/metis/workflows/metis_upload_workflow.rb +1 -0
  22. data/lib/etna/clients/models.rb +19 -0
  23. data/lib/etna/clients/polyphemus/client.rb +96 -0
  24. data/lib/etna/clients.rb +2 -0
  25. data/lib/etna/controller.rb +31 -6
  26. data/lib/etna/cross_origin.rb +1 -1
  27. data/lib/etna/cwl.rb +1 -1
  28. data/lib/etna/errors.rb +8 -0
  29. data/lib/etna/filesystem.rb +5 -170
  30. data/lib/etna/hmac.rb +4 -4
  31. data/lib/etna/instrumentation.rb +6 -6
  32. data/lib/etna/redirect.rb +1 -1
  33. data/lib/etna/remote.rb +18 -2
  34. data/lib/etna/route.rb +3 -0
  35. data/lib/etna/spec/event_log.rb +16 -0
  36. data/lib/etna/spec/vcr.rb +3 -3
  37. data/lib/etna/test_auth.rb +1 -1
  38. data/lib/etna/user.rb +1 -5
  39. data/lib/helpers.rb +8 -0
  40. metadata +22 -5
@@ -70,7 +70,6 @@ module Etna
70
70
  rd, wd = IO.pipe
71
71
 
72
72
  cmd = mkcommand(rd, wd, file, opts, size_hint: size_hint)
73
- puts "in mkio: #{cmd}"
74
73
  pid = spawn(*cmd)
75
74
  q = Queue.new
76
75
 
@@ -103,173 +102,6 @@ module Etna
103
102
  end
104
103
  end
105
104
 
106
- class AsperaCliFilesystem < Filesystem
107
- include WithPipeConsumer
108
-
109
- def initialize(ascli_bin:, ascp_bin:, host:, username:, password: nil, key_file: nil, port: 33001)
110
- @ascli_bin = ascli_bin
111
- @ascp_bin = ascp_bin
112
- @username = username
113
- @password = password
114
- @key_file = key_file
115
- @host = host
116
- @port = port
117
-
118
- @config_file = File.join(Dir.mktmpdir, "config.yml")
119
- config = {}
120
- config["config"] = {"version" => `#{ascli_bin} --version`.chomp}
121
- config["default"] = {"server" => "clifilesystem"}
122
- server_config = config["clifilesystem"] = {
123
- "url" => "ssh://#{host}:#{port}",
124
- "username" => username,
125
- "ssh_options" => {append_all_supported_algorithms: true},
126
- }
127
-
128
- if password
129
- server_config["password"] = password
130
- elsif key_file
131
- server_config["ssh_keys"] = key_file
132
- else
133
- raise "One of password or key_file must be provided"
134
- end
135
-
136
- ::File.open(@config_file, "w") do |file|
137
- file.write(config.to_yaml)
138
- end
139
- end
140
-
141
- def run_ascli_cmd(cmd, *opts)
142
- output, status = Open3.capture2(@ascli_bin, "server", cmd, *opts, "--format=json", "--config=#{@config_file}")
143
-
144
- if status.success?
145
- return JSON.parse(output)
146
- end
147
-
148
- nil
149
- end
150
-
151
- def with_writeable(dest, opts = 'w', size_hint: nil, &block)
152
- mkio(dest, opts, size_hint: size_hint, &block)
153
- end
154
-
155
- def with_readable(src, opts = 'r', &block)
156
- mkio(src, opts, &block)
157
- end
158
-
159
- def mkdir_p(dir)
160
- raise "Failed to mkdir #{dir}" unless run_ascli_cmd("mkdir", dir)
161
- end
162
-
163
- def rm_rf(dir)
164
- raise "Failed to rm_rf #{dir}" unless run_ascli_cmd("rm", dir)
165
- end
166
-
167
- def tmpdir
168
- tmpdir = "/Upload/Temp/#{SecureRandom.hex}"
169
- mkdir_p(tmpdir)
170
- tmpdir
171
- end
172
-
173
- def exist?(src)
174
- !run_ascli_cmd("ls", src).nil?
175
- end
176
-
177
- def mv(src, dest)
178
- raise "Failed to mv #{src} to #{dest}" unless run_ascli_cmd("mv", src, dest)
179
- end
180
-
181
- def mkcommand(rd, wd, file, opts, size_hint: nil)
182
- env = {}
183
- cmd = [env, @ascp_bin]
184
-
185
- if @password
186
- env['ASPERA_SCP_PASS'] = @password
187
- else
188
- cmd << "-i"
189
- cmd << @key_file
190
- end
191
-
192
- cmd << "-O"
193
- cmd << @port.to_s
194
-
195
- cmd << "-P"
196
- cmd << @port.to_s
197
-
198
- cmd << "-v"
199
- cmd << "-k"
200
- cmd << "0"
201
- cmd << "--file-manifest=text"
202
- cmd << "--file-manifest-path=/var/tmp"
203
- cmd << "--file-checksum=md5"
204
- cmd << "-l"
205
- cmd << "100m"
206
- cmd << "--overwrite=always"
207
-
208
- remote_path = file
209
- # https://download.asperasoft.com/download/docs/entsrv/3.9.1/es_admin_linux/webhelp/index.html#dita/stdio_2.html
210
- local_path = "stdio://"
211
- if size_hint
212
- local_path += "/?#{size_hint}"
213
- end
214
-
215
- if opts.include?('r')
216
- cmd << '--mode=recv'
217
- cmd << "--host=#{@host}"
218
- cmd << "--user=#{@username}"
219
- cmd << remote_path
220
- cmd << local_path
221
-
222
- cmd << {out: wd}
223
- elsif opts.include?('w')
224
- cmd << '--mode=send'
225
- cmd << "--host=#{@host}"
226
- cmd << "--user=#{@username}"
227
- cmd << local_path
228
- cmd << remote_path
229
-
230
- cmd << {in: rd}
231
- end
232
-
233
- puts "end of mkcmd: #{cmd}"
234
- cmd
235
- end
236
- end
237
-
238
- # Genentech's aspera deployment doesn't support modern commands, unfortunately...
239
- class GeneAsperaCliFilesystem < AsperaCliFilesystem
240
- def mkdir_p(dest)
241
- # Pass through -- this file system creates containing directories by default, womp womp.
242
- end
243
-
244
- def mkcommand(rd, wd, file, opts, size_hint: nil)
245
- if opts.include?('w')
246
- super.map do |e|
247
- if e.instance_of?(String) && e.start_with?("stdio://")
248
- "stdio-tar://"
249
- elsif e == file
250
- dir = ::File.dirname(file)
251
- dir[0] == '/' ? dir : "/#{dir}"
252
- else
253
- e
254
- end
255
- end.insert(2, "-d")
256
- else
257
- super
258
- end
259
- end
260
-
261
- def with_writeable(dest, opts = 'w', size_hint: nil, &block)
262
- raise "#{self.class.name} requires size_hint in with_writeable" if size_hint.nil?
263
-
264
- super do |io|
265
- io.write("File: #{::File.basename(dest)}\n")
266
- io.write("Size: #{size_hint}\n")
267
- io.write("\n")
268
- yield io
269
- end
270
- end
271
- end
272
-
273
105
  class Metis < Filesystem
274
106
  attr_reader :project_name, :bucket_name
275
107
 
@@ -438,9 +270,11 @@ module Etna
438
270
  end
439
271
 
440
272
  def sftp_file_from_path(src)
441
- file = ls(::File.dirname(src)).split("\n").map do |listing|
273
+ files = ls(::File.dirname(src)).split("\n").map do |listing|
442
274
  SftpFile.new(listing)
443
- end.select do |file|
275
+ end
276
+
277
+ file = files.select do |file|
444
278
  file.name == ::File.basename(src)
445
279
  end
446
280
 
@@ -457,6 +291,7 @@ module Etna
457
291
  cmd << authn
458
292
  cmd << "-o"
459
293
  cmd << "-"
294
+ cmd << "-s"
460
295
  cmd << "-N"
461
296
  cmd << url(file)
462
297
 
data/lib/etna/hmac.rb CHANGED
@@ -46,7 +46,7 @@ module Etna
46
46
  end
47
47
 
48
48
  def signature
49
- @application.sign.hmac(text_to_sign, @application.config(:hmac_keys)[@id])
49
+ @application.sign.hmac(text_to_sign, @application.config(@id)[:hmac_key])
50
50
  end
51
51
 
52
52
  private
@@ -60,8 +60,8 @@ module Etna
60
60
  end
61
61
 
62
62
  def valid_id?
63
- return false if !@application.config(:hmac_keys)
64
- @application.config(:hmac_keys).key?(@id)
63
+ return false if !@application.config(@id)
64
+ @application.config(@id).key?(:hmac_key)
65
65
  end
66
66
 
67
67
  # This scheme is adapted from the Hawk spec
@@ -79,7 +79,7 @@ module Etna
79
79
  # these are set as headers or params
80
80
  @nonce,
81
81
  @id,
82
- @headers.to_json,
82
+ JSON.generate(@headers),
83
83
  @expiration,
84
84
  ].join("\n")
85
85
  end
@@ -6,8 +6,8 @@ module Etna
6
6
  orig_method_name = :"#{method_name}_without_time_it"
7
7
  self.alias_method orig_method_name, method_name
8
8
 
9
- self.define_method method_name do |*args|
10
- time_it(orig_method_name, args, &metric_block)
9
+ self.define_method method_name do |*args, **kwargs|
10
+ time_it(orig_method_name, args, kwargs, &metric_block)
11
11
  end
12
12
  end
13
13
  end
@@ -20,11 +20,11 @@ module Etna
20
20
  end
21
21
  end
22
22
 
23
- def time_it(method_name, args, &metric_block)
23
+ def time_it(method_name, args, kwargs = {}, &metric_block)
24
24
  if has_yabeda?
25
25
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
26
26
  begin
27
- return send(method_name, *args)
27
+ return send(method_name, *args, **kwargs)
28
28
  ensure
29
29
  dur = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
30
30
  if block_given?
@@ -37,13 +37,13 @@ module Etna
37
37
  metric.measure(tags, dur)
38
38
  end
39
39
  else
40
- return send(method_name, *args, **kwds)
40
+ return send(method_name, *args, **kwargs)
41
41
  end
42
42
  end
43
43
 
44
44
  def with_yabeda_tags(tags, &block)
45
45
  if has_yabeda?
46
- Yabeda.with_tags(tags, &block)
46
+ Yabeda.with_tags(**tags, &block)
47
47
  else
48
48
  yield
49
49
  end
data/lib/etna/redirect.rb CHANGED
@@ -26,7 +26,7 @@ module Etna
26
26
  private
27
27
 
28
28
  def matches_domain?(path)
29
- top_domain(@request.hostname) == top_domain(URI(path).host)
29
+ top_domain(Etna::Application.instance.host) == top_domain(URI(path).host)
30
30
  end
31
31
 
32
32
  def top_domain(host_name)
data/lib/etna/remote.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "net/ssh"
2
+ require "net/scp"
3
+ require "tempfile"
2
4
 
3
5
  module Etna
4
6
  class RemoteSSH
@@ -11,6 +13,7 @@ module Etna
11
13
  @host = host
12
14
  @port = port
13
15
  @root = root
16
+ raise "RemoteSSH must have host, username and password" unless @host && @username && @password
14
17
  end
15
18
 
16
19
  def ssh
@@ -23,8 +26,8 @@ module Etna
23
26
  raise RemoteSSHError.new("Unable to mkdir -p, #{output}") unless 0 == output.exitstatus
24
27
  end
25
28
 
26
- def lftp_get(username:, password:, host:, remote_filename:, &block)
27
- full_local_path = ::File.join(@root, host, remote_filename)
29
+ def lftp_get(username:, password:, host:, remote_filename:, local_filename:, &block)
30
+ full_local_path = local_filename
28
31
  full_local_dir = ::File.dirname(full_local_path)
29
32
  mkdir_p(full_local_dir)
30
33
 
@@ -34,5 +37,18 @@ module Etna
34
37
  raise RemoteSSHError.new("LFTP get failure: #{output}") unless 0 == output.exitstatus
35
38
  yield remote_filename if block_given?
36
39
  end
40
+
41
+ def file_upload(remote_path, content)
42
+ begin
43
+ Tempfile.create do |temp_file|
44
+ temp_file.binmode
45
+ temp_file.write(content)
46
+ temp_file.flush
47
+ ssh.scp.upload!(temp_file.path, remote_path)
48
+ end
49
+ rescue StandardError => e
50
+ raise RemoteSSHError.new("File upload failed: #{e.message}")
51
+ end
52
+ end
37
53
  end
38
54
  end
data/lib/etna/route.rb CHANGED
@@ -221,6 +221,9 @@ module Etna
221
221
  # for the project
222
222
  return false if user.permissions.keys.include?(params[:project_name])
223
223
 
224
+ # Only check for a CC if the user is not flagged 'external'
225
+ return false if user.has_flag?('external')
226
+
224
227
  !janus.community_projects(user.token).select do |project|
225
228
  project.project_name == params[:project_name]
226
229
  end.first.nil?
@@ -0,0 +1,16 @@
1
+ require 'webmock/rspec'
2
+
3
+ def stub_event_log(project_name='labors')
4
+ polyphemus_host = Etna::Application.instance.config(:polyphemus)[:host]
5
+ WebMock.stub_request(:post, /#{polyphemus_host}\/api\/log\/#{project_name}/).
6
+ to_return(status: 200, body: { log: 1 }.to_json, headers: {'Content-Type': 'application/json'})
7
+
8
+ WebMock.stub_request(:options, polyphemus_host).
9
+ to_return({
10
+ status: 200,
11
+ headers: { 'Content-Type': "application/json" },
12
+ body: [
13
+ { :method => "POST", :route => "/api/log/:project_name/write", :name => "log_write", :params => ["project_name"] }
14
+ ].to_json
15
+ })
16
+ end
data/lib/etna/spec/vcr.rb CHANGED
@@ -71,8 +71,8 @@ def setup_base_vcr(spec_helper_dir, server: nil, application: nil)
71
71
  end
72
72
  end
73
73
 
74
- if File.exists?('log')
75
- c.debug_logger = File.open('log/vcr_debug.log', 'w')
74
+ if ::File.exist?('log')
75
+ c.debug_logger = ::File.open('log/vcr_debug.log', 'w')
76
76
  end
77
77
 
78
78
  c.default_cassette_options = {
@@ -147,4 +147,4 @@ def prepare_vcr_secret
147
147
  digest = Digest::SHA256.new
148
148
  digest.update(secret)
149
149
  digest.digest
150
- end
150
+ end
@@ -80,7 +80,7 @@ module Etna
80
80
 
81
81
  hmac_params = {
82
82
  method: request.request_method,
83
- host: request.host,
83
+ host: application.host,
84
84
  path: request.path,
85
85
 
86
86
  expiration: etna_param(request, :expiration) || DateTime.now.iso8601,
data/lib/etna/user.rb CHANGED
@@ -65,11 +65,7 @@ module Etna
65
65
  end
66
66
 
67
67
  def is_admin? project
68
- is_superuser? || has_any_role?(project, :admin)
69
- end
70
-
71
- def active? project=nil
72
- permissions.keys.length > 0
68
+ is_supereditor? || has_any_role?(project, :admin)
73
69
  end
74
70
 
75
71
  def display_name
data/lib/helpers.rb CHANGED
@@ -51,6 +51,14 @@ module WithEtnaClients
51
51
  **EtnaApp.instance.config(:magma, environment) || {})
52
52
  end
53
53
 
54
+ def gnomon_client(logger: nil)
55
+ @gnomon_client ||= Etna::Clients::Gnomon.new(
56
+ token: token,
57
+ ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
58
+ logger: logger,
59
+ **EtnaApp.instance.config(:magma, environment) || {})
60
+ end
61
+
54
62
  def metis_client(logger: nil)
55
63
  @metis_client ||= Etna::Clients::Metis.new(
56
64
  token: token,
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.51
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saurabh Asthana
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-03-20 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rack
@@ -38,6 +37,20 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: addressable
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: nokogiri
43
56
  requirement: !ruby/object:Gem::Requirement
@@ -143,6 +156,9 @@ files:
143
156
  - lib/etna/clients.rb
144
157
  - lib/etna/clients/base_client.rb
145
158
  - lib/etna/clients/enum.rb
159
+ - lib/etna/clients/gnomon.rb
160
+ - lib/etna/clients/gnomon/client.rb
161
+ - lib/etna/clients/gnomon/models.rb
146
162
  - lib/etna/clients/janus.rb
147
163
  - lib/etna/clients/janus/client.rb
148
164
  - lib/etna/clients/janus/models.rb
@@ -179,6 +195,7 @@ files:
179
195
  - lib/etna/clients/metis/workflows/sync_metis_data_workflow.rb
180
196
  - lib/etna/clients/metis/workflows/walk_metis_diff_workflow.rb
181
197
  - lib/etna/clients/metis/workflows/walk_metis_workflow.rb
198
+ - lib/etna/clients/models.rb
182
199
  - lib/etna/clients/polyphemus.rb
183
200
  - lib/etna/clients/polyphemus/client.rb
184
201
  - lib/etna/clients/polyphemus/models.rb
@@ -215,6 +232,7 @@ files:
215
232
  - lib/etna/sign_service.rb
216
233
  - lib/etna/spec.rb
217
234
  - lib/etna/spec/auth.rb
235
+ - lib/etna/spec/event_log.rb
218
236
  - lib/etna/spec/vcr.rb
219
237
  - lib/etna/symbolize_params.rb
220
238
  - lib/etna/synchronize_db.rb
@@ -241,8 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
241
259
  - !ruby/object:Gem::Version
242
260
  version: '0'
243
261
  requirements: []
244
- rubygems_version: 3.1.6
245
- signing_key:
262
+ rubygems_version: 3.6.9
246
263
  specification_version: 4
247
264
  summary: Base classes for Mount Etna applications
248
265
  test_files: []