4 Star 18 Fork 184

Fengguang/lkp-tests

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ccb_api_client.rb 4.40 KB
一键复制 编辑 原始数据 按行查看 历史
Fengguang 提交于 10个月前 . Merge files from eulermaker
# 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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wu_fengguang/lkp-tests.git
git@gitee.com:wu_fengguang/lkp-tests.git
wu_fengguang
lkp-tests
lkp-tests
master

搜索帮助