session-validator-client 5.1.2 → 6.0.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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +2 -2
- data/.gitignore +1 -0
- data/Dockerfile +20 -0
- data/Makefile +5 -6
- data/docker-compose.yml +2 -3
- data/lib/session_validator/client.rb +41 -5
- data/lib/session_validator.rb +4 -0
- data/session-validator-client.gemspec +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2498a668e8f669382a1a88f6555356823e7115d6978d8c9331bf84d1395190cc
|
4
|
+
data.tar.gz: 2ea169bd1b520056db1b7cc8fd65c0bac5aa206c8e7899e533267c104bec45e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e0884a245a05850cc5412fe3f710ca875467093431f4514d591bcfcc9a8c8fc4373cede425204ccf80268e52c7f2ac9f3440fcb66bf32ab37fa4dba63833575
|
7
|
+
data.tar.gz: 023273a70c9d99daa8768ba44b1e50abc8cb8e76f39991e3def548f4bcebecf2771c704f9ffbb9e142cedb16c5cdee995ba1037b17a1ba39e276bb9ef2453e56
|
data/.github/workflows/ruby.yml
CHANGED
@@ -7,7 +7,7 @@ jobs:
|
|
7
7
|
runs-on: ubuntu-latest
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby-versions: ['
|
10
|
+
ruby-versions: ['3.2', '3.3', '3.4']
|
11
11
|
|
12
12
|
steps:
|
13
13
|
- uses: actions/checkout@v4
|
@@ -19,7 +19,7 @@ jobs:
|
|
19
19
|
- name: Run tests
|
20
20
|
run: bundle exec rspec
|
21
21
|
- name: Deploy
|
22
|
-
if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && matrix.ruby-versions == '3.
|
22
|
+
if : github.event_name == 'push' && startsWith(github.ref, 'refs/tags') && matrix.ruby-versions == '3.2'
|
23
23
|
run: |
|
24
24
|
mkdir -p $HOME/.gem
|
25
25
|
touch $HOME/.gem/credentials
|
data/.gitignore
CHANGED
data/Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
FROM ruby:3.2-alpine
|
2
|
+
|
3
|
+
RUN addgroup -g 1000 ruby && \
|
4
|
+
adduser -u 1000 -G ruby -s /bin/sh -D ruby && \
|
5
|
+
mkdir /app && \
|
6
|
+
chown ruby:ruby /app
|
7
|
+
|
8
|
+
RUN apk update && \
|
9
|
+
apk upgrade
|
10
|
+
RUN apk add --virtual .build-deps build-base git
|
11
|
+
|
12
|
+
RUN gem update --system && \
|
13
|
+
gem update && \
|
14
|
+
gem cleanup && \
|
15
|
+
gem install bundler
|
16
|
+
|
17
|
+
USER ruby
|
18
|
+
WORKDIR /app
|
19
|
+
|
20
|
+
RUN bundle config --local path .bundle
|
data/Makefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
.PHONY: test sh
|
1
|
+
.PHONY: build install test sh
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
sh:
|
7
|
-
docker compose run --rm app bash -c "bundle install && bash"
|
3
|
+
build: ; docker compose build
|
4
|
+
install: ; docker compose run --rm app bundle install
|
5
|
+
test: ; docker compose run --rm app bundle exec rspec
|
6
|
+
sh: ; docker compose run --rm app sh
|
data/docker-compose.yml
CHANGED
@@ -5,6 +5,7 @@ require "faraday/retry"
|
|
5
5
|
require "faraday_middleware/escher"
|
6
6
|
|
7
7
|
class SessionValidator::Client
|
8
|
+
MSID_PATTERN = /^[a-z0-9._]+_[0-9a-f]{14}\.[0-9]{8}$/.freeze
|
8
9
|
CREDENTIAL_SCOPE = "eu/session-validator/ems_request".freeze
|
9
10
|
ESCHER_AUTH_OPTIONS = {
|
10
11
|
algo_prefix: "EMS",
|
@@ -19,13 +20,26 @@ class SessionValidator::Client
|
|
19
20
|
@use_escher = use_escher
|
20
21
|
end
|
21
22
|
|
22
|
-
def valid?(
|
23
|
-
|
24
|
-
|
23
|
+
def valid?(id)
|
24
|
+
if id.match(MSID_PATTERN)
|
25
|
+
valid_by_msid? id
|
26
|
+
else
|
27
|
+
valid_by_session_data_token? id
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def session_data(token)
|
32
|
+
response = client.get("/sessions", nil, headers.merge(authorization_header token))
|
33
|
+
case response.status
|
34
|
+
when 200 then JSON.parse(response.body)
|
35
|
+
when 400..499 then raise SessionValidator::SessionDataNotFound
|
36
|
+
when 500.. then raise SessionValidator::SessionDataError, "Service unreachable"
|
37
|
+
end
|
25
38
|
rescue *NETWORK_ERRORS
|
26
|
-
|
39
|
+
raise SessionValidator::SessionDataError, "Service unreachable"
|
27
40
|
end
|
28
41
|
|
42
|
+
# @deprecated
|
29
43
|
def filter_invalid(msids)
|
30
44
|
response = client.post("/sessions/filter", JSON.generate({ msids: msids }), headers)
|
31
45
|
if response.status == 200
|
@@ -39,11 +53,29 @@ class SessionValidator::Client
|
|
39
53
|
|
40
54
|
private
|
41
55
|
|
56
|
+
def valid_by_msid?(msid)
|
57
|
+
response_status = client.get("/sessions/#{msid}", nil, headers).status
|
58
|
+
(200..299).include?(response_status) || (500..599).include?(response_status)
|
59
|
+
rescue *NETWORK_ERRORS
|
60
|
+
true
|
61
|
+
end
|
62
|
+
|
63
|
+
def valid_by_session_data_token?(token)
|
64
|
+
response_status = client.head("/sessions", nil, headers.merge(authorization_header token)).status
|
65
|
+
case response_status
|
66
|
+
when 200 then true
|
67
|
+
when 400..499 then false
|
68
|
+
when 500.. then raise SessionValidator::SessionDataError, "Service unreachable"
|
69
|
+
end
|
70
|
+
rescue *NETWORK_ERRORS
|
71
|
+
raise SessionValidator::SessionDataError, "Service unreachable"
|
72
|
+
end
|
73
|
+
|
42
74
|
def client
|
43
75
|
Faraday.new(url) do |faraday|
|
44
76
|
faraday.options[:open_timeout] = SERVICE_REQUEST_TIMEOUT
|
45
77
|
faraday.options[:timeout] = SERVICE_REQUEST_TIMEOUT
|
46
|
-
faraday.request :retry, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, methods: [:get, :post], exceptions: NETWORK_ERRORS
|
78
|
+
faraday.request :retry, interval: 0.05, interval_randomness: 0.5, backoff_factor: 2, methods: [:head, :get, :post], exceptions: NETWORK_ERRORS
|
47
79
|
faraday.use(Faraday::Middleware::Escher::RequestSigner, escher_config) if @use_escher
|
48
80
|
faraday.adapter Faraday.default_adapter
|
49
81
|
end
|
@@ -73,4 +105,8 @@ class SessionValidator::Client
|
|
73
105
|
def headers
|
74
106
|
{ "content-type" => "application/json" }
|
75
107
|
end
|
108
|
+
|
109
|
+
def authorization_header(token)
|
110
|
+
{ "Authorization" => "Bearer #{token}" }
|
111
|
+
end
|
76
112
|
end
|
data/lib/session_validator.rb
CHANGED
@@ -3,6 +3,10 @@ module SessionValidator
|
|
3
3
|
autoload :CachedClient, "session_validator/cached_client"
|
4
4
|
autoload :InMemoryCache, "session_validator/in_memory_cache"
|
5
5
|
|
6
|
+
class SessionDataError < StandardError; end
|
7
|
+
|
8
|
+
class SessionDataNotFound < SessionDataError; end
|
9
|
+
|
6
10
|
def self.base_url
|
7
11
|
ENV['SESSION_VALIDATOR_URL']
|
8
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: session-validator-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emarsys Technologies Ltd.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escher-keypool
|
@@ -128,7 +128,7 @@ dependencies:
|
|
128
128
|
- - ">="
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
|
-
description:
|
131
|
+
description:
|
132
132
|
email: security@emarsys.com
|
133
133
|
executables: []
|
134
134
|
extensions: []
|
@@ -138,6 +138,7 @@ files:
|
|
138
138
|
- ".github/workflows/ruby.yml"
|
139
139
|
- ".gitignore"
|
140
140
|
- ".rspec"
|
141
|
+
- Dockerfile
|
141
142
|
- Gemfile
|
142
143
|
- LICENSE.txt
|
143
144
|
- Makefile
|
@@ -154,7 +155,7 @@ homepage: https://github.com/emartech/session-validator-client-ruby
|
|
154
155
|
licenses:
|
155
156
|
- MIT
|
156
157
|
metadata: {}
|
157
|
-
post_install_message:
|
158
|
+
post_install_message:
|
158
159
|
rdoc_options: []
|
159
160
|
require_paths:
|
160
161
|
- lib
|
@@ -169,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
requirements: []
|
172
|
-
rubygems_version: 3.
|
173
|
-
signing_key:
|
173
|
+
rubygems_version: 3.4.19
|
174
|
+
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: Ruby client for Emarsys session validator service
|
176
177
|
test_files: []
|