@oondemand/oon-core-back 0.3.19 → 0.3.21

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.
@@ -19,6 +19,11 @@ function flag(name, fallback) {
19
19
  const index = process.argv.indexOf(name);
20
20
  return index < 0 ? fallback : process.argv[index + 1];
21
21
  }
22
+
23
+ function setting(flagName, envName, fallback) {
24
+ return flag(flagName, process.env[envName] || fallback);
25
+ }
26
+
22
27
  function required(value, name) {
23
28
  if (!value) throw new Error(`${name} obrigatório.`);
24
29
  return value;
@@ -28,16 +33,43 @@ async function main() {
28
33
  const appCode = dnsLabel(flag("--app-code", "central-ativacao"));
29
34
  const imageDigest = required(flag("--image-digest"), "--image-digest");
30
35
  const infra = validateInfraFromCluster().config;
36
+ const protocol = infra.DEFAULT_PROTOCOL || "https";
31
37
  const hostname = flag("--hostname", `${appCode}.${infra.DNS}`);
32
- const publicUrl = `${infra.DEFAULT_PROTOCOL || "https"}://${hostname}`;
38
+ const publicUrl = `${protocol}://${hostname}`;
33
39
  const apiUrl = `${publicUrl}/api`;
34
40
  const namespace = `${infra.RUNTIME_NAMESPACE_PREFIX || "oon"}-${appCode}-dev`
35
41
  .slice(0, 63)
36
42
  .replace(/-+$/, "");
43
+ const registryOwner = setting(
44
+ "--registry-owner",
45
+ "PLATFORM_REGISTRY_OWNER",
46
+ "oondemand",
47
+ );
37
48
  const imageRepository = flag(
38
49
  "--image-repository",
39
- `${infra.REGISTRY_HOST || "ghcr.io"}/oondemand/${appCode}`,
50
+ `${infra.REGISTRY_HOST || "ghcr.io"}/${registryOwner}/${appCode}`,
51
+ );
52
+ const deliveryRepository = setting(
53
+ "--delivery-repository",
54
+ "PLATFORM_DELIVERY_REPOSITORY",
55
+ "oondemand/central-ativacao",
40
56
  );
57
+ const deliveryWorkflow = setting(
58
+ "--delivery-workflow",
59
+ "PLATFORM_DELIVERY_WORKFLOW",
60
+ "publish-central-dev.yml",
61
+ );
62
+ const deliveryRef = setting(
63
+ "--delivery-ref",
64
+ "PLATFORM_DELIVERY_REF",
65
+ "main",
66
+ );
67
+ const administrativeEmail = setting(
68
+ "--administrative-email",
69
+ "PLATFORM_ADMINISTRATIVE_EMAIL",
70
+ "plataforma@oondemand.com.br",
71
+ );
72
+
41
73
  const context = {
42
74
  releaseId: `bootstrap-${appCode}`,
43
75
  appCode,
@@ -51,16 +83,16 @@ async function main() {
51
83
  const extraSecrets = {
52
84
  GITHUB_OIDC_AUDIENCE: apiUrl,
53
85
  PLATFORM_DNS: infra.DNS,
54
- PLATFORM_DEFAULT_PROTOCOL: infra.DEFAULT_PROTOCOL || "https",
86
+ PLATFORM_DEFAULT_PROTOCOL: protocol,
55
87
  PLATFORM_REGISTRY_HOST: infra.REGISTRY_HOST || "ghcr.io",
56
- PLATFORM_REGISTRY_OWNER: "oondemand",
88
+ PLATFORM_REGISTRY_OWNER: registryOwner,
57
89
  PLATFORM_RUNTIME_NAMESPACE_PREFIX:
58
90
  infra.RUNTIME_NAMESPACE_PREFIX || "oon",
59
- PLATFORM_DELIVERY_REPOSITORY: "oondemand/oon-platform",
60
- PLATFORM_DELIVERY_WORKFLOW: "publish-dev.yml",
61
- PLATFORM_DELIVERY_REF: "main",
91
+ PLATFORM_DELIVERY_REPOSITORY: deliveryRepository,
92
+ PLATFORM_DELIVERY_WORKFLOW: deliveryWorkflow,
93
+ PLATFORM_DELIVERY_REF: deliveryRef,
62
94
  PLATFORM_API_URL: apiUrl,
63
- PLATFORM_ADMINISTRATIVE_EMAIL: "plataforma@oondemand.com.br",
95
+ PLATFORM_ADMINISTRATIVE_EMAIL: administrativeEmail,
64
96
  };
65
97
 
66
98
  const provisioned = await provisionRuntime({ context, extraSecrets });
@@ -90,6 +122,9 @@ async function main() {
90
122
  apiUrl,
91
123
  activationUrl: `${publicUrl}/ativacao`,
92
124
  imageDigest,
125
+ deliveryRepository,
126
+ deliveryWorkflow,
127
+ deliveryRef,
93
128
  },
94
129
  null,
95
130
  2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oondemand/oon-core-back",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/oondemand/oon-platform.git",
@@ -22,14 +22,45 @@ function buildMongoUri() {
22
22
  return uri;
23
23
  }
24
24
 
25
+ function connectionOptions() {
26
+ // MONGO_URI é um contrato completo e pode conter usuário, senha, authSource,
27
+ // TLS e demais opções. Passar user/pass indefinidos ao Mongoose pode
28
+ // sobrescrever a autenticação embutida e abrir uma sessão não autenticada.
29
+ if (process.env.MONGO_URI) return {};
30
+
31
+ const hasUser = Boolean(process.env.DB_USER);
32
+ const hasPassword = Boolean(process.env.DB_PASSWORD);
33
+
34
+ if (hasUser !== hasPassword) {
35
+ throw new Error("DB_USER e DB_PASSWORD devem ser configurados em conjunto.");
36
+ }
37
+
38
+ return hasUser
39
+ ? { user: process.env.DB_USER, pass: process.env.DB_PASSWORD }
40
+ : {};
41
+ }
42
+
43
+ function databaseLabel(uri) {
44
+ if (process.env.DB_NAME) return process.env.DB_NAME;
45
+
46
+ try {
47
+ const name = decodeURIComponent(new URL(uri).pathname.replace(/^\//, ""));
48
+ return name || "configurado";
49
+ } catch {
50
+ return "configurado";
51
+ }
52
+ }
53
+
25
54
  async function connectDB() {
26
55
  const uri = buildMongoUri();
27
- await mongoose.connect(uri, {
28
- user: process.env.DB_USER,
29
- pass: process.env.DB_PASSWORD,
30
- });
31
- console.log(`Conectado ao MongoDB (${process.env.DB_NAME || uri})`);
56
+ await mongoose.connect(uri, connectionOptions());
57
+ console.log(`Conectado ao MongoDB (${databaseLabel(uri)})`);
32
58
  return mongoose.connection;
33
59
  }
34
60
 
35
- module.exports = { connectDB, buildMongoUri };
61
+ module.exports = {
62
+ connectDB,
63
+ buildMongoUri,
64
+ connectionOptions,
65
+ databaseLabel,
66
+ };