draft: first gms-api request against local gms-server

This commit is contained in:
Claus-Peter Huebner 2023-11-20 21:32:24 +01:00
parent d29e41e025
commit aade850d0e
11 changed files with 204 additions and 3 deletions

View File

@ -62,4 +62,8 @@ WEBHOOK_ELOPAGE_SECRET=secret
# LOG_LEVEL=info
# Federation
FEDERATION_VALIDATE_COMMUNITY_TIMER=60000
FEDERATION_VALIDATE_COMMUNITY_TIMER=60000
# GMS
GMS_HOST=54.176.169.179
GMS_PORT=3071

View File

@ -1,5 +1,5 @@
# must match the CONFIG_VERSION.EXPECTED definition in scr/config/index.ts
CONFIG_VERSION=v20.2023-09-19
CONFIG_VERSION=v21.2023-11-15
# Server
JWT_SECRET=$JWT_SECRET
@ -61,3 +61,7 @@ WEBHOOK_ELOPAGE_SECRET=$WEBHOOK_ELOPAGE_SECRET
# Federation
FEDERATION_VALIDATE_COMMUNITY_TIMER=$FEDERATION_VALIDATE_COMMUNITY_TIMER
# GMS
GMS_HOST=$GMS_HOST
GMS_PORT=$GMS_PORT

View File

@ -0,0 +1,80 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import axios from 'axios'
import { CONFIG } from '@/config'
import { LogError } from '@/server/LogError'
import { backendLogger as logger } from '@/server/logger'
import { GmsCommunity } from './model/GmsCommunity'
import { GmsUser } from './model/GmsUser'
export async function communityList(): Promise<GmsCommunity[] | string | undefined> {
const baseUrl = 'http://'.concat(CONFIG.GMS_HOST).concat(':').concat(CONFIG.GMS_PORT).concat('/')
const service = 'community/list?page=1&perPage=20'
const config = {
headers: {
accept: 'application/json',
language: 'en',
timezone: 'UTC',
connection: 'keep-alive',
authorization:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiVTJGc2RHVmtYMThuNzllbGJscThDbmxxZ0I2SGxicTZuajlpM2lmV3BTc3pHZFRtOFVTQjJZNWY2bG56elhuSUF0SEwvYVBWdE1uMjA3bnNtWDQ0M21xWVFyd0xJMklHNGtpRkZ3U2FKbVJwRk9VZXNDMXIyRGlta3VLMklwN1lYRTU0c2MzVmlScmMzaHE3djlFNkRabk4xeVMrU1QwRWVZRFI5c09pTDJCdmg4a05DNUc5NTdoZUJzeWlRbXcrNFFmMXFuUk5SNXpWdXhtZEE2WUUrT3hlcS85Y0d6NURyTmhoaHM3MTJZTFcvTmprZGNwdU55dUgxeWxhNEhJZyIsImlhdCI6MTcwMDUxMDg4OX0.WhtNGZc9A_hUfh8CcPjr44kWQWMkKJ7hlYXELOd3yy4',
},
}
try {
const result = await axios.get(baseUrl.concat(service), config)
logger.debug('GET-Response of community/list:', result)
if (result.status !== 200) {
throw new LogError('HTTP Status Error in community/list:', result.status, result.statusText)
}
logger.debug('responseData:', result.data.responseData.data)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const gmsCom = JSON.parse(result.data.responseData.data)
logger.debug('gmsCom:', gmsCom)
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return gmsCom
} catch (error: any) {
logger.error('Error in Get community/list:', error)
const errMsg: string = error.message
return errMsg
}
}
export async function userList(): Promise<GmsUser[] | string | undefined> {
const baseUrl = 'http://'.concat(CONFIG.GMS_HOST).concat(':').concat(CONFIG.GMS_PORT).concat('/')
const service = 'community-user/list?page=1&perPage=20'
const config = {
headers: {
accept: 'application/json',
language: 'en',
timezone: 'UTC',
connection: 'keep-alive',
authorization:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiVTJGc2RHVmtYMThuNzllbGJscThDbmxxZ0I2SGxicTZuajlpM2lmV3BTc3pHZFRtOFVTQjJZNWY2bG56elhuSUF0SEwvYVBWdE1uMjA3bnNtWDQ0M21xWVFyd0xJMklHNGtpRkZ3U2FKbVJwRk9VZXNDMXIyRGlta3VLMklwN1lYRTU0c2MzVmlScmMzaHE3djlFNkRabk4xeVMrU1QwRWVZRFI5c09pTDJCdmg4a05DNUc5NTdoZUJzeWlRbXcrNFFmMXFuUk5SNXpWdXhtZEE2WUUrT3hlcS85Y0d6NURyTmhoaHM3MTJZTFcvTmprZGNwdU55dUgxeWxhNEhJZyIsImlhdCI6MTcwMDUxMDg4OX0.WhtNGZc9A_hUfh8CcPjr44kWQWMkKJ7hlYXELOd3yy4',
},
}
try {
const result = await axios.get(baseUrl.concat(service), config)
logger.debug('GET-Response of community/list:', result)
if (result.status !== 200) {
throw new LogError(
'HTTP Status Error in community-user/list:',
result.status,
result.statusText,
)
}
logger.debug('responseData:', result.data.responseData.data)
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const gmsUser = JSON.parse(result.data.responseData.data)
logger.debug('gmsUser:', gmsUser)
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return gmsUser
} catch (error: any) {
logger.error('Error in Get community-user/list:', error)
const errMsg: string = error.message
return errMsg
}
}

