File: deploy_token_methods.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (28 lines) | stat: -rw-r--r-- 917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module DeployTokenMethods
  def create_deploy_token_for(entity, current_user, params)
    entity_name = entity.class.name.downcase
    params[:deploy_token_type] = DeployToken.deploy_token_types["#{entity_name}_type".to_sym]
    params["#{entity_name}_id".to_sym] = entity.id

    entity.deploy_tokens.create(params) do |deploy_token|
      deploy_token.username = params[:username].presence
      deploy_token.creator_id = current_user.id
    end
  end

  def destroy_deploy_token(entity, params)
    deploy_token = entity.deploy_tokens.find(params[:token_id])

    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
end