pipebuilder_common 0.2.2

lib for pipebuilder components
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
use crate::{
    api::constants::{
        DISPLAY_ADDRESS_WIDTH, DISPLAY_BUILD_STATUS_WIDTH, DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
        DISPLAY_COUNT_WIDTH, DISPLAY_ID_WIDTH, DISPLAY_MESSAGE_WIDTH, DISPLAY_NAMESPACE_WIDTH,
        DISPLAY_NODE_ARCH_WIDTH, DISPLAY_NODE_OS_WIDTH, DISPLAY_NODE_ROLE_WIDTH,
        DISPLAY_NODE_STATUS_WIDTH, DISPLAY_SIZE_WIDTH, DISPLAY_TIMESTAMP_WIDTH,
        DISPLAY_VERSION_WIDTH,
    },
    grpc::{build, node, repository},
    utils::prost_timestamp_to_datetime_utc,
    BuildStatus, Error, NodeArch, NodeOS, NodeRole, NodeStatus,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::fmt::Display;

pub trait PrintHeader {
    fn print_header();
}

#[derive(Serialize, Deserialize)]
pub struct BuildRequest {
    pub namespace: String,
    // project id
    pub id: String,
    pub manifest_version: u64,
    pub target_platform: Option<String>,
}

impl BuildRequest {
    pub fn set_target_platform(&mut self, target_platform: String) {
        self.target_platform = Some(target_platform)
    }
}

#[derive(Serialize, Deserialize)]
pub struct BuildResponse {
    pub build_version: u64,
}

impl Display for BuildResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "build version: {}", self.build_version)
    }
}

#[derive(Serialize, Deserialize)]
pub struct GetBuildRequest {
    // namespace
    pub namespace: String,
    // project id
    pub id: String,
    // build version
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct PostManifestRequest {
    pub namespace: String,
    pub id: String,
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize)]
pub struct PostManifestResponse {
    pub version: u64,
}

impl Display for PostManifestResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "manifest version: {}", self.version)
    }
}

#[derive(Serialize, Deserialize)]
pub struct GetManifestRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct GetManifestResponse {
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct DeleteManifestRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteManifestResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListManifestMetadataRequest {
    pub namespace: String,
    pub id: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct ManifestMetadata {
    // project id
    pub id: String,
    // manifest version
    pub version: u64,
    pub pulls: u64,
    pub size: usize,
    pub created: DateTime<Utc>,
}

impl Display for ManifestMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{version:<version_width$}{pulls:<pulls_width$}{size:<size_width$}{created:<created_width$}",
            id = self.id,
            version = self.version,
            pulls = self.pulls,
            size = self.size,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
            pulls_width = DISPLAY_COUNT_WIDTH,
            size_width = DISPLAY_SIZE_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for ManifestMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}",
            col0 = "Id",
            col1 = "Version",
            col2 = "Pulls",
            col3 = "Size",
            col4 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
            col2_width = DISPLAY_COUNT_WIDTH,
            col3_width = DISPLAY_SIZE_WIDTH,
            col4_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ListManifestSnapshotRequest {
    pub namespace: String,
}

#[derive(Serialize, Deserialize)]
pub struct ManifestSnapshot {
    pub id: String,
    pub latest_version: u64,
}

impl Display for ManifestSnapshot {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{latest_version:<version_width$}",
            id = self.id,
            latest_version = self.latest_version,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

impl PrintHeader for ManifestSnapshot {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Latest Version",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct DeleteManifestSnapshotRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteManifestSnapshotResponse {}

#[derive(Serialize, Deserialize)]
pub struct PostCatalogSchemaRequest {
    pub namespace: String,
    pub id: String,
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize)]
pub struct PostCatalogSchemaResponse {
    pub version: u64,
}

impl Display for PostCatalogSchemaResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "catalog schema version: {}", self.version)
    }
}

