From a7f33fda9efdf037f4081ec6d1c0d20c6a94253a Mon Sep 17 00:00:00 2001 From: kanchanasuriya Date: Wed, 6 Nov 2024 14:03:24 -0800 Subject: [PATCH 1/6] 96002 EPS Redis Client Implementation --- config/redis.yml | 3 +++ .../app/services/vaos/v2/eps/redis_client.rb | 20 +++++++++++++++++++ .../spec/services/v2/eps/redis_client_spec.rb | 18 +++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 modules/vaos/app/services/vaos/v2/eps/redis_client.rb create mode 100644 modules/vaos/spec/services/v2/eps/redis_client_spec.rb diff --git a/config/redis.yml b/config/redis.yml index b80c51249c0..ca3eff30da2 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -120,6 +120,9 @@ development: &defaults va_mobile_session_refresh_lock: namespace: va-mobile-session-refresh-lock each_ttl: 60 + eps_appointment_access_token: + namespace: eps-appointment-access-token + each_ttl: 900 # 15 minutes saml_request_tracker: namespace: saml_request_tracker each_ttl: 3600 # 1 hour diff --git a/modules/vaos/app/services/vaos/v2/eps/redis_client.rb b/modules/vaos/app/services/vaos/v2/eps/redis_client.rb new file mode 100644 index 00000000000..a78a2db8c51 --- /dev/null +++ b/modules/vaos/app/services/vaos/v2/eps/redis_client.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'common/models/redis_store' +require 'common/models/concerns/cache_aside' + +module VAOS + module V2 + module Eps + class RedisClient < Common::RedisStore + include Common::CacheAside + + redis_config_key :eps_appointment_access_token + + def store(access_token) + cache('jwt-bearer', access_token) + end + end + end + end +end diff --git a/modules/vaos/spec/services/v2/eps/redis_client_spec.rb b/modules/vaos/spec/services/v2/eps/redis_client_spec.rb new file mode 100644 index 00000000000..8dd25eb57b9 --- /dev/null +++ b/modules/vaos/spec/services/v2/eps/redis_client_spec.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe VAOS::V2::Eps::RedisClient do + subject { described_class } + + let(:redis_client) { subject.new } + + describe '#save' do + let(:token) { 'test-access-token' } + + it 'saves the value in cache' do + expect(redis_client.store(access_token: token)).to eq(true) + expect(redis_client.cached?(key: 'jwt-bearer')).to eq(true) + end + end +end From 9e92c787b4c572ae99ffe0126852860fb0066e7b Mon Sep 17 00:00:00 2001 From: kanchanasuriya <89944361+kanchanasuriya@users.noreply.github.com> Date: Fri, 15 Nov 2024 10:59:04 -0800 Subject: [PATCH 2/6] Update config/redis.yml Co-authored-by: Gaurav Gupta --- config/redis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/redis.yml b/config/redis.yml index ca3eff30da2..0d815acb8a5 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -120,8 +120,8 @@ development: &defaults va_mobile_session_refresh_lock: namespace: va-mobile-session-refresh-lock each_ttl: 60 - eps_appointment_access_token: - namespace: eps-appointment-access-token + eps_access_token: + namespace: eps-access-token each_ttl: 900 # 15 minutes saml_request_tracker: namespace: saml_request_tracker From 974ecbb6b97c776cf1066027731971b18e6a5530 Mon Sep 17 00:00:00 2001 From: kanchanasuriya Date: Mon, 18 Nov 2024 16:28:48 -0800 Subject: [PATCH 3/6] Addressing review comments --- modules/vaos/app/services/eps/redis_client.rb | 14 +++++++ .../spec/services/eps/redis_client_spec.rb | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 modules/vaos/app/services/eps/redis_client.rb create mode 100644 modules/vaos/spec/services/eps/redis_client_spec.rb diff --git a/modules/vaos/app/services/eps/redis_client.rb b/modules/vaos/app/services/eps/redis_client.rb new file mode 100644 index 00000000000..7a31890893c --- /dev/null +++ b/modules/vaos/app/services/eps/redis_client.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require 'common/models/redis_store' + +module Eps + class RedisClient < Common::RedisStore + redis_store REDIS_CONFIG[:eps_access_token][:namespace] + redis_ttl REDIS_CONFIG[:eps_access_token][:each_ttl] + redis_key :token_type + + attribute :token_type + attribute :access_token + end +end diff --git a/modules/vaos/spec/services/eps/redis_client_spec.rb b/modules/vaos/spec/services/eps/redis_client_spec.rb new file mode 100644 index 00000000000..b95724b3b9f --- /dev/null +++ b/modules/vaos/spec/services/eps/redis_client_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe Eps::RedisClient do + subject { described_class } + + let(:access_token) { 'test-access-token' } + let(:token_type) { 'jwt_bearer' } + let(:redis_key) { "eps-access-token:#{token_type}" } + let(:cache_data) { { token_type:, access_token: } } + let(:redis_client) { subject.new(token_type:, access_token:) } + + describe '#save' do + it 'saves the value in cache' do + redis_client.save + + token = Oj.load($redis.get(redis_key))[:access_token] + expect(token).to eq(access_token) + end + end + + describe '#ttl' do + before do + redis_client.save + end + + it 'sets cache data expire to time from config file' do + expect($redis.ttl(redis_key)).to eq(900) + end + end + + describe '#find' do + before do + redis_client.save + end + + it 'gets data from cache' do + expect(Oj.load($redis.get(redis_key))).to eq(cache_data) + end + end +end From 1f41c7255aeaad251a4612ba3a92bcbf7521f4a3 Mon Sep 17 00:00:00 2001 From: kanchanasuriya Date: Mon, 18 Nov 2024 16:29:48 -0800 Subject: [PATCH 4/6] Deleting unwanted files --- .../app/services/vaos/v2/eps/redis_client.rb | 20 ------------------- .../spec/services/v2/eps/redis_client_spec.rb | 18 ----------------- 2 files changed, 38 deletions(-) delete mode 100644 modules/vaos/app/services/vaos/v2/eps/redis_client.rb delete mode 100644 modules/vaos/spec/services/v2/eps/redis_client_spec.rb diff --git a/modules/vaos/app/services/vaos/v2/eps/redis_client.rb b/modules/vaos/app/services/vaos/v2/eps/redis_client.rb deleted file mode 100644 index a78a2db8c51..00000000000 --- a/modules/vaos/app/services/vaos/v2/eps/redis_client.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require 'common/models/redis_store' -require 'common/models/concerns/cache_aside' - -module VAOS - module V2 - module Eps - class RedisClient < Common::RedisStore - include Common::CacheAside - - redis_config_key :eps_appointment_access_token - - def store(access_token) - cache('jwt-bearer', access_token) - end - end - end - end -end diff --git a/modules/vaos/spec/services/v2/eps/redis_client_spec.rb b/modules/vaos/spec/services/v2/eps/redis_client_spec.rb deleted file mode 100644 index 8dd25eb57b9..00000000000 --- a/modules/vaos/spec/services/v2/eps/redis_client_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -describe VAOS::V2::Eps::RedisClient do - subject { described_class } - - let(:redis_client) { subject.new } - - describe '#save' do - let(:token) { 'test-access-token' } - - it 'saves the value in cache' do - expect(redis_client.store(access_token: token)).to eq(true) - expect(redis_client.cached?(key: 'jwt-bearer')).to eq(true) - end - end -end From ecd39a3843eb3a5a70b1aa689f956d6c3d636550 Mon Sep 17 00:00:00 2001 From: kanchanasuriya Date: Mon, 18 Nov 2024 17:51:01 -0800 Subject: [PATCH 5/6] Renaming redis_client to access_token_store --- .../eps/{redis_client.rb => access_token_store.rb} | 2 +- ...redis_client_spec.rb => access_token_store_spec.rb} | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) rename modules/vaos/app/services/eps/{redis_client.rb => access_token_store.rb} (86%) rename modules/vaos/spec/services/eps/{redis_client_spec.rb => access_token_store_spec.rb} (79%) diff --git a/modules/vaos/app/services/eps/redis_client.rb b/modules/vaos/app/services/eps/access_token_store.rb similarity index 86% rename from modules/vaos/app/services/eps/redis_client.rb rename to modules/vaos/app/services/eps/access_token_store.rb index 7a31890893c..e478d40bd3a 100644 --- a/modules/vaos/app/services/eps/redis_client.rb +++ b/modules/vaos/app/services/eps/access_token_store.rb @@ -3,7 +3,7 @@ require 'common/models/redis_store' module Eps - class RedisClient < Common::RedisStore + class AccessTokenStore < Common::RedisStore redis_store REDIS_CONFIG[:eps_access_token][:namespace] redis_ttl REDIS_CONFIG[:eps_access_token][:each_ttl] redis_key :token_type diff --git a/modules/vaos/spec/services/eps/redis_client_spec.rb b/modules/vaos/spec/services/eps/access_token_store_spec.rb similarity index 79% rename from modules/vaos/spec/services/eps/redis_client_spec.rb rename to modules/vaos/spec/services/eps/access_token_store_spec.rb index b95724b3b9f..2c43f2261b1 100644 --- a/modules/vaos/spec/services/eps/redis_client_spec.rb +++ b/modules/vaos/spec/services/eps/access_token_store_spec.rb @@ -2,18 +2,18 @@ require 'rails_helper' -describe Eps::RedisClient do +describe Eps::AccessTokenStore do subject { described_class } let(:access_token) { 'test-access-token' } let(:token_type) { 'jwt_bearer' } let(:redis_key) { "eps-access-token:#{token_type}" } let(:cache_data) { { token_type:, access_token: } } - let(:redis_client) { subject.new(token_type:, access_token:) } + let(:token_store_client) { subject.new(token_type:, access_token:) } describe '#save' do it 'saves the value in cache' do - redis_client.save + token_store_client.save token = Oj.load($redis.get(redis_key))[:access_token] expect(token).to eq(access_token) @@ -22,7 +22,7 @@ describe '#ttl' do before do - redis_client.save + token_store_client.save end it 'sets cache data expire to time from config file' do @@ -32,7 +32,7 @@ describe '#find' do before do - redis_client.save + token_store_client.save end it 'gets data from cache' do From 8a42abdde300b9c181770687232c14a36c272a5b Mon Sep 17 00:00:00 2001 From: kanchanasuriya Date: Tue, 19 Nov 2024 07:20:33 -0800 Subject: [PATCH 6/6] Defining before block for all specs --- .../spec/services/eps/access_token_store_spec.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/modules/vaos/spec/services/eps/access_token_store_spec.rb b/modules/vaos/spec/services/eps/access_token_store_spec.rb index 2c43f2261b1..8d4606d4bd4 100644 --- a/modules/vaos/spec/services/eps/access_token_store_spec.rb +++ b/modules/vaos/spec/services/eps/access_token_store_spec.rb @@ -11,30 +11,24 @@ let(:cache_data) { { token_type:, access_token: } } let(:token_store_client) { subject.new(token_type:, access_token:) } + before do + token_store_client.save + end + describe '#save' do it 'saves the value in cache' do - token_store_client.save - token = Oj.load($redis.get(redis_key))[:access_token] expect(token).to eq(access_token) end end describe '#ttl' do - before do - token_store_client.save - end - it 'sets cache data expire to time from config file' do expect($redis.ttl(redis_key)).to eq(900) end end describe '#find' do - before do - token_store_client.save - end - it 'gets data from cache' do expect(Oj.load($redis.get(redis_key))).to eq(cache_data) end