debian-mirror-gitlab/app/services/concerns/deploy_token_methods.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
836 B
Ruby
Raw Normal View History

2020-04-08 14:13:33 +05:30
# frozen_string_literal: true
module DeployTokenMethods
2022-06-21 17:19:12 +05:30
def create_deploy_token_for(entity, current_user, params)
2020-04-08 14:13:33 +05:30
params[:deploy_token_type] = DeployToken.deploy_token_types["#{entity.class.name.downcase}_type".to_sym]
entity.deploy_tokens.create(params) do |deploy_token|
deploy_token.username = params[:username].presence
2022-06-21 17:19:12 +05:30
deploy_token.creator_id = current_user.id
2020-04-08 14:13:33 +05:30
end
end
2020-04-22 19:07:51 +05:30
def destroy_deploy_token(entity, params)
2022-06-21 17:19:12 +05:30
deploy_token = entity.deploy_tokens.find(params[:token_id])
2020-04-22 19:07:51 +05:30
deploy_token.destroy
end
def create_deploy_token_payload_for(deploy_token)
if deploy_token.persisted?
success(deploy_token: deploy_token, http_status: :created)
else
error(deploy_token.errors.full_messages.to_sentence, :bad_request, pass_back: { deploy_token: deploy_token })
end
end
2020-04-08 14:13:33 +05:30
end