代码拉取完成,页面将自动刷新
# frozen_string_literal: true
require 'rest-client'
# ccb api client class
class CcbApiClient
def initialize(host = '172.17.0.1', port = 10_012)
@host = host
@port = port
@url_prefix = url_prefix
end
def search(jwt, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/data-api/search"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def create_os_project(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def create_branch_project(jwt, os_project, sub_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}/sub-project/#{sub_project}"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def update_os_project(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}"
begin
RestClient.put(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def create_snapshot(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}/snapshot"
begin
RestClient::Request.execute(:method => :post, :url => url, :payload => request_json, :headers => {content_type: :json, accept: :json, 'Authorization' => jwt}, :timeout => 600)
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def build_single(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}/build_single"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def build_dag(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}/build_dag"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def abort_build(jwt, os_project, request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/api/os/#{os_project}/abort_build"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json, 'Authorization' => jwt })
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
def get_jwt(access_code)
resource = RestClient::Resource.new("#{@url_prefix}#{@host}:#{@port}/api/user_auth/access_code_authorize?access_code=#{access_code}")
resource.get
end
def get_client_info
resource = RestClient::Resource.new("#{@url_prefix}#{@host}:#{@port}/api/user_auth/get_client_info")
resource.get
end
def get_remote_status
resource = RestClient::Resource.new("#{@url_prefix}#{@host}:#{@port}/api/user_auth/api_status")
resource.get
end
def get_offline_jwt(request_json)
url = "#{@url_prefix}#{@host}:#{@port}/api/user_auth/auth_code_authorize"
begin
RestClient.post(url, request_json, { content_type: :json, accept: :json})
rescue RestClient::ExceptionWithResponse => e
return "{\"status_code\": #{e.response.code}, \"url\": \"#{url}\"}"
end
end
private def url_prefix
@url_prefix = if @host.match('.*[a-zA-Z]+.*')
# Internet users should use domain name and https
'https://'
else
# used in intranet for now
'http://'
end
end
end
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。