etna 0.1.46 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
@@ -133,7 +133,7 @@ MESSAGE_END
133
133
  end
134
134
 
135
135
  def config_hosts
136
- [:janus, :magma, :timur, :metis, :vulcan, :polyphemus].map do |host|
136
+ [:janus, :magma, :timur, :metis, :vulcan, :polyphemus, :gnomon].map do |host|
137
137
  [ :"#{host}_host", @server.send(:application).config(host)&.dig(:host) ]
138
138
  end.to_h.compact
139
139
  end
@@ -14,45 +14,48 @@ module Etna
14
14
  ::File.open(dest, opts, &block)
15
15
  end
16
16
 
17
+ class Error < StandardError
18
+ end
19
+
17
20
  def ls(dir)
18
- raise "ls not supported by #{self.class.name}" unless self.class == Filesystem
21
+ raise Etna::Filesystem::Error, "ls not supported by #{self.class.name}" unless self.class == Filesystem
19
22
  ::Dir.entries(dir).select { |p| !p.start_with?('.') }.map do |path|
20
23
  ::File.file?(::File.join(dir, path)) ? [:file, path] : [:dir, path]
21
24
  end
22
25
  end
23
26
 
24
27
  def with_readable(src, opts = 'r', &block)
25
- raise "with_readable not supported by #{self.class.name}" unless self.class == Filesystem
28
+ raise Etna::Filesystem::Error, "with_readable not supported by #{self.class.name}" unless self.class == Filesystem
26
29
  ::File.open(src, opts, &block)
27
30
  end
28
31
 
29
32
  def mkdir_p(dir)
30
- raise "mkdir_p not supported by #{self.class.name}" unless self.class == Filesystem
33
+ raise Etna::Filesystem::Error, "mkdir_p not supported by #{self.class.name}" unless self.class == Filesystem
31
34
  ::FileUtils.mkdir_p(dir)
32
35
  end
33
36
 
34
37
  def rm_rf(dir)
35
- raise "rm_rf not supported by #{self.class.name}" unless self.class == Filesystem
38
+ raise Etna::Filesystem::Error, "rm_rf not supported by #{self.class.name}" unless self.class == Filesystem
36
39
  ::FileUtils.rm_rf(dir)
37
40
  end
38
41
 
39
42
  def tmpdir
40
- raise "tmpdir not supported by #{self.class.name}" unless self.class == Filesystem
43
+ raise Etna::Filesystem::Error, "tmpdir not supported by #{self.class.name}" unless self.class == Filesystem
41
44
  ::Dir.mktmpdir
42
45
  end
43
46
 
44
47
  def exist?(src)
45
- raise "exist? not supported by #{self.class.name}" unless self.class == Filesystem
48
+ raise Etna::Filesystem::Error, "exist? not supported by #{self.class.name}" unless self.class == Filesystem
46
49
  ::File.exist?(src)
47
50
  end
48
51
 
49
52
  def mv(src, dest)
50
- raise "mv not supported by #{self.class.name}" unless self.class == Filesystem
53
+ raise Etna::Filesystem::Error, "mv not supported by #{self.class.name}" unless self.class == Filesystem
51
54
  ::FileUtils.mv(src, dest)
52
55
  end
53
56
 
54
57
  def stat(src)
55
- raise "stat not supported by #{self.class.name}" unless self.class == Filesystem
58
+ raise Etna::Filesystem::Error, "stat not supported by #{self.class.name}" unless self.class == Filesystem
56
59
  ::File.stat(src)
57
60
  end
58
61
 
@@ -66,7 +69,9 @@ module Etna
66
69
  def mkio(file, opts, size_hint: nil, &block)
67
70
  rd, wd = IO.pipe
68
71
 
69
- pid = spawn(*mkcommand(rd, wd, file, opts, size_hint: size_hint))
72
+ cmd = mkcommand(rd, wd, file, opts, size_hint: size_hint)
73
+ puts "in mkio: #{cmd}"
74
+ pid = spawn(*cmd)
70
75
  q = Queue.new
71
76
 
72
77
  closer = Thread.new do
@@ -184,9 +189,22 @@ module Etna
184
189
  cmd << @key_file
185
190
  end
186
191
 
192
+ cmd << "-O"
193
+ cmd << @port.to_s
194
+
187
195
  cmd << "-P"
188
196
  cmd << @port.to_s
189
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
+
190
208
  remote_path = file
191
209
  # https://download.asperasoft.com/download/docs/entsrv/3.9.1/es_admin_linux/webhelp/index.html#dita/stdio_2.html
192
210
  local_path = "stdio://"
@@ -212,6 +230,7 @@ module Etna
212
230
  cmd << {in: rd}
213
231
  end
