summaryrefslogtreecommitdiff
path: root/scripts/rabbitmq.schema
blob: b7663700ccad89d934d77e7e9ace473cf0b7b703 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
% ==============================
% Rabbit app section
% ==============================

%%
%% Network Connectivity
%% ====================
%%

%% By default, RabbitMQ will listen on all interfaces, using
%% the standard (reserved) AMQP port.
%%
%% {tcp_listeners, [5672]},
%% To listen on a specific interface, provide a tuple of {IpAddress, Port}.
%% For example, to listen only on localhost for both IPv4 and IPv6:
%%
%% {tcp_listeners, [{"127.0.0.1", 5672},
%%                  {"::1",       5672}]},

{mapping, "listeners.tcp.$name", "rabbit.tcp_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbit.tcp_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("listeners.tcp", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% SSL listeners are configured in the same fashion as TCP listeners,
%% including the option to control the choice of interface.
%%
%% {ssl_listeners, [5671]},

{mapping, "listeners.ssl.$name", "rabbit.ssl_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbit.ssl_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("listeners.ssl", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% Number of Erlang processes that will accept connections for the TCP
%% and SSL listeners.
%%
%% {num_tcp_acceptors, 10},
%% {num_ssl_acceptors, 1},

{mapping, "num_acceptors.ssl", "rabbit.num_ssl_acceptors", [
    {datatype, integer}
]}.

{mapping, "num_acceptors.tcp", "rabbit.num_tcp_acceptors", [
    {datatype, integer}
]}.


%% Maximum time for AMQP 0-8/0-9/0-9-1 handshake (after socket connection
%% and SSL handshake), in milliseconds.
%%
%% {handshake_timeout, 10000},

{mapping, "handshake_timeout", "rabbit.handshake_timeout", [
    {datatype, integer}
]}.

%% Set to 'true' to perform reverse DNS lookups when accepting a
%% connection. Hostnames will then be shown instead of IP addresses
%% in rabbitmqctl and the management plugin.
%%
%% {reverse_dns_lookups, true},

{mapping, "reverse_dns_lookups", "rabbit.reverse_dns_lookups", [
    {datatype, {enum, [true, false]}}
]}.

{mapping, "erlang.K", "vm_args.+K", [
  {default, "true"},
  {level, advanced}
]}.

%%
%% Security / AAA
%% ==============
%%

%% The default "guest" user is only permitted to access the server
%% via a loopback interface (e.g. localhost).
%% {loopback_users, [<<"guest">>]},
%%
%% Uncomment the following line if you want to allow access to the
%% guest user from anywhere on the network.
%% {loopback_users, []},

{mapping, "loopback_users.$user", "rabbit.loopback_users", [
    {datatype, atom}
]}.

{translation, "rabbit.loopback_users",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("loopback_users", Conf),
    [ list_to_binary(U) || {["loopback_users", U], V} <- Settings, V == true ]
end}.

%% Configuring SSL.
%% See http://www.rabbitmq.com/ssl.html for full documentation.
%%
%% {ssl_options, [{cacertfile,           "/path/to/testca/cacert.pem"},
%%                {certfile,             "/path/to/server/cert.pem"},
%%                {keyfile,              "/path/to/server/key.pem"},
%%                {verify,               verify_peer},
%%                {fail_if_no_peer_cert, false}]},

%% SSL options section ========================================================

{mapping, "ssl_options.verify", "rabbit.ssl_options.verify", [
    {datatype, {enum, [verify_peer, verify_none]}}]}.

{mapping, "ssl_options.fail_if_no_peer_cert", "rabbit.ssl_options.fail_if_no_peer_cert", [
    {datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.cacertfile", "rabbit.ssl_options.cacertfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "ssl_options.certfile", "rabbit.ssl_options.certfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "ssl_options.cacerts.$name", "rabbit.ssl_options.cacerts", 
    [{datatype, string}]}.

{translation, "rabbit.ssl_options.cacerts",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("ssl_options.cacerts", Conf),
    [ list_to_binary(V) || {_, V} <- Settings ]
end}.

{mapping, "ssl_options.cert", "rabbit.ssl_options.cert", 
    [{datatype, string}]}.

{translation, "rabbit.ssl_options.cert",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("ssl_options.cert", Conf))
end}.

{mapping, "ssl_options.client_renegotiation", "rabbit.ssl_options.client_renegotiation", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.crl_check", "rabbit.ssl_options.crl_check", 
    [{datatype, [{enum, [true, false, peer, best_effort]}]}]}.

{mapping, "ssl_options.depth", "rabbit.ssl_options.depth", 
    [{datatype, integer}, {validators, ["byte"]}]}.

{mapping, "ssl_options.dh", "rabbit.ssl_options.dh", 
    [{datatype, string}]}.

{translation, "rabbit.ssl_options.dh",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("ssl_options.dh", Conf))
end}.

{mapping, "ssl_options.dhfile", "rabbit.ssl_options.dhfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "ssl_options.honor_cipher_order", "rabbit.ssl_options.honor_cipher_order", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.key.RSAPrivateKey", "rabbit.ssl_options.key", 
    [{datatype, string}]}.

{mapping, "ssl_options.key.DSAPrivateKey", "rabbit.ssl_options.key", 
    [{datatype, string}]}.

{mapping, "ssl_options.key.PrivateKeyInfo", "rabbit.ssl_options.key", 
    [{datatype, string}]}.

{translation, "rabbit.ssl_options.key",
fun(Conf) ->
    case cuttlefish_variable:filter_by_prefix("ssl_options.key", Conf) of
        [{[_,_,Key], Val}|_] -> {list_to_atom(Key), list_to_binary(Val)};
        _ -> undefined
    end
end}.

{mapping, "ssl_options.keyfile", "rabbit.ssl_options.keyfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "ssl_options.log_alert", "rabbit.ssl_options.log_alert", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.password", "rabbit.ssl_options.password", 
    [{datatype, string}]}.

{mapping, "ssl_options.psk_identity", "rabbit.ssl_options.psk_identity", 
    [{datatype, string}]}.

{mapping, "ssl_options.reuse_sessions", "rabbit.ssl_options.reuse_sessions", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.secure_renegotiate", "rabbit.ssl_options.secure_renegotiate", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "ssl_options.versions.$version", "rabbit.ssl_options.versions", 
    [{datatype, atom}]}.

{translation, "rabbit.ssl_options.versions",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("ssl_options.cacerts", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% ===========================================================================

%% Choose the available SASL mechanism(s) to expose.
%% The two default (built in) mechanisms are 'PLAIN' and
%% 'AMQPLAIN'. Additional mechanisms can be added via
%% plugins.
%%
%% See http://www.rabbitmq.com/authentication.html for more details.
%%
%% {auth_mechanisms, ['PLAIN', 'AMQPLAIN']},

{mapping, "auth_mechanisms.$name", "rabbit.auth_mechanisms", [
    {datatype, atom}]}.

{translation, "rabbit.auth_mechanisms", 
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("auth_mechanisms", Conf),
    [ V || {_, V} <- Settings ]
end}.


%% Select an authentication database to use. RabbitMQ comes bundled
%% with a built-in auth-database, based on mnesia.
%%
%% {auth_backends, [rabbit_auth_backend_internal]},

{translation, "rabbit.auth_backends", 
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("auth_backends", Conf),
    BackendModule = fun
        (internal) -> rabbit_auth_backend_internal;
        (ldap)     -> rabbit_auth_backend_ldap;
        (http)     -> rabbit_auth_backend_http;
        (amqp)     -> rabbit_auth_backend_amqp;
        (dummy)    -> rabbit_auth_backend_dummy;
        (Other) when is_atom(Other) -> Other;
        (_) -> cuttlefish:invalid("Invalid auth backend")
    end,
    AuthBackends = [ {Num, {default, BackendModule(V)}} || {["auth_backends", Num], V} <- Settings ],
    AuthNBackends = [ {Num, {authn, BackendModule(V)}} || {["auth_backends", Num, "authn"], V} <- Settings ],
    AuthZBackends = [ {Num, {authz, BackendModule(V)}} || {["auth_backends", Num, "authz"], V} <- Settings ],
    Backends = lists:foldl(
        fun({NumStr, {Type, V}}, Acc) ->
            Num = case catch list_to_integer(NumStr) of
                N when is_integer(N) -> N;
                Err -> 
                    cuttlefish:invalid(
                        iolist_to_binary(io_lib:format(
                            "Auth backend number should be integer ~p", [Err])))
            end,
            NewVal = case dict:find(Num, Acc) of
                {ok, {AuthN, AuthZ}} ->
                    case {Type, AuthN, AuthZ} of
                        {authn, undefined, _} ->
                            {V, AuthZ};
                        {authz, _, undefined} ->
                            {AuthN, V};
                        _ ->
                            cuttlefish:invalid(
                                iolist_to_binary(
                                    io_lib:format(
                                        "Auth backend already defined for ~pth ~p backend", 
                                        [Num, Type])))
                    end;
                error ->
                    case Type of
                        authn   -> {V, undefined};
                        authz   -> {undefined, V};
                        default -> {V, V}
                    end
            end,
            dict:store(Num, NewVal, Acc)
        end,
        dict:new(),
        AuthBackends ++ AuthNBackends ++ AuthZBackends),
    lists:map(
        fun
            ({Num, {undefined, AuthZ}}) ->
                cuttlefish:warn(
                    io_lib:format(
                        "Auth backend undefined for ~pth authz backend. Using ~p", 
                        [Num, AuthZ])),
                {AuthZ, AuthZ};
            ({Num, {AuthN, undefined}}) ->
                cuttlefish:warn(
                    io_lib:format(
                        "Auth backend undefined for ~pth authn backend. Using ~p", 
                        [Num, AuthN])),
                {AuthN, AuthN};
            ({_Num, {Auth, Auth}})   -> Auth;
            ({_Num, {AuthN, AuthZ}}) -> {AuthN, AuthZ}
        end,
        lists:keysort(1, dict:to_list(Backends)))
end}.

{mapping, "auth_backends.$num", "rabbit.auth_backends", [
    {datatype, atom}
]}.

{mapping, "auth_backends.$num.authn", "rabbit.auth_backends",[
    {datatype, atom}
]}.

{mapping, "auth_backends.$num.authz", "rabbit.auth_backends",[
    {datatype, atom}
]}.

%% This pertains to both the rabbitmq_auth_mechanism_ssl plugin and
%% STOMP ssl_cert_login configurations. See the rabbitmq_stomp
%% configuration section later in this file and the README in
%% https://github.com/rabbitmq/rabbitmq-auth-mechanism-ssl for further
%% details.
%%
%% To use the SSL cert's CN instead of its DN as the username
%%
%% {ssl_cert_login_from, common_name},

{mapping, "ssl_cert_login_from", "rabbit.ssl_cert_login_from", [
    {datatype, {enum, [distinguished_name, common_name]}}
]}.

%% SSL handshake timeout, in milliseconds.
%%
%% {ssl_handshake_timeout, 5000},

{mapping, "ssl_handshake_timeout", "rabbit.ssl_handshake_timeout", [
    {datatype, integer}
]}.

%% Password hashing implementation. Will only affect newly
%% created users. To recalculate hash for an existing user
%% it's necessary to update her password.
%%
%% When importing definitions exported from versions earlier
%% than 3.6.0, it is possible to go back to MD5 (only do this
%% as a temporary measure!) by setting this to rabbit_password_hashing_md5.
%%
%% To use SHA-512, set to rabbit_password_hashing_sha512.
%%
%% {password_hashing_module, rabbit_password_hashing_sha256},

{mapping, "password_hashing_module", "rabbit.password_hashing_module", [
    {datatype, atom}
]}.

%%
%% Default User / VHost
%% ====================
%%

%% On first start RabbitMQ will create a vhost and a user. These
%% config items control what gets created. See
%% http://www.rabbitmq.com/access-control.html for further
%% information about vhosts and access control.
%%
%% {default_vhost,       <<"/">>},
%% {default_user,        <<"guest">>},
%% {default_pass,        <<"guest">>},
%% {default_permissions, [<<".*">>, <<".*">>, <<".*">>]},

{mapping, "default_vhost", "rabbit.default_vhost", [
    {datatype, string}
]}.

{translation, "rabbit.default_vhost",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("default_vhost", Conf))
end}.

{mapping, "default_user", "rabbit.default_user", [
    {datatype, string}
]}.

{translation, "rabbit.default_user",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("default_user", Conf))
end}.

{mapping, "default_pass", "rabbit.default_pass", [
    {datatype, string}
]}.

{translation, "rabbit.default_pass",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("default_pass", Conf))
end}.

{mapping, "default_permissions.configure", "rabbit.default_permissions", [
    {datatype, string}
]}.

{mapping, "default_permissions.read", "rabbit.default_permissions", [
    {datatype, string}
]}.

{mapping, "default_permissions.write", "rabbit.default_permissions", [
    {datatype, string}
]}.

{translation, "rabbit.default_permissions", 
fun(Conf) ->
    Settings  = cuttlefish_variable:filter_by_prefix("default_permissions", Conf),
    Configure = proplists:get_value(["default_permissions", "configure"], Settings),
    Read      = proplists:get_value(["default_permissions", "read"], Settings),
    Write     = proplists:get_value(["default_permissions", "write"], Settings),
    [list_to_binary(Configure), list_to_binary(Read), list_to_binary(Write)]
end}.

%% Tags for default user
%%
%% For more details about tags, see the documentation for the
%% Management Plugin at http://www.rabbitmq.com/management.html.
%%
%% {default_user_tags, [administrator]},

{mapping, "default_user_tags.$tag", "rabbit.default_user_tags", 
    [{datatype, {enum, [true, false]}}]}.

{translation, "rabbit.default_user_tags",
fun(Conf) ->
    Settings  = cuttlefish_variable:filter_by_prefix("default_user_tags", Conf),
    [ list_to_atom(Key) || {[_,Key], Val} <- Settings, Val == true ]
end}.

%%
%% Additional network and protocol related configuration
%% =====================================================
%%

%% Set the default AMQP heartbeat delay (in seconds).
%%
%% {heartbeat, 600},

{mapping, "heartbeat", "rabbit.heartbeat", [{datatype, integer}]}.

%% Set the max permissible size of an AMQP frame (in bytes).
%%
%% {frame_max, 131072},

{mapping, "frame_max", "rabbit.frame_max", [{datatype, bytesize}]}.

%% Set the max frame size the server will accept before connection
%% tuning occurs
%%
%% {initial_frame_max, 4096},

{mapping, "initial_frame_max", "rabbit.initial_frame_max", [{datatype, bytesize}]}.

%% Set the max permissible number of channels per connection.
%% 0 means "no limit".
%%
%% {channel_max, 128},

{mapping, "channel_max", "rabbit.channel_max", [{datatype, integer}]}.

%% Customising Socket Options.
%%
%% See (http://www.erlang.org/doc/man/inet.html#setopts-2) for
%% further documentation.
%%
%% {tcp_listen_options, [{backlog,       128},
%%                       {nodelay,       true},
%%                       {exit_on_close, false}]},

%% TCP listener section ======================================================

{mapping, "tcp_listen_options.backlog", "rabbit.tcp_listen_options.backlog", [
    {datatype, integer}
]}.

{mapping, "tcp_listen_options.nodelay", "rabbit.tcp_listen_options.nodelay", [
    {datatype, {enum, [true, false]}}
]}.

{mapping, "tcp_listen_options.buffer", "rabbit.tcp_listen_options.buffer", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.delay_send", "rabbit.tcp_listen_options.delay_send", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "tcp_listen_options.dontroute", "rabbit.tcp_listen_options.dontroute", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "tcp_listen_options.exit_on_close", "rabbit.tcp_listen_options.exit_on_close", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "tcp_listen_options.fd", "rabbit.tcp_listen_options.fd", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.high_msgq_watermark", "rabbit.tcp_listen_options.high_msgq_watermark", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.high_watermark", "rabbit.tcp_listen_options.high_watermark", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.keepalive", "rabbit.tcp_listen_options.keepalive", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "tcp_listen_options.low_msgq_watermark", "rabbit.tcp_listen_options.low_msgq_watermark", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.low_watermark", "rabbit.tcp_listen_options.low_watermark", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.port", "rabbit.tcp_listen_options.port", 
    [{datatype, integer}, {validators, ["port"]}]}.

{mapping, "tcp_listen_options.priority", "rabbit.tcp_listen_options.priority", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.recbuf", "rabbit.tcp_listen_options.recbuf", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.send_timeout", "rabbit.tcp_listen_options.send_timeout", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.send_timeout_close", "rabbit.tcp_listen_options.send_timeout_close", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "tcp_listen_options.sndbuf", "rabbit.tcp_listen_options.sndbuf", 
    [{datatype, integer}]}.

{mapping, "tcp_listen_options.tos", "rabbit.tcp_listen_options.tos", 
    [{datatype, integer}]}.

%% ==========================================================================

%%
%% Resource Limits & Flow Control
%% ==============================
%%
%% See http://www.rabbitmq.com/memory.html for full details.

%% Memory-based Flow Control threshold.
%%
%% {vm_memory_high_watermark, 0.4},

%% Alternatively, we can set a limit (in bytes) of RAM used by the node.
%%
%% {vm_memory_high_watermark, {absolute, 1073741824}},
%%
%% Or you can set absolute value using memory units (with RabbitMQ 3.6.0+).
%%
%% {vm_memory_high_watermark, {absolute, "1024M"}},
%%
%% Supported units suffixes:
%%
%% kb, KB: kibibytes (2^10 bytes)
%% mb, MB: mebibytes (2^20)
%% gb, GB: gibibytes (2^30)

{mapping, "vm_memory_high_watermark.relative", "rabbit.vm_memory_high_watermark", [
    {datatype, float}]}.

{mapping, "vm_memory_high_watermark.absolute", "rabbit.vm_memory_high_watermark", [
    {datatype, [integer, string]}]}.


{translation, "rabbit.vm_memory_high_watermark", 
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("vm_memory_high_watermark", Conf),
    Absolute = proplists:get_value(["vm_memory_high_watermark", "absolute"], Settings),
    Relative = proplists:get_value(["vm_memory_high_watermark", "relative"], Settings),
    case {Absolute, Relative} of
        {undefined, undefined} -> cuttlefish:invalid("No vm watermark defined");
        {_,         undefined} -> {absolute, Absolute};
        _                      -> Relative
    end
end}.

%% Fraction of the high watermark limit at which queues start to
%% page message out to disc in order to free up memory.
%%
%% Values greater than 0.9 can be dangerous and should be used carefully.
%%
%% {vm_memory_high_watermark_paging_ratio, 0.5},

{mapping, "vm_memory_high_watermark_paging_ratio", 
          "rabbit.vm_memory_high_watermark_paging_ratio", 
          [{datatype, float}, {validators, ["less_than_1"]}]}.

%% Interval (in milliseconds) at which we perform the check of the memory
%% levels against the watermarks.
%%
%% {memory_monitor_interval, 2500},

{mapping, "memory_monitor_interval", "rabbit.memory_monitor_interval", 
    [{datatype, integer}]}.

%% Set disk free limit (in bytes). Once free disk space reaches this
%% lower bound, a disk alarm will be set - see the documentation
%% listed above for more details.
%%
%% {disk_free_limit, 50000000},
%%
%% Or you can set it using memory units (same as in vm_memory_high_watermark)
%% with RabbitMQ 3.6.0+.
%% {disk_free_limit, "50MB"},
%% {disk_free_limit, "50000kB"},
%% {disk_free_limit, "2GB"},

%% Alternatively, we can set a limit relative to total available RAM.
%%
%% Values lower than 1.0 can be dangerous and should be used carefully.
%% {disk_free_limit, {mem_relative, 2.0}},

{mapping, "disk_free_limit.relative", "rabbit.disk_free_limit", [
    {datatype, float}]}.

{mapping, "disk_free_limit.absolute", "rabbit.disk_free_limit", [
    {datatype, [integer, string]}]}.


{translation, "rabbit.disk_free_limit", 
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("disk_free_limit", Conf),
    Absolute = proplists:get_value(["disk_free_limit", "absolute"], Settings),
    Relative = proplists:get_value(["disk_free_limit", "relative"], Settings),
    case {Absolute, Relative} of
        {undefined, undefined} -> cuttlefish:invalid("No disk limit defined");
        {_,         undefined} -> Absolute;
        _                      -> {mem_relative, Relative}
    end
end}.

%%
%% Clustering
%% =====================
%%

%% How to respond to cluster partitions.
%% See http://www.rabbitmq.com/partitions.html for further details.
%%
%% {cluster_partition_handling, ignore},

{mapping, "cluster_partition_handling", "rabbit.cluster_partition_handling", 
    [{datatype, {enum, [ignore, pause_minority, autoheal, pause_if_all_down]}}]}.

{mapping, "cluster_partition_handling.pause_if_all_down.recover", 
          "rabbit.cluster_partition_handling",
          [{datatype, {enum, [ignore, autoheal]}}]}.

{mapping, "cluster_partition_handling.pause_if_all_down.node.$name", 
          "rabbit.cluster_partition_handling",
          [{datatype, atom}]}.

{translation, "rabbit.cluster_partition_handling",
fun(Conf) ->
    case cuttlefish:conf_get("cluster_partition_handling", Conf) of
        pause_if_all_down ->
            PauseIfAllDownNodes = cuttlefish_variable:filter_by_prefix(
                "cluster_partition_handling.pause_if_all_down.node", 
                Conf),
            case PauseIfAllDownNodes of
                [] -> 
                    cuttlefish:invalid("Nodes required for pause_if_all_down");
                _  ->
                    Nodes = [ V || {K,V} <- PauseIfAllDownNodes ],
                    PauseIfAllDownRecover = cuttlefish:conf_get(
                        "cluster_partition_handling.pause_if_all_down.recover",
                        Conf),
                    case PauseIfAllDownRecover of
                        Recover when Recover == ignore; Recover == autoheal ->
                            {pause_if_all_down, Nodes, Recover};
                        Invalid -> 
                            cuttlefish:invalid("Recover strategy required for pause_if_all_down")
                    end
            end;
        Other -> Other
    end
end}.

%% Mirror sync batch size, in messages. Increasing this will speed
%% up syncing but total batch size in bytes must not exceed 2 GiB.
%% Available in RabbitMQ 3.6.0 or later.
%%
%% {mirroring_sync_batch_size, 4096},

{mapping, "mirroring_sync_batch_size", "rabbit.mirroring_sync_batch_size", 
    [{datatype, bytesize}, {validators, ["size_less_than_2G"]}]}.

%% Make clustering happen *automatically* at startup - only applied
%% to nodes that have just been reset or started for the first time.
%% See http://www.rabbitmq.com/clustering.html#auto-config for
%% further details.
%%
%% {cluster_nodes, {['rabbit@my.host.com'], disc}},

{mapping, "cluster_nodes.disc.$node", "rabbit.cluster_nodes", 
    [{datatype, atom}]}.

{mapping, "cluster_nodes.ram.$node", "rabbit.cluster_nodes", 
    [{datatype, atom}]}.

{translation, "rabbit.cluster_nodes",
fun(Conf) ->
    DiskNodes = [ V || {_, V} <- cuttlefish_variable:filter_by_prefix("cluster_nodes.disc", Conf)],
    RamNodes  = [ V || {_, V} <- cuttlefish_variable:filter_by_prefix("cluster_nodes.ram", Conf)],

    case {DiskNodes, RamNodes} of
        {_,  []} -> {DiskNodes, disc};
        {[],  _} -> {RamNodes, ram}
    end
end}.


%% Interval (in milliseconds) at which we send keepalive messages
%% to other cluster members. Note that this is not the same thing
%% as net_ticktime; missed keepalive messages will not cause nodes
%% to be considered down.
%%
%% {cluster_keepalive_interval, 10000},

{mapping, "cluster_keepalive_interval", "rabbit.cluster_keepalive_interval", 
    [{datatype, integer}]}.

%%
%% Statistics Collection
%% =====================
%%

%% Set (internal) statistics collection granularity.
%%
%% {collect_statistics, none},

{mapping, "collect_statistics", "rabbit.collect_statistics", 
    [{datatype, {enum, [none, coarse, fine]}}]}.

%% Statistics collection interval (in milliseconds). Increasing
%% this will reduce the load on management database.
%%
%% {collect_statistics_interval, 5000},

{mapping, "collect_statistics_interval", "rabbit.collect_statistics_interval",
    [{datatype, integer}]}.

%%
%% Misc/Advanced Options
%% =====================
%%
%% NB: Change these only if you understand what you are doing!
%%

%% Explicitly enable/disable hipe compilation.
%%
%% {hipe_compile, true},

{mapping, "hipe_compile", "rabbit.hipe_compile", 
    [{datatype, {enum, [true, false]}}]}.

%% Timeout used when waiting for Mnesia tables in a cluster to
%% become available.
%%
%% {mnesia_table_loading_timeout, 30000},

{mapping, "mnesia_table_loading_timeout", "rabbit.mnesia_table_loading_timeout",
    [{datatype, integer}]}.

%% Size in bytes below which to embed messages in the queue index. See
%% http://www.rabbitmq.com/persistence-conf.html
%%
%% {queue_index_embed_msgs_below, 4096}

{mapping, "queue_index_embed_msgs_below", "rabbit.queue_index_embed_msgs_below",
    [{datatype, bytesize}]}.

%% ----------------------------------------------------------------------------
%% Advanced Erlang Networking/Clustering Options.
%%
%% See http://www.rabbitmq.com/clustering.html for details
%% ----------------------------------------------------------------------------
%% Sets the net_kernel tick time.
%% Please see http://erlang.org/doc/man/kernel_app.html and
%% http://www.rabbitmq.com/nettick.html for further details.
%%
%% {kernel, [{net_ticktime, 60}]},
{mapping, "kernel.net_ticktime", "kernel.net_ticktime", 
    [{datatype, integer}]}.

{mapping, "kernel.inet_dist_listen_min", "kernel.inet_dist_listen_min", 
    [{datatype, integer}]}.

{mapping, "kernel.inet_dist_listen_max", "kernel.inet_dist_listen_max", 
    [{datatype, integer}]}.

%% ----------------------------------------------------------------------------
%% RabbitMQ AMQP 1.0 Support
%%
%% See https://github.com/rabbitmq/rabbitmq-amqp1.0/blob/stable/README.md
%% for details
%% ----------------------------------------------------------------------------

%  {rabbitmq_amqp1_0,[
%% Connections that are not authenticated with SASL will connect as this
%% account. See the README for more information.
%%
%% Please note that setting this will allow clients to connect without
%% authenticating!
%%
%% {default_user, "guest"},
{mapping, "amqp1_0.default_user", "rabbitmq_amqp1_0.default_user", 
    [{datatype, string}]}.
%% Enable protocol strict mode. See the README for more information.
%%
%% {protocol_strict_mode, false}
%   ]},
{mapping, "amqp1_0.protocol_strict_mode", "rabbitmq_amqp1_0.protocol_strict_mode", 
    [{datatype, {enum, [true, false]}}]}.


% ==========================
% Lager section
% ==========================

{mapping, "log.dir", "lager.log_root", [
    {datatype, string},
    {validators, ["dir_writable"]}]}.

{mapping, "log.console", "lager.handlers", [
    {datatype, {enum, [true, false]}}
]}.

{mapping, "log.syslog", "lager.handlers", [
    {datatype, {enum, [true, false]}}
]}.
{mapping, "log.file", "lager.handlers", [
    {datatype, [{enum, [false]}, string]}
]}.

{mapping, "log.file.level", "lager.handlers", [
    {datatype, {enum, [debug, info, warning, error]}}
]}.
{mapping, "log.$handler.level", "lager.handlers", [
    {datatype, {enum, [debug, info, warning, error]}}
]}.
{mapping, "log.file.rotation.date", "lager.handlers", [
    {datatype, string}
]}.
{mapping, "log.file.rotation.size", "lager.handlers", [
    {datatype, integer}
]}.
{mapping, "log.file.rotation.count", "lager.handlers", [
    {datatype, integer}
]}.

{mapping, "log.syslog.identity", "lager.handlers", [
    {datatype, string}
]}.
{mapping, "log.syslog.facility", "lager.handlers", [
    {datatype, atom}
]}.

{translation, "lager.handlers",
fun(Conf) ->
    ConsoleHandler = case cuttlefish:conf_get("log.console", Conf, false) of
        true  ->
            ConsoleLevel = cuttlefish:conf_get("log.console.level", Conf, info),
            [{lager_console_backend, ConsoleLevel}];
        false -> []
    end,
    FileHandler = case cuttlefish:conf_get("log.file", Conf, false) of
        false -> [];
        File  -> 
            FileLevel = cuttlefish:conf_get("log.file.level", Conf, info),
            RotationDate  = cuttlefish:conf_get("log.file.rotation.date", Conf, ""),
            RotationSize  = cuttlefish:conf_get("log.file.rotation.size", Conf, 0),
            RotationCount = cuttlefish:conf_get("log.file.rotation.count", Conf, 10),
            [{lager_file_backend, [{file, File}, 
                                   {level, FileLevel}, 
                                   {date, RotationDate}, 
                                   {size, RotationSize}, 
                                   {count, RotationCount}]}]
    end,
    SyslogHandler = case cuttlefish:conf_get("log.syslog", Conf, false) of
        false -> [];
        true  ->
            SyslogLevel = cuttlefish:conf_get("log.syslog.level", Conf, info),
            Identity = cuttlefish:conf_get("log.syslog.identity", Conf),
            Facility = cuttlefish:conf_get("log.syslog.facility", Conf),
            [{lager_syslog_backend, [Identity, Facility, SyslogLevel]}]
    end,
    case ConsoleHandler ++ FileHandler ++ SyslogHandler of
        []    -> undefined;
        Other -> Other
    end
end}.


% ===============================
% Validators
% ===============================

{validator, "size_less_than_2G", "Byte size should be less than 2G and greater than 0",
fun(Size) when is_integer(Size) ->
    Size > 0 andalso Size < 2147483648
end}.

{validator, "less_than_1", "Flooat is not beetween 0 and 1",
fun(Float) when is_float(Float) ->
    Float > 0 andalso Float < 1
end}.

{validator, "port", "Invalid port number",
fun(Port) when is_integer(Port) ->
    Port > 0 andalso Port < 65535
end}.

{validator, "byte", "Integer is not 0<i<255",
fun(Int) when is_integer(Int) ->
    Int > 0 andalso Int < 255
end}.

{validator, "dir_writable", "Cannot create file in dir",
fun(Dir) ->
    TestFile = filename:join(Dir, "test_file"),
    file:delete(TestFile),
    Res = ok == file:write_file(TestFile, <<"test">>),
    file:delete(TestFile),
    Res
end}.

{validator, "file_accessible", "file doesnt exist",
fun(File) ->
    ReadFile = file:read_file_info(File),
    element(1, ReadFile) == ok
end}.
%% ----------------------------------------------------------------------------
%% RabbitMQ LDAP Plugin
%%
%% See http://www.rabbitmq.com/ldap.html for details.
%%
%% ----------------------------------------------------------------------------

%  {rabbitmq_auth_backend_ldap,
%   [
%%
%% Connecting to the LDAP server(s)
%% ================================
%%

%% Specify servers to bind to. You *must* set this in order for the plugin
%% to work properly.
%%
%% {servers, ["your-server-name-goes-here"]},

{mapping, "ldap.servers.$server", "rabbitmq_auth_backend_ldap.servers", 
    [{datatype, string}]}.

{translation, "rabbitmq_auth_backend_ldap.servers",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("ldap.servers", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% Connect to the LDAP server using SSL
%%
%% {use_ssl, false},

{mapping, "ldap.use_ssl", "rabbitmq_auth_backend_ldap.use_ssl", 
    [{datatype, {enum, [true, false]}}]}.

%% Specify the LDAP port to connect to
%%
%% {port, 389},

{mapping, "ldap.port", "rabbitmq_auth_backend_ldap.port", 
    [{datatype, integer}]}.

%% LDAP connection timeout, in milliseconds or 'infinity'
%%
%% {timeout, infinity},

{mapping, "ldap.timeout", "rabbitmq_auth_backend_ldap.timeout", 
    [{datatype, [integer, {atom, infinity}]}]}.

%% Enable logging of LDAP queries.
%% One of
%%   - false (no logging is performed)
%%   - true (verbose logging of the logic used by the plugin)
%%   - network (as true, but additionally logs LDAP network traffic)
%%
%% Defaults to false.
%%
%% {log, false},

{mapping, "ldap.log", "rabbitmq_auth_backend_ldap.log", 
    [{datatype, {enum, [true, false, network]}}]}.

%%
%% Authentication
%% ==============
%%

%% Pattern to convert the username given through AMQP to a DN before
%% binding
%%
%% {user_dn_pattern, "cn=${username},ou=People,dc=example,dc=com"},

{mapping, "ldap.user_dn_pattern", "rabbitmq_auth_backend_ldap.user_dn_pattern", 
    [{datatype, string}]}.

%% Alternatively, you can convert a username to a Distinguished
%% Name via an LDAP lookup after binding. See the documentation for
%% full details.

%% When converting a username to a dn via a lookup, set these to
%% the name of the attribute that represents the user name, and the
%% base DN for the lookup query.
%%
%% {dn_lookup_attribute,   "userPrincipalName"},
%% {dn_lookup_base,        "DC=gopivotal,DC=com"},

{mapping, "ldap.dn_lookup_attribute", "rabbitmq_auth_backend_ldap.dn_lookup_attribute", 
    [{datatype, string}]}.

{mapping, "ldap.dn_lookup_base", "rabbitmq_auth_backend_ldap.dn_lookup_base", 
    [{datatype, string}]}.

%% Controls how to bind for authorisation queries and also to
%% retrieve the details of users logging in without presenting a
%% password (e.g., SASL EXTERNAL).
%% One of
%%  - as_user (to bind as the authenticated user - requires a password)
%%  - anon    (to bind anonymously)
%%  - {UserDN, Password} (to bind with a specified user name and password)
%%
%% Defaults to 'as_user'.
%%
%% {other_bind, as_user},

{mapping, "ldap.other_bind", "rabbitmq_auth_backend_ldap.other_bind", 
    [{datatype, {enum, [as_user, anon]}}]}.

{mapping, "ldap.other_bind.user_dn", "rabbitmq_auth_backend_ldap.other_bind", 
    [{datatype, string}]}.

{mapping, "ldap.other_bind.password", "rabbitmq_auth_backend_ldap.other_bind", 
    [{datatype, string}]}.

{translation, "rabbitmq_auth_backend_ldap.other_bind",
fun(Conf) ->
    case cuttlefish:conf_get("ldap.other_bind", Conf) of
        as_user -> as_user;
        anon    -> anon;
        _       ->
            User = cuttlefish:conf_get("ldap.other_bind.user_dn", Conf),
            Pass = cuttlefish:conf_get("ldap.other_bind.password", Conf),
            case {User, Pass} of
                {undefined, _} -> as_user;
                {_, undefined} -> as_user;
                _              -> {User, Pass}
            end
    end                    
end}.

%%
%% Authorisation
%% =============
%%

%% The LDAP plugin can perform a variety of queries against your
%% LDAP server to determine questions of authorisation. See
%% http://www.rabbitmq.com/ldap.html#authorisation for more
%% information.

%% Set the query to use when determining vhost access
%%
%% {vhost_access_query, {in_group,
%%                       "ou=${vhost}-users,ou=vhosts,dc=example,dc=com"}},

%% Set the query to use when determining resource (e.g., queue) access
%%
%% {resource_access_query, {constant, true}},

%% Set queries to determine which tags a user has
%%
%% {tag_queries, []}
%   ]},
 % %% ----------------------------------------------------------------------------
 % %% RabbitMQ Management Plugin
 % %%
 % %% See http://www.rabbitmq.com/management.html for details
 % %% ----------------------------------------------------------------------------

 % {rabbitmq_management,
  % [%% Pre-Load schema definitions from the following JSON file. See
%% http://www.rabbitmq.com/management.html#load-definitions
%%
%% {load_definitions, "/path/to/schema.json"},
{mapping, "management.load_definitions", "rabbitmq_management.load_definitions",
    [{datatype, string},
     {validators, ["file_accessible"]}]}.

%% Log all requests to the management HTTP API to a file.
%%
%% {http_log_dir, "/path/to/access.log"},

{mapping, "management.http_log_dir", "rabbitmq_management.http_log_dir",
    [{datatype, string},
     {validators, ["file_accessible"]}]}.


%% Change the port on which the HTTP listener listens,
%% specifying an interface for the web server to bind to.
%% Also set the listener to use SSL and provide SSL options.
%%
%% {listener, [{port,     12345},
%%             {ip,       "127.0.0.1"},
%%             {ssl,      true},
%%             {ssl_opts, [{cacertfile, "/path/to/cacert.pem"},
%%                         {certfile,   "/path/to/cert.pem"},
%%                         {keyfile,    "/path/to/key.pem"}]}]},

{mapping, "management.listeners.port", "rabbitmq_management.listeners.port",
    [{datatype, integer}]}.

{mapping, "management.listeners.ip", "rabbitmq_management.listeners.ip",
    [{datatype, string},
     {validators, ["is_ip"]}]}.

{mapping, "management.listeners.ssl", "rabbitmq_management.listeners.ssl",
    [{datatype, {enum, [true, false]}}]}.


%% SSL options section ========================================================

{mapping, "management.listeners.ssl_opts.verify", "rabbitmq_management.listeners.ssl_opts.verify", [
    {datatype, {enum, [verify_peer, verify_none]}}]}.

{mapping, "management.listeners.ssl_opts.fail_if_no_peer_cert", "rabbitmq_management.listeners.ssl_opts.fail_if_no_peer_cert", [
    {datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.cacertfile", "rabbitmq_management.listeners.ssl_opts.cacertfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "management.listeners.ssl_opts.certfile", "rabbitmq_management.listeners.ssl_opts.certfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "management.listeners.ssl_opts.cacerts.$name", "rabbitmq_management.listeners.ssl_opts.cacerts", 
    [{datatype, string}]}.

{translation, "rabbitmq_management.listeners.ssl_opts.cacerts",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("management.listeners.ssl_opts.cacerts", Conf),
    [ list_to_binary(V) || {_, V} <- Settings ]
end}.

{mapping, "management.listeners.ssl_opts.cert", "rabbitmq_management.listeners.ssl_opts.cert", 
    [{datatype, string}]}.

{translation, "rabbitmq_management.listeners.ssl_opts.cert",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("management.listeners.ssl_opts.cert", Conf))
end}.

{mapping, "management.listeners.ssl_opts.client_renegotiation", "rabbitmq_management.listeners.ssl_opts.client_renegotiation", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.crl_check", "rabbitmq_management.listeners.ssl_opts.crl_check", 
    [{datatype, [{enum, [true, false, peer, best_effort]}]}]}.

{mapping, "management.listeners.ssl_opts.depth", "rabbitmq_management.listeners.ssl_opts.depth", 
    [{datatype, integer}, {validators, ["byte"]}]}.

{mapping, "management.listeners.ssl_opts.dh", "rabbitmq_management.listeners.ssl_opts.dh", 
    [{datatype, string}]}.

{translation, "rabbitmq_management.listeners.ssl_opts.dh",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("management.listeners.ssl_opts.dh", Conf))
end}.

{mapping, "management.listeners.ssl_opts.dhfile", "rabbitmq_management.listeners.ssl_opts.dhfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "management.listeners.ssl_opts.honor_cipher_order", "rabbitmq_management.listeners.ssl_opts.honor_cipher_order", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.key.RSAPrivateKey", "rabbitmq_management.listeners.ssl_opts.key", 
    [{datatype, string}]}.

{mapping, "management.listeners.ssl_opts.key.DSAPrivateKey", "rabbitmq_management.listeners.ssl_opts.key", 
    [{datatype, string}]}.

{mapping, "management.listeners.ssl_opts.key.PrivateKeyInfo", "rabbitmq_management.listeners.ssl_opts.key", 
    [{datatype, string}]}.

{translation, "rabbitmq_management.listeners.ssl_opts.key",
fun(Conf) ->
    case cuttlefish_variable:filter_by_prefix("management.listeners.ssl_opts.key", Conf) of
        [{[_,_,Key], Val}|_] -> {list_to_atom(Key), list_to_binary(Val)};
        _ -> undefined
    end
end}.

{mapping, "management.listeners.ssl_opts.keyfile", "rabbitmq_management.listeners.ssl_opts.keyfile", 
    [{datatype, string}, {validators, ["file_accessible"]}]}.

{mapping, "management.listeners.ssl_opts.log_alert", "rabbitmq_management.listeners.ssl_opts.log_alert", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.password", "rabbitmq_management.listeners.ssl_opts.password", 
    [{datatype, string}]}.

{mapping, "management.listeners.ssl_opts.psk_identity", "rabbitmq_management.listeners.ssl_opts.psk_identity", 
    [{datatype, string}]}.

{mapping, "management.listeners.ssl_opts.reuse_sessions", "rabbitmq_management.listeners.ssl_opts.reuse_sessions", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.secure_renegotiate", "rabbitmq_management.listeners.ssl_opts.secure_renegotiate", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "management.listeners.ssl_opts.versions.$version", "rabbitmq_management.listeners.ssl_opts.versions", 
    [{datatype, atom}]}.

{translation, "rabbitmq_management.listeners.ssl_opts.versions",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("management.listeners.ssl_opts.cacerts", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% ===========================================================================


%% One of 'basic', 'detailed' or 'none'. See
%% http://www.rabbitmq.com/management.html#fine-stats for more details.
%% {rates_mode, basic},
{mapping, "management.rates_mode", "rabbitmq_management.rates_mode", 
    [{datatype, {enum, [basic, detailed, none]}}]}.

%% Configure how long aggregated data (such as message rates and queue
%% lengths) is retained. Please read the plugin's documentation in
%% http://www.rabbitmq.com/management.html#configuration for more
%% details.
%%
%% {sample_retention_policies,
%%  [{global,   [{60, 5}, {3600, 60}, {86400, 1200}]},
%%   {basic,    [{60, 5}, {3600, 60}]},
%%   {detailed, [{10, 5}]}]}
%   ]},

{mapping, "management.sample_retention_policies.$section.$interval", 
          "rabbitmq_management.sample_retention_policies",
          [{datatype, integer}]}.

{translation, "rabbitmq_management.sample_retention_policies",
fun(Conf) ->
    Global = cuttlefish_variable:filter_by_prefix("management.sample_retention_policies.global", Conf),
    Basic = cuttlefish_variable:filter_by_prefix("management.sample_retention_policies.basic", Conf),
    Detailed = cuttlefish_variable:filter_by_prefix("management.sample_retention_policies.detailed", Conf),
    TranslateKey = fun("minute") -> 60; 
                      ("hour") -> 3600; 
                      ("day") -> 86400;
                      (Other) -> list_to_integer(Other)
                   end,
    TranslatePolicy = fun(Section) ->
        [ {TranslateKey(Key), Val} || {[_,_,_,Key], Val} <- Section ]
    end,
    [{global,   TranslatePolicy(Global)}, 
     {basic,    TranslatePolicy(Basic)}, 
     {detailed, TranslatePolicy(Detailed)}]
end}.

{validator, "file_accessible", "file exists",
fun(File) ->
    ReadFile = file:read_file_info(File),
    element(1, ReadFile) == ok
end}.

{validator, "is_ip", "String is ip",
fun(IpStr) ->
    Res = inet:parse_address(IpStr),
    element(1, Res) == ok
end}.%% ----------------------------------------------------------------------------
%% RabbitMQ MQTT Adapter
%%
%% See https://github.com/rabbitmq/rabbitmq-mqtt/blob/stable/README.md
%% for details
%% ----------------------------------------------------------------------------

%  {rabbitmq_mqtt,
%   [%% Set the default user name and password. Will be used as the default login
%% if a connecting client provides no other login details.
%%
%% Please note that setting this will allow clients to connect without
%% authenticating!
%%
%% {default_user, <<"guest">>},
%% {default_pass, <<"guest">>},

{mapping, "mqtt.default_user", "rabbitmq_mqtt.default_user", [
    {datatype, string}
]}.

{mapping, "mqtt.default_pass", "rabbitmq_mqtt.default_pass", [
    {datatype, string}
]}.

{translation, "rabbitmq_mqtt.default_user",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("mqtt.default_user", Conf))
end}.

{translation, "rabbitmq_mqtt.default_pass",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("mqtt.default_pass", Conf))
end}.

%% Enable anonymous access. If this is set to false, clients MUST provide
%% login information in order to connect. See the default_user/default_pass
%% configuration elements for managing logins without authentication.
%%
%% {allow_anonymous, true},

{mapping, "mqtt.allow_anonymous", "rabbitmq_mqtt.allow_anonymous", 
    [{datatype, {enum, [true, false]}}]}.

%% If you have multiple chosts, specify the one to which the
%% adapter connects.
%%
%% {vhost, <<"/">>},

{mapping, "mqtt.vhost", "rabbitmq_mqtt.vhost", [{datatype, string}]}.

{translation, "rabbitmq_mqtt.vhost",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("mqtt.vhost", Conf))
end}.

%% Specify the exchange to which messages from MQTT clients are published.
%%
%% {exchange, <<"amq.topic">>},

{mapping, "mqtt.exchange", "rabbitmq_mqtt.exchange", [{datatype, string}]}.

{translation, "rabbitmq_mqtt.exchange",
fun(Conf) ->
    list_to_binary(cuttlefish:conf_get("mqtt.exchange", Conf))
end}.

%% Specify TTL (time to live) to control the lifetime of non-clean sessions.
%%
%% {subscription_ttl, 1800000},
{mapping, "mqtt.subscription_ttl", "rabbitmq_mqtt.subscription_ttl", [
    {datatype, integer}
]}.

%% Set the prefetch count (governing the maximum number of unacknowledged
%% messages that will be delivered).
%%
%% {prefetch, 10},
{mapping, "mqtt.prefetch", "rabbitmq_mqtt.prefetch",
    [{datatype, integer}]}.

%% TCP/SSL Configuration (as per the broker configuration).
%%
%% {tcp_listeners, [1883]},
%% {ssl_listeners, []},

{mapping, "mqtt.listeners.tcp.$name", "rabbitmq_mqtt.tcp_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_mqtt.tcp_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("mqtt.listeners.tcp", Conf),
    [ V || {_, V} <- Settings ]
end}.

{mapping, "mqtt.listeners.ssl.$name", "rabbitmq_mqtt.ssl_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_mqtt.ssl_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("mqtt.listeners.ssl", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% Number of Erlang processes that will accept connections for the TCP
%% and SSL listeners.
%%
%% {num_tcp_acceptors, 10},
%% {num_ssl_acceptors, 1},

{mapping, "mqtt.num_acceptors.ssl", "rabbitmq_mqtt.num_ssl_acceptors", [
    {datatype, integer}
]}.

{mapping, "mqtt.num_acceptors.tcp", "rabbitmq_mqtt.num_tcp_acceptors", [
    {datatype, integer}
]}.


%% TCP/Socket options (as per the broker configuration).
%%
%% {tcp_listen_options, [{backlog,   128},
%%                       {nodelay,   true}]}
%   ]},


%% TCP listener section ======================================================

{mapping, "mqtt.tcp_listen_options.backlog", "rabbitmq_mqtt.tcp_listen_options.backlog", [
    {datatype, integer}
]}.

{mapping, "mqtt.tcp_listen_options.nodelay", "rabbitmq_mqtt.tcp_listen_options.nodelay", [
    {datatype, {enum, [true, false]}}
]}.

{mapping, "mqtt.tcp_listen_options.buffer", "rabbitmq_mqtt.tcp_listen_options.buffer", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.delay_send", "rabbitmq_mqtt.tcp_listen_options.delay_send", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "mqtt.tcp_listen_options.dontroute", "rabbitmq_mqtt.tcp_listen_options.dontroute", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "mqtt.tcp_listen_options.exit_on_close", "rabbitmq_mqtt.tcp_listen_options.exit_on_close", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "mqtt.tcp_listen_options.fd", "rabbitmq_mqtt.tcp_listen_options.fd", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.high_msgq_watermark", "rabbitmq_mqtt.tcp_listen_options.high_msgq_watermark", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.high_watermark", "rabbitmq_mqtt.tcp_listen_options.high_watermark", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.keepalive", "rabbitmq_mqtt.tcp_listen_options.keepalive", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "mqtt.tcp_listen_options.low_msgq_watermark", "rabbitmq_mqtt.tcp_listen_options.low_msgq_watermark", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.low_watermark", "rabbitmq_mqtt.tcp_listen_options.low_watermark", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.port", "rabbitmq_mqtt.tcp_listen_options.port", 
    [{datatype, integer}, {validators, ["port"]}]}.

{mapping, "mqtt.tcp_listen_options.priority", "rabbitmq_mqtt.tcp_listen_options.priority", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.recbuf", "rabbitmq_mqtt.tcp_listen_options.recbuf", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.send_timeout", "rabbitmq_mqtt.tcp_listen_options.send_timeout", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.send_timeout_close", "rabbitmq_mqtt.tcp_listen_options.send_timeout_close", 
    [{datatype, {enum, [true, false]}}]}.

{mapping, "mqtt.tcp_listen_options.sndbuf", "rabbitmq_mqtt.tcp_listen_options.sndbuf", 
    [{datatype, integer}]}.

{mapping, "mqtt.tcp_listen_options.tos", "rabbitmq_mqtt.tcp_listen_options.tos", 
    [{datatype, integer}]}.

%% ==========================================================================
%% ----------------------------------------------------------------------------
%% RabbitMQ Stomp Adapter
%%
%% See http://www.rabbitmq.com/stomp.html for details
%% ----------------------------------------------------------------------------

%  {rabbitmq_stomp,
%   [%% Network Configuration - the format is generally the same as for the broker

%% Listen only on localhost (ipv4 & ipv6) on a specific port.
%% {tcp_listeners, [{"127.0.0.1", 61613},
%%                  {"::1",       61613}]},

{mapping, "stomp.listeners.tcp.$name", "rabbitmq_stomp.tcp_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_stomp.tcp_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("stomp.listeners.tcp", Conf),
    [ V || {_, V} <- Settings ]
end}.

{mapping, "stomp.listeners.ssl.$name", "rabbitmq_stomp.ssl_listeners",[
    {datatype, [integer, ip]}
]}.

{translation, "rabbitmq_stomp.ssl_listeners",
fun(Conf) ->
    Settings = cuttlefish_variable:filter_by_prefix("stomp.listeners.ssl", Conf),
    [ V || {_, V} <- Settings ]
end}.

%% Number of Erlang processes that will accept connections for the TCP
%% and SSL listeners.
%%
%% {num_tcp_acceptors, 10},
%% {num_ssl_acceptors, 1},

{mapping, "stomp.num_acceptors.ssl", "rabbitmq_stomp.num_ssl_acceptors", [
    {datatype, integer}
]}.

{mapping, "stomp.num_acceptors.tcp", "rabbitmq_stomp.num_tcp_acceptors", [
    {datatype, integer}
]}.

%% Additional SSL options

%% Extract a name from the client's certificate when using SSL.
%%
%% {ssl_cert_login, true},

{mapping, "stomp.ssl_cert_login", "rabbitmq_stomp.ssl_cert_login", 
    [{datatype, {enum, [true, false]}}]}.

%% Set a default user name and password. This is used as the default login
%% whenever a CONNECT frame omits the login and passcode headers.
%%
%% Please note that setting this will allow clients to connect without
%% authenticating!
%%
%% {default_user, [{login,    "guest"},
%%                 {passcode, "guest"}]},

{mapping, "stomp.default_user", "rabbitmq_stomp.default_user.login", [
    {datatype, string}
]}.

{mapping, "stomp.default_pass", "rabbitmq_stomp.default_user.passcode", [
    {datatype, string}
]}.

%% If a default user is configured, or you have configured use SSL client
%% certificate based authentication, you can choose to allow clients to
%% omit the CONNECT frame entirely. If set to true, the client is
%% automatically connected as the default user or user supplied in the
%% SSL certificate whenever the first frame sent on a session is not a
%% CONNECT frame.
%%
%% {implicit_connect, true}
%   ]},
{mapping, "stomp.implicit_connect", "rabbitmq_stomp.implicit_connect", 
    [{datatype, {enum, [true, false]}}]}.

%% ==========================================================================
%% ----------------------------------------------------------------------------
%% RabbitMQ HTTP Authorization
%%
%% ----------------------------------------------------------------------------

{mapping, "http.user_path", "rabbitmq_auth_backend_http.user_path", 
    [{datatype, string}, {validators, ["uri"]}]}.

{mapping, "http.vhost_path", "rabbitmq_auth_backend_http.vhost_path", 
    [{datatype, string}, {validators, ["uri"]}]}.

{mapping, "http.resource_path", "rabbitmq_auth_backend_http.resource_path", 
    [{datatype, string}, {validators, ["uri"]}]}.