Create abstraction for loading service token
We are currently lacking a good abstraction/interface for providing a service token to access a feature that is serviced via Cloud Connector. We currently duplicate code in several places that does the following:
if Gitlab.org_or_com?
token = Gitlab::Ai::AccessToken.new(
current_user,
scopes: [:code_suggestions],
gitlab_realm: gitlab_realm
).encoded
else
code_suggestions_token = ::Ai::ServiceAccessToken.active.last
unauthorized! if code_suggestions_token.nil?
token = code_suggestions_token.token
end
This puts the burden on the caller to decide whether this should work for both SaaS and SM. We should abstract this away and also deal with any errors behind an interface that provides this token transparently.
Edited by Matthias Käppler