@budibase/worker 1.0.182 → 1.0.185-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/worker",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.0.182",
4
+ "version": "1.0.185-alpha.0",
5
5
  "description": "Budibase background service",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -32,9 +32,9 @@
32
32
  "author": "Budibase",
33
33
  "license": "GPL-3.0",
34
34
  "dependencies": {
35
- "@budibase/backend-core": "^1.0.182",
36
- "@budibase/pro": "1.0.181",
37
- "@budibase/string-templates": "^1.0.182",
35
+ "@budibase/backend-core": "^1.0.185-alpha.0",
36
+ "@budibase/pro": "1.0.184",
37
+ "@budibase/string-templates": "^1.0.185-alpha.0",
38
38
  "@koa/router": "^8.0.0",
39
39
  "@sentry/node": "6.17.7",
40
40
  "@techpass/passport-openidconnect": "^0.3.0",
@@ -90,5 +90,5 @@
90
90
  "./scripts/jestSetup.js"
91
91
  ]
92
92
  },
93
- "gitHead": "1fb604e6019a0dc345128344f2622de87a3fc64a"
93
+ "gitHead": "ef65c070fb9f06bdd953bb26c08f2715143ff853"
94
94
  }
@@ -0,0 +1,172 @@
1
+ const fetch = require("node-fetch")
2
+
3
+ const MAX_RUNTIME_SEC = 600
4
+ const HOST = "http://localhost:10000"
5
+ const TENANT_ID = "default"
6
+ const RATE_MS = 500
7
+
8
+ let API_KEY = process.argv[2]
9
+ let STATS = {
10
+ iterations: 0,
11
+ error: 0,
12
+ success: 0,
13
+ }
14
+
15
+ if (!API_KEY) {
16
+ console.error("Must specify API key as first run command!")
17
+ process.exit(-1)
18
+ }
19
+
20
+ const USERS = [
21
+ {
22
+ email: "loadtest1@test.com",
23
+ password: "test",
24
+ },
25
+ {
26
+ email: "loadtest2@test.com",
27
+ password: "test",
28
+ },
29
+ {
30
+ email: "loadtest3@test.com",
31
+ password: "test",
32
+ },
33
+ {
34
+ email: "loadtest4@test.com",
35
+ password: "test",
36
+ },
37
+ {
38
+ email: "loadtest5@test.com",
39
+ password: "test",
40
+ },
41
+ {
42
+ email: "loadtest6@test.com",
43
+ password: "test",
44
+ },
45
+ {
46
+ email: "loadtest7@test.com",
47
+ password: "test",
48
+ },
49
+ ]
50
+
51
+ const REQUESTS = [
52
+ {
53
+ endpoint: `/api/global/self`,
54
+ method: "GET",
55
+ },
56
+ ]
57
+
58
+ function timeout() {
59
+ return new Promise(resolve => {
60
+ setTimeout(() => {
61
+ resolve()
62
+ }, MAX_RUNTIME_SEC * 1000)
63
+ })
64
+ }
65
+
66
+ async function preTest() {
67
+ // check if the user exists or not
68
+ const response = await fetch(`${HOST}/api/global/users`, {
69
+ method: "GET",
70
+ headers: {
71
+ "x-budibase-api-key": API_KEY,
72
+ },
73
+ })
74
+ if (response.status !== 200) {
75
+ throw new Error("Unable to retrieve users")
76
+ }
77
+ const users = await response.json()
78
+ for (let user of USERS) {
79
+ if (users.find(u => u.email === user.email)) {
80
+ continue
81
+ }
82
+ const response = await fetch(`${HOST}/api/global/users`, {
83
+ method: "POST",
84
+ headers: {
85
+ "x-budibase-api-key": API_KEY,
86
+ "Content-Type": "application/json",
87
+ },
88
+ body: JSON.stringify({
89
+ ...user,
90
+ roles: {},
91
+ status: "active",
92
+ }),
93
+ })
94
+ if (response.status !== 200) {
95
+ throw new Error(
96
+ `Unable to create user ${user.email}, reason: ${await response.text()}`
97
+ )
98
+ }
99
+ }
100
+ }
101
+
102
+ async function requests(user) {
103
+ let response = await fetch(`${HOST}/api/global/auth/${TENANT_ID}/login`, {
104
+ method: "POST",
105
+ body: JSON.stringify({
106
+ username: user.email,
107
+ password: user.password,
108
+ }),
109
+ headers: {
110
+ "Content-Type": "application/json",
111
+ },
112
+ })
113
+ // unable to login
114
+ if (response.status !== 200) {
115
+ STATS.error++
116
+ return
117
+ } else {
118
+ STATS.success++
119
+ }
120
+ const cookie = response.headers.get("set-cookie")
121
+ let promises = []
122
+ for (let request of REQUESTS) {
123
+ const headers = {
124
+ cookie,
125
+ }
126
+ if (request.body) {
127
+ headers["Content-Type"] = "application/json"
128
+ }
129
+ promises.push(
130
+ fetch(`${HOST}${request.endpoint}`, {
131
+ method: request.method,
132
+ headers: {
133
+ cookie,
134
+ },
135
+ })
136
+ )
137
+ }
138
+ const responses = await Promise.all(promises)
139
+ for (let resp of responses) {
140
+ if (resp.status !== 200) {
141
+ console.error(await resp.text())
142
+ STATS.error++
143
+ } else {
144
+ STATS.success++
145
+ }
146
+ }
147
+ }
148
+
149
+ async function run() {
150
+ await preTest()
151
+ setInterval(async () => {
152
+ let promises = []
153
+ for (let user of USERS) {
154
+ promises.push(requests(user))
155
+ }
156
+ await Promise.all(promises)
157
+ console.log(
158
+ `Iteration ${STATS.iterations++} - errors: ${STATS.error}, success: ${
159
+ STATS.success
160
+ }`
161
+ )
162
+ }, RATE_MS)
163
+ await timeout()
164
+ console.log(
165
+ `Max runtime of ${MAX_RUNTIME_SEC} seconds has been reached - stopping.`
166
+ )
167
+ process.exit(0)
168
+ }
169
+
170
+ run().catch(err => {
171
+ console.error("Failed to run - ", err)
172
+ })
@@ -0,0 +1,97 @@
1
+ // get the JWT secret etc
2
+ require("../../src/environment")
3
+ require("@budibase/backend-core").init()
4
+ const {
5
+ getProdAppID,
6
+ generateGlobalUserID,
7
+ } = require("@budibase/backend-core/db")
8
+ const { doInTenant, getGlobalDB } = require("@budibase/backend-core/tenancy")
9
+ const { internalSaveUser } = require("@budibase/backend-core/utils")
10
+ const { publicApiUserFix } = require("../../src/utilities/users")
11
+ const { hash } = require("@budibase/backend-core/utils")
12
+
13
+ const USER_LOAD_NUMBER = 10000
14
+ const BATCH_SIZE = 200
15
+ const PASSWORD = "test"
16
+ const TENANT_ID = "default"
17
+
18
+ const APP_ID = process.argv[2]
19
+
20
+ const words = [
21
+ "test",
22
+ "testing",
23
+ "budi",
24
+ "mail",
25
+ "age",
26
+ "risk",
27
+ "load",
28
+ "uno",
29
+ "arm",
30
+ "leg",
31
+ "pen",
32
+ "glass",
33
+ "box",
34
+ "chicken",
35
+ "bottle",
36
+ ]
37
+
38
+ if (!APP_ID) {
39
+ console.error("Must supply app ID as first CLI option!")
40
+ process.exit(-1)
41
+ }
42
+
43
+ const WORD_1 = words[Math.floor(Math.random() * words.length)]
44
+ const WORD_2 = words[Math.floor(Math.random() * words.length)]
45
+ let HASHED_PASSWORD
46
+
47
+ function generateUser(count) {
48
+ return {
49
+ _id: generateGlobalUserID(),
50
+ password: HASHED_PASSWORD,
51
+ email: `${WORD_1}${count}@${WORD_2}.com`,
52
+ roles: {
53
+ [getProdAppID(APP_ID)]: "BASIC",
54
+ },
55
+ status: "active",
56
+ forceResetPassword: false,
57
+ firstName: "John",
58
+ lastName: "Smith",
59
+ }
60
+ }
61
+
62
+ async function run() {
63
+ HASHED_PASSWORD = await hash(PASSWORD)
64
+ return doInTenant(TENANT_ID, async () => {
65
+ const db = getGlobalDB()
66
+ for (let i = 0; i < USER_LOAD_NUMBER; i += BATCH_SIZE) {
67
+ let userSavePromises = []
68
+ for (let j = 0; j < BATCH_SIZE; j++) {
69
+ // like the public API
70
+ const ctx = publicApiUserFix({
71
+ request: {
72
+ body: generateUser(i + j),
73
+ },
74
+ })
75
+ userSavePromises.push(
76
+ internalSaveUser(ctx.request.body, TENANT_ID, {
77
+ hashPassword: false,
78
+ requirePassword: true,
79
+ bulkCreate: true,
80
+ })
81
+ )
82
+ }
83
+ const users = await Promise.all(userSavePromises)
84
+ await db.bulkDocs(users)
85
+ console.log(`${i + BATCH_SIZE} users have been created.`)
86
+ }
87
+ })
88
+ }
89
+
90
+ run()
91
+ .then(() => {
92
+ console.log(`Generated ${USER_LOAD_NUMBER} users!`)
93
+ })
94
+ .catch(err => {
95
+ console.error("Failed for reason: ", err)
96
+ process.exit(-1)
97
+ })
@@ -25,6 +25,5 @@ export const getInfo = async (ctx: any) => {
25
25
  }