View File

@ -0,0 +1,17 @@
import { GmsCommunityProfile } from './GmsCommunityProfile'
import { GmsRole } from './GmsRoles'
export class GmsCommunity {
id: number
uuid: string
communityUuid: string
email: string
countryCode: string
mobile: string
status: number
createdAt: Date
updatedAt: Date
UserProfile: unknown
communityProfile: GmsCommunityProfile
roles: GmsRole[]
}

View File

@ -0,0 +1,16 @@
export class GmsCommunityProfile {
name: string
location: {
type: string
coordinates: [number]
}
address: string
communityId: number
radius: number
description: string
// eslint-disable-next-line camelcase
api_key: string
communityAuthUrl: unknown
profileImage: unknown
}

View File

@ -0,0 +1,6 @@
export class GmsRole {
code: string
status: number
name: string
Permissions: [unknown]
}

View File

@ -0,0 +1,18 @@
import { GmsRole } from './GmsRoles'
import { GmsUserAccount } from './GmsUserAccount'
import { GmsUserProfile } from './GmsUserProfile'
export class GmsUser {
id: number
uuid: string
communityUuid: string
email: string
countryCode: string
mobile: string
status: number
createdAt: Date
updatedAt: Date
userProfile: GmsUserProfile
userAccounts: GmsUserAccount[]
roles: GmsRole[]
}

View File

@ -0,0 +1,16 @@
import { Decimal } from 'decimal.js-light'
export class GmsUserAccount {
name: string
location: {
type: string
coordinates: [Decimal, Decimal]
}
address: string
radius: number
description: string
// eslint-disable-next-line camelcase
api_key: string
profileImage: unknown
}

View File

@ -0,0 +1,22 @@
import { Decimal } from 'decimal.js-light'
export class GmsUserProfile {
firstName: string
lastName: string
alias: string
type: number
name: string
location: {
type: string
coordinates: [Decimal, Decimal]
}
accuracy: unknown
address: string
city: string
state: string
country: string
zipCode: string
language: string
profileImage: unknown
}

View File

@ -19,7 +19,7 @@ const constants = {
LOG_LEVEL: process.env.LOG_LEVEL ?? 'info',
CONFIG_VERSION: {
DEFAULT: 'DEFAULT',
EXPECTED: 'v20.2023-09-19',
EXPECTED: 'v21.2023-11-15',
CURRENT: '',
},
}
@ -134,6 +134,12 @@ const federation = {
process.env.FEDERATION_XCOM_MAXREPEAT_REVERTSENDCOINS ?? 3,
}
const gms = {
// koordinates of Illuminz-instance of GMS
GMS_HOST: process.env.GMS_HOST ?? 'localhost',
GMS_PORT: process.env.GMS_PORT ?? '4044',
}
export const CONFIG = {
...constants,
...server,
@ -145,4 +151,5 @@ export const CONFIG = {
...loginServer,
...webhook,
...federation,
...gms,
}

View File

@ -12,6 +12,7 @@ import { backendLogger as logger } from '@/server/logger'
import { startCommunityAuthentication } from './authenticateCommunities'
import { ApiVersionType } from './enum/apiVersionType'
import { communityList, userList } from '@/apis/gms/GmsClient'
export async function startValidateCommunities(timerInterval: number): Promise<void> {
logger.info(
@ -29,6 +30,16 @@ export async function startValidateCommunities(timerInterval: number): Promise<v
}
export async function validateCommunities(): Promise<void> {
// test GMS-Api Client
try {
const gmsComArray = await communityList()
logger.debug('GMS-Community-List:', gmsComArray)
const gmsUserArray = await userList()
logger.debug('GMS-Community-User-List:', gmsUserArray)
} catch (err) {
logger.error('Error in GMS-API:', err)
}
const dbFederatedCommunities: DbFederatedCommunity[] =
await DbFederatedCommunity.createQueryBuilder()
.where({ foreign: true, verifiedAt: IsNull() })