Skip to content

Commit

Permalink
Merge pull request akopytov#353 from ddinu/master
Browse files Browse the repository at this point in the history
Command line flag to set the sslmode for PostgreSQL (Closes: akopytov#326)
  • Loading branch information
akopytov authored Dec 8, 2021
2 parents ead2689 + 1947e53 commit df89d34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/drivers/pgsql/drv_pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ static sb_arg_t pgsql_drv_args[] =
SB_OPT("pgsql-user", "PostgreSQL user", "sbtest", STRING),
SB_OPT("pgsql-password", "PostgreSQL password", "", STRING),
SB_OPT("pgsql-db", "PostgreSQL database name", "sbtest", STRING),
SB_OPT("pgsql-sslmode", "PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full)", "prefer", STRING),

SB_OPT_END
};
Expand Down Expand Up @@ -180,7 +181,15 @@ int pgsql_drv_init(void)
args.port = sb_get_value_string("pgsql-port");
args.user = sb_get_value_string("pgsql-user");
args.password = sb_get_value_string("pgsql-password");
args.db = sb_get_value_string("pgsql-db");

char * dbname = sb_get_value_string("pgsql-db");
char * sslmode = sb_get_value_string("pgsql-sslmode");

args.db = malloc(strlen("dbname= sslmode=") +
strlen(dbname) +
strlen(sslmode) +
1);
sprintf(args.db, "dbname=%s sslmode=%s", dbname, sslmode);

use_ps = 0;
pgsql_drv_caps.prepared_statements = 1;
Expand Down
3 changes: 2 additions & 1 deletion tests/t/help_drv_pgsql.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Skip test if the PostgreSQL driver is not available.
--pgsql-user=STRING PostgreSQL user [sbtest]
--pgsql-password=STRING PostgreSQL password []
--pgsql-db=STRING PostgreSQL database name [sbtest]

--pgsql-sslmode=STRING PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full) [prefer]

0 comments on commit df89d34

Please sign in to comment.