Skip to content

Commit 6cd53d6

Browse files
getsolarisjedrazb
andauthored
Make authentication validation more flexible (#27)
* feat: add tool to retrieve shard information for indices * feat: flexible auth validation * refactor: validation message Co-authored-by: Jedr Blaszyk <[email protected]> --------- Co-authored-by: Jedr Blaszyk <[email protected]>
1 parent 2abcaa6 commit 6cd53d6

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

index.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,28 @@ const ConfigSchema = z
3838
})
3939
.refine(
4040
(data) => {
41-
// Either apiKey is present, or both username and password are present
42-
return !!data.apiKey || (!!data.username && !!data.password);
41+
// If username is provided, password must be provided
42+
if (data.username) {
43+
return !!data.password;
44+
}
45+
46+
// If password is provided, username must be provided
47+
if (data.password) {
48+
return !!data.username;
49+
}
50+
51+
// If apiKey is provided, it's valid
52+
if (data.apiKey) {
53+
return true;
54+
}
55+
56+
// No auth is also valid (for local development)
57+
return true;
4358
},
4459
{
4560
message:
46-
"Either ES_API_KEY or both ES_USERNAME and ES_PASSWORD must be provided",
47-
path: ["apiKey", "username", "password"],
61+
"Either ES_API_KEY or both ES_USERNAME and ES_PASSWORD must be provided, or no auth for local development",
62+
path: ["username", "password"],
4863
}
4964
);
5065

0 commit comments

Comments
 (0)