26
26
 
27
27
  export const getQuotaUsage = async (ctx: any) => {
28
- const usage = await quotas.getQuotaUsage()
29
- ctx.body = usage
28
+ ctx.body = await quotas.getQuotaUsage()
30
29
  }
@@ -75,8 +75,8 @@ const checkCurrentApp = ctx => {
75
75
  const addSessionAttributesToUser = ctx => {
76
76
  ctx.body.account = ctx.user.account
77
77
  ctx.body.license = ctx.user.license
78
- ctx.body.budibaseAccess = ctx.user.budibaseAccess
79
- ctx.body.accountPortalAccess = ctx.user.accountPortalAccess
78
+ ctx.body.budibaseAccess = !!ctx.user.budibaseAccess
79
+ ctx.body.accountPortalAccess = !!ctx.user.accountPortalAccess
80
80
  ctx.body.csrfToken = ctx.user.csrfToken
81
81
  }
82
82
 
@@ -27,33 +27,40 @@ function parseIntSafe(number) {
27
27
  }
28
28
 
29
29
  module.exports = {
30
- NODE_ENV: process.env.NODE_ENV,
31
- SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
32
- PORT: process.env.PORT || process.env.WORKER_PORT,
33
- CLUSTER_PORT: process.env.CLUSTER_PORT,
30
+ // auth
34
31
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
35
32
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
36
- MINIO_URL: process.env.MINIO_URL,
37
- COUCH_DB_URL: process.env.COUCH_DB_URL,
38
- LOG_LEVEL: process.env.LOG_LEVEL,
39
33
  JWT_SECRET: process.env.JWT_SECRET,
40
34
  SALT_ROUNDS: process.env.SALT_ROUNDS,
41
- REDIS_URL: process.env.REDIS_URL,
42
35
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
43
36
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
37
+ COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
38
+ // urls
39
+ MINIO_URL: process.env.MINIO_URL,
40
+ COUCH_DB_URL: process.env.COUCH_DB_URL,
41
+ REDIS_URL: process.env.REDIS_URL,
42
+ ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
43
+ PLATFORM_URL: process.env.PLATFORM_URL,
44
+ APPS_URL: process.env.APPS_URL,
45
+ // ports
46
+ PORT: process.env.PORT || process.env.WORKER_PORT,
47
+ CLUSTER_PORT: process.env.CLUSTER_PORT,
48
+ // flags
49
+ NODE_ENV: process.env.NODE_ENV,
50
+ SELF_HOSTED: !!parseInt(process.env.SELF_HOSTED),
51
+ LOG_LEVEL: process.env.LOG_LEVEL,
44
52
  MULTI_TENANCY: process.env.MULTI_TENANCY,
45
53
  DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
46
- ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
47
54
  SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
55
+ DISABLE_DEVELOPER_LICENSE: process.env.DISABLE_DEVELOPER_LICENSE,
56
+ // smtp
48
57
  SMTP_USER: process.env.SMTP_USER,
49
58
  SMTP_PASSWORD: process.env.SMTP_PASSWORD,
50
59
  SMTP_HOST: process.env.SMTP_HOST,
51
60
  SMTP_PORT: process.env.SMTP_PORT,
52
61
  SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
53
- PLATFORM_URL: process.env.PLATFORM_URL,
54
- COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
62
+ // other
55
63
  CHECKLIST_CACHE_TTL: parseIntSafe(process.env.CHECKLIST_CACHE_TTL) || 3600,
56
- APPS_URL: process.env.APPS_URL,
57
64
  _set(key, value) {
58
65
  process.env[key] = value
59
66
  module.exports[key] = value