Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit 759b5e9

Browse files
committed
add validation check on unique constraint on different index kinds in client
1 parent 4e44a9b commit 759b5e9

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

lib/cipherstash/client.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def collections
145145
#
146146
# @raise [CipherStash::Client::Error::DecryptionFailure] if there was a problem decrypting the naming key.
147147
#
148+
# @raise [CipherStash::Client::Error::InvalidSchemaError] if there was a problem with the format of the schema.
149+
#
148150
def create_collection(name, schema)
149151
@metrics.measure_client_call("create_collection") do
150152
metadata = {
@@ -153,6 +155,10 @@ def create_collection(name, schema)
153155
}
154156

155157
indexes = schema.fetch("indexes", {}).map do |idx_name, idx_settings|
158+
if Index.invalid_unique_constraint?(idx_settings["unique"], idx_settings["kind"])
159+
raise CipherStash::Client::Error::InvalidSchemaError, "Unique constraint not allowed on type #{idx_settings["kind"].inspect}"
160+
end
161+
156162
# New match, dynamic-match, and field-dynamic-match indexes should use filter indexes.
157163
# ORE match indexes require specifically using a *-ore-match index.
158164
idx_settings["kind"] = case idx_settings["kind"]

0 commit comments

Comments
 (0)