Skip to content

Commit

Permalink
fix: Use source credentials if target principle is null (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 authored Oct 10, 2024
1 parent 67b4e46 commit 6f690f8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions apps/event-worker/src/target-scan/google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ClusterManagerClient } from "@google-cloud/container";
import type { google } from "@google-cloud/container/build/protos/protos.js";
import type { AuthClient } from "google-auth-library";
import Container from "@google-cloud/container";
import { KubeConfig } from "@kubernetes/client-node";
import { GoogleAuth, Impersonated } from "google-auth-library";
Expand All @@ -24,16 +25,15 @@ export const getImpersonatedClient = async (targetPrincipal: string) =>

export const getGoogleClusterClient = async (
targetPrincipal?: string | null,
) => {
let authClient: Impersonated | undefined;

if (targetPrincipal != null)
authClient = await getImpersonatedClient(targetPrincipal);

return [
new Container.v1.ClusterManagerClient({ authClient }),
authClient,
] as const;
): Promise<[ClusterManagerClient, AuthClient | undefined]> => {
if (targetPrincipal == null)
return [
new Container.v1.ClusterManagerClient(),
await sourceCredentials.getClient(),
];

const authClient = await getImpersonatedClient(targetPrincipal);
return [new Container.v1.ClusterManagerClient({ authClient }), authClient];
};

export const getClusters = async (
Expand All @@ -48,7 +48,7 @@ export const getClusters = async (

export const connectToCluster = async (
clusterClient: ClusterManagerClient,
authClient: Impersonated | undefined,
authClient: AuthClient | undefined,
project: string,
clusterName: string,
clusterLocation: string,
Expand Down

0 comments on commit 6f690f8

Please sign in to comment.