214
232
 
233
+ puts "end of mkcmd: #{cmd}"
215
234
  cmd
216
235
  end
217
236
  end
@@ -228,7 +247,8 @@ module Etna
228
247
  if e.instance_of?(String) && e.start_with?("stdio://")
229
248
  "stdio-tar://"
230
249
  elsif e == file
231
- ::File.dirname(file)
250
+ dir = ::File.dirname(file)
251
+ dir[0] == '/' ? dir : "/#{dir}"
232
252
  else
233
253
  e
234
254
  end
@@ -565,4 +585,4 @@ module Etna
565
585
  end
566
586
  end
567
587
  end
568
- end
588
+ end
@@ -0,0 +1,56 @@
1
+ module Etna
2
+ module Instrumentation
3
+ def self.included(cls)
4
+ cls.instance_eval do
5
+ def self.time_it(method_name, &metric_block)
6
+ orig_method_name = :"#{method_name}_without_time_it"
7
+ self.alias_method orig_method_name, method_name
8
+
9
+ self.define_method method_name do |*args|
10
+ time_it(orig_method_name, args, &metric_block)
11
+ end
12
+ end
13
+ end
14
+ end
15
+
16
+ def increment_it(&block)
17
+ if has_yabeda?
18
+ metric = yield
19
+ metric.increment({})
20
+ end
21
+ end
22
+
23
+ def time_it(method_name, args, &metric_block)
24
+ if has_yabeda?
25
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
26
+ begin
27
+ return send(method_name, *args)
28
+ ensure
29
+ dur = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
30
+ if block_given?
31
+ metric = yield
32
+ tags = {}
33
+ else
34
+ tags = {class_name: self.class.name, method_name: method_name.to_s}
35
+ metric = Yabeda.etna.perf
36
+ end
37
+ metric.measure(tags, dur)
38
+ end
39
+ else
40
+ return send(method_name, *args, **kwds)
41
+ end
42
+ end
43
+
44
+ def with_yabeda_tags(tags, &block)
45
+ if has_yabeda?
46
+ Yabeda.with_tags(tags, &block)
47
+ else
48
+ yield
49
+ end
50
+ end
51
+
52
+ def has_yabeda?
53
+ defined?(Yabeda) && Yabeda.configured?
54
+ end
55
+ end
56
+ end
data/lib/etna/route.rb CHANGED
@@ -1,9 +1,13 @@
1
1
  require 'digest'
2
2
  require 'date'
3
+ require "addressable/uri"
3
4
  require_relative "./censor"
5
+ require_relative './instrumentation'
4
6
 
5
7
  module Etna
6
8
  class Route
9
+ include Etna::Instrumentation
10
+
7
11
  attr_reader :name
8
12
 
9
13
  def initialize(method, route, options, &block)
@@ -42,7 +46,7 @@ module Etna
42
46
  if params
43
47
  PARAM_TYPES.reduce(route) do |path,pat|
44
48
  path.gsub(pat) do
45
- params[$1.to_sym].split('/').map { |c| block_given? ? yield(c) : URI.encode_www_form_component(c) }.join('/')
49
+ params[$1.to_sym].split('/').map { |c| block_given? ? yield(c) : Addressable::URI.normalized_encode(c) }.join('/')
46
50
  end
47
51
  end
48
52
  else
@@ -64,19 +68,27 @@ module Etna
64
68
  end
65
69
 
66
70
  def call(app, request)
67
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
71
+ update_params(request)
68
72
 
69
- try_yabeda(request) do |tags|
70
- Yabeda.etna.visits.increment(tags)
73
+ tags = {}
74
+ if @action
75
+ tags[:controller], tags[:action] = @action.split('#')
76
+ elsif @name
77
+ tags[:action] = @name
78
+ else
79
+ tags[:action] = @route
71
80
  end
72
81
 
73
- begin
82
+ params = request.env['rack.request.params']
83
+ user = request.env['etna.user']
84
+ tags[:user_hash] = user ? hash_user_email(user.email) : 'unknown'
85
+ if params && (params.include?(:project_name) || params.include?('project_name'))
86
+ tags[:project_name] = params[:project_name] || params['project_name']
87
+ end
88
+
89
+ with_yabeda_tags(tags) do
90
+ increment_it { Yabeda.etna.visits }
74
91
  process_call(app, request)
75
- ensure
76
- try_yabeda(request) do |tags|
77
- dur = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
78
- Yabeda.etna.response_time.measure(tags, dur)
79
- end
80
92
  end
81
93
  end
82
94
 
@@ -93,36 +105,7 @@ module Etna
93
105
  Digest::MD5.hexdigest(digest)
94
106
  end
95
107
 
