mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 00:27:30 +00:00
Improve URL management on Chef PKI fns
This commit is contained in:
@@ -27,6 +27,17 @@ export const getChefServerUrl = async (serverUrl?: string) => {
|
|||||||
return chefServerUrl;
|
return chefServerUrl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildSecureUrl = (baseUrl: string, path: string): string => {
|
||||||
|
try {
|
||||||
|
const url = new URL(path, baseUrl);
|
||||||
|
return url.toString();
|
||||||
|
} catch (error) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Invalid URL construction parameters"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Helper to ensure private key is in proper PEM format
|
// Helper to ensure private key is in proper PEM format
|
||||||
const formatPrivateKey = (key: string): string => {
|
const formatPrivateKey = (key: string): string => {
|
||||||
let formattedKey = key.trim();
|
let formattedKey = key.trim();
|
||||||
@@ -138,7 +149,8 @@ export const validateChefConnectionCredentials = async (config: TChefConnectionC
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("GET", path, "", inputCredentials.userName, inputCredentials.privateKey);
|
const headers = getChefAuthHeaders("GET", path, "", inputCredentials.userName, inputCredentials.privateKey);
|
||||||
|
|
||||||
await request.get(`${hostServerUrl}${path}`, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
await request.get(secureUrl, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
@@ -168,7 +180,8 @@ export const listChefDataBags = async (appConnection: TChefConnection): Promise<
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
||||||
|
|
||||||
const res = await request.get<Record<string, string>>(`${hostServerUrl}${path}`, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
const res = await request.get<Record<string, string>>(secureUrl, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -203,7 +216,8 @@ export const listChefDataBagItems = async (
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
||||||
|
|
||||||
const res = await request.get<Record<string, string>>(`${hostServerUrl}${path}`, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
const res = await request.get<Record<string, string>>(secureUrl, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -238,7 +252,8 @@ export const getChefDataBagItem = async ({
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("GET", path, body, userName, privateKey);
|
||||||
|
|
||||||
const res = await request.get<TChefDataBagItemContent>(`${hostServerUrl}${path}`, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
const res = await request.get<TChefDataBagItemContent>(secureUrl, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -271,7 +286,8 @@ export const createChefDataBagItem = async ({
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("POST", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("POST", path, body, userName, privateKey);
|
||||||
|
|
||||||
await request.post(`${hostServerUrl}${path}`, data, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
await request.post(secureUrl, data, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -303,7 +319,8 @@ export const updateChefDataBagItem = async ({
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("PUT", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("PUT", path, body, userName, privateKey);
|
||||||
|
|
||||||
await request.put(`${hostServerUrl}${path}`, data, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
await request.put(secureUrl, data, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -334,7 +351,8 @@ export const removeChefDataBagItem = async ({
|
|||||||
|
|
||||||
const headers = getChefAuthHeaders("DELETE", path, body, userName, privateKey);
|
const headers = getChefAuthHeaders("DELETE", path, body, userName, privateKey);
|
||||||
|
|
||||||
await request.delete(`${hostServerUrl}${path}`, {
|
const secureUrl = buildSecureUrl(hostServerUrl, path);
|
||||||
|
await request.delete(secureUrl, {
|
||||||
headers
|
headers
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user