blob: 67d690d64e737554910d644050076502291a1fda (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# frozen_string_literal: true
module ErrorTracking
class ListProjectsService < ErrorTracking::BaseService
private
def perform
return error('Access denied', :unauthorized) unless can?(current_user, :admin_sentry, project)
unless project_error_tracking_setting.valid?
return error(project_error_tracking_setting.errors.full_messages.join(', '), :bad_request)
end
response = project_error_tracking_setting.list_sentry_projects
compose_response(response)
end
def parse_response(response)
{ projects: response[:projects] }
end
def project_error_tracking_setting
(super || project.build_error_tracking_setting).tap do |setting|
setting.api_url = ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from(
api_host: params[:api_host],
organization_slug: 'org',
project_slug: 'proj'
)
setting.token = token(setting)
setting.enabled = true
end
end
strong_memoize_attr :project_error_tracking_setting
def token(setting)
return if setting.api_url_changed? && masked_token?
# Use param token if not masked, otherwise use database token
return params[:token] unless masked_token?
setting.token
end
def masked_token?
ErrorTracking::SentryClient::Token.masked_token?(params[:token])
end
end
end
|