UNPKG

5.33 kBJavaScriptView Raw
1/* Copyright (c) 2015, 2023, Oracle and/or its affiliates. */
2
3/******************************************************************************
4 *
5 * This software is dual-licensed to you under the Universal Permissive License
6 * (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
7 * 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
8 * either license.
9 *
10 * If you elect to accept the software under the Apache License, Version 2.0,
11 * the following applies:
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * https://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 * NAME
26 * dbconfig.js
27 *
28 * DESCRIPTION
29 * Holds the credentials used by node-oracledb examples to connect to the
30 * database. Production applications should consider using External
31 * Authentication to avoid hard coded credentials.
32 *
33 * To create a database user, see
34 * https://blogs.oracle.com/sql/post/how-to-create-users-grant-them-privileges-and-remove-them-in-oracle-database
35 *
36 * Applications can set the connectString value to an Easy Connect string,
37 * or a Net Service Name from the tnsnames.ora file or an external naming
38 * service, or it can be the name of a local Oracle Database instance.
39 *
40 * If node-oracledb is linked with Instant Client, then an Easy
41 * Connect string is generally appropriate. The basic syntax is:
42 *
43 * [//]host_name[:port][/service_name][:server_type][/instance_name]
44 *
45 * Commonly just the host_name and service_name are needed
46 * e.g. "localhost/orclpdb1" or "example.com/XEPDB1"
47 *
48 * The Easy Connect syntax supports lots of options. To know more, please
49 * refer to the latest Oracle documentation on Easy Connect syntax:
50 * https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-B0437826-43C1-49EC-A94D-B650B6A4A6EE
51 *
52 * If using a tnsnames.ora file, the file can be in a default location such
53 * as $ORACLE_HOME/network/admin/tnsnames.ora or /etc/tnsnames.ora.
54 * Alternatively set the TNS_ADMIN environment variable and put the file in
55 * $TNS_ADMIN/tnsnames.ora.
56 *
57 * If connectString is not specified, the empty string "" is used which
58 * indicates to connect to the local, default database.
59 *
60 * External Authentication can be used by setting the optional property
61 * externalAuth to true. External Authentication allows applications to use
62 * an external password store such as Oracle Wallet, so that passwords
63 * do not need to be hard coded into the application. The user and password
64 * application. The user and password properties for connecting or creating
65 * a pool should not be set when externalAuth is true.
66 *
67 * TROUBLESHOOTING
68 * Refer to the Error Handling section in node-oracledb documentation
69 * to understand the different types of errors in both the Thin and Thick
70 * modes of node-oracledb:
71 * https://node-oracledb.readthedocs.io/en/latest/user_guide/exception_handling.html#errors-in-thin-and-thick-modes
72 *
73 *****************************************************************************/
74
75const config = {
76 user: process.env.NODE_ORACLEDB_USER,
77
78 // Get the password from the environment variable
79 // NODE_ORACLEDB_PASSWORD. The password could also be a hard coded
80 // string (not recommended), or it could be prompted for.
81 // Alternatively use External Authentication so that no password is needed.
82 password: process.env.NODE_ORACLEDB_PASSWORD,
83
84 // For information on connection strings see:
85 // https://node-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#connectionstrings
86 connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING,
87
88 // Setting externalAuth is optional. It defaults to false. See:
89 // https://node-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html#extauth
90 externalAuth: process.env.NODE_ORACLEDB_EXTERNALAUTH ? true : false,
91};
92
93// Set the NODE_ORACLEDB_WALLET_LOCATION and NODE_ORACLEDB_WALLET_PASSWORD
94// environment variables for database connections that require wallets.
95// For example, creating and dropping a user.
96// See the README.md file in this directory for more details.
97if (process.env.NODE_ORACLEDB_WALLET_PASSWORD) {
98 config.walletPassword = process.env.NODE_ORACLEDB_WALLET_PASSWORD;
99}
100
101if (process.env.NODE_ORACLEDB_WALLET_LOCATION) {
102 config.walletLocation = process.env.NODE_ORACLEDB_WALLET_LOCATION;
103}
104
105// Set the NODE_ORACLEDB_DBA_USER and NODE_ORACLEDB_DBA_PASSWORD environment
106// variables for database operations which require SYSDBA privileges.
107// For example, creating and dropping a user. See the README.md file in this
108// directory for more details.
109if (process.env.NODE_ORACLEDB_DBA_USER) {
110 config.DBA_user = process.env.NODE_ORACLEDB_DBA_USER;
111}
112
113if (process.env.NODE_ORACLEDB_DBA_PASSWORD) {
114 config.DBA_password = process.env.NODE_ORACLEDB_DBA_PASSWORD;
115}
116
117module.exports = config;