-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FCXPINFRA-76] Added Tiger token to requests #88
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
FROM ruby:2.6.6 | ||
WORKDIR /app | ||
COPY Gemfile Gemfile | ||
COPY Gemfile.lock Gemfile.lock | ||
COPY little_monster.gemspec little_monster.gemspec | ||
RUN mkdir .git | ||
RUN mkdir -p lib/little_monster | ||
COPY lib/little_monster/version.rb lib/little_monster/version.rb | ||
RUN gem install bundler:2.3.16 | ||
RUN bundle install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build: | ||
docker build -f Dockerfile.dev -t fury-little_monster-gem-dev . | ||
|
||
rspec: | ||
docker run -it -v .:/app fury-little_monster-gem-dev bundle exec rspec | ||
|
||
rubocop: | ||
docker run -it -v .:/app fury-little_monster-gem-dev bundle exec rubocop lib spec --format simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require 'jwt' | ||
require 'typhoeus' | ||
|
||
module LittleMonster | ||
module Tiger | ||
module API | ||
module_function | ||
|
||
def bearer_token | ||
token = cached_shark_token | ||
"Bearer #{token}" if token | ||
end | ||
|
||
def cached_shark_token | ||
shark_token = Cache.instance.get(:shark_token) | ||
return shark_token if shark_token | ||
|
||
shark_token = new_shark_token | ||
return nil if shark_token.nil? | ||
Cache.instance.set(:shark_token, shark_token, 60 * 60) | ||
shark_token | ||
end | ||
|
||
def new_shark_token | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hay instalaciones de LM API fuera de shark, quizas se puede agregar una config para no buscar el client credential de kubernetes y no ir a tiger (retornar directamente nil) A futuro estas instalaciones deberian hacer login mediante el client credential de tiger |
||
return nil unless LittleMonster.enable_tiger_token | ||
shark_token = File.read(LittleMonster.shark_login_file_path) | ||
response = make_call(:post, 'login/shark', body: { token: shark_token }.to_json) | ||
return nil if response.failure? | ||
|
||
MultiJson.load(response.body, symbolize_keys: true)[:token] | ||
end | ||
|
||
def make_call(method, endpoint, options = {}) | ||
Typhoeus::Request.new( | ||
"#{LittleMonster.tiger_api_url}/#{endpoint}", | ||
method: method, | ||
params: options[:params], | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: options[:body] | ||
).run | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'moneta' | ||
|
||
module LittleMonster | ||
module Tiger | ||
class Cache | ||
include Singleton | ||
|
||
attr_reader :cache | ||
|
||
def initialize | ||
@cache = Moneta.new(:Memory, expires: true) | ||
end | ||
|
||
def set(key, value, expires = 0) | ||
@cache.store(key, value, expires: expires) | ||
end | ||
|
||
def get(key) | ||
@cache[key] | ||
end | ||
|
||
def clear | ||
@cache.clear | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
colocar URL real
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
en la configuración cuando la utilicen deberían agregar la url real
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
el valor por defecto no debería ser la url real? para evitar problemas en los entornos donde no se configuró áun el valor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sobretodo porque por defecto tenemos la funcionalidad habilitada (enable_tiger_token:true)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya que el api_url tampoco esta el original definido quise seguir esa linea, pero la puedo agregar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creo que mejor la agregan al momento de usarla, ya que puede ser para Meli, FaaP, Sulamerica, etc... en implementación tal vez la obtengan de una ENV