/
SecretValue.Codeunit.al
84 lines (71 loc) · 2.59 KB
/
SecretValue.Codeunit.al
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
codeunit 60250 SecretValueAJK
{
Access = Internal;
var
IsolatedStorageKeyTxt: Label '6c33fba1-ae4b-40b9-b805-ee04f6f5be87';
SecretValueTooLongErr: Label 'Length of secret value may not exceed 215 characters';
NoSecretValueFoundErr: Label 'Could not find the secret value.';
ExecutionContextErr: Label 'This function can ony be called during installation or upgrade.';
[NonDebuggable]
procedure ImportSecretValue()
var
SecretValue: Record SecretValueAJK;
begin
if not (GetCurrentModuleExecutionContext() in [ExecutionContext::Install, ExecutionContext::Upgrade]) then
Error(ExecutionContextErr);
SecretValue.DeleteAll();
NavApp.LoadPackageData(Database::SecretValueAJK);
MoveSecretValueToIsolatedStorage();
end;
[NonDebuggable]
local procedure MoveSecretValueToIsolatedStorage()
var
SecretValue: Record SecretValueAJK;
SecretValueText: Text;
begin
if not SecretValue.FindFirst() then
exit;
SecretValueText := SecretValue.GetSecretTextValue();
if SecretValueText = '' then
exit;
StoreSecretValueInIsolatedStorage(SecretValueText);
SecretValue.DeleteAll();
end;
[NonDebuggable]
local procedure StoreSecretValueInIsolatedStorage(SecretValue: Text)
begin
if StrLen(SecretValue) > 215 then
Error(SecretValueTooLongErr);
if IsolatedStorage.Contains(IsolatedStorageKeyTxt, DataScope::Module) then
IsolatedStorage.Delete(IsolatedStorageKeyTxt, DataScope::Module);
if not EncryptionEnabled() then
IsolatedStorage.Set(IsolatedStorageKeyTxt, SecretValue, DataScope::Module)
else
IsolatedStorage.SetEncrypted(IsolatedStorageKeyTxt, SecretValue, DataScope::Module);
end;
[NonDebuggable]
procedure GetSecretValueFromIsolatedStorage() SecretValue: Text
begin
if not IsolatedStorage.Get(IsolatedStorageKeyTxt, DataScope::Module, SecretValue) then
Error(NoSecretValueFoundErr);
end;
[NonDebuggable]
procedure SetSecretValue(SecretValue: Text[215])
begin
StoreSecretValueInIsolatedStorage(SecretValue);
end;
[NonDebuggable]
procedure PrepareSecretValueTableForExport()
var
SecretValue: Record SecretValueAJK;
begin
SecretValue.SetSecretTextValue(GetSecretValueFromIsolatedStorage());
end;
[NonDebuggable]
procedure RemoveSecretValueTableData()
var
SecretValue: Record SecretValueAJK;
begin
SecretValue.DeleteAll();
end;
}