Class: Gitlab::ConanToken
- Inherits:
-
Object
- Object
- Gitlab::ConanToken
- Defined in:
- lib/gitlab/conan_token.rb
Constant Summary collapse
- HMAC_KEY =
'gitlab-conan-packages'
- CONAN_TOKEN_EXPIRE_TIME =
1.day.freeze
Instance Attribute Summary collapse
-
#access_token_id ⇒ Object
readonly
Returns the value of attribute access_token_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Class Method Summary collapse
- .decode(jwt) ⇒ Object
- .from_deploy_token(deploy_token) ⇒ Object
- .from_job(job) ⇒ Object
- .from_personal_access_token(user_id, token) ⇒ Object
- .secret ⇒ Object
Instance Method Summary collapse
-
#initialize(access_token_id:, user_id:) ⇒ ConanToken
constructor
A new instance of ConanToken.
- #to_jwt ⇒ Object
Constructor Details
#initialize(access_token_id:, user_id:) ⇒ ConanToken
Returns a new instance of ConanToken.
46 47 48 49 |
# File 'lib/gitlab/conan_token.rb', line 46 def initialize(access_token_id:, user_id:) @access_token_id = access_token_id @user_id = user_id end |
Instance Attribute Details
#access_token_id ⇒ Object (readonly)
Returns the value of attribute access_token_id.
13 14 15 |
# File 'lib/gitlab/conan_token.rb', line 13 def access_token_id @access_token_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
13 14 15 |
# File 'lib/gitlab/conan_token.rb', line 13 def user_id @user_id end |
Class Method Details
.decode(jwt) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/gitlab/conan_token.rb', line 28 def decode(jwt) payload = JSONWebToken::HMACToken.decode(jwt, secret).first new(access_token_id: payload['access_token'], user_id: payload['user_id']) rescue JWT::DecodeError, JWT::ExpiredSignature, JWT::ImmatureSignature # we return on expired and errored tokens because the Conan client # will request a new token automatically. end |
.from_deploy_token(deploy_token) ⇒ Object
24 25 26 |
# File 'lib/gitlab/conan_token.rb', line 24 def from_deploy_token(deploy_token) new(access_token_id: deploy_token.token, user_id: deploy_token.username) end |
.from_job(job) ⇒ Object
20 21 22 |
# File 'lib/gitlab/conan_token.rb', line 20 def from_job(job) new(access_token_id: job.token, user_id: job.user.id) end |
.from_personal_access_token(user_id, token) ⇒ Object
16 17 18 |
# File 'lib/gitlab/conan_token.rb', line 16 def from_personal_access_token(user_id, token) new(access_token_id: token, user_id: user_id) end |
.secret ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/gitlab/conan_token.rb', line 37 def secret OpenSSL::HMAC.hexdigest( OpenSSL::Digest.new('SHA256'), ::Settings.attr_encrypted_db_key_base, HMAC_KEY ) end |
Instance Method Details
#to_jwt ⇒ Object
51 52 53 |
# File 'lib/gitlab/conan_token.rb', line 51 def to_jwt hmac_token.encoded end |