forked from Trustie/forgeplus
sca
This commit is contained in:
parent
bbc12e5503
commit
0db7e28248
|
|
@ -2,13 +2,13 @@ class Api::V1::Projects::ScaController < Api::V1::BaseController
|
|||
before_action :require_public_and_member_above
|
||||
before_action :load_project
|
||||
def index
|
||||
@auth_token, @result = Api::V1::Projects::Sca::ShowProjectService.call(@project)
|
||||
@auth_token, @result = Api::V1::Projects::Sca::ProjectShowService.call(@project)
|
||||
set_sca_cookie
|
||||
end
|
||||
def create
|
||||
result = Api::V1::Projects::Sca::CreateProjectService.call(@project)
|
||||
if result
|
||||
@auth_token, @result = Api::V1::Projects::Sca::ShowProjectService.call(@project)
|
||||
@auth_token, @result = Api::V1::Projects::Sca::ProjectShowService.call(@project)
|
||||
set_sca_cookie
|
||||
else
|
||||
{
|
||||
|
|
@ -16,6 +16,37 @@ class Api::V1::Projects::ScaController < Api::V1::BaseController
|
|||
"url": nil,
|
||||
}
|
||||
end
|
||||
render index
|
||||
end
|
||||
|
||||
def scanner #创建扫描
|
||||
@result = Api::V1::Projects::Sca::ScannerService.call(@project, params[:branch])
|
||||
render index
|
||||
end
|
||||
|
||||
def scanner_list #扫描列表
|
||||
@result = Api::V1::Projects::Sca::ScannerListService.call(@project, params[:scan_type], params[:limit], params[:page])
|
||||
render index
|
||||
end
|
||||
|
||||
def scanner_show #扫描详情
|
||||
@result = Api::V1::Projects::Sca::ScannerShowService.call(params[:scan_id])
|
||||
render index
|
||||
end
|
||||
|
||||
def reports #创建报告 ASC SCA SAST
|
||||
@result = Api::V1::Projects::Sca::ReportService.call(params[:scan_type], params[:scan_id])
|
||||
render index
|
||||
end
|
||||
|
||||
def report_list #报告列表
|
||||
@result = Api::V1::Projects::Sca::ReportListService.call(params[:scan_id])
|
||||
render index
|
||||
end
|
||||
|
||||
def report_export #报告导出
|
||||
@result = Api::V1::Projects::Sca::ReportExportService.call(params[:scan_type], params[:scan_id])
|
||||
render index
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
class Api::V1::Projects::Sca::CreateReportService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(project)
|
||||
@project = project
|
||||
end
|
||||
|
||||
def call
|
||||
params = {
|
||||
"org_id": sca_user_info["default_org"],
|
||||
"team_id_list": [sca_team_id],
|
||||
"name": @repo,
|
||||
"provider": "gitea_hs",
|
||||
"external_id": "#{@owner}&|&#{@repo}",
|
||||
"description": @project.description
|
||||
}
|
||||
data = sca_post_request("reports", params)
|
||||
@project.update(sca_project_id:data[:json]["id"])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
class Api::V1::Projects::Sca::ShowProjectService < Api::V1::Projects::Sca::BaseService
|
||||
class Api::V1::Projects::Sca::ProjectShowService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(project)
|
||||
@project = project
|
||||
end
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
class Api::V1::Projects::Sca::ReportExportService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(sca,scan_id)
|
||||
@sca = sca
|
||||
@scan_id = scan_id
|
||||
end
|
||||
|
||||
def call
|
||||
data = if @sca == "SCA"
|
||||
%w[component vulnerability compliance]
|
||||
else
|
||||
%w[issue_code]
|
||||
end
|
||||
params = data.map { |e|
|
||||
{
|
||||
format: "pdf",
|
||||
language: "cn",
|
||||
scan_id: @scan_id,
|
||||
type: e
|
||||
}
|
||||
}
|
||||
|
||||
sca_post_request("reports/export/", params)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
class Api::V1::Projects::Sca::ReportListService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(scan_id)
|
||||
@scan_id = scan_id
|
||||
end
|
||||
|
||||
def call
|
||||
sca_get_request("reports/?&scans=#{@scan_id}&language=cn&filter=format")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
class Api::V1::Projects::Sca::ReportService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(sca,scan_id)
|
||||
@sca = sca
|
||||
@scan_id = scan_id
|
||||
end
|
||||
|
||||
def call
|
||||
data = if @sca == "SCA"
|
||||
%w[component vulnerability compliance]
|
||||
else
|
||||
%w[issue_code]
|
||||
end
|
||||
params = data.map { |e|
|
||||
{
|
||||
format: "pdf",
|
||||
language: "cn",
|
||||
scan_id: @scan_id,
|
||||
type: e
|
||||
}
|
||||
}
|
||||
|
||||
sca_post_request("reports/", params)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
class Api::V1::Projects::Sca::ScannerListService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(project,sca="SCA",limit=5,page=1)
|
||||
@project = project
|
||||
@sca = sca
|
||||
@page = page
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def call
|
||||
sca_get_request("scans/?project_id=#{@project.sca_project_id}&engine_type=#{@sca}&limit=#{@limit}&page=#{@page}")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
class Api::V1::Projects::Sca::ScannerService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(project,branch)
|
||||
@project = project
|
||||
@branch = branch
|
||||
end
|
||||
|
||||
def call
|
||||
params = [
|
||||
{
|
||||
engine_type: "SCA",
|
||||
project_id: @project.sca_project_id,
|
||||
sca_scan_parameter: {
|
||||
compliance_policy_id: 1000,
|
||||
branch: @branch
|
||||
},
|
||||
scan_type: "source_code",
|
||||
source: "Gitea_hs SCM",
|
||||
system_version: "v4.17.0"
|
||||
},
|
||||
{
|
||||
engine_type: "SAST",
|
||||
project_id: @project.sca_project_id,
|
||||
sast_scan_parameter: {
|
||||
compliance_policy_id: 1000,
|
||||
branch: @branch
|
||||
},
|
||||
scan_type: "source_code",
|
||||
source: "Gitea_hs SCM",
|
||||
system_version: "v4.17.0"
|
||||
}
|
||||
]
|
||||
|
||||
sca_post_request("scans/scan/", params)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
class Api::V1::Projects::Sca::ScannerShowService < Api::V1::Projects::Sca::BaseService
|
||||
def initialize(scan_id)
|
||||
@scan_id = scan_id
|
||||
end
|
||||
|
||||
def call
|
||||
#projects/18748/list-branches/?branch_name_query=&page=1&limit=5
|
||||
|
||||
sca_get_request("scans/#{@scan_id}/")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
json.data @result
|
||||
|
|
@ -223,7 +223,16 @@ defaults format: :json do
|
|||
end
|
||||
end
|
||||
end
|
||||
resources :sca, only: [:index,:create]
|
||||
resources :sca, only: [:index,:create] do
|
||||
collection do
|
||||
post :scanner
|
||||
get :scanner_list
|
||||
get :scanner_show
|
||||
post :reports
|
||||
get :report_list
|
||||
get :report_export
|
||||
end
|
||||
end
|
||||
resources :pipelines do
|
||||
post :build_yaml, on: :collection
|
||||
post :save_yaml, on: :collection
|
||||
|
|
|
|||
Loading…
Reference in New Issue