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

Release version 4.14.0 #349

Merged
merged 20 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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": "bfx-reports-framework",
"version": "4.13.0",
"version": "4.14.0",
"description": "Bitfinex reports framework",
"main": "worker.js",
"license": "Apache-2.0",
Expand Down
21 changes: 21 additions & 0 deletions test/test-cases/api-sync-mode-sqlite-test-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ module.exports = (
} = params
const auth = { token: '' }

it('it should be successfully performed by the isStagingBfxApi method', async function () {
this.timeout(5000)

const res = await agent
.post(`${basePath}/json-rpc`)
.type('json')
.send({
method: 'isStagingBfxApi',
id: 5
})
.expect('Content-Type', /json/)
.expect(200)

assert.isObject(res.body)
assert.propertyVal(res.body, 'id', 5)
assert.isBoolean(res.body.result)
})

it('it should be successfully performed by the getPlatformStatus method', async function () {
this.timeout(5000)

Expand Down Expand Up @@ -184,6 +202,7 @@ module.exports = (
assert.isNull(res.body.result.authTokenTTLSec)
assert.isNull(res.body.result.localUsername)
assert.isNull(res.body.result.lastSyncMts)
assert.isBoolean(res.body.result.isStagingBfxApi)

auth.token = res.body.result.token
})
Expand Down Expand Up @@ -283,6 +302,7 @@ module.exports = (
assert.isNumber(res.body.result.authTokenTTLSec)
assert.isNull(res.body.result.localUsername)
assert.isNull(res.body.result.lastSyncMts)
assert.isBoolean(res.body.result.isStagingBfxApi)
})

