Skip to content

Commit

Permalink
blockchain: explicitly allow empty env values
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelPull authored Oct 31, 2024
1 parent f11b835 commit 0b72629
Showing 1 changed file with 74 additions and 35 deletions.
109 changes: 74 additions & 35 deletions blockchain/src/envVarsSchema.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const Joi = require("joi");

const envVarsSchema = Joi.object({
PORT: Joi.number().port().default(8085).note("This is the port where the multichain can be downloaded (backup)"),
PORT: Joi.number()
.port()
.allow("", null)
.empty(["", null])
.default(8085)
.note("This is the port where the multichain can be downloaded (backup)"),
ORGANIZATION: Joi.string()
.allow("")
.empty(["", null])
Expand Down Expand Up @@ -31,57 +36,82 @@ const envVarsSchema = Joi.object({
"Password used by the API to connect to the blockchain. The password is set by the origin node upon start. Every beta node needs to use the same RPC password in order to be able to connect to the blockchain. <br/>**Hint:** Although the MULTICHAIN_RPC_PASSWORD is not required it is highly recommended to set an own secure one, at least 32 characters long.",
),
RPC_ALLOW_IP: Joi.string()
.allow("", null)
.empty(["", null])
.default("0.0.0.0/0")
.note(
"It refers to an allowed IP address range, given either by IP or CIDR notation. 0.0.0.0/0 will allow access from anywhere. ",
),
CERT_PATH: Joi.string()
.allow("", null)
.empty(["", null])
.empty(null)
.default("")
.note(
"The path to the certificate used by the blockchain to authenticate with the connection peer. Note that self-signed certificates are not allowed in production environments. [More information can be found here](https://www.cloudflare.com/en-gb/learning/access-management/what-is-mutual-authentication/) ",
),
CERT_CA_PATH: Joi.string()
.allow("", null)
.empty(["", null])
.empty(null)
.default("")
.note(
"The path to the certificate authority root certificate by the blockchain to authenticate with the connection peer. Note that self-signed certificates are not allowed in production environments.[More information can be found here](https://www.cloudflare.com/en-gb/learning/access-management/what-is-mutual-authentication/)",
),
CERT_KEY_PATH: Joi.string()
.empty("")
.allow("", null)
.empty(null)
.default("")
.note(
"The path to the certificate key used by the blockchain to authenticate with the connection peer. [More information can be found here](https://www.cloudflare.com/en-gb/learning/access-management/what-is-mutual-authentication/)",
),
AUTOSTART: Joi.boolean()
.default(true)
.empty("")
.allow("", null)
.empty(["", null])
.note("If set to false multichain daemon will not start automatically."),
EXTERNAL_IP: Joi.string().note(
"The EXTERNAL_IP option is the IP address with which the current node can be reached. The variable is forwarded to the multichain daemon as `externalip` argument. This will be reported to other nodes in the Trubudget network. By default, daemon will try to automatically detect an external IP address. However, this might not always be accurate, especially if a node is behind a NAT or a firewall. By using EXTERNAL_IP, you can manually specify the IP. This can be useful if you want to ensure that your node is reachable at a specific address. If your node is not actually reachable at the specified IP address (e.g. because of a firewall), other nodes might not be able to connect to it. <br/>Example: If you have a VM running on 22.22.22.22 and you want to start a beta node from this VM to connect to an alpha running on 11.11.11.11, you set `EXTERNAL_IP` to 11.11.11.11 on alpha node and 22.22.22.22 on beta node.",
),
EXTERNAL_IP: Joi.string()
.allow("", null)
.empty(["", null])
.note(
"The EXTERNAL_IP option is the IP address with which the current node can be reached. The variable is forwarded to the multichain daemon as `externalip` argument. This will be reported to other nodes in the Trubudget network. By default, daemon will try to automatically detect an external IP address. However, this might not always be accurate, especially if a node is behind a NAT or a firewall. By using EXTERNAL_IP, you can manually specify the IP. This can be useful if you want to ensure that your node is reachable at a specific address. If your node is not actually reachable at the specified IP address (e.g. because of a firewall), other nodes might not be able to connect to it. <br/>Example: If you have a VM running on 22.22.22.22 and you want to start a beta node from this VM to connect to an alpha running on 11.11.11.11, you set `EXTERNAL_IP` to 11.11.11.11 on alpha node and 22.22.22.22 on beta node.",
),
LOG_LEVEL: Joi.string()
.default("info")
.allow("fatal", "error", "warn", "info", "debug", "trace", "")
.allow("fatal", "error", "warn", "info", "debug", "trace", "") // TODO should be valid('gsg','gdsf')
.empty(["", null])
.note("Defines the log output."),
P2P_HOST: Joi.string().note(
"The IP address of the blockchain node you want to connect to. When given, the node joins the existing network rather than creating its own chain.",
),
P2P_HOST: Joi.string()
.allow("", null)
.empty(["", null])
.note(
"The IP address of the blockchain node you want to connect to. When given, the node joins the existing network rather than creating its own chain.",
),
P2P_PORT: Joi.number()
.port()
.default(7447)
.allow("", null)
.empty(["", null])
.note("The port on which the node you want to connect to has exposed the blockchain."),
API_PROTOCOL: Joi.string()
.allow("http", "https")
.allow("http", "https", "", null)
.empty(["", null])
.default("http")
.note("The Protocol which should be used to connect to the alpha-node's api."),
API_HOST: Joi.string()
.allow("", null)
.empty(["", null])
.default("localhost")
.note(
"Used to build the URL to the alpha-node's API when requesting network access. (The IP addresses are usually the same as for the P2P host address).",
),
API_PORT: Joi.number().port().default(8080).note("The port used to connect to the alpha-node's api."),
API_PORT: Joi.number()
.port()
.allow("", null)
.empty(["", null])
.default(8080)
.note("The port used to connect to the alpha-node's api."),
MULTICHAIN_DIR: Joi.string()
.allow("", null)
.empty(["", null])
.default("/root")
.note(
"The path to the multichain folder where the blockchain data is persisted. For installations via `docker compose`, this refers to the path within the docker container of the blockchain. For bare metal installations, this refers to the path on the machine the blockchain is running on.",
Expand All @@ -96,75 +126,84 @@ const envVarsSchema = Joi.object({
})
.note("The IP address from the email-notification service."),
EMAIL_PORT: Joi.number()
.allow("")
.empty(["", null])
.when("EMAIL_SERVICE_ENABLED", {
is: true,
then: Joi.required(),
otherwise: Joi.optional(),
otherwise: Joi.optional().allow(""),
})
.note("The port address from the email-notification service."),
EMAIL_SSL: Joi.boolean()
.default(false)
.empty("")
.allow("", null)
.empty(["", null])
.note(
"If set to `true` the connection between blockchain and email-notification service is https instead of http.",
),
NOTIFICATION_PATH: Joi.string()
.allow("", null)
.empty(["", null])
.default("./notifications/")
.note("The path where notification files shall be saved on the blockchain environment"),
NOTIFICATION_MAX_LIFETIME: Joi.number()
.allow("", null)
.empty(["", null])
.default(24)
.note("This number configure how long notifications shall be saved in the NOTIFICATION_PATH in hours"),
NOTIFICATION_SEND_INTERVAL: Joi.number()
.allow("", null)
.empty(["", null])
.default(10)
.note(
"This number configure in which interval the notifications in the NOTIFICATION_PATH should be checked and send.",
),
JWT_SECRET: Joi.string()
.allow("")
.empty(["", null])
.when("EMAIL_SERVICE_ENABLED", {
is: true,
then: Joi.required(),
otherwise: Joi.optional(),
otherwise: Joi.optional().allow("", null),
})
.note(
"The `JWT_SECRET` is only required if the Email feature is enabled. It is used to authenticate the blockchain at the email-service, so it can send notifications.",
),
EMAIL_SERVICE_ENABLED: Joi.boolean()
.default(false)
.empty("")
.allow("", null)
.empty(["", null])
.note("If set to `true` the Email-Service feature is enabled and the EMAIL_* variables are required"),
MULTICHAIN_FEED_ENABLED: Joi.boolean()
.default(false)
.empty("")
.when("EMAIL_SERVICE_ENABLED", {
is: true,
then: Joi.required(),
otherwise: Joi.optional().allow("", null).empty(["", null]).default(false),
})
.note(
"If set to true the multichain-feed go script in src/multichain-feed/multichain-feed is passed to the multichain daemon and executed in a separate process. ",
),
NODE_ENV: Joi.string()
.allow("")
NODE_ENV: Joi.string() // TODO add .valid()
.allow("", null)
.empty(["", null])
.default("production")
.note(
"Environment: Default development when running development-script. Production when running production-script",
),
BLOCKNOTIFY_SCRIPT: Joi.string().note(
"Configure the blocknotifiy argument of the multichain configuration like -blocknotify=[BLOCKNOTIFY_SCRIPT]",
),
KUBE_SERVICE_NAME: Joi.string().default(""),
KUBE_NAMESPACE: Joi.string().default(""),
EXPOSE_MC: Joi.boolean().default(false),
BLOCKNOTIFY_SCRIPT: Joi.string()
.allow("", null)
.empty(null)
.default("")
.note("Configure the blocknotifiy argument of the multichain configuration like -blocknotify=[BLOCKNOTIFY_SCRIPT]"),
KUBE_SERVICE_NAME: Joi.string().allow("", null).empty(null).default(""),
KUBE_NAMESPACE: Joi.string().allow("", null).empty(null).default(""),
EXPOSE_MC: Joi.boolean().allow("", null).empty(["", null]).default(false),
PRETTY_PRINT: Joi.boolean()
.default(false)
.allow("", null)
.empty(["", null])
.default(false)
.note(
"Decides whether the logs printed by the API are pretty printed or not. Pretty printed logs are easier to read while non-pretty printed logs are easier to store and use e.g. in the ELK (Elasticsearch-Logstash-Kabana) stack.",
),
CI_COMMIT_SHA: Joi.string().empty("").note("The /version endpoint returns this variable as `commit` property."),
CI_COMMIT_SHA: Joi.string().allow("").note("The /version endpoint returns this variable as `commit` property."),
BUILDTIMESTAMP: Joi.string()
.empty("")
.allow("")
.note("The /version endpoint returns this variable as `buildTimestamp` property."),
})
.unknown()
Expand Down

0 comments on commit 0b72629

Please sign in to comment.