From af80525248dc066a923d754d1ab979ed3f799874 Mon Sep 17 00:00:00 2001 From: stevenplc Date: Fri, 2 Feb 2024 14:54:29 +0900 Subject: [PATCH] feat: add kms support --- package.json | 2 +- src/core/auth.service.ts | 9 ++++++++- src/core/identity.service.ts | 9 ++++++++- src/core/lemon-storage.service.ts | 10 +++++++++- src/helper/types/lemon-oauth-token.type.ts | 4 ++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b9eb2a8..21f99e7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lemoncloud/lemon-front-lib", - "version": "1.4.2", + "version": "1.4.3", "description": "Web Core Library for Lemoncloud", "exports": "./dist/index.js", "types": "./dist/index.d.ts", diff --git a/src/core/auth.service.ts b/src/core/auth.service.ts index 9045ac2..69176d9 100644 --- a/src/core/auth.service.ts +++ b/src/core/auth.service.ts @@ -1,5 +1,5 @@ import * as AWS from 'aws-sdk/global.js'; -import { LemonOAuthTokenResult, LemonOptions } from '../helper'; +import { LemonKMS, LemonOAuthTokenResult, LemonOptions } from '../helper'; import { IdentityService } from './identity.service'; import { Storage } from './lemon-storage.service'; @@ -53,6 +53,13 @@ export class AuthService { return await this.identityService.getCredentials(); } + /** + * @param kms Save kms to LocalStorage + */ + async saveKMS(kms: LemonKMS): Promise { + await this.identityService.saveKMS(kms); + } + /** * get the current AWS Credentials and automatically renews the token when it expires. If has not, it returns null. */ diff --git a/src/core/identity.service.ts b/src/core/identity.service.ts index 84c46d8..ef88945 100644 --- a/src/core/identity.service.ts +++ b/src/core/identity.service.ts @@ -1,6 +1,6 @@ import * as AWS from 'aws-sdk/global.js'; // services -import { AxiosService, calcSignature, Cloud, createAsyncDelay, SignedHttpService } from '../helper'; +import { AxiosService, calcSignature, Cloud, createAsyncDelay, LemonKMS, SignedHttpService } from '../helper'; import { LemonStorageService, Storage } from './lemon-storage.service'; // types import { AxiosRequestConfig } from 'axios'; @@ -51,6 +51,13 @@ export class IdentityService { return this.lemonStorage.getAllItems(); } + async saveKMS(kms: LemonKMS): Promise { + const cloud = this.options.cloud; + if (cloud === 'aws') { + return await this.lemonStorage.saveKMS(kms); + } + } + async buildCredentialsByToken(token: LemonOAuthTokenResult): Promise { this.logger.log('buildCredentialsByToken()...'); // TODO: refactor below. create class diff --git a/src/core/lemon-storage.service.ts b/src/core/lemon-storage.service.ts index 6492aaf..ff20606 100644 --- a/src/core/lemon-storage.service.ts +++ b/src/core/lemon-storage.service.ts @@ -1,4 +1,4 @@ -import { Cloud, LemonCredentials, LemonOAuthTokenResult, LocalStorageService } from '../helper'; +import { Cloud, LemonCredentials, LemonKMS, LemonOAuthTokenResult, LocalStorageService } from '../helper'; export interface Storage { getItem(key: string, ...params: any): any; @@ -152,4 +152,12 @@ export class LemonStorageService { ); return; } + + async saveKMS(kms: LemonKMS): Promise { + const kmsArn = kms.arn; + + this.storageService.setItem(`${this.prefix}.kmsArn`, kmsArn || ''); + + return; + } } diff --git a/src/helper/types/lemon-oauth-token.type.ts b/src/helper/types/lemon-oauth-token.type.ts index 99d1aeb..2c8f1dc 100644 --- a/src/helper/types/lemon-oauth-token.type.ts +++ b/src/helper/types/lemon-oauth-token.type.ts @@ -1,3 +1,7 @@ +export interface LemonKMS { + arn: string; +} + export interface LemonOAuthTokenResult { accountId: string; authId: string;