mirror of
https://github.com/certd/certd.git
synced 2026-04-23 11:37:23 +08:00
refactor: huawei
This commit is contained in:
@@ -3,12 +3,13 @@ import signer from "./signer";
|
||||
import https from "https";
|
||||
import { HuaweiAccess } from "../access";
|
||||
import { axios } from "@certd/acme-client";
|
||||
import { logger } from "@certd/pipeline";
|
||||
|
||||
export type ApiRequestOptions = {
|
||||
method: string;
|
||||
url: string;
|
||||
headers: any;
|
||||
body: any;
|
||||
headers?: any;
|
||||
data?: any;
|
||||
};
|
||||
export class HuaweiYunClient {
|
||||
access: HuaweiAccess;
|
||||
@@ -26,17 +27,29 @@ export class HuaweiYunClient {
|
||||
//Set request host.
|
||||
//Set request URI.
|
||||
//Set parameters for the request URL.
|
||||
const r = new signer.HttpRequest(options.method, options.url, options.headers, options.body);
|
||||
let body = undefined;
|
||||
if (options.data) {
|
||||
body = JSON.stringify(options.data);
|
||||
}
|
||||
const r = new signer.HttpRequest(options.method, options.url, options.headers, body);
|
||||
//Add header parameters, for example, x-domain-id for invoking a global service and x-project-id for invoking a project-level service.
|
||||
r.headers = { "Content-Type": "application/json" };
|
||||
//Add a body if you have specified the PUT or POST method. Special characters, such as the double quotation mark ("), contained in the body must be escaped.
|
||||
r.body = "";
|
||||
|
||||
// r.body = option;
|
||||
const opt = sig.Sign(r);
|
||||
console.log("opt", opt);
|
||||
console.log(opt.headers["X-Sdk-Date"]);
|
||||
console.log(opt.headers["Authorization"]);
|
||||
const res = await axios.request(opt);
|
||||
return res;
|
||||
try {
|
||||
const res = await axios.request({
|
||||
url: options.url,
|
||||
method: options.method,
|
||||
headers: opt.headers,
|
||||
data: body,
|
||||
});
|
||||
return res.data;
|
||||
} catch (e: any) {
|
||||
logger.error("华为云接口请求出错:", e?.response?.data);
|
||||
const error: any = new Error(e?.response?.data.message);
|
||||
error.code = e?.response?.code;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user