Skip to content

Commit df7e13b

Browse files
committed
Allow using camelCase and snake_case for encryption methods
1 parent f3bfcbc commit df7e13b

4 files changed

Lines changed: 78 additions & 9 deletions

File tree

rust/agama-lib/share/storage.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@
886886
},
887887
"encryptionSwap": {
888888
"description": "Swap encryptions.",
889-
"enum": ["protected_swap", "secure_swap", "random_swap"]
889+
"enum": ["protected_swap", "secure_swap", "random_swap", "protectedSwap", "secureSwap", "randomSwap"]
890890
},
891891
"encryptionPassword": {
892892
"description": "Password to use when creating a new encryption device.",

service/lib/agama/storage/config_conversions/from_json_conversions/encryption.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ def swap_encryption_conversions
130130
return {} unless encryption_json.is_a?(String)
131131

132132
# TODO: Report issue if the schema admits an unknown method.
133-
method = Y2Storage::EncryptionMethod.find(encryption_json.to_sym)
133+
# Normalize camelCase to snake_case (y2storage uses "random_swap", "tmp_fde", etc.).
134+
normalized = encryption_json.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
135+
method = Y2Storage::EncryptionMethod.find(normalized.to_sym)
134136
return {} unless method
135137

136138
{

service/test/agama/storage/config_conversions/from_json_conversions/examples.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,72 @@
248248
expect(encryption.label).to be_nil
249249
end
250250
end
251+
252+
context "if 'encryption' is 'random_swap' (snake_case)" do
253+
let(:encryption) { "random_swap" }
254+
255+
it "sets #encryption to the expected value" do
256+
config = subject.convert
257+
encryption = config.encryption
258+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
259+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::RANDOM_SWAP)
260+
end
261+
end
262+
263+
context "if 'encryption' is 'randomSwap' (camelCase)" do
264+
let(:encryption) { "randomSwap" }
265+
266+
it "sets #encryption to the expected value" do
267+
config = subject.convert
268+
encryption = config.encryption
269+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
270+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::RANDOM_SWAP)
271+
end
272+
end
273+
274+
context "if 'encryption' is 'protected_swap' (snake_case)" do
275+
let(:encryption) { "protected_swap" }
276+
277+
it "sets #encryption to the expected value" do
278+
config = subject.convert
279+
encryption = config.encryption
280+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
281+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::PROTECTED_SWAP)
282+
end
283+
end
284+
285+
context "if 'encryption' is 'protectedSwap' (camelCase)" do
286+
let(:encryption) { "protectedSwap" }
287+
288+
it "sets #encryption to the expected value" do
289+
config = subject.convert
290+
encryption = config.encryption
291+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
292+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::PROTECTED_SWAP)
293+
end
294+
end
295+
296+
context "if 'encryption' is 'secure_swap' (snake_case)" do
297+
let(:encryption) { "secure_swap" }
298+
299+
it "sets #encryption to the expected value" do
300+
config = subject.convert
301+
encryption = config.encryption
302+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
303+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::SECURE_SWAP)
304+
end
305+
end
306+
307+
context "if 'encryption' is 'secureSwap' (camelCase)" do
308+
let(:encryption) { "secureSwap" }
309+
310+
it "sets #encryption to the expected value" do
311+
config = subject.convert
312+
encryption = config.encryption
313+
expect(encryption).to be_a(Agama::Storage::Configs::Encryption)
314+
expect(encryption.method).to eq(Y2Storage::EncryptionMethod::SECURE_SWAP)
315+
end
316+
end
251317
end
252318
end
253319

web/src/openapi/config/storage.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ export type SearchMax = number;
4343
* How to handle the section if the device is not found.
4444
*/
4545
export type SearchActions = "skip" | "error";
46-
export type Encryption =
47-
| EncryptionLuks1
48-
| EncryptionLuks2
49-
| EncryptionPervasiveLuks2
50-
| EncryptionTPM
51-
| EncryptionSwap;
46+
export type Encryption = EncryptionLuks1 | EncryptionLuks2 | EncryptionPervasiveLuks2 | EncryptionTPM | EncryptionSwap;
5247
/**
5348
* Password to use when creating a new encryption device.
5449
*/
@@ -65,7 +60,13 @@ export type EncryptionPbkdFunction = "pbkdf2" | "argon2i" | "argon2id";
6560
/**
6661
* Swap encryptions.
6762
*/
68-
export type EncryptionSwap = "protected_swap" | "secure_swap" | "random_swap";
63+
export type EncryptionSwap =
64+
| "protected_swap"
65+
| "secure_swap"
66+
| "random_swap"
67+
| "protectedSwap"
68+
| "secureSwap"
69+
| "randomSwap";
6970
export type FilesystemType = FilesystemTypeAny | FilesystemTypeBtrfs;
7071
export type FilesystemTypeAny =
7172
| "bcachefs"

0 commit comments

Comments
 (0)