it('it should not be successfully performed by the signIn method', async function () {
Expand Down Expand Up @@ -483,6 +503,7 @@ module.exports = (
assert.isBoolean(user.isRestrictedToBeAddedToSubAccount)
assert.isBoolean(user.isApiKeysAuth)
assert.isArray(user.subUsers)
assert.isBoolean(user.isStagingBfxApi)

user.subUsers.forEach((subUser) => {
assert.isString(subUser.email)
Expand Down
15 changes: 12 additions & 3 deletions workers/loc.api/service.report.framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ class FrameworkReportService extends ReportService {
}, 'verifyOnBFX', args, cb)
}

isStagingBfxApi (space, args, cb) {
return this._responder(() => {
return this._authenticator.isStagingBfxApi()
}, 'isStagingBfxApi', args, cb)
}

signUp (space, args, cb) {
return this._responder(() => {
return this._authenticator.signUp(args)
Expand All @@ -114,7 +120,8 @@ class FrameworkReportService extends ReportService {
shouldNotSyncOnStartupAfterUpdate,
isSyncOnStartupRequired,
authTokenTTLSec,
localUsername
localUsername,
isStagingBfxApi
} = await this._authenticator.signIn(
args,
{ isReturnedUser: true }
Expand Down Expand Up @@ -148,7 +155,8 @@ class FrameworkReportService extends ReportService {
shouldNotSyncOnStartupAfterUpdate,
authTokenTTLSec,
localUsername,
lastSyncMts: lastFinishedSyncQueueJob?.updatedAt ?? null
lastSyncMts: lastFinishedSyncQueueJob?.updatedAt ?? null,
isStagingBfxApi
}
}, 'signIn', args, cb)
}
Expand Down Expand Up @@ -208,7 +216,8 @@ class FrameworkReportService extends ReportService {
'isNotProtected',
'subUsers',
'isRestrictedToBeAddedToSubAccount',
'isApiKeysAuth'
'isApiKeysAuth',
'isStagingBfxApi'
]
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = (session, isReturnedPassword) => {
'shouldNotSyncOnStartupAfterUpdate',
'isSyncOnStartupRequired',
'authTokenTTLSec',
'isStagingBfxApi',
...passwordProp
]
const { subUsers: reqSubUsers } = { ...session }
Expand Down
37 changes: 33 additions & 4 deletions workers/loc.api/sync/authenticator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ const depsTypes = (TYPES) => [
TYPES.Crypto,
TYPES.SyncFactory,
TYPES.WSEventEmitterFactory,
TYPES.Logger
TYPES.Logger,
TYPES.CONF
]
class Authenticator {
constructor (
Expand All @@ -50,7 +51,8 @@ class Authenticator {
crypto,
syncFactory,
wsEventEmitterFactory,
logger
logger,
conf
) {
this.dao = dao
this.TABLES_NAMES = TABLES_NAMES
Expand All @@ -60,6 +62,7 @@ class Authenticator {
this.syncFactory = syncFactory
this.wsEventEmitterFactory = wsEventEmitterFactory
this.logger = logger
this.conf = conf

/**
* It may only work for one grenache worker instance
Expand All @@ -80,6 +83,12 @@ class Authenticator {
this.authTokenInvalidateIntervalsSec = 10 * 60
}

isStagingBfxApi () {
const bfxApiUrl = this.conf?.restUrl ?? ''

return /staging/gi.test(bfxApiUrl)
}

async signUp (args, opts) {
const { auth, params } = args ?? {}
const {
Expand Down Expand Up @@ -216,7 +225,8 @@ class Authenticator {
shouldNotSyncOnStartupAfterUpdate: 0,
isSyncOnStartupRequired: 0,
authTokenTTLSec,
localUsername
localUsername,
isStagingBfxApi: this.isStagingBfxApi()
},
{ isNotInTrans, withWorkerThreads, doNotQueueQuery }
)
Expand Down Expand Up @@ -332,17 +342,21 @@ class Authenticator {
userData = await this.rService._checkAuthInApi({
auth: { authToken: newAuthToken, apiKey, apiSecret }
})
userData.isStagingBfxApi = this.isStagingBfxApi()
} catch (err) {
if (!isENetError(err)) {
throw err
}

this.logger.debug(err)
}

const {
id,
timezone,
username: uName,
email: emailFromApi
email: emailFromApi,
isStagingBfxApi
} = userData ?? {}
const username = generateSubUserName(
{ username: uName },
Expand All @@ -360,6 +374,7 @@ class Authenticator {
isDataFromDb: isDataFromDb === null
? user.isDataFromDb
: isDataFromDb,
isStagingBfxApi,
...newAuthToken
? { authToken: newAuthToken }
: null
Expand All @@ -376,6 +391,20 @@ class Authenticator {
{ withWorkerThreads, doNotQueueQuery }
)

// Need to update `isStagingBfxApi` flag for sub-users if `isSubAccount`
if (
isSubAccount &&
Array.isArray(user?.subUsers) &&
user.subUsers.length > 0
) {
await this.dao.updateCollBy(
this.TABLES_NAMES.USERS,
{ $in: { _id: user.subUsers.map(({ _id }) => (_id)) } },
{ isStagingBfxApi },
{ withWorkerThreads, doNotQueueQuery }
)
}

if (res && res.changes < 1) {
throw new AuthError()
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict'

/*
* CREATED_AT: 2023-12-07T11:57:58.668Z
* VERSION: v39
*/

const {
ID_PRIMARY_KEY
} = require('./helpers/const')
const {
getSqlArrToModifyColumns
} = require('./helpers')

const AbstractMigration = require('./abstract.migration')

class MigrationV39 extends AbstractMigration {
/**
* @override
*/
up () {
const sqlArr = [
'ALTER TABLE users ADD COLUMN isStagingBfxApi INT'
]

this.addSql(sqlArr)
}

/**
* @override
*/
down () {
const sqlArr = [
...getSqlArrToModifyColumns(
'users',
{
_id: ID_PRIMARY_KEY,
id: 'BIGINT',
email: 'VARCHAR(255)',
apiKey: 'VARCHAR(255)',
apiSecret: 'VARCHAR(255)',
authToken: 'VARCHAR(255)',
active: 'INT',
isDataFromDb: 'INT',
timezone: 'VARCHAR(255)',
username: 'VARCHAR(255)',
localUsername: 'VARCHAR(255)',
passwordHash: 'VARCHAR(255)',
isNotProtected: 'INT',
isSubAccount: 'INT',
isSubUser: 'INT',
shouldNotSyncOnStartupAfterUpdate: 'INT',
isSyncOnStartupRequired: 'INT',
authTokenTTLSec: 'INT',
createdAt: 'BIGINT',
updatedAt: 'BIGINT'
}
)
]

this.addSql(sqlArr)
}

/**
* @override
*/
beforeDown () { return this.dao.disableForeignKeys() }

/**
* @override
*/
afterDown () { return this.dao.enableForeignKeys() }
}

module.exports = MigrationV39
6 changes: 4 additions & 2 deletions workers/loc.api/sync/dao/helpers/users/normalize-user-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const _normalize = (userData) => {
haveSubUsers,
isNotProtected,
shouldNotSyncOnStartupAfterUpdate,
isSyncOnStartupRequired
isSyncOnStartupRequired,
isStagingBfxApi
} = userData ?? {}

return {
Expand All @@ -21,7 +22,8 @@ const _normalize = (userData) => {
haveSubUsers: !!haveSubUsers,
isNotProtected: !!isNotProtected,
shouldNotSyncOnStartupAfterUpdate: !!shouldNotSyncOnStartupAfterUpdate,
isSyncOnStartupRequired: !!isSyncOnStartupRequired
isSyncOnStartupRequired: !!isSyncOnStartupRequired,
isStagingBfxApi: !!isStagingBfxApi
}
}

Expand Down
Loading