COBOL Std 10 Configuration and Credentials
Jump to navigation
Jump to search
10. Configuration and Credentials[edit]
10.1 Externalise Credentials[edit]
Hard-coded database credentials in WORKING-STORAGE (pgcobol defect D-04) are prohibited in production code. Use one of the following patterns, in preference order:
- Environment variables accepted via
ACCEPT … FROM ENVIRONMENT-VALUEat runtime. - A configuration file read at startup, with path supplied via an environment variable.
- A GnuCOBOL external data item shared from a configuration sub-program.
<syntaxhighlight lang="cobol">
01 WS-DB-USER PIC X(64).
01 WS-DB-PWD PIC X(64).
...
B000-INITIALISE.
ACCEPT WS-DB-USER FROM ENVIRONMENT-VALUE 'PRIMES_DB_USER'
ACCEPT WS-DB-PWD FROM ENVIRONMENT-VALUE 'PRIMES_DB_PWD'
</syntaxhighlight>
10.2 Connection String[edit]
Store the full connection string in a named constant in WORKING-STORAGE. The GixSQL pgsql driver string format is:
<syntaxhighlight lang="cobol">
01 WS-DATASRC PIC X(64)
VALUE 'pgsql://localhost:5432/primes&default_schema=primes'.
</syntaxhighlight>
| name = Ambox{{subst:void|Don't change anything on this line. It will change itself when you save.}} | subst = {{subst:substcheck}}