Class: Gitlab::LfsToken
- Inherits:
-
Object
- Object
- Gitlab::LfsToken
- Includes:
- LfsTokenHelper
- Defined in:
- lib/gitlab/lfs_token.rb
Defined Under Namespace
Modules: LfsTokenHelper Classes: HMACToken
Constant Summary collapse
- DEFAULT_EXPIRE_TIME =
Default value 2 hours
7200
Instance Attribute Summary collapse
-
#actor ⇒ Object
Returns the value of attribute actor.
Instance Method Summary collapse
- #authentication_payload(repository_http_path) ⇒ Object
- #basic_encoding ⇒ Object
- #deploy_key_pushable?(project) ⇒ Boolean
-
#initialize(actor, container) ⇒ LfsToken
constructor
A new instance of LfsToken.
- #token ⇒ Object
-
#token_valid?(token_to_check) ⇒ Boolean
When the token is an lfs one and the actor is blocked or the password has been changed, the token is no longer valid.
- #type ⇒ Object
- #valid_user? ⇒ Boolean
Methods included from LfsTokenHelper
#actor_name, #container_gid, #user?
Constructor Details
#initialize(actor, container) ⇒ LfsToken
Returns a new instance of LfsToken.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/lfs_token.rb', line 25 def initialize(actor, container) @actor = case actor when DeployKey, User actor when Key actor.user else raise 'Bad Actor' end @container = container end |
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
23 24 25 |
# File 'lib/gitlab/lfs_token.rb', line 23 def actor @actor end |
Instance Method Details
#authentication_payload(repository_http_path) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/gitlab/lfs_token.rb', line 64 def authentication_payload(repository_http_path) { username: actor_name, lfs_token: token, repository_http_path: repository_http_path, expires_in: DEFAULT_EXPIRE_TIME } end |
#basic_encoding ⇒ Object
73 74 75 |
# File 'lib/gitlab/lfs_token.rb', line 73 def basic_encoding ActionController::HttpAuthentication::Basic.encode_credentials(actor_name, token) end |
#deploy_key_pushable?(project) ⇒ Boolean
50 51 52 |
# File 'lib/gitlab/lfs_token.rb', line 50 def deploy_key_pushable?(project) actor.is_a?(DeployKey) && actor.can_push_to?(project) end |
#token ⇒ Object
39 40 41 |
# File 'lib/gitlab/lfs_token.rb', line 39 def token HMACToken.new(actor, container).token(DEFAULT_EXPIRE_TIME) end |
#token_valid?(token_to_check) ⇒ Boolean
When the token is an lfs one and the actor is blocked or the password has been changed, the token is no longer valid
46 47 48 |
# File 'lib/gitlab/lfs_token.rb', line 46 def token_valid?(token_to_check) HMACToken.new(actor, container).token_valid?(token_to_check) && valid_user? end |
#type ⇒ Object
54 55 56 |
# File 'lib/gitlab/lfs_token.rb', line 54 def type user? ? :lfs_token : :lfs_deploy_token end |
#valid_user? ⇒ Boolean
58 59 60 61 62 |
# File 'lib/gitlab/lfs_token.rb', line 58 def valid_user? return true unless user? !actor.blocked? && !actor.password_expired_if_applicable? end |