mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-09 09:20:54 +00:00
initial implementation
Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
parent
973bdfd34d
commit
646cffeb61
@ -8,6 +8,8 @@ import { getType } from 'mime'
|
||||
import { readdirSync, lstatSync } from 'fs'
|
||||
import { join } from 'path'
|
||||
|
||||
import { handle } from '@anticrm/dev-account'
|
||||
|
||||
const siteBucket = new aws.s3.Bucket('anticrm-app', {
|
||||
acl: "public-read",
|
||||
website: {
|
||||
@ -92,14 +94,7 @@ const api = new awsx.apigateway.API("login", {
|
||||
path: "/",
|
||||
method: "POST",
|
||||
eventHandler: async (event) => {
|
||||
if (event.body === null) {
|
||||
return { statusCode: 401, body: '' }
|
||||
}
|
||||
const req = JSON.parse(event.body)
|
||||
return {
|
||||
statusCode: 200,
|
||||
body: "Hello, API Gateway!",
|
||||
}
|
||||
return handle(event.body, serverEndpoint)
|
||||
},
|
||||
}],
|
||||
})
|
||||
|
75
cloud/app/package-lock.json
generated
75
cloud/app/package-lock.json
generated
@ -3,6 +3,66 @@
|
||||
"requires": true,
|
||||
"lockfileVersion": 1,
|
||||
"dependencies": {
|
||||
"@anticrm/dev-account": {
|
||||
"version": "0.6.1",
|
||||
"resolved": "https://registry.npmjs.org/@anticrm/dev-account/-/dev-account-0.6.1.tgz",
|
||||
"integrity": "sha512-98OTYTLxjmi4/CN0Fq8ClM/d9jZbsFIy7BFAWi5+GT2kkSFtZq/vwjaJSLIIsCxalXC0Dv6cTVaypY6sOwgI3g==",
|
||||
"requires": {
|
||||
"@anticrm/platform": "~0.6.0"
|
||||
}
|
||||
},
|
||||
"@anticrm/platform": {
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/@anticrm/platform/-/platform-0.6.3.tgz",
|
||||
"integrity": "sha512-gLjxO2Oa9P5x69NZ11gQ+JNB2texUT/MNilsZcf5OP13nJiFfTEhjXnYw+JCc0GnYOTIhKwycPUJJl0kISGeXA==",
|
||||
"requires": {
|
||||
"intl-messageformat": "^9.7.1"
|
||||
}
|
||||
},
|
||||
"@formatjs/ecma402-abstract": {
|
||||
"version": "1.9.6",
|
||||
"resolved": "https://registry.npmjs.org/@formatjs/ecma402-abstract/-/ecma402-abstract-1.9.6.tgz",
|
||||
"integrity": "sha512-fgXUydhzng3JCSm3HB1bt01m1otnMybX4b/CEI/fJRPvzgtq5XwV2qW/WQQdOLTr29/ttRHCEk2Mb9IP5K/PjQ==",
|
||||
"requires": {
|
||||
"@formatjs/intl-localematcher": "0.2.19",
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@formatjs/fast-memoize": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@formatjs/fast-memoize/-/fast-memoize-1.1.2.tgz",
|
||||
"integrity": "sha512-HfN6D9yd9vhypWwTVpJHqoSb50KFuoxZ2ZS6AM1XNSyihWk7JJXjZ3mgvboJU4eNSsdxAWwR1ke5KIOobEVwBA==",
|
||||
"requires": {
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@formatjs/icu-messageformat-parser": {
|
||||
"version": "2.0.9",
|
||||
"resolved": "https://registry.npmjs.org/@formatjs/icu-messageformat-parser/-/icu-messageformat-parser-2.0.9.tgz",
|
||||
"integrity": "sha512-L1a4W7Tbk41EjENYLLeYy1B9mX85kP6Wx2bzF/VLkGOk2bkFSEFzyb2XtYuklMzWhgka665LhxyPyJy3Ktpq6A==",
|
||||
"requires": {
|
||||
"@formatjs/ecma402-abstract": "1.9.6",
|
||||
"@formatjs/icu-skeleton-parser": "1.2.10",
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@formatjs/icu-skeleton-parser": {
|
||||
"version": "1.2.10",
|
||||
"resolved": "https://registry.npmjs.org/@formatjs/icu-skeleton-parser/-/icu-skeleton-parser-1.2.10.tgz",
|
||||
"integrity": "sha512-S96jf8V2SLBhjN7zTJ9xsroOOxS+STKtrjKKmF84+PAEGYAn5qlP62k9mbR0ir2cY80WNB5ehUmeDbo0plAkqg==",
|
||||
"requires": {
|
||||
"@formatjs/ecma402-abstract": "1.9.6",
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@formatjs/intl-localematcher": {
|
||||
"version": "0.2.19",
|
||||
"resolved": "https://registry.npmjs.org/@formatjs/intl-localematcher/-/intl-localematcher-0.2.19.tgz",
|
||||
"integrity": "sha512-eyrTiqciBSBfwx6PyyVJCEhXeAOXVJWWlvyR0Lx7OkTikWIrqhl8VIifyq3wwBiCMPOyCDN1ccik9VBdGcDiHA==",
|
||||
"requires": {
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"@grpc/grpc-js": {
|
||||
"version": "1.3.4",
|
||||
"resolved": "https://registry.npmjs.org/@grpc/grpc-js/-/grpc-js-1.3.4.tgz",
|
||||
@ -461,6 +521,16 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"intl-messageformat": {
|
||||
"version": "9.8.2",
|
||||
"resolved": "https://registry.npmjs.org/intl-messageformat/-/intl-messageformat-9.8.2.tgz",
|
||||
"integrity": "sha512-Qjefia3jFUML9XWRl0G3VAeiMUX7GiWvKcY9EQZJCkX8eLbe1HvLOPQvMQ5UlQLrnis1qk1BcQqbpPPvWnM2iw==",
|
||||
"requires": {
|
||||
"@formatjs/fast-memoize": "1.1.2",
|
||||
"@formatjs/icu-messageformat-parser": "2.0.9",
|
||||
"tslib": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"is-bigint": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.2.tgz",
|
||||
@ -862,6 +932,11 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"tslib": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.0.tgz",
|
||||
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
|
||||
},
|
||||
"type-is": {
|
||||
"version": "1.6.18",
|
||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||
|
@ -5,6 +5,7 @@
|
||||
"@types/mime": "^2.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anticrm/dev-account": "^0.6.1",
|
||||
"@pulumi/aws": "^4.11.0",
|
||||
"@pulumi/cloud": "^0.30.1",
|
||||
"@pulumi/cloud-aws": "^0.30.1",
|
||||
|
@ -8446,7 +8446,7 @@ packages:
|
||||
dev: false
|
||||
|
||||
file:projects/dev-account.tgz_6c259fadfeb3a4b20890aefe87070b8b:
|
||||
resolution: {integrity: sha512-JgOQNgqk+nWDo+xJOQ1cDyAtOqh2vKY56EWohCcHQuSGKw2mgn1oMiZp1IhFwk36/QyjSok8wKM1hYh5fGIszQ==, tarball: file:projects/dev-account.tgz}
|
||||
resolution: {integrity: sha512-TAqsbX91LUYsbg1ZILddY2vOiup5qwFbo+TDusmlMJb55egEniPQPfqkblGoSQY4jbPYYH599YhRLbvpap9EYw==, tarball: file:projects/dev-account.tgz}
|
||||
id: file:projects/dev-account.tgz
|
||||
name: '@rush-temp/dev-account'
|
||||
version: 0.0.0
|
||||
@ -8457,6 +8457,7 @@ packages:
|
||||
eslint-plugin-import: 2.23.4_eslint@7.32.0
|
||||
eslint-plugin-node: 11.1.0_eslint@7.32.0
|
||||
eslint-plugin-promise: 4.3.1
|
||||
jwt-simple: 0.5.6
|
||||
simplytyped: 3.3.0_typescript@4.3.5
|
||||
transitivePeerDependencies:
|
||||
- '@typescript-eslint/parser'
|
||||
|
@ -19,6 +19,7 @@
|
||||
"simplytyped": "^3.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@anticrm/platform": "~0.6.0"
|
||||
"@anticrm/platform": "~0.6.0",
|
||||
"jwt-simple": "^0.5.6"
|
||||
}
|
||||
}
|
||||
|
@ -13,3 +13,37 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import type { Request, Response } from '@anticrm/platform'
|
||||
import platform, { Status, Severity } from '@anticrm/platform'
|
||||
|
||||
import { encode } from 'jwt-simple'
|
||||
|
||||
interface LoginInfo {
|
||||
token: string,
|
||||
endpoint: string
|
||||
}
|
||||
|
||||
function login(endpoint: string, email: string, password: string, workspace: string): Response<LoginInfo> {
|
||||
if (email !== 'rosamund@hc.engineering' && email !== 'elon@hc.engineering') {
|
||||
return { error: new Status(Severity.ERROR, platform.status.Unauthorized, {}) }
|
||||
}
|
||||
|
||||
if (password !== '1111') {
|
||||
return { error: new Status(Severity.ERROR, platform.status.Unauthorized, {}) }
|
||||
}
|
||||
|
||||
if (workspace !== 'ws1' && workspace !== 'ws2') {
|
||||
return { error: new Status(Severity.ERROR, platform.status.Unauthorized, {}) }
|
||||
}
|
||||
|
||||
const token = encode({ email, workspace }, 'secret')
|
||||
return { result: { token, endpoint } }
|
||||
}
|
||||
|
||||
export function handleRequest(req: Request<any[]>, serverEndpoint: string): Response<any> {
|
||||
if (req.method === 'login')
|
||||
return login(serverEndpoint, ...(req as Request<[string, string, string]>).params)
|
||||
|
||||
return { error: new Status(Severity.ERROR, platform.status.BadRequest, {}) }
|
||||
}
|
||||
|
@ -14,9 +14,14 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { handleRequest } from "./account"
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export function handle (req: string | null): { statusCode: number, body: string } {
|
||||
return { statusCode: 200, body: 'hello' }
|
||||
export function handle (req: string | null, serverEndpoint: string): { statusCode: number, body: string } {
|
||||
if (req === null) return { statusCode: 401, body: 'unauthorized' }
|
||||
const resp = handleRequest(JSON.parse(req), serverEndpoint)
|
||||
if (resp.error !== undefined) { return { statusCode: 401, body: '' } }
|
||||
return { statusCode: 200, body: JSON.stringify(resp.result) }
|
||||
}
|
||||
|
@ -43,3 +43,5 @@ export type URL = string
|
||||
* @public
|
||||
*/
|
||||
export type Asset = Metadata<URL>
|
||||
|
||||
export { default } from './platform'
|
||||
|
@ -134,9 +134,9 @@ export default plugin(platformId, {
|
||||
|
||||
NoLoaderForStrings: '' as StatusCode<{ plugin: Plugin }>,
|
||||
|
||||
BadRequest: '' as StatusCode
|
||||
// Forbidden: '' as StatusCode,
|
||||
// Unauthorized: '' as StatusCode,
|
||||
// UnknownMethod: '' as StatusCode<{ method: string }>
|
||||
BadRequest: '' as StatusCode,
|
||||
Forbidden: '' as StatusCode,
|
||||
Unauthorized: '' as StatusCode,
|
||||
UnknownMethod: '' as StatusCode<{ method: string }>
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user