Skip to content

Commit

Permalink
Merge pull request #881 from hcengineering/server-upgrade-update
Browse files Browse the repository at this point in the history
Server upgrade update (depend from #880)
  • Loading branch information
haiodo authored Jan 27, 2022
2 parents 8094370 + 659063d commit 60a3793
Show file tree
Hide file tree
Showing 31 changed files with 293 additions and 139 deletions.
43 changes: 36 additions & 7 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dev/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
},
"dependencies": {
"@anticrm/platform": "~0.6.5",
"jwt-simple": "^0.5.6"
"@anticrm/server-token": "~0.6.0"
}
}
4 changes: 2 additions & 2 deletions dev/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { Request, Response } from '@anticrm/platform'
import platform, { Status, Severity } from '@anticrm/platform'

import { encode } from 'jwt-simple'
import { generateToken } from '@anticrm/server-token'

interface LoginInfo {
token: string
Expand All @@ -37,7 +37,7 @@ function login (endpoint: string, email: string, password: string, workspace: st
return { error: new Status(Severity.ERROR, platform.status.Unauthorized, {}) }
}

const token = encode({ email, workspace }, 'secret')
const token = generateToken(email, workspace)
return { result: { token, endpoint } }
}

Expand Down
4 changes: 2 additions & 2 deletions dev/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"dependencies": {
"commander": "^8.1.0",
"@anticrm/account": "~0.6.0",
"jwt-simple": "^0.5.6",
"@anticrm/core": "~0.6.11",
"@anticrm/contact": "~0.6.2",
"@anticrm/model-all": "~0.6.0",
Expand All @@ -59,6 +58,7 @@
"minio": "^7.0.19",
"@types/pdfkit": "~0.12.3",
"@anticrm/task": "~0.6.0",
"jpeg-js": "~0.4.3"
"jpeg-js": "~0.4.3",
"@anticrm/server-token": "~0.6.0"
}
}
4 changes: 2 additions & 2 deletions dev/generator/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import client from '@anticrm/client'
import clientResources from '@anticrm/client-resources'
import { Client } from '@anticrm/core'
import { setMetadata } from '@anticrm/platform'
import { encode } from 'jwt-simple'
import { generateToken } from '@anticrm/server-token'

// eslint-disable-next-line
const WebSocket = require('ws')

export async function connect (transactorUrl: string, workspace: string): Promise<Client> {
console.log('connecting to transactor...')
const token = encode({ email: '[email protected]', workspace }, 'secret')
const token = generateToken('[email protected]', workspace)

// We need to override default factory with 'ws' one.
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
Expand Down
2 changes: 1 addition & 1 deletion dev/tool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"mongodb": "^4.1.1",
"commander": "^8.1.0",
"@anticrm/account": "~0.6.0",
"jwt-simple": "^0.5.6",
"@anticrm/core": "~0.6.11",
"@anticrm/contact": "~0.6.2",
"minio": "^7.0.19",
Expand All @@ -58,6 +57,7 @@
"@elastic/elasticsearch": "^7.14.0",
"@anticrm/elastic": "~0.6.0",
"@anticrm/server-core": "~0.6.1",
"@anticrm/server-token": "~0.6.0",
"@anticrm/model-attachment": "~0.6.0",
"@anticrm/mongo": "~0.6.0",
"@anticrm/dev-storage": "~0.6.0",
Expand Down
4 changes: 2 additions & 2 deletions dev/tool/src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import client from '@anticrm/client'
import clientResources from '@anticrm/client-resources'
import { Client } from '@anticrm/core'
import { setMetadata } from '@anticrm/platform'
import { encode } from 'jwt-simple'
import { generateToken } from '@anticrm/server-token'

// eslint-disable-next-line
const WebSocket = require('ws')

export async function connect (transactorUrl: string, workspace: string): Promise<Client> {
console.log('connecting to transactor...')
const token = encode({ email: '[email protected]', workspace }, 'secret')
const token = generateToken('[email protected]', workspace)

// We need to override default factory with 'ws' one.
setMetadata(client.metadata.ClientSocketFactory, (url) => new WebSocket(url))
Expand Down
3 changes: 2 additions & 1 deletion dev/tool/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import {
upgradeWorkspace
} from '@anticrm/account'
import { setMetadata } from '@anticrm/platform'
import toolPlugin, { generateToken, prepareTools, version } from '@anticrm/server-tool'
import { generateToken } from '@anticrm/server-token'
import toolPlugin, { prepareTools, version } from '@anticrm/server-tool'
import { program } from 'commander'
import { Db, MongoClient } from 'mongodb'
import { rebuildElastic } from './elastic'
Expand Down
5 changes: 5 additions & 0 deletions rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,11 @@
"projectFolder": "server/core",
"shouldPublish": true
},
{
"packageName": "@anticrm/server-token",
"projectFolder": "server/token",
"shouldPublish": true
},
{
"packageName": "@anticrm/server",
"projectFolder": "server/server",
Expand Down
4 changes: 2 additions & 2 deletions server/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"@anticrm/contact": "~0.6.2",
"@anticrm/client-resources": "~0.6.4",
"@anticrm/client": "~0.6.1",
"jwt-simple": "~0.5.6",
"ws": "^8.2.0",
"@anticrm/model": "~0.6.0",
"@anticrm/server-tool": "~0.6.0"
"@anticrm/server-tool": "~0.6.0",
"@anticrm/server-token": "~0.6.0"
}
}
7 changes: 4 additions & 3 deletions server/account/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import platform, {
Status,
StatusCode
} from '@anticrm/platform'
import toolPlugin, { connect, initModel, upgradeModel, version, decodeToken, generateToken } from '@anticrm/server-tool'
import toolPlugin, { connect, initModel, upgradeModel, version } from '@anticrm/server-tool'
import { decodeToken, generateToken } from '@anticrm/server-token'
import { pbkdf2Sync, randomBytes } from 'crypto'
import { Binary, Db, ObjectId } from 'mongodb'

