etna 0.1.35 → 0.1.36

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: bf1f86e15c74113a4591afd3d8a43064b6ed3b448bdfad3739baa27061df7913
4
- data.tar.gz: ed543c8775c89679b4755ca3119899639fc125df2d7e65c3515998f06ae45de8
3
+ metadata.gz: a6d9abd6b64884e701b1055215018b85939ee0bf6cc19275eccae0ebffe92856
4
+ data.tar.gz: a382140c854224855b317923551d467baa3b29202ec6ebccc2fb8d7782115d06
5
5
  SHA512:
6
- metadata.gz: 8523211434696c74c03ca5319a089c74dba9bc3c3cc086f723dcadd1789c91f2e6c7fe43701cd3ac467460bc5a8ee1f4c82c032a5d0ac16e666a565212fba209
7
- data.tar.gz: 60e3338c3021ea2e1a54dcfb7f2a15c9ffce71aed5a12db7739992649cfd9518f19edc49262a0095ba09c8783e0ef499bcb3015aebca0d2b7751e7096cbf88eb
6
+ metadata.gz: e150a0e7dac99e3c637151033d4105617910188f9c61c8e2812b2fa75c3d3967e95bb2fa43babb98802b14640658e02167c81b825fa0e1be41cef6340a74d4fa
7
+ data.tar.gz: 6f7365324ceed077161b4507397380837cc0d355f6cbd4dfff22b2abb527eaeafc2455e3cb3138d7b9a8085d3b4a2b3cf05b86417f2458a9bc80da859c77ed24
@@ -31,6 +31,12 @@ module Etna::Application
31
31
  raise "Could not find application instance from #{namespace}, and not subclass of Application found."
32
32
  end
33
33
 
34
+ # Used to find the application in development recorded vcr tests.
35
+ # see spec/vcr.rb
36
+ def dev_route
37
+ "#{self.class.name.split('::').first.downcase}.development.local"
38
+ end
39
+
34
40
  def self.register(app)
35
41
  @instance = app
36
42
  end
data/lib/etna/auth.rb CHANGED
@@ -86,7 +86,7 @@ module Etna
86
86
  host: application.config(:janus)[:host]
87
87
  )
88
88
 
89
- response = janus_client.validate_task_token()
89
+ response = janus_client.validate_task_token
90
90
 
91
91
  return false unless response.code == '200'
92
92
 
data/lib/etna/client.rb CHANGED
@@ -173,7 +173,7 @@ module Etna
173
173
  verify_mode = @ignore_ssl ?
174
174
  OpenSSL::SSL::VERIFY_NONE :
175
175
  OpenSSL::SSL::VERIFY_PEER
176
- Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: verify_mode) do |http|
176
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: verify_mode, read_timeout: 300) do |http|
177
177
  http.request(data) do |response|
178
178
  status_check!(response)
179
179
  yield response
@@ -183,7 +183,7 @@ module Etna
183
183
  verify_mode = @ignore_ssl ?
184
184
  OpenSSL::SSL::VERIFY_NONE :
185
185
  OpenSSL::SSL::VERIFY_PEER
186
- Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: verify_mode) do |http|
186
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true, verify_mode: verify_mode, read_timeout: 300) do |http|
187
187
  response = http.request(data)
188
188
  status_check!(response)
189
189
  return response
@@ -29,7 +29,8 @@ module Etna
29
29
  def token_will_expire?(offset=3000)
30
30
  # offset in seconds
31
31
  # Will the user's token expire in the given amount of time?
32
- epoch_seconds = JSON.parse(Base64.urlsafe_decode64(token.split('.')[1]))["exp"]
32
+ payload = JSON.parse(Base64.urlsafe_decode64(token.split('.')[1]))
33
+ epoch_seconds = payload["exp"]
33
34
  expiration = DateTime.strptime(epoch_seconds.to_s, "%s")
34
35
  expiration <= DateTime.now.new_offset + offset
35
36
  end
@@ -58,20 +58,19 @@ module Etna
58
58
  TokenResponse.new(token)
59
59
  end
60
60
 
61
- def validate_task_token(validate_task_token_request = ValidateTaskTokenRequest.new)
62
- token = nil
63
- @etna_client.post('/api/tokens/task/validate', validate_task_token_request)
61
+ def validate_task_token
62
+ @etna_client.post('/api/tokens/validate_task')
64
63
  end
