Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skyflow-node",
"version": "2.0.1",
"version": "2.0.1-dev.907ebbb",
"description": "Skyflow SDK for Node.js",
"main": "./lib/index.js",
"module": "./lib/index.js",
Expand Down
9 changes: 5 additions & 4 deletions src/utils/validations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
Expand All @@ -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]);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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<string, any>
if (stringCred.context !== undefined && (typeof stringCred.context !== 'string' && typeof stringCred.context !== 'object')) {
throw new SkyflowError(SKYFLOW_ERROR_CODE.INVALID_CONTEXT);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/vault/config/credentials/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface TokenCredentials {
export interface PathCredentials {
path: string;
roles?: Array<string>;
context?: string;
context?: string | Record<string, any>;
}

export interface StringCredentials {
credentialsString: string;
roles?: Array<string>;
context?: string;
context?: string | Record<string, any>
}

export interface ApiKeyCredentials {
Expand Down
10 changes: 10 additions & 0 deletions test/utils/validations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>;
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
Expand Down Expand Up @@ -3930,6 +3939,7 @@ describe('validateCredentialsWithId', () => {
};
expect(() => validateCredentialsWithId(credentials, type, typeId, id)).not.toThrow();
});
// validate
});

// Test TokenCredentials validation
Expand Down
Loading