From b7263e87b4a7ead50631e8a5a1fb1266b03bff99 Mon Sep 17 00:00:00 2001 From: skyflow-bharti Date: Fri, 28 Nov 2025 17:21:23 +0530 Subject: [PATCH] SK-2422 allow context as object --- src/utils/validations/index.ts | 9 +++++---- src/vault/config/credentials/index.ts | 4 ++-- test/utils/validations.test.js | 10 ++++++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/utils/validations/index.ts b/src/utils/validations/index.ts index 6efcee2..f688040 100644 --- a/src/utils/validations/index.ts +++ b/src/utils/validations/index.ts @@ -169,7 +169,7 @@ export const validateCredentialsWithId = (credentials: Credentials, type: string if (pathCred.roles !== undefined && !Array.isArray(pathCred.roles)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ROLES_KEY_TYPE, [type, typeId, id]); } - if (pathCred.context !== undefined && typeof pathCred.context !== 'string') { + if (pathCred.context !== undefined && (typeof pathCred.context !== 'string' && typeof pathCred.context !== 'object')) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTEXT, [type, typeId, id]); } } @@ -184,7 +184,7 @@ export const validateCredentialsWithId = (credentials: Credentials, type: string if (stringCred.roles !== undefined && !Array.isArray(stringCred.roles)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ROLES_KEY_TYPE, [type, typeId, id]); } - if (stringCred.context !== undefined && typeof stringCred.context !== 'string') { + if (stringCred.context !== undefined && (typeof stringCred.context !== 'string' && typeof stringCred.context !== 'object')) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTEXT, [type, typeId, id]); } } @@ -295,7 +295,7 @@ export const validateSkyflowCredentials = (credentials: Credentials, logLevel: L if (pathCred.roles !== undefined && !Array.isArray(pathCred.roles)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ROLES_KEY_TYPE); } - if (pathCred.context !== undefined && typeof pathCred.context !== 'string') { + if (pathCred.context !== undefined && (typeof pathCred.context !== 'string' && typeof pathCred.context !== 'object')) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTEXT); } } @@ -310,7 +310,8 @@ export const validateSkyflowCredentials = (credentials: Credentials, logLevel: L if (stringCred.roles !== undefined && !Array.isArray(stringCred.roles)) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_ROLES_KEY_TYPE); } - if (stringCred.context !== undefined && typeof stringCred.context !== 'string') { + // validate both string | Record + if (stringCred.context !== undefined && (typeof stringCred.context !== 'string' && typeof stringCred.context !== 'object')) { throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTEXT); } } diff --git a/src/vault/config/credentials/index.ts b/src/vault/config/credentials/index.ts index dbffc72..53f342c 100644 --- a/src/vault/config/credentials/index.ts +++ b/src/vault/config/credentials/index.ts @@ -11,13 +11,13 @@ export interface TokenCredentials { export interface PathCredentials { path: string; roles?: Array; - context?: string; + context?: string | Record; } export interface StringCredentials { credentialsString: string; roles?: Array; - context?: string; + context?: string | Record } export interface ApiKeyCredentials { diff --git a/test/utils/validations.test.js b/test/utils/validations.test.js index 956b797..3dba882 100644 --- a/test/utils/validations.test.js +++ b/test/utils/validations.test.js @@ -691,6 +691,15 @@ describe('validateSkyflowCredentials', () => { jest.spyOn(require('fs'), 'existsSync').mockReturnValue(true); expect(() => validateSkyflowCredentials(credentials)).toThrow(SKYFLOW_ERROR_CODE.INVALID_CONTEXT); }); + // validate string | Record; + test('should accept valid context as object', () => { + const credentials = { + path: '/valid/path', + context: { env: 'production' } // valid object + }; + jest.spyOn(require('fs'), 'existsSync').mockReturnValue(true); + expect(() => validateSkyflowCredentials(credentials)).not.toThrow(); + }); }); // Test StringCredentials validation @@ -3930,6 +3939,7 @@ describe('validateCredentialsWithId', () => { }; expect(() => validateCredentialsWithId(credentials, type, typeId, id)).not.toThrow(); }); + // validate }); // Test TokenCredentials validation