96
- def try_yabeda(request, &block)
97
- if @action
98
- controller, action = @action.split('#')
99
- elsif @name
100
- controller = "none"
101
- action = @name
102
- else
103
- controller = "none"
104
- action = @route
105
- end
106
-
107
- params = request.env['rack.request.params']
108
- user = request.env['etna.user']
109
- user_hash = user ? hash_user_email(user.email) : 'unknown'
110
- project_name = "unknown"
111
-
112
- if params && (params.include?(:project_name) || params.include?('project_name'))
113
- project_name = params[:project_name] || params['project_name']
114
- end
115
-
116
- begin
117
- block.call({ controller: controller, action: action, user_hash: user_hash, project_name: project_name })
118
- rescue => e
119
- raise e unless Etna::Application.instance.environment == :production
120
- end
121
- end
122
-
123
108
  def process_call(app, request)
124
- update_params(request)
125
-
126
109
  unless authorized?(request)
127
110
  if cc_available?(request)
128
111
  if request.content_type == 'application/json'
@@ -155,6 +138,8 @@ module Etna
155
138
  end
156
139
  end
157
140
 
141
+ time_it(:process_call) { Yabeda.etna.response_time }
142
+
158
143
  # the route does not require authorization
159
144
  def noauth?
160
145
  @auth && @auth[:noauth]
@@ -256,7 +241,7 @@ module Etna
256
241
  Hash[
257
242
  match.names.map(&:to_sym).zip(
258
243
  match.captures.map do |capture|
259
- capture.split('/').map {|c| URI.decode_www_form_component(c) }.join('/')
244
+ capture.split('/').map {|c| Addressable::URI.unencode_component(c) }.join('/')
260
245
  end
261
246
  )
262
247
  ]
@@ -31,9 +31,17 @@ module Etna::Spec
31
31
  def below_admin_roles
32
32
  [:editor, :viewer, :guest]
33
33
  end
34
-
34
+
35
35
  def below_editor_roles
36
36
  [:viewer, :guest]
37
37
  end
38
+
39
+ def stub_janus_refresh
40
+ stub_request(:post, /\/api\/tokens\/generate/)
41
+ .to_return({
42
+ status: 200,
43
+ body: ""
44
+ })
45
+ end
38
46
  end
39
47
  end
data/lib/etna/user.rb CHANGED
@@ -71,5 +71,9 @@ module Etna
71
71
  def active? project=nil
72
72
  permissions.keys.length > 0
73
73
  end
74
+
75
+ def display_name
76
+ [ email, name ].join('|')
77
+ end
74
78
  end
75
79
  end
data/lib/etna.rb CHANGED
@@ -28,6 +28,7 @@ require_relative './etna/metrics'
28
28
  require_relative './etna/remote'
29
29
  require_relative './etna/synchronize_db'
30
30
  require_relative './etna/janus_utils'
31
+ require_relative './etna/instrumentation'
31
32
 
32
33
  class EtnaApp
33
34
  include Etna::Application
data/lib/helpers.rb CHANGED
@@ -43,17 +43,19 @@ module WithEtnaClients
43
43
  env_token
44
44
  end
45
45
 
46
- def magma_client
46
+ def magma_client(logger: nil)
47
47
  @magma_client ||= Etna::Clients::Magma.new(
48
48
  token: token,
49
49
  ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
50
+ logger: logger,
50
51
  **EtnaApp.instance.config(:magma, environment) || {})
51
52
  end
52
53
 
53
- def metis_client
54
+ def metis_client(logger: nil)
54
55
  @metis_client ||= Etna::Clients::Metis.new(
55
56
  token: token,
56
57
  ignore_ssl: EtnaApp.instance.config(:ignore_ssl),
58
+ logger: logger,
57
59
  **EtnaApp.instance.config(:metis, environment) || {})
58
60
  end
59
61
 
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.46
4
+ version: 0.1.48
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-08-02 00:00:00.000000000 Z
11
+ date: 2023-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -200,6 +200,7 @@ files:
200
200
  - lib/etna/generate_autocompletion_script.rb
201
201
  - lib/etna/hmac.rb
202
202
  - lib/etna/injection.rb
203
+ - lib/etna/instrumentation.rb
203
204
  - lib/etna/janus_utils.rb
204
205
  - lib/etna/json_serializable_struct.rb
205
206
  - lib/etna/logger.rb
@@ -240,8 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
241
  - !ruby/object:Gem::Version
241
242
  version: '0'
242
243
  requirements: []
243
- rubyforge_project:
244
- rubygems_version: 2.7.6.3
244
+ rubygems_version: 3.1.6
245
245
  signing_key:
246
246
  specification_version: 4
247
247
  summary: Base classes for Mount Etna applications