samanbayaka 0.0.21 → 0.0.22

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/commit-hash.mjs CHANGED
@@ -1 +1 @@
1
- export const COMMIT_HASH = '85a1def';
1
+ export const COMMIT_HASH = '02c6744';
@@ -0,0 +1,21 @@
1
+ import { Etcd3 } from "etcd3"
2
+ import YAML from 'yaml'
3
+
4
+ const [user, pass] = (process.env.SBK_CONFIG_URPW || "ur:pa").split(":")
5
+
6
+ const client = new Etcd3({
7
+ hosts: "http://etcd:12379",
8
+ auth: {
9
+ username: user,
10
+ password: pass
11
+ }
12
+ })
13
+
14
+ try {
15
+ const yamlText = await client.get("/config/yaml/telemetry")
16
+ const obj = YAML.parse(yamlText);
17
+
18
+ console.log(obj);
19
+ } catch (err) {
20
+ console.error("Configuration reading error: ", err.message)
21
+ }
@@ -7,13 +7,24 @@ import os from "os"
7
7
  import { createRequire } from 'module'
8
8
 
9
9
  import chokidar from "chokidar"
10
-
10
+ import { Etcd3 } from "etcd3"
11
+ import YAML from 'yaml'
11
12
 
12
13
  const __filename = fileURLToPath(import.meta.url)
13
14
  const __dirname = path.dirname(__filename)
14
15
  const require = createRequire(import.meta.url)
15
16
 
16
17
 
18
+ const [user, pass] = (process.env.SBK_CONFIG_URPW || "ur:pa").split(":")
19
+
20
+ const client = new Etcd3({
21
+ hosts: "http://etcd:12379",
22
+ auth: {
23
+ username: user,
24
+ password: pass
25
+ }
26
+ })
27
+
17
28
  /**
18
29
  * Configuration path
19
30
  * @type {string}
@@ -47,42 +58,51 @@ const SERVICES_DIR = __dirname.split('node_modules')[0]
47
58
  * @return {object}
48
59
  */
49
60
  export const getConfig = async (fileName) => {
50
- const configFile = path.
51
- join(
52
- CONFIG_PATH,
53
- `${fileName}.mjs`
54
- )
55
-
56
- // /**
57
- // * Validate Configuration
58
- // */
59
- // if(process.env.NODE_ENV){
60
- // console.error("NODE_ENV must be 'production', 'testing', or 'development'")
61
- // process.exit(0)
62
- // }
61
+ // const configFile = path
62
+ // .join(
63
+ // CONFIG_PATH,
64
+ // `${fileName}.mjs`
65
+ // )
66
+
67
+ // // /**
68
+ // // * Validate Configuration
69
+ // // */
70
+ // // if(process.env.NODE_ENV){
71
+ // // console.error("NODE_ENV must be 'production', 'testing', or 'development'")
72
+ // // process.exit(0)
73
+ // // }
63
74
 
64
75
 
65
- return (await import(pathToFileURL(configFile).href)).default
76
+ // return (await import(pathToFileURL(configFile).href)).default
77
+
78
+ // try {
79
+ const yamlText = await client.get(`/config/yaml/${fileName}`)
80
+ return Object.freeze(
81
+ YAML.parse(yamlText)
82
+ )
83
+ // } catch (err) {
84
+ // throw new Error(`Configuration reading error: ${err.message}`)
85
+ // }
66
86
  }
67
87
 
68
88
 
69
- /**
70
- * Getting server configuration.
71
- * @type {string}
72
- */
73
- const CONFIG = await getConfig('server')
89
+ // /**
90
+ // * Getting server configuration.
91
+ // * @type {string}
92
+ // */
93
+ // const CONFIG = await getConfig('server')
74
94
 
75
95
 
76
- /**
77
- * Assets path
78
- */
79
- export const assetPath = {
80
- rootFolder: path
81
- .join(
82
- ABSOLUTE_PATH,
83
- CONFIG.assetPath,
84
- ),
85
- }
96
+ // /**
97
+ // * Assets path
98
+ // */
99
+ // export const assetPath = {
100
+ // rootFolder: path
101
+ // .join(
102
+ // ABSOLUTE_PATH,
103
+ // CONFIG.assetPath,
104
+ // ),
105
+ // }
86
106
 
87
107
 
