Module: DeployTokenMethods

Instance Method Summary collapse

Instance Method Details

#create_deploy_token_for(entity, params) ⇒ Object


4
5
6
7
8
9
10
# File 'app/services/concerns/deploy_token_methods.rb', line 4

def create_deploy_token_for(entity, params)
  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
  end
end

#create_deploy_token_payload_for(deploy_token) ⇒ Object


18
19
20
21
22
23
24
# File 'app/services/concerns/deploy_token_methods.rb', line 18

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

#destroy_deploy_token(entity, params) ⇒ Object


12
13
14
15
16
# File 'app/services/concerns/deploy_token_methods.rb', line 12

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

  deploy_token.destroy
end