Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix user case sync secret

adilsonf59454238704
diff --git a/backend/src/services/secret-sync/ona/ona-sync-fns.ts b/backend/src/services/secret-sync/ona/ona-sync-fns.ts
index 1a1aca7211..5e7dca5cbd 100644
--- a/backend/src/services/secret-sync/ona/ona-sync-fns.ts
+++ b/backend/src/services/secret-sync/ona/ona-sync-fns.ts
@@ -54,37 +54,29 @@ const getAuthHeaders = (secretSync: TOnaSyncWithCredentials) => ({
"Content-Type": "application/json"
});
-const makeUserIdResolver = (secretSync: TOnaSyncWithCredentials) => {
- let cached: string | undefined;
- return async (): Promise<string> => {
- if (cached) return cached;
- const { data } = await withOnaRetry(() =>
- request.post<TOnaAuthenticatedIdentityResponse>(
- `${IntegrationUrls.ONA_API_URL}${ONA_GET_AUTHENTICATED_IDENTITY_PATH}`,
- {},
- { headers: getAuthHeaders(secretSync) }
- )
- );
- const userId = data?.identity?.subject?.id ?? data?.userId;
- if (!userId) {
- throw new SecretSyncError({
- message: "Unable to resolve authenticated Ona user ID for user-scoped sync.",
- shouldRetry: false
- });
- }
- cached = userId;
- return cached;
- };
+const resolveUserId = async (secretSync: TOnaSyncWithCredentials): Promise<string> => {
+ const { data } = await withOnaRetry(() =>
+ request.post<TOnaAuthenticatedIdentityResponse>(
+ `${IntegrationUrls.ONA_API_URL}${ONA_GET_AUTHENTICATED_IDENTITY_PATH}`,
+ {},
+ { headers: getAuthHeaders(secretSync) }
+ )
+ );
+ const userId = data?.subject?.id;
+ if (!userId) {
+ throw new SecretSyncError({
+ message: "Unable to resolve authenticated Ona user ID for user-scoped sync.",
+ shouldRetry: false
+ });
+ }
+ return userId;
};
-const buildScopeFilter = async (
- secretSync: TOnaSyncWithCredentials,
- resolveUserId: () => Promise<string>
-): Promise<TOnaScopeFilter> => {
+const buildScopeFilter = async (secretSync: TOnaSyncWithCredentials): Promise<TOnaScopeFilter> => {
if (secretSync.destinationConfig.scope === OnaSyncScope.Project) {
return { projectId: secretSync.destinationConfig.projectId };
}
- return { userId: await resolveUserId() };
+ return { userId: await resolveUserId(secretSync) };
};
const listEnvVarSecrets = async (
@@ -177,8 +169,7 @@ const wrapApiError = (error: unknown, secretKey: string): never => {
export const OnaSyncFns = {
syncSecrets: async (secretSync: TOnaSyncWithCredentials, secretMap: TSecretMap) => {
- const resolveUserId = makeUserIdResolver(secretSync);
- const scope = await buildScopeFilter(secretSync, resolveUserId);
+ const scope = await buildScopeFilter(secretSync);
const existingSecrets = await listEnvVarSecrets(secretSync, scope);
const existingByName = new Map(existingSecrets.map((s) => [s.name, s]));
@@ -226,8 +217,7 @@ export const OnaSyncFns = {
},
removeSecrets: async (secretSync: TOnaSyncWithCredentials, secretMap: TSecretMap) => {
- const resolveUserId = makeUserIdResolver(secretSync);
- const scope = await buildScopeFilter(secretSync, resolveUserId);
+ const scope = await buildScopeFilter(secretSync);
const existingSecrets = await listEnvVarSecrets(secretSync, scope);
for (const existing of existingSecrets) {
diff --git a/backend/src/services/secret-sync/ona/ona-sync-types.ts b/backend/src/services/secret-sync/ona/ona-sync-types.ts
index a85fde036b..740148da65 100644
--- a/backend/src/services/secret-sync/ona/ona-sync-types.ts
+++ b/backend/src/services/secret-sync/ona/ona-sync-types.ts
@@ -43,11 +43,8 @@ export type TOnaGetSecretValueResponse = {
};
export type TOnaAuthenticatedIdentityResponse = {
- identity?: {
- subject?: {
- id?: string;
- principal?: string;
- };
+ subject?: {
+ id?: string;
+ principal?: string;
};
- userId?: string;
};