2020-07-17 02:09:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Helpers
|
|
|
|
module PackagesManagerClientsHelpers
|
|
|
|
extend Grape::API::Helpers
|
|
|
|
include ::API::Helpers::PackagesHelpers
|
|
|
|
|
|
|
|
def find_job_from_http_basic_auth
|
2020-08-25 02:10:18 -04:00
|
|
|
return unless request.headers
|
2020-07-17 02:09:11 -04:00
|
|
|
|
|
|
|
token = decode_token
|
|
|
|
|
|
|
|
return unless token
|
|
|
|
|
2020-09-02 11:10:54 -04:00
|
|
|
::Ci::AuthJobFinder.new(token: token).execute
|
2020-07-17 02:09:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def find_deploy_token_from_http_basic_auth
|
2020-08-25 02:10:18 -04:00
|
|
|
return unless request.headers
|
2020-07-17 02:09:11 -04:00
|
|
|
|
|
|
|
token = decode_token
|
|
|
|
|
|
|
|
return unless token
|
|
|
|
|
|
|
|
DeployToken.active.find_by_token(token)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def decode_token
|
2020-08-25 02:10:18 -04:00
|
|
|
encoded_credentials = request.headers['Authorization'].to_s.split('Basic ', 2).second
|
2020-07-17 02:09:11 -04:00
|
|
|
Base64.decode64(encoded_credentials || '').split(':', 2).second
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|