Skip to content

Commit 4857e13

Browse files
committed
feat: implement dropdown for postgres database with sslmode
1 parent 68a260c commit 4857e13

File tree

7 files changed

+45
-7
lines changed

7 files changed

+45
-7
lines changed

ui/src/app/app.constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum StorageKeys {
1515

1616
export enum SourceDbNames {
1717
MySQL = 'MySQL',
18-
Postgres = 'Postgres',
18+
Postgres = 'postgres',
1919
SQLServer = 'SQL Server',
2020
Oracle = 'Oracle',
2121
Cassandra = 'cassandra',

ui/src/app/components/direct-connection/direct-connection.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ <h3 class="primary-header">Connection Detail</h3>
6262
<mat-label *ngIf="connectForm.value.dbEngine !== 'cassandra'">Database Name</mat-label>
6363
<input matInput name="dbname" type="text" formControlName="dbName" id="dbname-input" />
6464
</mat-form-field>
65-
65+
<mat-form-field class="full-width" appearance="outline" *ngIf="connectForm.value.dbEngine === 'postgres'">
66+
<mat-label>SSL Mode</mat-label>
67+
<mat-select formControlName="sslMode">
68+
<mat-option *ngFor="let mode of sslModeList" [value]="mode.value">
69+
{{ mode.displayName }}
70+
</mat-option>
71+
</mat-select>
72+
</mat-form-field>
6673
<mat-form-field class="full-width" appearance="outline" *ngIf="connectForm.value.dbEngine === 'cassandra'">
6774
<mat-label>Datacenter</mat-label>
6875
<input matInput placeholder="dc" name="dataCenter" type="text" formControlName="dataCenter" id="datacenter-input"/>

ui/src/app/components/direct-connection/direct-connection.component.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ describe('DirectConnectionComponent', () => {
9292
dbname?.setValue('mysql')
9393
expect(dbname?.invalid).toBeFalsy()
9494

95+
let sslMode = component.connectForm.get('sslMode')
96+
sslMode?.setValue('disable')
97+
expect(sslMode?.invalid).toBeTruthy()
98+
sslMode?.setValue('enable')
99+
expect(sslMode?.invalid).toBeFalsy()
100+
95101
let dialect = component.connectForm.get('dialect')
96102
dialect?.setValue('')
97103
expect(dialect?.invalid).toBeTruthy()
@@ -123,6 +129,7 @@ describe('DirectConnectionComponent', () => {
123129
port: '1433',
124130
userName: 'sa',
125131
password: 'password',
132+
sslMode: 'disable',
126133
dbName: 'database',
127134
dialect: 'postgresql',
128135
})
@@ -158,6 +165,7 @@ describe('DirectConnectionComponent', () => {
158165
password: 'pass',
159166
dbName: 'keyspace1',
160167
dataCenter: 'dc1',
168+
sslMode: 'disable',
161169
dialect: 'google_standard_sql',
162170
})
163171

ui/src/app/components/direct-connection/direct-connection.component.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class DirectConnectionComponent implements OnInit {
2525
port: new FormControl('', [Validators.required, Validators.pattern('^[0-9]+$')]),
2626
userName: new FormControl('', [Validators.required]),
2727
password: new FormControl(''),
28+
sslMode: new FormControl(''),
2829
dbName: new FormControl('', [Validators.required]),
2930
dialect: new FormControl('', [Validators.required]),
3031
dataCenter: new FormControl(''),
@@ -47,6 +48,10 @@ export class DirectConnectionComponent implements OnInit {
4748
{ value: false, displayName: 'No'},
4849
{ value: true, displayName: 'Yes'},
4950
]
51+
sslModeList = [
52+
{ value: 'disable', displayName: 'Disable'},
53+
{ value: 'require', displayName: 'Require'},
54+
]
5055

5156
dialect: { value: string, displayName: string }[] = []
5257

@@ -80,8 +85,18 @@ export class DirectConnectionComponent implements OnInit {
8085
})
8186
this.connectForm.get('dbEngine')?.valueChanges.subscribe((dbEngine) => {
8287
this.updateDialectAndDataCenterOptions(dbEngine || '')
88+
this.updateSslModeValue(dbEngine || '')
8389
})
8490
this.updateDialectAndDataCenterOptions(this.connectForm.value.dbEngine || '')
91+
this.updateSslModeValue(this.connectForm.value.dbEngine || '')
92+
}
93+
94+
updateSslModeValue(dbEngine: string) {
95+
if (dbEngine !== SourceDbNames.Postgres) {
96+
this.connectForm.get('sslMode')?.setValue('')
97+
} else if (!this.connectForm.get('sslMode')?.value) {
98+
this.connectForm.get('sslMode')?.setValue('disable')
99+
}
85100
}
86101

87102
updateDialectAndDataCenterOptions(dbEngine: string) {
@@ -100,7 +115,7 @@ export class DirectConnectionComponent implements OnInit {
100115

101116
testConn() {
102117
this.clickEvent.openDatabaseLoader('test-connection', this.connectForm.value.dbName!)
103-
const { dbEngine, isSharded, hostName, port, userName, password, dbName, dialect, dataCenter } = this.connectForm.value
118+
const { dbEngine, isSharded, hostName, port, userName, password, sslMode, dbName, dialect, dataCenter } = this.connectForm.value
104119
localStorage.setItem(PersistedFormValues.DirectConnectForm, JSON.stringify(this.connectForm.value))
105120
let config: IDbConfig = {
106121
dbEngine: dbEngine!,
@@ -109,6 +124,7 @@ export class DirectConnectionComponent implements OnInit {
109124
port: port!,
110125
userName: userName!,
111126
password: password!,
127+
sslMode: sslMode!,
112128
dbName: dbName!,
113129
dataCenter: dataCenter!,
114130
}
@@ -149,7 +165,7 @@ export class DirectConnectionComponent implements OnInit {
149165
window.scroll(0, 0);
150166
this.data.resetStore();
151167
localStorage.clear();
152-
const { dbEngine, isSharded, hostName, port, userName, password, dbName, dialect, dataCenter } = this.connectForm.value;
168+
const { dbEngine, isSharded, hostName, port, userName, password, dbName, sslMode, dialect, dataCenter } = this.connectForm.value;
153169
localStorage.setItem(PersistedFormValues.DirectConnectForm, JSON.stringify(this.connectForm.value));
154170
let config: IDbConfig = {
155171
dbEngine: dbEngine!,
@@ -159,6 +175,7 @@ export class DirectConnectionComponent implements OnInit {
159175
userName: userName!,
160176
password: password!,
161177
dbName: dbName!,
178+
sslMode: sslMode!,
162179
dataCenter: dataCenter!,
163180
};
164181
this.connectRequest = this.fetch.connectTodb(config, dialect!).subscribe({
@@ -167,7 +184,7 @@ export class DirectConnectionComponent implements OnInit {
167184
this.data.conv.subscribe((res) => {
168185
localStorage.setItem(
169186
StorageKeys.Config,
170-
JSON.stringify({ dbEngine, hostName, port, userName, password, dbName })
187+
JSON.stringify({ dbEngine, hostName, port, userName, password, dbName, sslMode })
171188
);
172189
localStorage.setItem(StorageKeys.Type, InputType.DirectConnect);
173190
localStorage.setItem(StorageKeys.SourceDbName, extractSourceDbName(dbEngine!));

ui/src/app/model/db-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export default interface IDbConfig {
66
userName: string
77
password: string
88
dbName: string
9+
sslMode?: string
910
dataCenter?: string
1011
shardId?: string
1112
}

ui/src/app/services/fetch/fetch.service.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ describe('FetchService', () => {
3434
port: '9042',
3535
userName: 'user',
3636
password: 'password',
37+
sslMode: false,
3738
dbName: 'testdb',
3839
dataCenter: 'dc1',
3940
}
@@ -51,6 +52,7 @@ describe('FetchService', () => {
5152
Database: 'testdb',
5253
User: 'user',
5354
Password: 'password',
55+
Sslmode: false,
5456
Dialect: 'google_standard_sql',
5557
DataCenter: 'dc1',
5658
})
@@ -67,6 +69,7 @@ describe('FetchService', () => {
6769
port: '9042',
6870
userName: 'user',
6971
password: 'password',
72+
sslMode: false,
7073
dbName: 'testdb',
7174
dataCenter: 'dc1',
7275
}
@@ -82,6 +85,7 @@ describe('FetchService', () => {
8285
Database: 'testdb',
8386
User: 'user',
8487
Password: 'password',
88+
Sslmode: false,
8589
DataCenter: 'dc1',
8690
})
8791
req.flush({})

ui/src/app/services/fetch/fetch.service.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import ICreateSequence from 'src/app/model/auto-gen'
2525
providedIn: 'root',
2626
})
2727
export class FetchService {
28-
private url: string = window.location.origin
28+
private url: string = 'http://localhost:8080' // Update with your backend URL
2929
constructor(private http: HttpClient) {}
3030

3131
connectTodb(payload: IDbConfig, dialect: string) {
32-
const { dbEngine, isSharded, hostName, port, dbName, userName, password, dataCenter} = payload
32+
const { dbEngine, isSharded, hostName, port, dbName, userName, password, sslMode, dataCenter} = payload
3333
return this.http.post<HttpResponse<null>>(
3434
`${this.url}/connect`,
3535
{
@@ -40,6 +40,7 @@ export class FetchService {
4040
Database: dbName,
4141
User: userName,
4242
Password: password,
43+
Sslmode: sslMode,
4344
Dialect: dialect,
4445
DataCenter: dataCenter,
4546
},

0 commit comments

Comments
 (0)