Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented marketplace #27

Merged
merged 8 commits into from
Jul 11, 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
141 changes: 70 additions & 71 deletions .deploy/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -15,73 +14,73 @@ spec:
app: developer-dashboard-backend-app
spec:
containers:
- name: developer-dashboard-backend-app
image: __GOOGLE_ARTIFACT_URL__/__GOOGLE_PROJECT_ID__/__GOOGLE_ARTIFACT_REPO__/entity-developer-dashbord-service:__LATEST_RELEASE_TAG__
imagePullPolicy: Always
resources:
limits:
memory: "1Gi"
cpu: "500m"
ports:
- containerPort: __PORT__
# livenessProbe:
# httpGet:
# path: /api
# port: __PORT__
# initialDelaySeconds: 15
# periodSeconds: 10
env:
- name: PORT
value: "__PORT__"
- name: DATABASE_CONNECTION_PATH
value: "__DATABASE_CONNECTION_PATH__"
- name: HID_NETWORK_RPC
value: __HID_NETWORK_RPC__
- name: HID_NETWORK_API
value: __HID_NETWORK_API__
- name: HID_NETWORK_NAMESPACE
value: __HID_NETWORK_NAMESPACE__
- name: EDV_BASE_URL
value: __EDV_BASE_URL__
- name: EDV_CONFIG_DIR
value: __EDV_CONFIG_DIR__
- name: EDV_DID_FILE_PATH
value: __EDV_DID_FILE_PATH__
- name: EDV_KEY_FILE_PATH
value: __EDV_KEY_FILE_PATH__
- name: MNEMONIC
value: __MNEMONIC__
- name: JWT_SECRET
value: __JWT_SECRET__
- name: EMAIL_CREDENTITAL_SCHEMA_ID
value: __EMAIL_CREDENTITAL_SCHEMA_ID__
- name: WHITELISTED_CORS
value: '["https://entity.hypersign.id","http://localhost:9001", "https://wallet-prajna.hypersign.id", "http://localhost:4999","https://entity.dashboard.hypersign.id"]'
- name: ENTITY_API_SERVICE_BASE_URL
value: __ENTITY_API_SERVICE_BASE_URL__
- name: DEVELOPER_DASHBOARD_SERVICE_PUBLIC_EP
value: __DEVELOPER_DASHBOARD_SERVICE_PUBLIC_EP__
- name: TENANT_SUBDOMAIN_PREFIX
value: __TENANT_SUBDOMAIN_PREFIX__
- name: SSI_API_DOMAIN
value: __SSI_API_DOMAIN__
- name: CAVACH_API_DOMAIN
value: __CAVACH_API_DOMAIN__
- name: VAULT_PREFIX
value: __VAULT_PREFIX__
- name: GOOGLE_CLIENT_ID
value: __GOOGLE_CLIENT_ID__
- name: GOOGLE_CLIENT_SECRET
value: __GOOGLE_CLIENT_SECRET__
- name: REDIRECT_URL
value: __REDIRECT_URL__
volumeMounts:
- name: mongo
mountPath: "/data"
volumes:
- name: developer-dashboard-backend-app
image: __GOOGLE_ARTIFACT_URL__/__GOOGLE_PROJECT_ID__/__GOOGLE_ARTIFACT_REPO__/entity-developer-dashbord-service:__LATEST_RELEASE_TAG__
imagePullPolicy: Always
resources:
limits:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: __PORT__
# livenessProbe:
# httpGet:
# path: /api
# port: __PORT__
# initialDelaySeconds: 15
# periodSeconds: 10
env:
- name: PORT
value: "__PORT__"
- name: DATABASE_CONNECTION_PATH
value: "__DATABASE_CONNECTION_PATH__"
- name: HID_NETWORK_RPC
value: __HID_NETWORK_RPC__
- name: HID_NETWORK_API
value: __HID_NETWORK_API__
- name: HID_NETWORK_NAMESPACE
value: __HID_NETWORK_NAMESPACE__
- name: EDV_BASE_URL
value: __EDV_BASE_URL__
- name: EDV_CONFIG_DIR
value: __EDV_CONFIG_DIR__
- name: EDV_DID_FILE_PATH
value: __EDV_DID_FILE_PATH__
- name: EDV_KEY_FILE_PATH
value: __EDV_KEY_FILE_PATH__
- name: MNEMONIC
value: __MNEMONIC__
- name: JWT_SECRET
value: __JWT_SECRET__
- name: EMAIL_CREDENTITAL_SCHEMA_ID
value: __EMAIL_CREDENTITAL_SCHEMA_ID__
- name: WHITELISTED_CORS
value: '["https://entity.hypersign.id","http://localhost:9001", "https://wallet-prajna.hypersign.id", "http://localhost:4999","https://entity.dashboard.hypersign.id"]'
- name: ENTITY_API_SERVICE_BASE_URL
value: __ENTITY_API_SERVICE_BASE_URL__
- name: DEVELOPER_DASHBOARD_SERVICE_PUBLIC_EP
value: __DEVELOPER_DASHBOARD_SERVICE_PUBLIC_EP__
- name: TENANT_SUBDOMAIN_PREFIX
value: __TENANT_SUBDOMAIN_PREFIX__
- name: SSI_API_DOMAIN
value: __SSI_API_DOMAIN__
- name: CAVACH_API_DOMAIN
value: __CAVACH_API_DOMAIN__
- name: VAULT_PREFIX
value: __VAULT_PREFIX__
- name: GOOGLE_CLIENT_ID
value: __GOOGLE_CLIENT_ID__
- name: GOOGLE_CLIENT_SECRET
value: __GOOGLE_CLIENT_SECRET__
- name: REDIRECT_URL
value: __REDIRECT_URL__
volumeMounts:
- name: mongo
secret:
secretName: mongo
mountPath: "/data"
volumes:
- name: mongo
secret:
secretName: mongo

