File tree Expand file tree Collapse file tree 16 files changed +42
-20
lines changed Expand file tree Collapse file tree 16 files changed +42
-20
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' hive ' : minor
3
+ ---
4
+
5
+ encode postgres variables and introduce optional password
Original file line number Diff line number Diff line change 1
1
export function createConnectionString ( config : {
2
2
host : string ;
3
3
port : number ;
4
- password : string ;
4
+ password : string | undefined ;
5
5
user : string ;
6
6
db : string ;
7
7
ssl : boolean ;
8
8
} ) {
9
9
// prettier-ignore
10
- return `postgres://${ config . user } :${ config . password } @${ config . host } :${ config . port } /${ config . db } ${ config . ssl ? '?sslmode=require' : '?sslmode=disable' } ` ;
10
+ const encodedUser = encodeURIComponent ( config . user ) ;
11
+ const encodedPassword =
12
+ typeof config . password === 'string' ? `:${ encodeURIComponent ( config . password ) } ` : '' ;
13
+ const encodedHost = encodeURIComponent ( config . host ) ;
14
+ const encodedDb = encodeURIComponent ( config . db ) ;
15
+
16
+ return `postgres://${ encodedUser } ${ encodedPassword } @${ encodedHost } :${ config . port } /${ encodedDb } ${ config . ssl ? '?sslmode=require' : '?sslmode=disable' } ` ;
11
17
}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ const PostgresModel = zod.object({
43
43
POSTGRES_PORT : NumberFromString ,
44
44
POSTGRES_DB : zod . string ( ) ,
45
45
POSTGRES_USER : zod . string ( ) ,
46
- POSTGRES_PASSWORD : zod . string ( ) ,
46
+ POSTGRES_PASSWORD : emptyString ( zod . string ( ) . optional ( ) ) ,
47
47
} ) ;
48
48
49
49
const ClickHouseModel = zod . union ( [
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ const PostgresModel = zod.object({
36
36
POSTGRES_PORT : NumberFromString ,
37
37
POSTGRES_DB : zod . string ( ) ,
38
38
POSTGRES_USER : zod . string ( ) ,
39
- POSTGRES_PASSWORD : zod . string ( ) ,
39
+ POSTGRES_PASSWORD : emptyString ( zod . string ( ) . optional ( ) ) ,
40
40
} ) ;
41
41
42
42
const configs = {
Original file line number Diff line number Diff line change 1
1
const {
2
2
POSTGRES_USER = 'postgres' ,
3
- POSTGRES_PASSWORD = 'postgres' ,
3
+ POSTGRES_PASSWORD = null ,
4
4
POSTGRES_HOST = 'localhost' ,
5
5
POSTGRES_PORT = 5432 ,
6
6
POSTGRES_DB = 'registry' ,
@@ -9,11 +9,16 @@ const {
9
9
} = process . env ;
10
10
11
11
function cn ( dbName = POSTGRES_DB ) {
12
+ const user = encodeURIComponent ( POSTGRES_USER ) ;
13
+ const password =
14
+ typeof POSTGRES_PASSWORD === 'string' ? `:${ encodeURIComponent ( POSTGRES_PASSWORD ) } ` : '' ;
15
+ const host = encodeURIComponent ( POSTGRES_HOST ) ;
16
+ const dbNameEncoded = encodeURIComponent ( dbName ) ;
17
+ const sslMode = POSTGRES_SSL ? 'require' : 'disable' ;
18
+
12
19
return (
13
20
POSTGRES_CONNECTION_STRING ||
14
- `postgres://${ POSTGRES_USER } :${ POSTGRES_PASSWORD } @${ POSTGRES_HOST } :${ POSTGRES_PORT } /${ dbName } ${
15
- POSTGRES_SSL ? '?sslmode=require' : '?sslmode=disable'
16
- } `
21
+ `postgres://${ user } ${ password } @${ host } :${ POSTGRES_PORT } /${ dbNameEncoded } ?sslmode=${ sslMode } `
17
22
) ;
18
23
}
19
24
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ you don't need this service.
13
13
| ` POSTGRES_PORT ` | ** Yes** | Port of the postgres database | ` 5432 ` |
14
14
| ` POSTGRES_DB ` | ** Yes** | Name of the postgres database. | ` registry ` |
15
15
| ` POSTGRES_USER ` | ** Yes** | User name for accessing the postgres database. | ` postgres ` |
16
- | ` POSTGRES_PASSWORD ` | ** Yes ** | Password for accessing the postgres database. | ` postgres ` |
16
+ | ` POSTGRES_PASSWORD ` | No | Password for accessing the postgres database. | ` postgres ` |
17
17
| ` USAGE_ESTIMATOR_ENDPOINT ` | ** Yes** | The endpoint of the usage estimator service. | ` http://127.0.0.1:4011 ` |
18
18
| ` EMAILS_ENDPOINT ` | No (if not provided no limit emails will be sent.) | The endpoint of the GraphQL Hive Email service. | ` http://127.0.0.1:6260 ` |
19
19
| ` ENVIRONMENT ` | No | The environment of your Hive app. (** Note:** This will be used for Sentry reporting.) | ` staging ` |
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ const PostgresModel = zod.object({
44
44
POSTGRES_PORT : NumberFromString ,
45
45
POSTGRES_DB : zod . string ( ) ,
46
46
POSTGRES_USER : zod . string ( ) ,
47
- POSTGRES_PASSWORD : zod . string ( ) ,
47
+ POSTGRES_PASSWORD : emptyString ( zod . string ( ) . optional ( ) ) ,
48
48
} ) ;
49
49
50
50
const PrometheusModel = zod . object ( {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ The GraphQL API for GraphQL Hive.
21
21
| ` POSTGRES_PORT ` | ** Yes** | Port of the postgres database | ` 5432 ` |
22
22
| ` POSTGRES_DB ` | ** Yes** | Name of the postgres database. | ` registry ` |
23
23
| ` POSTGRES_USER ` | ** Yes** | User name for accessing the postgres database. | ` postgres ` |
24
- | ` POSTGRES_PASSWORD ` | ** Yes ** | Password for accessing the postgres database. | ` postgres ` |
24
+ | ` POSTGRES_PASSWORD ` | No | Password for accessing the postgres database. | ` postgres ` |
25
25
| ` CLICKHOUSE_PROTOCOL ` | ** Yes** | The clickhouse protocol for connecting to the clickhouse instance. | ` http ` |
26
26
| ` CLICKHOUSE_HOST ` | ** Yes** | The host of the clickhouse instance. | ` 127.0.0.1 ` |
27
27
| ` CLICKHOUSE_PORT ` | ** Yes** | The port of the clickhouse instance | ` 8123 ` |
Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ const PostgresModel = zod.object({
76
76
POSTGRES_PORT : NumberFromString ,
77
77
POSTGRES_DB : zod . string ( ) ,
78
78
POSTGRES_USER : zod . string ( ) ,
79
- POSTGRES_PASSWORD : zod . string ( ) ,
79
+ POSTGRES_PASSWORD : emptyString ( zod . string ( ) . optional ( ) ) ,
80
80
} ) ;
81
81
82
82
const ClickHouseModel = zod . object ( {
Original file line number Diff line number Diff line change @@ -3,13 +3,19 @@ import { sql } from 'slonik';
3
3
export function createConnectionString ( config : {
4
4
host : string ;
5
5
port : number ;
6
- password : string ;
6
+ password : string | undefined ;
7
7
user : string ;
8
8
db : string ;
9
9
ssl : boolean ;
10
10
} ) {
11
11
// prettier-ignore
12
- return `postgres://${ config . user } :${ config . password } @${ config . host } :${ config . port } /${ config . db } ${ config . ssl ? '?sslmode=require' : '?sslmode=disable' } ` ;
12
+ const encodedUser = encodeURIComponent ( config . user ) ;
13
+ const encodedPassword =
14
+ typeof config . password === 'string' ? `:${ encodeURIComponent ( config . password ) } ` : '' ;
15
+ const encodedHost = encodeURIComponent ( config . host ) ;
16
+ const encodedDb = encodeURIComponent ( config . db ) ;
17
+
18
+ return `postgres://${ encodedUser } ${ encodedPassword } @${ encodedHost } :${ config . port } /${ encodedDb } ${ config . ssl ? '?sslmode=require' : '?sslmode=disable' } ` ;
13
19
}
14
20
15
21
export function toDate ( date : Date ) {
You can’t perform that action at this time.
0 commit comments