Ensure `runners_token` in project
See: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2294 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2294#note_3135776
The problem is that
runners_token
is not properly ensured. This commit https://gitlab.com/gitlab-org/gitlab-ce/commit/8cdd54cc0696b76daa2baf463d02d944b50bac6a introduced runners token in a way, that doesn't work for previous installations, where runners_token isnil
.
Recently, I fixed similar problem with
runners_registration_token
, see here: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2039 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2185.
My approach was to refactor
TokenAuthenticatable
to make it reusable. Then it is possible to add to model:
include TokenAuthenticatable add_authentication_token_field :runners_token
> This adds several methods to `Project` -- method that generates token, and several other methods. With this approach then we can add this method to `Project`:
> ```ruby
def runners_token
ensure_runners_token!
end
If someone checks runners token it will be returned if it exists. If it doesn't exist -- it will be generated instantly, saved to database and returned.
As a matter of fact, currently, users can prevent errors by editing project, as runners_token will be generated on
before_validation
, according to https://gitlab.com/gitlab-org/gitlab-ce/commit/8cdd54cc0696b76daa2baf463d02d944b50bac6a.
\cc @stanhu