---
apiVersion: v1
Expand All @@ -96,8 +95,8 @@ spec:
selector:
app: developer-dashboard-backend-app
ports:
- port: __PORT__
targetPort: __PORT__
protocol: TCP
---
- port: __PORT__
targetPort: __PORT__
protocol: TCP

---
25 changes: 25 additions & 0 deletions .deploy/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: developer-dashboard-backend-app
namespace: hypermine-development
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: developer-dashboard-backend-app
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 70
6 changes: 5 additions & 1 deletion src/app-auth/app-auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Module,
NestModule,
RequestMethod,
forwardRef,

Check warning on line 6 in src/app-auth/app-auth.module.ts

View workflow job for this annotation

GitHub Actions / build

'forwardRef' is defined but never used
} from '@nestjs/common';

import { AppAuthService } from './services/app-auth.service';
Expand Down Expand Up @@ -55,6 +55,10 @@
{ path: 'app/:appId', method: RequestMethod.GET },
)
.forRoutes(AppAuthController);
consumer.apply(JWTAuthorizeMiddleware).forRoutes(AppAuthController);

consumer
.apply(JWTAuthorizeMiddleware)
.exclude({ path: '/api/v1/app/marketplace', method: RequestMethod.GET })
.forRoutes(AppAuthController);
}
}
24 changes: 23 additions & 1 deletion src/app-auth/controllers/app-auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import { PaginationDto } from 'src/utils/pagination.dto';
import { TransformResponseInterceptor } from '../interceptors/transformResponse.interseptor';
@UseFilters(AllExceptionsFilter)
@ApiTags('Application')
@ApiBearerAuth('Authorization')
@Controller('/api/v1/app')
export class AppAuthController {
constructor(private readonly appAuthService: AppAuthService) {}
@ApiBearerAuth('Authorization')
@UseInterceptors(
MongooseClassSerializerInterceptor(App, {
excludePrefixes: ['apiKeySecret', 'apiKeyPrefix', '_', '__'],
Expand Down Expand Up @@ -85,6 +85,24 @@ export class AppAuthController {
if (appList) return appList;
}

@Get('marketplace')
@ApiResponse({
status: 200,
description: 'App List',
type: GetAppList,
})
@ApiNotFoundResponse({
status: 404,
description: 'App not found',
type: AppError,
})
async getAppsForMarketPlace(): Promise<object[]> {
Logger.log('getAppsForMarketPlace() method: starts', 'AppAuthController');
const appList: any = await this.appAuthService.getAppsForMarketplace();
if (appList) return appList;
}

@ApiBearerAuth('Authorization')
@UseInterceptors(
MongooseClassSerializerInterceptor(App, {
excludePrefixes: ['apiKeySecret', 'apiKeyPrefix', '_', '__'],
Expand Down Expand Up @@ -115,6 +133,7 @@ export class AppAuthController {
else throw new AppNotFoundException(); // Custom Exception handling
}

@ApiBearerAuth('Authorization')
@Post()
@UseInterceptors(
MongooseClassSerializerInterceptor(createAppResponse, {
Expand All @@ -140,6 +159,7 @@ export class AppAuthController {
return this.appAuthService.createAnApp(createAppDto, userId);
}

@ApiBearerAuth('Authorization')
@UseInterceptors(
MongooseClassSerializerInterceptor(App, {
excludePrefixes: ['apiKeySecret', 'apiKeyPrefix', '_', '__'],
Expand Down Expand Up @@ -179,6 +199,7 @@ export class AppAuthController {
} else throw new AppNotFoundException();
}

@ApiBearerAuth('Authorization')
@Delete(':appId')
@ApiResponse({
status: 200,
Expand All @@ -205,6 +226,7 @@ export class AppAuthController {
return app;
}

@ApiBearerAuth('Authorization')
@Post(':appId/secret/new')
@HttpCode(200)
@ApiResponse({
Expand Down
10 changes: 10 additions & 0 deletions src/app-auth/dtos/update-app.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export class UpdateAppDto {
@IsUrlEmpty()
logoUrl: string;

@ApiProperty({
description: 'dependentServices',
example: ['asdasda123123123123'],
isArray: true,
required: false,
})
@IsOptional()
@IsArray()
dependentServices: Array<string>; // ids of dependent services / apps

@ApiProperty({
description: 'environment',
example: APP_ENVIRONMENT.dev,
Expand Down
4 changes: 4 additions & 0 deletions src/app-auth/repositories/app.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { SupportedServiceService } from 'src/supported-service/services/supported-service.service';
import * as url from 'url';

Check warning on line 7 in src/app-auth/repositories/app.repository.ts

View workflow job for this annotation

GitHub Actions / build

'url' is defined but never used

@Injectable()
export class AppRepository {
Expand Down Expand Up @@ -144,6 +144,10 @@
return this.appModel.aggregate(pipeline);
}

async findAppsByPipeline(pipeline): Promise<any[]> {
return await this.appModel.aggregate(pipeline);
}

async create(app: App): Promise<App> {
Logger.log(
'create() method: starts, adding app data to db',
Expand Down
38 changes: 38 additions & 0 deletions src/app-auth/services/app-auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import { UpdateAppDto } from '../dtos/update-app.dto';
import { HidWalletService } from '../../hid-wallet/services/hid-wallet.service';
import { ConfigService } from '@nestjs/config';
import { EdvDocsDto } from 'src/edv/dtos/create-edv.dto';

Check warning on line 15 in src/app-auth/services/app-auth.service.ts

View workflow job for this annotation

GitHub Actions / build

'EdvDocsDto' is defined but never used
import { AppAuthSecretService } from './app-auth-passord.service';
import { JwtService } from '@nestjs/jwt';
import { AppAuthApiKeyService } from './app-auth-apikey.service';
Expand Down Expand Up @@ -242,6 +242,31 @@
});
}

getAppsForMarketplace() {
Logger.log('getAppsForMarketplace() method: starts....', 'AppAuthService');
const pipeline = [
{
$match: {
hasDomainVerified: true,
env: APP_ENVIRONMENT.prod,
},
},
{
$project: {
domain: 1,
logoUrl: 1,
domainLinkageCredentialString: 1,
issuerDid: 1,
appName: 1,
appId: 1,
description: 1,
env: 1,
},
},
];
return this.appRepository.findAppsByPipeline(pipeline);
}

async getAppById(appId: string, userId: string): Promise<any> {
Logger.log('getAppById() method: starts....', 'AppAuthService');
const app: App = await this.appRepository.findOne({ appId, userId });
Expand Down Expand Up @@ -535,8 +560,21 @@
edvId: appDetail.edvId,
accessList,
env: appDetail.env ? appDetail.env : APP_ENVIRONMENT.dev,
appName: appDetail.appName,
};

if (appDetail.issuerDid) {
payload['issuerDid'] = appDetail.issuerDid;
}

if (
appDetail.dependentServices &&
appDetail.dependentServices.length > 0 &&
appDetail.dependentServices[0]
) {
payload['dependentServices'] = appDetail.dependentServices;
}

const secret = this.config.get('JWT_SECRET');
const token = await this.jwt.signAsync(payload, {
expiresIn: expiresin.toString() + 'h',
Expand Down
Loading