2020-07-28 23:09:34 +05:30
|
|
|
# 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-11-24 15:15:51 +05:30
|
|
|
return unless request.headers
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
token = decode_token
|
|
|
|
|
|
|
|
return unless token
|
|
|
|
|
2020-09-03 11:15:55 +05:30
|
|
|
::Ci::AuthJobFinder.new(token: token).execute
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def find_deploy_token_from_http_basic_auth
|
2020-11-24 15:15:51 +05:30
|
|
|
return unless request.headers
|
2020-07-28 23:09:34 +05:30
|
|
|
|
|
|
|
token = decode_token
|
|
|
|
|
|
|
|
return unless token
|
|
|
|
|
|
|
|
DeployToken.active.find_by_token(token)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def decode_token
|
2020-11-24 15:15:51 +05:30
|
|
|
encoded_credentials = request.headers['Authorization'].to_s.split('Basic ', 2).second
|
2020-07-28 23:09:34 +05:30
|
|
|
Base64.decode64(encoded_credentials || '').split(':', 2).second
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|