#[derive(Serialize, Deserialize)]
pub struct GetCatalogSchemaRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct GetCatalogSchemaResponse {
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct DeleteCatalogSchemaRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogSchemaResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListCatalogSchemaMetadataRequest {
    pub namespace: String,
    pub id: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct CatalogSchemaMetadata {
    // schema id
    pub id: String,
    // manifest version
    pub version: u64,
    pub pulls: u64,
    pub size: usize,
    pub created: DateTime<Utc>,
}

impl Display for CatalogSchemaMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{version:<version_width$}{pulls:<pulls_width$}{size:<size_width$}{created:<created_width$}",
            id = self.id,
            version = self.version,
            pulls = self.pulls,
            size = self.size,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
            pulls_width = DISPLAY_COUNT_WIDTH,
            size_width = DISPLAY_SIZE_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for CatalogSchemaMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}",
            col0 = "Id",
            col1 = "Version",
            col2 = "Pulls",
            col3 = "Size",
            col4 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
            col2_width = DISPLAY_COUNT_WIDTH,
            col3_width = DISPLAY_SIZE_WIDTH,
            col4_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ListCatalogSchemaSnapshotRequest {
    pub namespace: String,
}

#[derive(Serialize, Deserialize)]
pub struct CatalogSchemaSnapshot {
    pub id: String,
    pub latest_version: u64,
}

impl Display for CatalogSchemaSnapshot {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{latest_version:<version_width$}",
            id = self.id,
            latest_version = self.latest_version,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

impl PrintHeader for CatalogSchemaSnapshot {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Latest Version",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogSchemaSnapshotRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogSchemaSnapshotResponse {}

#[derive(Serialize, Deserialize)]
pub struct PostCatalogsRequest {
    pub namespace: String,
    pub id: String,
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize)]
pub struct PostCatalogsResponse {
    pub version: u64,
}

impl Display for PostCatalogsResponse {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "catalogs version: {}", self.version)
    }
}

#[derive(Serialize, Deserialize)]
pub struct GetCatalogsRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct GetCatalogsResponse {
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct DeleteCatalogsRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogsResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListCatalogsMetadataRequest {
    pub namespace: String,
    pub id: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct CatalogsMetadata {
    // project id
    pub id: String,
    // manifest version
    pub version: u64,
    pub pulls: u64,
    pub size: usize,
    pub created: DateTime<Utc>,
}

impl Display for CatalogsMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{version:<version_width$}{pulls:<pulls_width$}{size:<size_width$}{created:<created_width$}",
            id = self.id,
            version = self.version,
            pulls = self.pulls,
            size = self.size,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
            pulls_width = DISPLAY_COUNT_WIDTH,
            size_width = DISPLAY_SIZE_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for CatalogsMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}",
            col0 = "Id",
            col1 = "Version",
            col2 = "Pulls",
            col3 = "Size",
            col4 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
            col2_width = DISPLAY_COUNT_WIDTH,
            col3_width = DISPLAY_SIZE_WIDTH,
            col4_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ListCatalogsSnapshotRequest {
    pub namespace: String,
}

#[derive(Serialize, Deserialize)]
pub struct CatalogsSnapshot {
    pub id: String,
    pub latest_version: u64,
}

impl Display for CatalogsSnapshot {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{latest_version:<version_width$}",
            id = self.id,
            latest_version = self.latest_version,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

impl PrintHeader for CatalogsSnapshot {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Latest Version",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogsSnapshotRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteCatalogsSnapshotResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListBuildSnapshotRequest {
    pub namespace: String,
}

#[derive(Serialize, Deserialize)]
pub struct BuildSnapshot {
    pub id: String,
    pub latest_version: u64,
}

impl Display for BuildSnapshot {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{latest_version:<version_width$}",
            id = self.id,
            latest_version = self.latest_version,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

impl PrintHeader for BuildSnapshot {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Latest Version",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct DeleteBuildSnapshotRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteBuildSnapshotResponse {}

// version build model for rest api
#[derive(Serialize, Deserialize)]
pub struct BuildMetadata {
    // id
    pub id: String,
    // version
    pub version: u64,
    // target platform
    pub target_platform: String,
    // build status
    pub status: BuildStatus,
    // timestamp
    pub timestamp: DateTime<Utc>,
    // builder id
    pub builder_id: String,
    // builder address
    pub builder_address: String,
    // message
    pub message: Option<String>,
}

impl Display for BuildMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let message = match self.message.as_ref() {
            Some(message) => message.as_str(),
            None => "",
        };
        let target_platform = self.target_platform.to_owned();
        let status = self.status.to_string();
        let timestamp = self.timestamp.to_string();
        writeln!(f,
                "{id:<id_width$}{version:<version_width$}{status:<status_width$}{builder_id:<id_width$}{builder_address:<address_width$}{target_platform:<target_platform_width$}{timestamp:<timestamp_width$}{message:<message_width$}",
                id = self.id,
                version = self.version,
                status = status,
                builder_id = self.builder_id,
                builder_address = self.builder_address,
                target_platform = target_platform,
                timestamp = timestamp,
                message = message,
                id_width = DISPLAY_ID_WIDTH,
                version_width = DISPLAY_VERSION_WIDTH,
                status_width = DISPLAY_BUILD_STATUS_WIDTH,
                target_platform_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
                timestamp_width = DISPLAY_TIMESTAMP_WIDTH,
                address_width = DISPLAY_ADDRESS_WIDTH,
                message_width = DISPLAY_MESSAGE_WIDTH,
                )
    }
}

impl PrintHeader for BuildMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}{col5:<col5_width$}{col6:<col6_width$}{col7:<col7_width$}",
            col0 = "Id",
            col1 = "Version",
            col2 = "Status",
            col3 = "Builder Id",
            col4 = "Builder Address",
            col5 = "Target Platform",
            col6 = "Timestamp",
            col7 = "Message",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
            col2_width = DISPLAY_BUILD_STATUS_WIDTH,
            col3_width = DISPLAY_ID_WIDTH,
            col4_width = DISPLAY_ADDRESS_WIDTH,
            col5_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
            col6_width = DISPLAY_TIMESTAMP_WIDTH,
            col7_width = DISPLAY_MESSAGE_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ListBuildRequest {
    pub namespace: String,
    // project id
    pub id: Option<String>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct CancelBuildRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct CancelBuildResponse {}

#[derive(Serialize, Deserialize, Clone)]
pub struct DeleteBuildRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteBuildResponse {}

#[derive(Serialize, Deserialize, Clone)]
pub struct DeleteAppRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteAppResponse {}

#[derive(Serialize, Deserialize)]
pub struct GetAppRequest {
    pub namespace: String,
    pub id: String,
    pub build_version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct GetAppResponse {
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize, Clone)]
pub struct GetBuildLogRequest {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

#[derive(Serialize, Deserialize)]
pub struct GetBuildLogResponse {
    pub buffer: Vec<u8>,
}

#[derive(Serialize, Deserialize)]
pub struct ListNodeStateRequest {
    pub role: Option<NodeRole>,
}

#[derive(Serialize, Deserialize)]
pub struct NodeState {
    // node id
    pub id: String,
    // node role
    pub role: NodeRole,
    // node arch
    pub arch: NodeArch,
    // node os
    pub os: NodeOS,
    // status
    pub status: NodeStatus,
    // timestamp
    pub timestamp: DateTime<Utc>,
}

impl Display for NodeState {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        let role = self.role.to_string();
        let arch = self.arch.to_string();
        let os = self.os.to_string();
        let status = self.status.to_string();
        let timestamp = self.timestamp.to_string();
        writeln!(f,
                "{id:<id_width$}{role:<role_width$}{arch:<arch_width$}{os:<os_width$}{status:<status_width$}{timestamp:<timestamp_width$}",
                id = self.id,
                role = role,
                status = status,
                arch = arch,
                os = os,
                timestamp = timestamp,
                id_width = DISPLAY_ID_WIDTH,
                role_width = DISPLAY_NODE_ROLE_WIDTH,
                arch_width = DISPLAY_NODE_ARCH_WIDTH,
                os_width = DISPLAY_NODE_OS_WIDTH,
                status_width = DISPLAY_NODE_STATUS_WIDTH,
                timestamp_width = DISPLAY_TIMESTAMP_WIDTH,
                )
    }
}

impl PrintHeader for NodeState {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}{col5:<col5_width$}",
            col0 = "Id",
            col1 = "Role",
            col2 = "Arch",
            col3 = "OS",
            col4 = "Status",
            col5 = "Timestamp",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_NODE_ROLE_WIDTH,
            col2_width = DISPLAY_NODE_ARCH_WIDTH,
            col3_width = DISPLAY_NODE_OS_WIDTH,
            col4_width = DISPLAY_NODE_STATUS_WIDTH,
            col5_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ScanBuildRequest {
    pub builder_id: String,
}

#[derive(Serialize, Deserialize)]
pub struct BuildMetadataKey {
    pub namespace: String,
    pub id: String,
    pub version: u64,
}

impl Display for BuildMetadataKey {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{namespace:<namespace_width$}{id:<id_width$}{version:<version_width$}",
            namespace = self.namespace,
            id = self.id,
            version = self.version,
            namespace_width = DISPLAY_NAMESPACE_WIDTH,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

impl PrintHeader for BuildMetadataKey {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}",
            col0 = "Namespace",
            col1 = "Id",
            col2 = "Version",
            col0_width = DISPLAY_NAMESPACE_WIDTH,
            col1_width = DISPLAY_ID_WIDTH,
            col2_width = DISPLAY_VERSION_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct ScanBuildCacheRequest {
    pub builder_id: String,
}

#[derive(Serialize, Deserialize)]
pub struct BuildCacheMetadata {
    pub namespace: String,
    pub id: String,
    pub target_platform: String,
    pub timestamp: DateTime<Utc>,
}

impl Display for BuildCacheMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{namespace:<namespace_width$}{id:<id_width$}{target_platform:<target_platform_width$}{timestamp:<timestamp_width$}",
            namespace = self.namespace,
            id = self.id,
            target_platform = self.target_platform,
            timestamp = self.timestamp,
            namespace_width = DISPLAY_NAMESPACE_WIDTH,
            id_width = DISPLAY_ID_WIDTH,
            target_platform_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
            timestamp_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for BuildCacheMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}",
            col0 = "Namespace",
            col1 = "Id",
            col2 = "Target Platform",
            col3 = "Timestamp",
            col0_width = DISPLAY_NAMESPACE_WIDTH,
            col1_width = DISPLAY_ID_WIDTH,
            col2_width = DISPLAY_BUILD_TARGET_PLATFORM_WIDTH,
            col3_width = DISPLAY_TIMESTAMP_WIDTH
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct DeleteBuildCacheRequest {
    pub builder_id: String,
    pub namespace: String,
    pub id: String,
    pub target_platform: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteBuildCacheResponse {}

#[derive(Serialize, Deserialize)]
pub struct ActivateNodeRequest {
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct ActivateNodeResponse {}

#[derive(Serialize, Deserialize)]
pub struct DeactivateNodeRequest {
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeactivateNodeResponse {}

#[derive(Serialize, Deserialize)]
pub struct ShutdownNodeRequest {
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct ShutdownNodeResponse {}

// shutdown local api node
#[derive(Serialize, Deserialize)]
pub struct ShutdownRequest {}

#[derive(Serialize, Deserialize)]
pub struct ShutdownResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListAppMetadataRequest {
    pub namespace: String,
    pub id: Option<String>,
}

#[derive(Serialize, Deserialize)]
pub struct AppMetadata {
    // project id
    pub id: String,
    // build version
    pub version: u64,
    pub pulls: u64,
    pub size: usize,
    pub created: DateTime<Utc>,
}

impl Display for AppMetadata {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{version:<version_width$}{pulls:<pulls_width$}{size:<size_width$}{created:<created_width$}",
            id = self.id,
            version = self.version,
            pulls = self.pulls,
            size = self.size,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            version_width = DISPLAY_VERSION_WIDTH,
            pulls_width = DISPLAY_COUNT_WIDTH,
            size_width = DISPLAY_SIZE_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for AppMetadata {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}{col2:<col2_width$}{col3:<col3_width$}{col4:<col4_width$}",
            col0 = "Id",
            col1 = "Version",
            col2 = "Pulls",
            col3 = "Size",
            col4 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_VERSION_WIDTH,
            col2_width = DISPLAY_COUNT_WIDTH,
            col3_width = DISPLAY_SIZE_WIDTH,
            col4_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct UpdateNamespaceRequest {
    // namespace id
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteNamespaceRequest {
    // namespace id
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteNamespaceResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListNamespaceRequest {}

#[derive(Serialize, Deserialize)]
pub struct Namespace {
    pub id: String,
    pub created: DateTime<Utc>,
}

impl Display for Namespace {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{created:<created_width$}",
            id = self.id,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for Namespace {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize)]
pub struct UpdateProjectRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteProjectRequest {
    pub namespace: String,
    pub id: String,
}

#[derive(Serialize, Deserialize)]
pub struct DeleteProjectResponse {}

#[derive(Serialize, Deserialize)]
pub struct ListProjectRequest {
    pub namespace: String,
}

#[derive(Serialize, Deserialize)]
pub struct Project {
    // project id
    pub id: String,
    pub created: DateTime<Utc>,
}

impl Display for Project {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{id:<id_width$}{created:<created_width$}",
            id = self.id,
            created = self.created,
            id_width = DISPLAY_ID_WIDTH,
            created_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

impl PrintHeader for Project {
    fn print_header() {
        println!(
            "{col0:<col0_width$}{col1:<col1_width$}",
            col0 = "Id",
            col1 = "Created",
            col0_width = DISPLAY_ID_WIDTH,
            col1_width = DISPLAY_TIMESTAMP_WIDTH,
        )
    }
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Failure {
    pub error: String,
}

impl Failure {
    pub fn new(error: String) -> Self {
        Failure { error }
    }
}

impl From<BuildRequest> for build::BuildRequest {
    fn from(origin: BuildRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let manifest_version = origin.manifest_version;
        let target_platform = origin.target_platform.unwrap_or_else(|| {
            panic!(
                "target platform undefined for build {}/{}/{}",
                namespace, id, manifest_version
            )
        });
        build::BuildRequest {
            namespace,
            id,
            manifest_version,
            target_platform,
        }
    }
}

impl From<build::BuildResponse> for BuildResponse {
    fn from(origin: build::BuildResponse) -> Self {
        let build_version = origin.version;
        BuildResponse { build_version }
    }
}

impl From<CancelBuildRequest> for build::CancelBuildRequest {
    fn from(origin: CancelBuildRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        build::CancelBuildRequest {
            namespace,
            id,
            build_version: version,
        }
    }
}

impl From<build::CancelBuildResponse> for CancelBuildResponse {
    fn from(_origin: build::CancelBuildResponse) -> Self {
        CancelBuildResponse {}
    }
}

impl From<PostManifestRequest> for repository::PutManifestRequest {
    fn from(origin: PostManifestRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let buffer = origin.buffer;
        repository::PutManifestRequest {
            namespace,
            id,
            buffer,
        }
    }
}

impl From<repository::PutManifestResponse> for PostManifestResponse {
    fn from(origin: repository::PutManifestResponse) -> Self {
        let version = origin.version;
        PostManifestResponse { version }
    }
}

impl From<GetManifestRequest> for repository::GetManifestRequest {
    fn from(origin: GetManifestRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::GetManifestRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::GetManifestResponse> for GetManifestResponse {
    fn from(origin: repository::GetManifestResponse) -> Self {
        let buffer = origin.buffer;
        GetManifestResponse { buffer }
    }
}

impl From<DeleteManifestRequest> for repository::DeleteManifestRequest {
    fn from(origin: DeleteManifestRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::DeleteManifestRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::DeleteManifestResponse> for DeleteManifestResponse {
    fn from(_: repository::DeleteManifestResponse) -> Self {
        DeleteManifestResponse {}
    }
}

impl From<PostCatalogSchemaRequest> for repository::PutCatalogSchemaRequest {
    fn from(origin: PostCatalogSchemaRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let buffer = origin.buffer;
        repository::PutCatalogSchemaRequest {
            namespace,
            id,
            buffer,
        }
    }
}

impl From<repository::PutCatalogSchemaResponse> for PostCatalogSchemaResponse {
    fn from(origin: repository::PutCatalogSchemaResponse) -> Self {
        let version = origin.version;
        PostCatalogSchemaResponse { version }
    }
}

impl From<GetCatalogSchemaRequest> for repository::GetCatalogSchemaRequest {
    fn from(origin: GetCatalogSchemaRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::GetCatalogSchemaRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::GetCatalogSchemaResponse> for GetCatalogSchemaResponse {
    fn from(origin: repository::GetCatalogSchemaResponse) -> Self {
        let buffer = origin.buffer;
        GetCatalogSchemaResponse { buffer }
    }
}

impl From<DeleteCatalogSchemaRequest> for repository::DeleteCatalogSchemaRequest {
    fn from(origin: DeleteCatalogSchemaRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::DeleteCatalogSchemaRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::DeleteCatalogSchemaResponse> for DeleteCatalogSchemaResponse {
    fn from(_: repository::DeleteCatalogSchemaResponse) -> Self {
        DeleteCatalogSchemaResponse {}
    }
}

impl From<PostCatalogsRequest> for repository::PutCatalogsRequest {
    fn from(origin: PostCatalogsRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let buffer = origin.buffer;
        repository::PutCatalogsRequest {
            namespace,
            id,
            buffer,
        }
    }
}

impl From<repository::PutCatalogsResponse> for PostCatalogsResponse {
    fn from(origin: repository::PutCatalogsResponse) -> Self {
        let version = origin.version;
        PostCatalogsResponse { version }
    }
}

impl From<GetCatalogsRequest> for repository::GetCatalogsRequest {
    fn from(origin: GetCatalogsRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::GetCatalogsRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::GetCatalogsResponse> for GetCatalogsResponse {
    fn from(origin: repository::GetCatalogsResponse) -> Self {
        let buffer = origin.buffer;
        GetCatalogsResponse { buffer }
    }
}

impl From<DeleteCatalogsRequest> for repository::DeleteCatalogsRequest {
    fn from(origin: DeleteCatalogsRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::DeleteCatalogsRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::DeleteCatalogsResponse> for DeleteCatalogsResponse {
    fn from(_: repository::DeleteCatalogsResponse) -> Self {
        DeleteCatalogsResponse {}
    }
}

impl From<GetAppRequest> for repository::GetAppRequest {
    fn from(origin: GetAppRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.build_version;
        repository::GetAppRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::GetAppResponse> for GetAppResponse {
    fn from(origin: repository::GetAppResponse) -> Self {
        let buffer = origin.buffer;
        GetAppResponse { buffer }
    }
}

impl From<GetBuildLogRequest> for build::GetBuildLogRequest {
    fn from(origin: GetBuildLogRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let build_version = origin.version;
        build::GetBuildLogRequest {
            namespace,
            id,
            build_version,
        }
    }
}

impl From<build::GetBuildLogResponse> for GetBuildLogResponse {
    fn from(origin: build::GetBuildLogResponse) -> Self {
        let buffer = origin.buffer;
        GetBuildLogResponse { buffer }
    }
}

impl From<build::BuildMetadataKey> for BuildMetadataKey {
    fn from(origin: build::BuildMetadataKey) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        BuildMetadataKey {
            namespace,
            id,
            version,
        }
    }
}

impl From<ScanBuildRequest> for build::ScanBuildRequest {
    fn from(_: ScanBuildRequest) -> Self {
        build::ScanBuildRequest {}
    }
}

impl From<build::BuildCacheMetadata> for BuildCacheMetadata {
    fn from(origin: build::BuildCacheMetadata) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let target_platform = origin.target_platform;
        let timestamp = match origin.timestamp {
            Some(timestamp) => prost_timestamp_to_datetime_utc(timestamp),
            None => Utc::now(),
        };
        BuildCacheMetadata {
            namespace,
            id,
            target_platform,
            timestamp,
        }
    }
}

impl From<ScanBuildCacheRequest> for build::ScanBuildCacheRequest {
    fn from(_: ScanBuildCacheRequest) -> Self {
        build::ScanBuildCacheRequest {}
    }
}

impl From<DeleteBuildCacheRequest> for build::DeleteBuildCacheRequest {
    fn from(origin: DeleteBuildCacheRequest) -> Self {
        build::DeleteBuildCacheRequest {
            namespace: origin.namespace,
            id: origin.id,
            target_platform: origin.target_platform,
        }
    }
}

impl From<build::DeleteBuildCacheResponse> for DeleteBuildCacheResponse {
    fn from(_: build::DeleteBuildCacheResponse) -> Self {
        DeleteBuildCacheResponse {}
    }
}

impl From<node::ActivateResponse> for ActivateNodeResponse {
    fn from(_: node::ActivateResponse) -> Self {
        ActivateNodeResponse {}
    }
}

impl From<node::DeactivateResponse> for DeactivateNodeResponse {
    fn from(_: node::DeactivateResponse) -> Self {
        DeactivateNodeResponse {}
    }
}

impl From<node::ShutdownResponse> for ShutdownNodeResponse {
    fn from(_: node::ShutdownResponse) -> Self {
        ShutdownNodeResponse {}
    }
}

impl From<ShutdownRequest> for node::ShutdownRequest {
    fn from(_: ShutdownRequest) -> Self {
        node::ShutdownRequest {}
    }
}

impl From<node::ShutdownResponse> for ShutdownResponse {
    fn from(_: node::ShutdownResponse) -> Self {
        ShutdownResponse {}
    }
}

impl From<DeleteAppRequest> for repository::DeleteAppRequest {
    fn from(origin: DeleteAppRequest) -> Self {
        let namespace = origin.namespace;
        let id = origin.id;
        let version = origin.version;
        repository::DeleteAppRequest {
            namespace,
            id,
            version,
        }
    }
}

impl From<repository::DeleteAppResponse> for DeleteAppResponse {
    fn from(_: repository::DeleteAppResponse) -> Self {
        DeleteAppResponse {}
    }
}

impl From<Error> for Failure {
    fn from(error: Error) -> Self {
        Failure::new(format!("{}", error))
    }
}