Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

feat: add kms support #42

Merged
merged 1 commit into from
Feb 2, 2024
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": "@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",
Expand Down
9 changes: 8 additions & 1 deletion src/core/auth.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -53,6 +53,13 @@ export class AuthService {
return await this.identityService.getCredentials();
}

/**
* @param kms Save kms to LocalStorage
*/
async saveKMS(kms: LemonKMS): Promise<void> {
await this.identityService.saveKMS(kms);
}

/**
* get the current AWS Credentials and automatically renews the token when it expires. If has not, it returns null.
*/
Expand Down
9 changes: 8 additions & 1 deletion src/core/identity.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -51,6 +51,13 @@ export class IdentityService {
return this.lemonStorage.getAllItems();
}

async saveKMS(kms: LemonKMS): Promise<void> {
const cloud = this.options.cloud;
if (cloud === 'aws') {
return await this.lemonStorage.saveKMS(kms);
}
}

async buildCredentialsByToken(token: LemonOAuthTokenResult): Promise<void> {
this.logger.log('buildCredentialsByToken()...');
// TODO: refactor below. create class
Expand Down
10 changes: 9 additions & 1 deletion src/core/lemon-storage.service.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -152,4 +152,12 @@ export class LemonStorageService {
);
return;
}

async saveKMS(kms: LemonKMS): Promise<void> {
const kmsArn = kms.arn;

this.storageService.setItem(`${this.prefix}.kmsArn`, kmsArn || '');

return;
}
}
4 changes: 4 additions & 0 deletions src/helper/types/lemon-oauth-token.type.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export interface LemonKMS {
arn: string;
}

export interface LemonOAuthTokenResult {
accountId: string;
authId: string;
Expand Down
Loading