Skip to content

Commit 5bf641c

Browse files
author
ci bot
committed
Merge branch 'connection-form-fixes' into 'enterprise'
fix(connection-form): validation on file fields, clear db fields See merge request dkinternal/testgen/dataops-testgen!326
2 parents e7452bf + 8cd4849 commit 5bf641c

3 files changed

Lines changed: 31 additions & 26 deletions

File tree

testgen/ui/components/frontend/js/components/connection_form.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @property {string} connection_name
2323
* @property {string} sql_flavor
2424
* @property {string} sql_flavor_code
25+
* @property {string} project_code
2526
* @property {string} project_host
2627
* @property {string} project_port
2728
* @property {string} project_db
@@ -1005,7 +1006,7 @@ const SnowflakeForm = (
10051006
isValid.val = Object.values(validityPerField).every(v => v);
10061007
},
10071008
validators: [
1008-
required,
1009+
requiredIf(() => !originalConnection?.connection_id || !originalConnection?.private_key),
10091010
sizeLimit(200 * 1024 * 1024),
10101011
],
10111012
}),
@@ -1057,7 +1058,7 @@ const BigqueryForm = (
10571058
});
10581059

10591060
van.derive(() => {
1060-
onChange({ service_account_key: serviceAccountKey.val }, serviceAccountKeyFileRaw.val, isValid.val);
1061+
onChange({ service_account_key: serviceAccountKey.val, project_db: projectId.val }, serviceAccountKeyFileRaw.val, isValid.val);
10611062
});
10621063

10631064
return div(
@@ -1087,24 +1088,20 @@ const BigqueryForm = (
10871088
isFieldValid = false;
10881089
}
10891090
serviceAccountKeyFileRaw.val = value;
1091+
validityPerField['service_account_key'] = isFieldValid;
1092+
isValid.val = Object.values(validityPerField).every(v => v);
10901093
},
10911094
validators: [
1095+
requiredIf(() => !originalConnection?.connection_id || !originalConnection?.service_account_key),
10921096
sizeLimit(20 * 1024),
10931097
],
10941098
}),
10951099
);
10961100
},
10971101

10981102
div(
1099-
{ class: 'flex-row fx-gap-3 fx-flex' },
1100-
Input({
1101-
name: 'project_id',
1102-
label: 'Project ID',
1103-
value: projectId,
1104-
height: 38,
1105-
class: 'fx-flex',
1106-
disabled: true,
1107-
}),
1103+
{ class: 'text-caption text-right' },
1104+
`Project ID: ${projectId.val}`,
11081105
),
11091106
),
11101107
);

testgen/ui/components/frontend/js/pages/project_dashboard.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const TableGroupLatestProfile = (/** @type TableGroupSummary */ tableGroup) => {
164164
const daysAgo = Math.round((new Date() - new Date(tableGroup.latest_profile_start * 1000)) / (1000 * 60 * 60 * 24));
165165

166166
return div(
167-
{ class: 'flex-row tg-overview--row', style: 'width: calc(100% - 115px);' },
167+
{ class: 'flex-row tg-overview--row' },
168168
div(
169169
{ class: 'flex-row fx-gap-2', style: 'flex: 1 1 50%;' },
170170
span('Latest profile:'),
@@ -186,6 +186,7 @@ const TableGroupLatestProfile = (/** @type TableGroupSummary */ tableGroup) => {
186186
run_id: tableGroup.latest_profile_id,
187187
},
188188
width: 150,
189+
style: 'flex: 0 0 auto;',
189190
}),
190191
tableGroup.latest_anomalies_ct
191192
? SummaryCounts({
@@ -198,6 +199,7 @@ const TableGroupLatestProfile = (/** @type TableGroupSummary */ tableGroup) => {
198199
})
199200
: '',
200201
),
202+
div({ style: 'flex: 1 1 120px;' })
201203
);
202204
};
203205

testgen/ui/views/connections.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ class ConnectionsPage(Page):
5151
"url",
5252
"http_path",
5353
]
54+
encrypted_fields: typing.ClassVar[list[str]] = [
55+
"project_pw_encrypted",
56+
"private_key",
57+
"private_key_passphrase",
58+
"service_account_key",
59+
]
5460

5561
def render(self, project_code: str, **_kwargs) -> None:
5662
testgen.page_header(
@@ -95,25 +101,23 @@ def on_save_connection_clicked(updated_connection):
95101

96102
if updated_connection.get("connect_by_key"):
97103
updated_connection["project_pw_encrypted"] = ""
98-
if is_pristine(updated_connection["private_key_passphrase"]):
104+
if is_pristine(updated_connection.get("private_key_passphrase")):
99105
del updated_connection["private_key_passphrase"]
106+
elif updated_connection.get("private_key_passphrase") == CLEAR_SENTINEL:
107+
updated_connection["private_key_passphrase"] = ""
108+
109+
if is_pristine(updated_connection.get("private_key")):
110+
del updated_connection["private_key"]
111+
else:
112+
updated_connection["private_key"] = base64.b64decode(updated_connection["private_key"]).decode()
100113
else:
101114
updated_connection["private_key"] = ""
102115
updated_connection["private_key_passphrase"] = ""
103116

104-
if updated_connection.get("private_key_passphrase") == CLEAR_SENTINEL:
105-
updated_connection["private_key_passphrase"] = ""
106-
107-
if is_pristine(updated_connection.get("private_key")):
108-
del updated_connection["private_key"]
109-
else:
110-
updated_connection["private_key"] = base64.b64decode(updated_connection["private_key"]).decode()
111-
112-
if is_pristine(updated_connection.get("project_pw_encrypted")):
113-
del updated_connection["project_pw_encrypted"]
114-
115-
if updated_connection.get("project_pw_encrypted") == CLEAR_SENTINEL:
116-
updated_connection["project_pw_encrypted"] = ""
117+
if is_pristine(updated_connection.get("project_pw_encrypted")):
118+
del updated_connection["project_pw_encrypted"]
119+
elif updated_connection.get("project_pw_encrypted") == CLEAR_SENTINEL:
120+
updated_connection["project_pw_encrypted"] = ""
117121

118122
updated_connection["sql_flavor"] = self._get_sql_flavor_from_value(updated_connection["sql_flavor_code"]).flavor
119123

@@ -204,6 +208,8 @@ def _sanitize_connection_input(self, connection: dict) -> dict:
204208
sanitized_value = value
205209
if isinstance(value, str) and key in self.trim_fields:
206210
sanitized_value = value.strip()
211+
if isinstance(value, str) and key in self.encrypted_fields:
212+
sanitized_value = value if value != "" else None
207213
sanitized_connection_input[key] = sanitized_value
208214
return sanitized_connection_input
209215

0 commit comments

Comments
 (0)