mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-08 23:18:05 -05:00
Merge pull request #5130 from Infisical/fix/githubGatewayConnectionUrl
fix: getGitHubGatewayConnectionDetails filter path
This commit is contained in:
@@ -52,12 +52,21 @@ export const getGitHubGatewayConnectionDetails = async (
|
||||
gatewayId: string,
|
||||
targetHost: string,
|
||||
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">
|
||||
): Promise<Awaited<ReturnType<TGatewayV2ServiceFactory["getPlatformConnectionDetailsByGatewayId"]>>> => {
|
||||
return gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
|
||||
gatewayId,
|
||||
targetHost,
|
||||
targetPort: 443
|
||||
});
|
||||
): Promise<Awaited<ReturnType<TGatewayV2ServiceFactory["getPlatformConnectionDetailsByGatewayId"]>> | undefined> => {
|
||||
try {
|
||||
const urlString = targetHost.includes("://") ? targetHost : `https://${targetHost}`;
|
||||
const url = new URL(urlString);
|
||||
const { hostname } = url;
|
||||
|
||||
return await gatewayV2Service.getPlatformConnectionDetailsByGatewayId({
|
||||
gatewayId,
|
||||
targetHost: hostname,
|
||||
targetPort: 443
|
||||
});
|
||||
} catch {
|
||||
// Return undefined to allow fallback to V1 gateway
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
export const requestWithGitHubGateway = async <T>(
|
||||
|
||||
@@ -2049,8 +2049,8 @@ describe("CertificateV3Service", () => {
|
||||
id: "cert-123",
|
||||
profileId: "profile-123",
|
||||
renewedByCertificateId: null,
|
||||
notBefore: new Date("2026-01-01"),
|
||||
notAfter: new Date("2026-02-01"),
|
||||
notBefore: new Date(),
|
||||
notAfter: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30),
|
||||
projectId: "project-123",
|
||||
status: CertStatus.ACTIVE,
|
||||
revokedAt: null,
|
||||
@@ -2130,8 +2130,8 @@ describe("CertificateV3Service", () => {
|
||||
projectId: "project-123",
|
||||
status: CertStatus.ACTIVE,
|
||||
revokedAt: null,
|
||||
notBefore: new Date("2026-01-01"),
|
||||
notAfter: new Date("2026-02-01")
|
||||
notBefore: new Date(),
|
||||
notAfter: new Date(Date.now() + 1000 * 60 * 60 * 24 * 30)
|
||||
};
|
||||
|
||||
const mockProfile = {
|
||||
@@ -2173,8 +2173,8 @@ describe("CertificateV3Service", () => {
|
||||
id: "cert-123",
|
||||
profileId: "profile-123",
|
||||
renewedByCertificateId: null,
|
||||
notBefore: new Date("2026-01-01"),
|
||||
notAfter: new Date("2026-01-08"),
|
||||
notBefore: new Date(),
|
||||
notAfter: new Date(Date.now() + 1000 * 60 * 60 * 24 * 7),
|
||||
projectId: "project-123",
|
||||
status: CertStatus.ACTIVE,
|
||||
revokedAt: null
|
||||
|
||||
@@ -4,6 +4,7 @@ import { TGatewayServiceFactory } from "@app/ee/services/gateway/gateway-service
|
||||
import { TGatewayV2ServiceFactory } from "@app/ee/services/gateway-v2/gateway-v2-service";
|
||||
import {
|
||||
getGitHubAppAuthToken,
|
||||
getGitHubGatewayConnectionDetails,
|
||||
getGitHubInstanceApiUrl,
|
||||
GitHubConnectionMethod,
|
||||
makePaginatedGitHubRequest,
|
||||
@@ -77,15 +78,26 @@ const getPublicKey = async (
|
||||
}
|
||||
}
|
||||
|
||||
const response = await requestWithGitHubGateway<TGitHubPublicKey>(connection, gatewayService, gatewayV2Service, {
|
||||
url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
}
|
||||
});
|
||||
const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
|
||||
const gatewayConnectionDetails = connection.gatewayId
|
||||
? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
|
||||
: undefined;
|
||||
|
||||
const response = await requestWithGitHubGateway<TGitHubPublicKey>(
|
||||
connection,
|
||||
gatewayService,
|
||||
gatewayV2Service,
|
||||
{
|
||||
url: `https://${apiBaseUrl}${path}`,
|
||||
method: "GET",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
}
|
||||
},
|
||||
gatewayConnectionDetails
|
||||
);
|
||||
|
||||
return response.data;
|
||||
};
|
||||
@@ -116,15 +128,26 @@ const deleteSecret = async (
|
||||
}
|
||||
}
|
||||
|
||||
await requestWithGitHubGateway(connection, gatewayService, gatewayV2Service, {
|
||||
url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
}
|
||||
});
|
||||
const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
|
||||
const gatewayConnectionDetails = connection.gatewayId
|
||||
? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
|
||||
: undefined;
|
||||
|
||||
await requestWithGitHubGateway(
|
||||
connection,
|
||||
gatewayService,
|
||||
gatewayV2Service,
|
||||
{
|
||||
url: `https://${apiBaseUrl}${path}`,
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
}
|
||||
},
|
||||
gatewayConnectionDetails
|
||||
);
|
||||
};
|
||||
|
||||
const putSecret = async (
|
||||
@@ -163,16 +186,27 @@ const putSecret = async (
|
||||
}
|
||||
}
|
||||
|
||||
await requestWithGitHubGateway(connection, gatewayService, gatewayV2Service, {
|
||||
url: `https://${await getGitHubInstanceApiUrl(connection)}${path}`,
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
const apiBaseUrl = await getGitHubInstanceApiUrl(connection);
|
||||
const gatewayConnectionDetails = connection.gatewayId
|
||||
? await getGitHubGatewayConnectionDetails(connection.gatewayId, apiBaseUrl, gatewayV2Service)
|
||||
: undefined;
|
||||
|
||||
await requestWithGitHubGateway(
|
||||
connection,
|
||||
gatewayService,
|
||||
gatewayV2Service,
|
||||
{
|
||||
url: `https://${apiBaseUrl}${path}`,
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Accept: "application/vnd.github+json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
"X-GitHub-Api-Version": "2022-11-28"
|
||||
},
|
||||
data: body
|
||||
},
|
||||
data: body
|
||||
});
|
||||
gatewayConnectionDetails
|
||||
);
|
||||
};
|
||||
|
||||
export const GithubSyncFns = {
|
||||
|
||||
Reference in New Issue
Block a user