Refactor other endpoints and service methods

This commit is contained in:
Fang-Pen Lin
2025-11-07 09:18:31 -08:00
parent 96cb473192
commit 61af9734b4
2 changed files with 173 additions and 64 deletions
@@ -321,96 +321,171 @@ export const pkiAcmeServiceFactory = ({
}; };
}; };
const deactivateAcmeAccount = async ( const deactivateAcmeAccount = async ({
profileId: string, profileId,
accountId: string, accountId,
payload?: TDeactivateAcmeAccountPayload payload: { status } = { status: "deactivated" }
): Promise<TDeactivateAcmeAccountResponse> => { }: {
profileId: string;
accountId: string;
payload?: TDeactivateAcmeAccountPayload;
}): Promise<TAcmeResponse<TDeactivateAcmeAccountResponse>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME account deactivation // FIXME: Implement ACME account deactivation
return { return {
status: "deactivated" status: 200,
body: {
status: "deactivated"
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/accounts/${accountId}`)
}
}; };
}; };
const listAcmeOrders = async (profileId: string, accountId: string): Promise<TListAcmeOrdersResponse> => { const listAcmeOrders = async ({
profileId,
accountId
}: {
profileId: string;
accountId: string;
}): Promise<TAcmeResponse<TListAcmeOrdersResponse>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME list orders // FIXME: Implement ACME list orders
return { return {
orders: [] status: 200,
body: {
orders: []
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/accounts/${accountId}/orders`)
}
}; };
}; };
const getAcmeOrder = async (profileId: string, orderId: string): Promise<TGetAcmeOrderResponse> => { const getAcmeOrder = async ({
profileId,
orderId
}: {
profileId: string;
orderId: string;
}): Promise<TAcmeResponse<TGetAcmeOrderResponse>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME get order // FIXME: Implement ACME get order
return { return {
status: "pending", status: 200,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), body: {
identifiers: [], status: "pending",
authorizations: [], expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
finalize: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/finalize`) identifiers: [],
authorizations: [],
finalize: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/finalize`)
},
headers: { Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}`) }
}; };
}; };
const finalizeAcmeOrder = async ( const finalizeAcmeOrder = async ({
profileId: string, profileId,
orderId: string, orderId,
payload: TFinalizeAcmeOrderPayload payload
): Promise<TFinalizeAcmeOrderResponse> => { }: {
profileId: string;
orderId: string;
payload: TFinalizeAcmeOrderPayload;
}): Promise<TAcmeResponse<TFinalizeAcmeOrderResponse>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
const { csr } = payload; const { csr } = payload;
// FIXME: Implement ACME finalize order // FIXME: Implement ACME finalize order
return { return {
status: "processing", status: 200,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), body: {
identifiers: [], status: "processing",
authorizations: [], expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
finalize: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/finalize`), identifiers: [],
certificate: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/certificate`) authorizations: [],
finalize: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/finalize`),
certificate: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/certificate`)
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}`)
}
}; };
}; };
const downloadAcmeCertificate = async (profileId: string, orderId: string): Promise<string> => { const downloadAcmeCertificate = async ({
profileId,
orderId
}: {
profileId: string;
orderId: string;
}): Promise<TAcmeResponse<string>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME certificate download // FIXME: Implement ACME certificate download
// Return the certificate in PEM format // Return the certificate in PEM format
return "FIXME-certificate-pem";
};
const getAcmeAuthorization = async (profileId: string, authzId: string): Promise<TGetAcmeAuthorizationResponse> => {
const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME authorization retrieval
return { return {
status: "pending", status: 200,
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), body: "FIXME-certificate-pem",
identifier: { headers: {
type: "dns", Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/orders/${orderId}/certificate`)
value: "FIXME-domain-name" }
},
challenges: [
{
type: "http-01",
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
status: "pending",
token: "FIXME-challenge-token"
}
]
}; };
}; };
const respondToAcmeChallenge = async ( const getAcmeAuthorization = async ({
profileId: string, profileId,
authzId: string authzId
): Promise<TRespondToAcmeChallengeResponse> => { }: {
profileId: string;
authzId: string;
}): Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>> => {
const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME authorization retrieval
return {
status: 200,
body: {
status: "pending",
expires: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(),
identifier: {
type: "dns",
value: "FIXME-domain-name"
},
challenges: [
{
type: "http-01",
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
status: "pending",
token: "FIXME-challenge-token"
}
]
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}`)
}
};
};
const respondToAcmeChallenge = async ({
profileId,
authzId
}: {
profileId: string;
authzId: string;
}): Promise<TAcmeResponse<TRespondToAcmeChallengeResponse>> => {
const profile = await validateAcmeProfile(profileId); const profile = await validateAcmeProfile(profileId);
// FIXME: Implement ACME challenge response // FIXME: Implement ACME challenge response
// Trigger verification process // Trigger verification process
return { return {
type: "http-01", status: 200,
url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`), body: {
status: "pending", type: "http-01",
token: "FIXME-challenge-token" url: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`),
status: "pending",
token: "FIXME-challenge-token"
},
headers: {
Location: buildUrl(`/api/v1/pki/acme/profiles/${profileId}/authorizations/${authzId}/challenges/http-01`)
}
}; };
}; };
@@ -90,14 +90,48 @@ export type TPkiAcmeServiceFactory = {
accountId: string, accountId: string,
body?: TDeactivateAcmeAccountPayload body?: TDeactivateAcmeAccountPayload
) => Promise<TDeactivateAcmeAccountResponse>; ) => Promise<TDeactivateAcmeAccountResponse>;
listAcmeOrders: (profileId: string, accountId: string) => Promise<TListAcmeOrdersResponse>; listAcmeOrders: ({
getAcmeOrder: (profileId: string, orderId: string) => Promise<TGetAcmeOrderResponse>; profileId,
finalizeAcmeOrder: ( accountId
profileId: string, }: {
orderId: string, profileId: string;
body: TFinalizeAcmeOrderPayload accountId: string;
) => Promise<TFinalizeAcmeOrderResponse>; }) => Promise<TAcmeResponse<TListAcmeOrdersResponse>>;
downloadAcmeCertificate: (profileId: string, orderId: string) => Promise<string>; getAcmeOrder: ({
getAcmeAuthorization: (profileId: string, authzId: string) => Promise<TGetAcmeAuthorizationResponse>; profileId,
respondToAcmeChallenge: (profileId: string, authzId: string) => Promise<TRespondToAcmeChallengeResponse>; orderId
}: {
profileId: string;
orderId: string;
}) => Promise<TAcmeResponse<TGetAcmeOrderResponse>>;
finalizeAcmeOrder: ({
profileId,
orderId,
payload
}: {
profileId: string;
orderId: string;
payload: TFinalizeAcmeOrderPayload;
}) => Promise<TAcmeResponse<TFinalizeAcmeOrderResponse>>;
downloadAcmeCertificate: ({
profileId,
orderId
}: {
profileId: string;
orderId: string;
}) => Promise<TAcmeResponse<string>>;
getAcmeAuthorization: ({
profileId,
authzId
}: {
profileId: string;
authzId: string;
}) => Promise<TAcmeResponse<TGetAcmeAuthorizationResponse>>;
respondToAcmeChallenge: ({
profileId,
authzId
}: {
profileId: string;
authzId: string;
}) => Promise<TAcmeResponse<TRespondToAcmeChallengeResponse>>;
}; };