Expand Down Expand Up @@ -393,7 +394,7 @@ export async function assignWorkspace (db: Db, email: string, workspace: string)
}

async function createEmployeeAccount (account: Account, workspace: string): Promise<void> {
const connection = await connect(getTransactor(), workspace, account.email)
const connection = await connect(getTransactor(), workspace, false, account.email)
try {
const ops = new TxOperations(connection, core.account.System)

Expand Down Expand Up @@ -471,7 +472,7 @@ export async function changeName (db: Db, token: string, first: string, last: st
}

async function updateEmployeeAccount (account: Account, workspace: string): Promise<void> {
const connection = await connect(getTransactor(), workspace, account.email)
const connection = await connect(getTransactor(), workspace, false, account.email)
try {
const ops = new TxOperations(connection, core.account.System)

Expand Down
7 changes: 0 additions & 7 deletions server/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ export interface FullTextAdapter {
*/
export type FullTextAdapterFactory = (url: string, workspace: string) => Promise<FullTextAdapter>

/**
* @public
*/
export interface Token {
workspace: string
}

/**
* @public
*/
Expand Down
2 changes: 1 addition & 1 deletion server/front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"uuid": "^8.3.2",
"cors": "^2.8.5",
"@anticrm/elastic": "~0.6.0",
"jwt-simple": "^0.5.6",
"@anticrm/server-core": "~0.6.1",
"@anticrm/server-token": "~0.6.0",
"@anticrm/attachment": "~0.6.0",
"@anticrm/contrib": "~0.6.0",
"minio": "^7.0.19"
Expand Down
14 changes: 12 additions & 2 deletions server/front/src/__start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// limitations under the License.
//

import { start } from './app'
import { Client } from 'minio'
import { start } from './app'

const SERVER_PORT = parseInt(process.env.SERVER_PORT ?? '8080')

Expand Down Expand Up @@ -77,4 +77,14 @@ if (modelVersion === undefined) {

const config = { transactorEndpoint, elasticUrl, minio, accountsUrl, uploadUrl, modelVersion }
console.log('Starting Front service with', config)
start(config, SERVER_PORT)
const shutdown = start(config, SERVER_PORT)

const close = (): void => {
console.trace('Exiting from server')
console.log('Shutdown request accepted')
shutdown()
process.exit(0)
}

process.on('SIGINT', close)
process.on('SIGTERM', close)
Loading

0 comments on commit 60a3793

Please sign in to comment.