Merge pull request #5130 from Infisical/fix/githubGatewayConnectionUrl

fix: getGitHubGatewayConnectionDetails filter path
This commit is contained in:
carlosmonastyrski
2026-01-07 23:40:11 -03:00
committed by GitHub
3 changed files with 82 additions and 39 deletions

View File

@@ -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>(

View File

@@ -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

View File

@@ -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 = {