88
108
  /**
@@ -139,18 +159,18 @@ export const pkgDtls = {
139
159
  }
140
160
 
141
161
 
142
- /**
143
- * OpenAPI configuration
144
- */
145
- export const openApiConfig = {
146
- info: {
147
- title: pkgDtls.name,
148
- version: pkgDtls.version,
149
- summary: CONFIG.openApiInfo[0].summary,
150
- description: CONFIG.openApiInfo[0].description,
151
- },
152
- servers: CONFIG.openApiInfo[0].url,
153
- }
162
+ // /**
163
+ // * OpenAPI configuration
164
+ // */
165
+ // export const openApiConfig = {
166
+ // info: {
167
+ // title: pkgDtls.name,
168
+ // version: pkgDtls.version,
169
+ // summary: CONFIG.openApiInfo[0].summary,
170
+ // description: CONFIG.openApiInfo[0].description,
171
+ // },
172
+ // servers: CONFIG.openApiInfo[0].url,
173
+ // }
154
174
 
155
175
  // /**
156
176
  // * Load modules from path as moleculer-repl is only supports cjs files
@@ -2,9 +2,25 @@ import ApiGateway from "moleculer-web"
2
2
  import jwt from "jsonwebtoken"
3
3
  import jwksClient from "jwks-rsa"
4
4
 
5
+ // const OPENID_CONFIG = {
6
+ // url: "https://accounts.google.com/.well-known/openid-configuration",
7
+ // url: "",
8
+ // clientId: "184045176764-ugg28aegdro383pintufun14uubtt374.apps.googleusercontent.com",
9
+ // jwksClient: {
10
+ // cache: true,
11
+ // cacheMaxEntries: 5,
12
+ // cacheMaxAge: 10 * 60 * 1000,
13
+ // rateLimit: true,
14
+ // jwksRequestsPerMinute: 10,
15
+ // },
16
+ // jwtVerifyAlgo: ["RS256"],
17
+ // client: {},
18
+ // issuer: "",
19
+ // }
20
+
5
21
  const OPENID_CONFIG = {
6
- url: "https://accounts.google.com/.well-known/openid-configuration",
7
- clientId: "184045176764-ugg28aegdro383pintufun14uubtt374.apps.googleusercontent.com",
22
+ url: "https://auth.wbsedcl.in/realms/redpanda/.well-known/openid-configuration",
23
+ clientId: "bff-client",
8
24
  jwksClient: {
9
25
  cache: true,
10
26
  cacheMaxEntries: 5,
@@ -159,7 +175,18 @@ export const authorize = async (ctx, route, req) => {
159
175
  })
160
176
 
161
177
  ctx.broker.logger.debug({message: "Decoded Token Object", token: decoded})
162
- ctx.meta.user = { name: decoded?.name, email: decoded?.email }
178
+ ctx.meta.user = {
179
+ sessionId: decoded?.sid,
180
+ id: decoded?.sub,
181
+ userId: (decoded?.sub).split(":").at(-1),
182
+ username: decoded?.preferred_username,
183
+ firstName: decoded?.given_name,
184
+ lastName: decoded?.family_name,
185
+ fullName: [...new Set(decoded?.name.split(/\s+/))].join(" "),
186
+ emailIds: decoded?.email,
187
+ mobileNos: decoded?.mobile_no,
188
+ userRoles: decoded?.user_role,
189
+ }
163
190
  return decoded
164
191
 
165
192
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "samanbayaka",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Moleculer Gateway service with kafka transporter",
5
5
  "homepage": "https://gitlab.com/dalal.suvendu/samanbayaka#readme",
6
6
  "bugs": {
@@ -41,6 +41,7 @@
41
41
  "chokidar": "^5.0.0",
42
42
  "compression": "^1.8.1",
43
43
  "cookie-parser": "^1.4.7",
44
+ "etcd3": "^1.1.2",
44
45
  "helmet": "^8.1.0",
45
46
  "ioredis": "^5.10.1",
46
47
  "jsonwebtoken": "^9.0.3",
@@ -55,7 +56,8 @@
55
56
  "nats": "^2.29.3",
56
57
  "pino": "^10.3.1",
57
58
  "pnpm": "^10.32.1",
58
- "sinon": "^21.1.2"
59
+ "sinon": "^21.1.2",
60
+ "yaml": "^2.9.0"
59
61
  },
60
62
  "devDependencies": {
61
63
  "chai": "^6.2.2",
@@ -41,7 +41,8 @@ export default {
41
41
  },
42
42
 
43
43
  handler: async(ctx) => {
44
- return ctx.meta.user
44
+ const { sessionId, id, ...profile } = ctx.meta.user
45
+ return profile
45
46
  }
46
47
  }
47
48
  },
@@ -73,7 +73,7 @@ export default {
73
73
  */
74
74
  {
75
75
  path: "/api",
76
- authorization: true,
76
+ authorization: false,
77
77
  whitelist: [
78
78
  /**
79
79
  * Access any actions except 'gateway' and 'system' service