Skip to content

Commit

Permalink
chore: re-phraze some log message
Browse files Browse the repository at this point in the history
  • Loading branch information
vanthome committed Oct 2, 2024
1 parent 9a94b82 commit 52182ae
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/oauth_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class OAuthService implements OAuthServiceImplementation<WithRequestID> {
}));
// append auth token on user entity
await this.userService.updateUserTokens(user.id, authToken);
this.logger.info('Token updated successfully on user entity', { id: user.id });
this.logger.info('Token updated on user entity', { id: user.id });

authToken.expires_in = new Date(authToken.expires_in);
return {
Expand Down Expand Up @@ -339,7 +339,7 @@ export class OAuthService implements OAuthServiceImplementation<WithRequestID> {

// append access token on user entity
await this.userService.updateUserTokens(user.payload.id, newAccessToken);
this.logger.info('Token updated successfully on user entity', {id: user.payload.id});
this.logger.info('Token updated on user entity', {id: user.payload.id});
return { token: newAccessToken.token };
} catch (err: any) {
this.logger.error('Error Updating Token', err);
Expand Down
20 changes: 10 additions & 10 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
});
const res = await query(this.db.db, 'users', token_remove, bindTokenVars);
await res.all();
this.logger.debug('Expired tokens removed successfully');
this.logger.debug('Expired tokens removed');
}
}
}
Expand All @@ -394,7 +394,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
});
const res = await query(this.db.db, 'users', token_remove, bindTokenVars);
await res.all();
this.logger.debug(`Removed token ${tokenObj[0].token} successfully`);
this.logger.debug(`Removed token ${tokenObj[0].token}`);
}
}

Expand Down Expand Up @@ -430,8 +430,8 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
} else {
// delete token from redis and update user entity
const numberOfDeletedKeys = await this.tokenRedisClient.del(token);
logger.info('Redis cached data for findByToken deleted successfully', { noOfKeys: numberOfDeletedKeys });
return { status: returnCodeMessage(401, 'Redis cached data for findByToken deleted successfully') };
logger.info('Redis cached data for findByToken deleted', { noOfKeys: numberOfDeletedKeys });
return { status: returnCodeMessage(401, 'Redis cached data for findByToken deleted') };
}
} else {
// when not set in redis
Expand Down Expand Up @@ -486,9 +486,9 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
);

if (updatedUser) {
logger.debug('update of user token last login successfully', { updatedUser });
logger.debug('update of user token last login', { updatedUser });
await this.tokenRedisClient.set(token, JSON.stringify(updatedUser));
logger.debug('Stored user data to redis cache successfully');
logger.debug('Stored user data to redis cache');
return {
payload: updatedUser,
status: { code: 200, message: 'success' }
Expand Down Expand Up @@ -821,7 +821,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme

if (rolesData?.items?.length < targetUserRoleIds.length) {
const message = `One or more of the target role IDs are invalid ${targetUserRoleIds},` +
` no such role exist in system`;
` no such role exist in the system`;
this.logger.error(message, rolesData);
return returnStatus(400, message, user.id);
}
Expand All @@ -833,7 +833,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
!createAccessRole.some((role) => targetRole?.payload?.assignable_by_roles?.includes(role))) {
const userNameId = user?.name ? user.name : user?.id;
let message = `The target role ${targetRole.payload.id} cannot be assigned to` +
` user ${userNameId} as user role ${createAccessRole} does not have permissions`;
` user ${userNameId} as the user role ${createAccessRole} does not have the required permission`;
this.logger.verbose(message);
return returnStatus(403, message, user.id);
}
Expand Down Expand Up @@ -2006,7 +2006,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
if (!roleAssocEqual || !tokensEqual || (updatedRoleAssocs?.length != redisRoleAssocs?.length)) {
// flush token subject cache
await this.tokenRedisClient.del(tokenValue);
this.logger.info('Redis cached data for findByToken deleted successfully', { token: tokenValue });
this.logger.info('Redis cached data for findByToken deleted', { token: tokenValue });
}
}
}
Expand All @@ -2030,7 +2030,7 @@ export class UserService extends ServiceBase<UserListResponse, UserList> impleme
for (let token of user.tokens) {
const tokenValue = token.token;
await this.tokenRedisClient.del(tokenValue);
this.logger.info('Redis token deleted successfully', { token: tokenValue });
this.logger.info('Redis token deleted', { token: tokenValue });
}
user.tokens = [];
}
Expand Down
8 changes: 4 additions & 4 deletions src/token_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ export class TokenService implements TokenServiceImplementation {
// append tokens on user entity
this.logger.debug('Removing expired token list', expiredTokenList);
await this.userService.updateUserTokens(user.id, token, expiredTokenList);
this.logger.info('Token updated successfully on user entity', { token, id: user.id });
this.logger.info('Token updated on user entity', { token, id: user.id });
} catch (err: any) {
this.logger.error('Error Updating Token', err);
}
response = {
status: {
code: 200,
message: `Token updated successfully for Subject ${user.name}`
message: `Token updated for Subject ${user.name}`
}
};
} else {
Expand Down Expand Up @@ -237,14 +237,14 @@ export class TokenService implements TokenServiceImplementation {
return obj;
}
}));
this.logger.info('Removed token successfully from destroy api', { token: request.id, user });
this.logger.info('Removed token from destroy api', { token: request.id, user });
// flush token subject cache
const numberOfDeletedKeys = await this.userService.tokenRedisClient.del(request.id);
this.logger.info('Subject deleted from Redis', { noOfKeys: numberOfDeletedKeys });
response = {
status: {
code: 200,
message: `Key for subject ${user.id} deleted successfully`
message: `Key for subject ${user.id} deleted`
}
};
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export class Worker {
externalJobFiles.forEach(async (externalFile) => {
if (externalFile.endsWith('.js') || externalFile.endsWith('.cjs')) {
const require_dir = process.env.EXTERNAL_JOBS_REQUIRE_DIR ?? './jobs/';

try {
const fileImport = await import(require_dir + externalFile);
// check for double default
Expand Down Expand Up @@ -370,7 +370,7 @@ export class Worker {

service.superUpsert(serviceList.fromPartial({ items: seedData }), undefined)
.then(() => {
this.logger.info(`Seed ${entity} upserted successfully`);
this.logger.info(`Seed ${entity} upserted`);
resolve();
})
.catch( (err: any) => {
Expand Down Expand Up @@ -409,7 +409,7 @@ export class Worker {
items: seedAccounts,
}), undefined)
.then(() => {
this.logger.info('Seed accounts upserted successfully');
this.logger.info('Seed accounts upserted');
resolve();
})
.catch(err => {
Expand All @@ -425,7 +425,7 @@ export class Worker {

this.events = events;
this.server = server;
this.logger.info('Server started successfully');
this.logger.info('Server started');
}

async stop(): Promise<any> {
Expand Down
12 changes: 6 additions & 6 deletions test/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ const startGrpcMockServer = async (methodWithOutput: MethodWithOutput[]) => {

const stopGrpcMockServer = async () => {
await mockServer.stop();
logger.info('Mock ACS Server closed successfully');
logger.info('Mock ACS Server closed');
};

describe('testing identity-srv', () => {
Expand Down Expand Up @@ -1724,7 +1724,7 @@ describe('testing identity-srv', () => {
const result = await userService.create({ items: [testUser], subject });
result!.items![0]!.status!.code!.should.equal(400);
result!.items![0]!.status!.message!.should.equal(
`One or more of the target role IDs are invalid ${ testUser.role_associations!.map(ra => ra.role) }, no such role exist in system`
`One or more of the target role IDs are invalid ${ testUser.role_associations!.map(ra => ra.role) }, no such role exist in the system`
);
result!.items![0]!.status!.id!.should.equal('testuser');
result!.operation_status!.code!.should.equal(200);
Expand All @@ -1750,7 +1750,7 @@ describe('testing identity-srv', () => {

result!.items![0]!.status!.code!.should.equal(400);
result!.items![0]!.status!.message!.should.equal(
`One or more of the target role IDs are invalid ${ testUser.role_associations!.map(ra => ra.role) }, no such role exist in system`
`One or more of the target role IDs are invalid ${ testUser.role_associations!.map(ra => ra.role) }, no such role exist in the system`
);
result!.items![0]!.status!.id!.should.equal('testuser');
// first user created, validate result
Expand All @@ -1770,7 +1770,7 @@ describe('testing identity-srv', () => {
testUser.role_associations![0]!.role = 'super-admin-r-id';
const result = await userService.create({ items: [testUser], subject });
result!.items![0]!.status!.code!.should.equal(403);
result!.items![0]!.status!.message!.should.equal('The target role super-admin-r-id cannot be assigned to user test.user as user role admin-r-id,admin-r-id,user-r-id does not have permissions');
result!.items![0]!.status!.message!.should.equal('The target role super-admin-r-id cannot be assigned to user test.user as the user role admin-r-id,admin-r-id,user-r-id does not have the required permission');
result!.items![0]!.status!.id!.should.equal('testuser');
result!.operation_status!.code!.should.equal(200);
result!.operation_status!.message!.should.equal('success');
Expand Down Expand Up @@ -1935,11 +1935,11 @@ describe('testing identity-srv', () => {

describe('testing user Token service', async function testTokenService() {
let tokenService: TokenServiceClient;

before(async () => {
tokenService = await connect<TokenServiceClient>('client:token', 'token');
});

it('should upsert token to User', async () => {
await tokenService.upsert({
id: upsertUserID,
Expand Down

0 comments on commit 52182ae

Please sign in to comment.