65
64
 
66
65
  def get_nonce
67
66
  @etna_client.get('/api/tokens/nonce').body
68
67
  end
69
68
 
70
- def generate_token(token_type, signed_nonce: nil, project_name: nil)
69
+ def generate_token(token_type, signed_nonce: nil, project_name: nil, read_only: false)
71
70
  response = @etna_client.with_headers(
72
71
  'Authorization' => signed_nonce ? "Signed-Nonce #{signed_nonce}" : nil
73
72
  ) do
74
- post('/api/tokens/generate', token_type: token_type, project_name: project_name)
73
+ post('/api/tokens/generate', token_type: token_type, project_name: project_name, read_only: read_only)
75
74
  end
76
75
 
77
76
  response.body
data/lib/etna/spec/vcr.rb CHANGED
@@ -4,13 +4,32 @@ require 'openssl'
4
4
  require 'digest/sha2'
5
5
  require 'base64'
6
6
 
7
- def setup_base_vcr(spec_helper_dir)
7
+ def setup_base_vcr(spec_helper_dir, server: nil, application: nil)
8
8
  VCR.configure do |c|
9
9
  c.hook_into :webmock
10
10
  c.cassette_serializers
11
11
  c.cassette_library_dir = ::File.join(spec_helper_dir, 'fixtures', 'cassettes')
12
12
  c.allow_http_connections_when_no_cassette = true
13
13
 
14
+ c.register_request_matcher :verify_uri_route do |request_1, request_2|
15
+ next true if server.nil? || application.nil?
16
+
17
+ route_match = request_1.uri =~ /https:\/\/#{application.dev_route}(.*)/
18
+ if route_match && route_match[1]
19
+ def request_1.request_method
20
+ method.to_s.upcase
21
+ end
22
+
23
+ def request_1.path
24
+ URI(uri).path
25
+ end
26
+
27
+ !!server.find_route(request_1)
28
+ else
29
+ true
30
+ end
31
+ end
32
+
14
33
  c.register_request_matcher :try_body do |request_1, request_2|
15
34
  if request_1.headers['Content-Type'].first =~ /application\/json/
16
35
  if request_2.headers['Content-Type'].first =~ /application\/json/
@@ -39,7 +58,7 @@ def setup_base_vcr(spec_helper_dir)
39
58
  else
40
59
  ENV['RERECORD'] ? :all : :once
41
60
  end,
42
- match_requests_on: [:method, :uri, :try_body]
61
+ match_requests_on: [:method, :uri, :try_body, :verify_uri_route]
43
62
  }
44
63
 
45
64
  # Filter the authorization headers of any request by replacing any occurrence of that request's
@@ -42,7 +42,6 @@ module Etna
42
42
  # We do this to support Metis client tests, we pass in tokens with multiple "."-separated parts, so
43
43
  # have to account for that.
44
44
  payload = JSON.parse(Base64.decode64(token.split('.')[1]))
45
-
46
45
  request.env['etna.user'] = Etna::User.new(payload.map{|k,v| [k.to_sym, v]}.to_h, token)
47
46
  end
48
47
 
data/lib/etna/user.rb CHANGED
@@ -7,7 +7,7 @@ module Etna
7
7
  }
8
8
 
9
9
  def initialize params, token=nil
10
- @name, @email, @encoded_permissions, encoded_flags = params.values_at(:name, :email, :perm, :flags)
10
+ @name, @email, @encoded_permissions, encoded_flags, @task = params.values_at(:name, :email, :perm, :flags, :task)
11
11
 
12
12
  @flags = encoded_flags&.split(/;/) || []
13
13
  @token = token unless !token
@@ -16,6 +16,10 @@ module Etna
16
16
 
17
17
  attr_reader :name, :email, :token
18
18
 
19
+ def task?
20
+ !!@task
21
+ end
22
+
19
23
  def permissions
20
24
  @permissions ||= @encoded_permissions.split(/\;/).map do |roles|
21
25
  role, projects = roles.split(/:/)
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.35
4
+ version: 0.1.36
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-04-26 00:00:00.000000000 Z
11
+ date: 2021-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack