Merged PR 595: 各service.tsのoutログ追加

## 概要
[Task3162: licenses.service.tsのoutログ追加](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3162)

- 何をどう変更したか、追加したライブラリなど
・licenses.service.tsのolicenseOrdersとissueCardLicenseKeysの[OUT]ログを追加
・横展開として他のservice.tsでOUT、INログが不足している場合は追加する

## 動作確認状況
- ユニットテスト
This commit is contained in:
水本 祐希 2023-11-30 04:17:16 +00:00
parent ef376d3027
commit 15fa10e265
5 changed files with 194 additions and 85 deletions

View File

@ -152,6 +152,10 @@ export class AccountsService {
makeErrorResponse('E009999'), makeErrorResponse('E009999'),
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.getLicenseSummary.name}`,
);
} }
} }
/** /**
@ -179,7 +183,7 @@ export class AccountsService {
} | params: { ` + } | params: { ` +
`dealerAccountId: ${dealerAccountId}, ` + `dealerAccountId: ${dealerAccountId}, ` +
`role: ${role}, ` + `role: ${role}, ` +
`acceptedEulaVersion: ${acceptedEulaVersion} }, ` + `acceptedEulaVersion: ${acceptedEulaVersion}, ` +
`acceptedDpaVersion: ${acceptedDpaVersion} };`, `acceptedDpaVersion: ${acceptedDpaVersion} };`,
); );
try { try {
@ -333,6 +337,11 @@ export class AccountsService {
externalUserId: string, externalUserId: string,
context: Context, context: Context,
): Promise<void> { ): Promise<void> {
this.logger.log(
`[IN] [${context.getTrackingId()}] ${
this.createAccount.name
} | params: { ` + `externalUserId: ${externalUserId}};`,
);
try { try {
await this.adB2cService.deleteUser(externalUserId, context); await this.adB2cService.deleteUser(externalUserId, context);
this.logger.log( this.logger.log(
@ -344,6 +353,10 @@ export class AccountsService {
this.logger.error( this.logger.error(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete externalUser: ${externalUserId}`, `${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete externalUser: ${externalUserId}`,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteAdB2cUser.name}`,
);
} }
} }
@ -368,6 +381,10 @@ export class AccountsService {
this.logger.error( this.logger.error(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete account: ${accountId}, user: ${userId}`, `${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete account: ${accountId}, user: ${userId}`,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteAccount.name}`,
);
} }
} }
@ -396,6 +413,10 @@ export class AccountsService {
this.logger.error( this.logger.error(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete container: ${accountId}, country: ${country}`, `${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete container: ${accountId}, country: ${country}`,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteBlobContainer.name}`,
);
} }
} }
@ -1184,6 +1205,10 @@ export class AccountsService {
makeErrorResponse('E009999'), makeErrorResponse('E009999'),
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.createTypistGroup.name}`,
);
} }
} }

View File

@ -119,7 +119,7 @@ export class AuthService {
const privateKey = getPrivateKey(this.configService); const privateKey = getPrivateKey(this.configService);
// ユーザーのロールを設定 // ユーザーのロールを設定
const role = this.getUserRole(user.role); const role = this.getUserRole(context, user.role);
const token = sign<RefreshToken>( const token = sign<RefreshToken>(
{ {
@ -250,7 +250,7 @@ export class AuthService {
const privateKey = getPrivateKey(this.configService); const privateKey = getPrivateKey(this.configService);
// ユーザーのロールを設定 // ユーザーのロールを設定
const role = this.getUserRole(adminUser.role); const role = this.getUserRole(context, adminUser.role);
const token = sign<RefreshToken>( const token = sign<RefreshToken>(
{ {
@ -540,6 +540,7 @@ export class AuthService {
case jwt.JsonWebTokenError: case jwt.JsonWebTokenError:
// メッセージごとにエラーを判定しHTTPエラーを生成 // メッセージごとにエラーを判定しHTTPエラーを生成
throw this.makeHttpErrorFromJsonWebTokenErrorMessage( throw this.makeHttpErrorFromJsonWebTokenErrorMessage(
context,
message, message,
issuer, issuer,
); );
@ -561,6 +562,9 @@ export class AuthService {
} }
getPublicKeyFromJwk(context: Context, jwkKey: JwkSignKey): string { getPublicKeyFromJwk(context: Context, jwkKey: JwkSignKey): string {
this.logger.log(
`[IN] [${context.getTrackingId()}] ${this.getPublicKeyFromJwk.name}`,
);
try { try {
// JWK形式のJSONなのでJWTの公開鍵として使えるようにPEM形式に変換 // JWK形式のJSONなのでJWTの公開鍵として使えるようにPEM形式に変換
const publicKey = jwkToPem({ const publicKey = jwkToPem({
@ -584,53 +588,83 @@ export class AuthService {
* JWT検証時のErrorJsonWebTokenErrorをメッセージごとに仕分けてHTTPエラーを生成 * JWT検証時のErrorJsonWebTokenErrorをメッセージごとに仕分けてHTTPエラーを生成
*/ */
makeHttpErrorFromJsonWebTokenErrorMessage = ( makeHttpErrorFromJsonWebTokenErrorMessage = (
context: Context,
message: string, message: string,
issuer: string, issuer: string,
): Error => { ): Error => {
// 署名が不正 this.logger.log(
if (message === 'invalid signature') { `[IN] [${context.getTrackingId()}] ${
return new HttpException( this.makeHttpErrorFromJsonWebTokenErrorMessage.name
makeErrorResponse('E000104'), }`,
HttpStatus.UNAUTHORIZED,
);
}
// 想定発行元と異なる
if (message === `jwt issuer invalid. expected: ${issuer}`) {
return new HttpException(
makeErrorResponse('E000105'),
HttpStatus.UNAUTHORIZED,
);
}
// アルゴリズムが想定と異なる
if (message === 'invalid algorithm') {
return new HttpException(
makeErrorResponse('E000106'),
HttpStatus.UNAUTHORIZED,
);
}
// トークンの形式が不正
return new HttpException(
makeErrorResponse('E000101'),
HttpStatus.UNAUTHORIZED,
); );
try {
// 署名が不正
if (message === 'invalid signature') {
return new HttpException(
makeErrorResponse('E000104'),
HttpStatus.UNAUTHORIZED,
);
}
// 想定発行元と異なる
if (message === `jwt issuer invalid. expected: ${issuer}`) {
return new HttpException(
makeErrorResponse('E000105'),
HttpStatus.UNAUTHORIZED,
);
}
// アルゴリズムが想定と異なる
if (message === 'invalid algorithm') {
return new HttpException(
makeErrorResponse('E000106'),
HttpStatus.UNAUTHORIZED,
);
}
// トークンの形式が不正
return new HttpException(
makeErrorResponse('E000101'),
HttpStatus.UNAUTHORIZED,
);
} catch (e) {
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
throw e;
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${
this.makeHttpErrorFromJsonWebTokenErrorMessage.name
}`,
);
}
}; };
/** /**
* *
*/ */
getUserRole = (role: string): string => { getUserRole = (context: Context, role: string): string => {
// ユーザーのロールを設定 this.logger.log(
// 万一不正なRoleが登録されていた場合、そのままDBの値を使用すると不正なロールのリフレッシュトークンが発行されるため、 `[IN] [${context.getTrackingId()}] ${this.getUserRole.name}`,
// ロールの設定値はDBに保存したRoleの値を直接トークンに入れないように定数で設定する );
// ※none/author/typist以外はロールに設定されない try {
if (role === USER_ROLES.NONE) { // ユーザーのロールを設定
return USER_ROLES.NONE; // 万一不正なRoleが登録されていた場合、そのままDBの値を使用すると不正なロールのリフレッシュトークンが発行されるため、
} else if (role === USER_ROLES.AUTHOR) { // ロールの設定値はDBに保存したRoleの値を直接トークンに入れないように定数で設定する
return USER_ROLES.AUTHOR; // ※none/author/typist以外はロールに設定されない
} else if (role === USER_ROLES.TYPIST) { if (role === USER_ROLES.NONE) {
return USER_ROLES.TYPIST; return USER_ROLES.NONE;
} else { } else if (role === USER_ROLES.AUTHOR) {
throw new RoleUnexpectedError( return USER_ROLES.AUTHOR;
`Role from DB is unexpected value. role=${role}`, } else if (role === USER_ROLES.TYPIST) {
return USER_ROLES.TYPIST;
} else {
throw new RoleUnexpectedError(
`Role from DB is unexpected value. role=${role}`,
);
}
} catch (e) {
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
throw e;
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.getUserRole.name}`,
); );
} }
}; };

View File

@ -12,7 +12,6 @@ import {
import { LicensesRepositoryService } from '../../repositories/licenses/licenses.repository.service'; import { LicensesRepositoryService } from '../../repositories/licenses/licenses.repository.service';
import { UserNotFoundError } from '../../repositories/users/errors/types'; import { UserNotFoundError } from '../../repositories/users/errors/types';
import { import {
DateWithZeroTime,
GetAllocatableLicensesResponse, GetAllocatableLicensesResponse,
IssueCardLicensesResponse, IssueCardLicensesResponse,
} from './types/types'; } from './types/types';
@ -113,6 +112,10 @@ export class LicensesService {
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} }
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.licenseOrders.name}`,
);
} }
} }
async issueCardLicenseKeys( async issueCardLicenseKeys(
@ -164,6 +167,10 @@ export class LicensesService {
makeErrorResponse('E009999'), makeErrorResponse('E009999'),
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.issueCardLicenseKeys.name}`,
);
} }
} }

View File

@ -1,6 +1,5 @@
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import { TasksRepositoryService } from '../../repositories/tasks/tasks.repository.service'; import { TasksRepositoryService } from '../../repositories/tasks/tasks.repository.service';
import { AccessToken } from '../../common/token';
import { Assignee, Task } from './types/types'; import { Assignee, Task } from './types/types';
import { Task as TaskEntity } from '../../repositories/tasks/entity/task.entity'; import { Task as TaskEntity } from '../../repositories/tasks/entity/task.entity';
import { createTasks } from './types/convert'; import { createTasks } from './types/convert';
@ -625,6 +624,10 @@ export class TasksService {
...new Set(assigneesExternalIds.concat(typistExternalIds)), ...new Set(assigneesExternalIds.concat(typistExternalIds)),
]; ];
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.getB2cUsers.name}`,
);
// B2Cからユーザー名を取得する // B2Cからユーザー名を取得する
return await this.adB2cService.getUsers(context, distinctedExternalIds); return await this.adB2cService.getUsers(context, distinctedExternalIds);
} }
@ -769,5 +772,8 @@ export class TasksService {
priority: file.priority === '00' ? 'Normal' : 'High', priority: file.priority === '00' ? 'Normal' : 'High',
uploadedAt: file.uploaded_at.toISOString(), uploadedAt: file.uploaded_at.toISOString(),
}); });
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.sendNotify.name}`,
);
} }
} }

View File

@ -117,6 +117,10 @@ export class UsersService {
makeErrorResponse('E009999'), makeErrorResponse('E009999'),
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.confirmUser.name}`,
);
} }
} }
@ -313,6 +317,11 @@ export class UsersService {
// Azure AD B2Cに登録したユーザー情報を削除する // Azure AD B2Cに登録したユーザー情報を削除する
// TODO 「タスク 2452: リトライ処理を入れる箇所を検討し、実装する」の候補 // TODO 「タスク 2452: リトライ処理を入れる箇所を検討し、実装する」の候補
private async deleteB2cUser(externalUserId: string, context: Context) { private async deleteB2cUser(externalUserId: string, context: Context) {
this.logger.log(
`[IN] [${context.getTrackingId()}] ${
this.deleteB2cUser.name
} | params: { externalUserId: ${externalUserId} }`,
);
try { try {
await this.adB2cService.deleteUser(externalUserId, context); await this.adB2cService.deleteUser(externalUserId, context);
this.logger.log( this.logger.log(
@ -323,11 +332,20 @@ export class UsersService {
this.logger.error( this.logger.error(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete externalUser: ${externalUserId}`, `${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete externalUser: ${externalUserId}`,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteB2cUser.name}`,
);
} }
} }
// DBに登録したユーザー情報を削除する // DBに登録したユーザー情報を削除する
private async deleteUser(userId: number, context: Context) { private async deleteUser(userId: number, context: Context) {
this.logger.log(
`[IN] [${context.getTrackingId()}] ${
this.deleteUser.name
} | params: { userId: ${userId} }`,
);
try { try {
await this.usersRepository.deleteNormalUser(userId); await this.usersRepository.deleteNormalUser(userId);
this.logger.log(`[${context.getTrackingId()}] delete user: ${userId}`); this.logger.log(`[${context.getTrackingId()}] delete user: ${userId}`);
@ -336,6 +354,10 @@ export class UsersService {
this.logger.error( this.logger.error(
`${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete user: ${userId}`, `${MANUAL_RECOVERY_REQUIRED} [${context.getTrackingId()}] Failed to delete user: ${userId}`,
); );
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.deleteUser.name}`,
);
} }
} }
@ -368,47 +390,56 @@ export class UsersService {
`encryption: ${encryption}, ` + `encryption: ${encryption}, ` +
`prompt: ${prompt} };`, `prompt: ${prompt} };`,
); );
switch (role) { try {
case USER_ROLES.NONE: switch (role) {
case USER_ROLES.TYPIST: case USER_ROLES.NONE:
return { case USER_ROLES.TYPIST:
account_id: accountId, return {
external_id: externalId, account_id: accountId,
auto_renew: autoRenew, external_id: externalId,
license_alert: licenseAlert, auto_renew: autoRenew,
notification, license_alert: licenseAlert,
role, notification,
accepted_dpa_version: null, role,
accepted_eula_version: null, accepted_dpa_version: null,
encryption: false, accepted_eula_version: null,
encryption_password: null, encryption: false,
prompt: false, encryption_password: null,
author_id: null, prompt: false,
}; author_id: null,
case USER_ROLES.AUTHOR: };
return { case USER_ROLES.AUTHOR:
account_id: accountId, return {
external_id: externalId, account_id: accountId,
auto_renew: autoRenew, external_id: externalId,
license_alert: licenseAlert, auto_renew: autoRenew,
notification, license_alert: licenseAlert,
role, notification,
author_id: authorId ?? null, role,
encryption: encryption ?? false, author_id: authorId ?? null,
encryption_password: encryptionPassword ?? null, encryption: encryption ?? false,
prompt: prompt ?? false, encryption_password: encryptionPassword ?? null,
accepted_dpa_version: null, prompt: prompt ?? false,
accepted_eula_version: null, accepted_dpa_version: null,
}; accepted_eula_version: null,
default: };
//不正なroleが指定された場合はログを出力してエラーを返す default:
this.logger.error( //不正なroleが指定された場合はログを出力してエラーを返す
`[${context.getTrackingId()}] [NOT IMPLEMENT] [RECOVER] role: ${role}`, this.logger.error(
); `[${context.getTrackingId()}] [NOT IMPLEMENT] [RECOVER] role: ${role}`,
throw new HttpException( );
makeErrorResponse('E009999'), throw new HttpException(
HttpStatus.INTERNAL_SERVER_ERROR, makeErrorResponse('E009999'),
); HttpStatus.INTERNAL_SERVER_ERROR,
);
}
} catch (e) {
this.logger.error(`[${context.getTrackingId()}] error=${e}`);
return e;
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${this.createNewUserInfo.name}`,
);
} }
} }
@ -486,6 +517,12 @@ export class UsersService {
); );
} }
} }
} finally {
this.logger.log(
`[OUT] [${context.getTrackingId()}] ${
this.confirmUserAndInitPassword.name
}`,
);
} }
} }