Compare commits
824
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77f82e18b5 | ||
|
|
ed0b962588 | ||
|
|
7394ce0dd2 | ||
|
|
b01f0c7371 | ||
|
|
5bb5df85e2 | ||
|
|
ae1eab7d52 | ||
|
|
ee72571936 | ||
|
|
e5d2270535 | ||
|
|
2676e50bc1 | ||
|
|
f72d75db5a | ||
|
|
c305d62fd5 | ||
|
|
4e38f39e25 | ||
|
|
8576e735b1 | ||
|
|
9a180cece7 | ||
|
|
039be57dd2 | ||
|
|
3c9df3f2ea | ||
|
|
00fb114bce | ||
|
|
68f1d43f05 | ||
|
|
f71ad84bcf | ||
|
|
99c1b4365a | ||
|
|
18c1c94d85 | ||
|
|
b9f30231ca | ||
|
|
19d87ba475 | ||
|
|
bbfe579fef | ||
|
|
2c1e058767 | ||
|
|
0a686cf874 | ||
|
|
719f121225 | ||
|
|
b00526b153 | ||
|
|
391616f9cf | ||
|
|
ddda0fce2c | ||
|
|
0b4d69bc57 | ||
|
|
e929f89cee | ||
|
|
56f94fd375 | ||
|
|
2d305ce990 | ||
|
|
3296636c25 | ||
|
|
5349af0082 | ||
|
|
ceb07bee89 | ||
|
|
5ce725ba7d | ||
|
|
c652022dab | ||
|
|
d249b65941 | ||
|
|
b2d265dcc6 | ||
|
|
0f061900ee | ||
|
|
cf909e1063 | ||
|
|
c1d5d4cbb4 | ||
|
|
b3a00e0f8c | ||
|
|
06520070bb | ||
|
|
ce874fdc6a | ||
|
|
1e412f58a5 | ||
|
|
b0f40b4db7 | ||
|
|
10035268c4 | ||
|
|
9eb205cb62 | ||
|
|
0ba848a99e | ||
|
|
28909abaa4 | ||
|
|
383560b1c3 | ||
|
|
8585339d12 | ||
|
|
468ab39f41 | ||
|
|
217d92358b | ||
|
|
c32317ef80 | ||
|
|
089f833ce0 | ||
|
|
42b78ded3a | ||
|
|
147e8f5b3b | ||
|
|
e97f4324d5 | ||
|
|
859c5989a1 | ||
|
|
10c50368c5 | ||
|
|
bd925c01a1 | ||
|
|
030c8125eb | ||
|
|
6376279f15 | ||
|
|
5aee0b1c9e | ||
|
|
8d713ff927 | ||
|
|
318e707071 | ||
|
|
423ef1ba2a | ||
|
|
a4f20fe74c | ||
|
|
5cfac09600 | ||
|
|
b436cd2436 | ||
|
|
0019b7b83c | ||
|
|
cc8758c88d | ||
|
|
95e1f70eb5 | ||
|
|
b1a3941f22 | ||
|
|
147852cb37 | ||
|
|
bf7b5f620e | ||
|
|
f4dd5e4a07 | ||
|
|
19017536cc | ||
|
|
86907df91d | ||
|
|
1681e4497c | ||
|
|
35cb4b8177 | ||
|
|
bb4ff4951a | ||
|
|
308a8ea9d0 | ||
|
|
63eb4a4609 | ||
|
|
6ac18619cf | ||
|
|
95a03f54da | ||
|
|
9f4659884d | ||
|
|
a814b5deaf | ||
|
|
65aa514dfa | ||
|
|
d9b81b2956 | ||
|
|
2c4e3ad46b | ||
|
|
bad9b2c737 | ||
|
|
e20dea646f | ||
|
|
cf128de2cf | ||
|
|
07eeb10c06 | ||
|
|
ce0b434152 | ||
|
|
4616d11c20 | ||
|
|
609f32a4ff | ||
|
|
97fe232a9a | ||
|
|
a5a54b4429 | ||
|
|
be874766a7 | ||
|
|
3dac3d392f | ||
|
|
11ebe952ea | ||
|
|
37095dadcc | ||
|
|
41aca25f6c | ||
|
|
bbfe577d2e | ||
|
|
04c5116c9b | ||
|
|
f2d65b6c18 | ||
|
|
3092b6bf14 | ||
|
|
25ea06308f | ||
|
|
54268c4808 | ||
|
|
ba97441b5e | ||
|
|
efc60a8a90 | ||
|
|
a55d9a8d17 | ||
|
|
6801d70e55 | ||
|
|
2e10255b6d | ||
|
|
efa1b396f2 | ||
|
|
aca5c185fe | ||
|
|
690f3f8bb3 | ||
|
|
2c94b8d039 | ||
|
|
456709a2a4 | ||
|
|
479171e7be | ||
|
|
b34cd742cb | ||
|
|
21ab58a03f | ||
|
|
32b7b72193 | ||
|
|
e7d1e97852 | ||
|
|
d6886b33d2 | ||
|
|
487b874a2e | ||
|
|
58f15fca83 | ||
|
|
a56899e13c | ||
|
|
3cb570ff56 | ||
|
|
28d64f224a | ||
|
|
f0d2ad4708 | ||
|
|
6a06daa1de | ||
|
|
8ad22bb694 | ||
|
|
73e614aee9 | ||
|
|
58c42bc91b | ||
|
|
f6df01d750 | ||
|
|
ded36374e8 | ||
|
|
11034f9de1 | ||
|
|
4d498deb35 | ||
|
|
ddfd44cb35 | ||
|
|
ea33d018ca | ||
|
|
21d3ec0089 | ||
|
|
661e19b3b2 | ||
|
|
d6ff970125 | ||
|
|
26680ab77c | ||
|
|
7e4b64d12a | ||
|
|
74032bc16a | ||
|
|
bbdd9638f2 | ||
|
|
e0d2e95984 | ||
|
|
f5b325d9d3 | ||
|
|
6811427b8b | ||
|
|
3548007d5b | ||
|
|
dda9e96887 | ||
|
|
8876275c07 | ||
|
|
b72bd7992c | ||
|
|
a289dae750 | ||
|
|
adaf70c7eb | ||
|
|
e7c9a733c6 | ||
|
|
a472e3d9ed | ||
|
|
7a0a8f54d9 | ||
|
|
e44a1c612d | ||
|
|
17adf0abbb | ||
|
|
0bd92d778e | ||
|
|
3997483ce7 | ||
|
|
3cfa8642fd | ||
|
|
5040e61400 | ||
|
|
3774027cea | ||
|
|
ac55cd1023 | ||
|
|
a8fdcbe7cb | ||
|
|
d4b7b00d73 | ||
|
|
b46cf3c417 | ||
|
|
900235c14b | ||
|
|
1b890948e8 | ||
|
|
fdb36acbb1 | ||
|
|
0d8c4f8aa8 | ||
|
|
a96123be2e | ||
|
|
5378c957f5 | ||
|
|
45ae31533d | ||
|
|
62b110408f | ||
|
|
2fb9e21122 | ||
|
|
646712d5e5 | ||
|
|
b471de8d18 | ||
|
|
b317d0d63d | ||
|
|
dcb911bed9 | ||
|
|
9fad66d824 | ||
|
|
5b7b222371 | ||
|
|
4a3f5899c6 | ||
|
|
770097b64f | ||
|
|
afd408284e | ||
|
|
5dfaa31d67 | ||
|
|
2ed4cd91a7 | ||
|
|
e59e453a14 | ||
|
|
bc47cebd91 | ||
|
|
3ec030eb26 | ||
|
|
58a9cb37ec | ||
|
|
fe58afcd39 | ||
|
|
e701bce12c | ||
|
|
76c3674200 | ||
|
|
6bac84d281 | ||
|
|
0b13328b3a | ||
|
|
0e3d1d50bf | ||
|
|
9f8147bf0e | ||
|
|
f740a6d40b | ||
|
|
206d017878 | ||
|
|
89d742a76d | ||
|
|
7bac47fe04 | ||
|
|
9043bbf545 | ||
|
|
795ed1eb49 | ||
|
|
2508db9c56 | ||
|
|
53f59667f6 | ||
|
|
1ec55a5178 | ||
|
|
6302f888a5 | ||
|
|
33a43e9c6e | ||
|
|
daf5b18e18 | ||
|
|
98af07b69c | ||
|
|
66daa906eb | ||
|
|
c2bf38f647 | ||
|
|
94cf5edf7a | ||
|
|
f17313e7ab | ||
|
|
744dc910d8 | ||
|
|
403bf6bc3a | ||
|
|
e6288fa5f3 | ||
|
|
5ff2208a2d | ||
|
|
e7ef65e655 | ||
|
|
8156961333 | ||
|
|
1e69c2aadd | ||
|
|
7d5e4ed56d | ||
|
|
6bb045a5e6 | ||
|
|
1466ae7b50 | ||
|
|
669cb0a9a4 | ||
|
|
62b12a2770 | ||
|
|
e21762b5a7 | ||
|
|
1274167567 | ||
|
|
12f446e1de | ||
|
|
ba9fc6a307 | ||
|
|
9a5ef7c56d | ||
|
|
1d42ad0df6 | ||
|
|
ffade16689 | ||
|
|
ffa7a67bcf | ||
|
|
1ff6818938 | ||
|
|
bb25267eaa | ||
|
|
1edb08e74f | ||
|
|
7484802005 | ||
|
|
799ded568d | ||
|
|
2552dbf55e | ||
|
|
bf2d21809a | ||
|
|
d4305a5bf9 | ||
|
|
74e889f95b | ||
|
|
7f1da50991 | ||
|
|
59eca9fea8 | ||
|
|
bad0ad9dfb | ||
|
|
0ffee47910 | ||
|
|
370b7483b1 | ||
|
|
5386533bb9 | ||
|
|
f88eb55911 | ||
|
|
176f657e53 | ||
|
|
c27ddd4adf | ||
|
|
fb5dd2588c | ||
|
|
8e1573ec1b | ||
|
|
60286667cc | ||
|
|
9ad4ee9d08 | ||
|
|
c0462e64b2 | ||
|
|
34be0ed96a | ||
|
|
28f44cb9a0 | ||
|
|
8da737f8fd | ||
|
|
1facc1eef5 | ||
|
|
f78f391f8b | ||
|
|
bb65ba8874 | ||
|
|
1ba9435365 | ||
|
|
1e2c5cec0a | ||
|
|
d920e2b34b | ||
|
|
f5f7147b9e | ||
|
|
b7a7b05395 | ||
|
|
59e0e56b21 | ||
|
|
5e6ae2172e | ||
|
|
2178568417 | ||
|
|
16709e4bbc | ||
|
|
56d84e64b1 | ||
|
|
937b34616f | ||
|
|
d8342b68a0 | ||
|
|
fe05b5bb42 | ||
|
|
4724c024c6 | ||
|
|
6c9cdc27bc | ||
|
|
c3ebf165ee | ||
|
|
5124a01ae7 | ||
|
|
8c8e625217 | ||
|
|
b1d4341fcb | ||
|
|
d3773744a6 | ||
|
|
56803d2167 | ||
|
|
6829c3fabc | ||
|
|
7db80b6ad9 | ||
|
|
a5adf14769 | ||
|
|
011c61b254 | ||
|
|
b7dc9cc724 | ||
|
|
9f2fb2b6a9 | ||
|
|
b82f6c60b2 | ||
|
|
01df0ff497 | ||
|
|
c1f61a1e06 | ||
|
|
dae819544b | ||
|
|
1bcbe9019d | ||
|
|
b798764785 | ||
|
|
75e722216a | ||
|
|
39a57a14b8 | ||
|
|
2678c2c8e5 | ||
|
|
97cc12fdc5 | ||
|
|
0440badc41 | ||
|
|
2c6ae7d1f7 | ||
|
|
eb6f304e2e | ||
|
|
d2a2bdb07b | ||
|
|
903a1f202c | ||
|
|
062f28c9cc | ||
|
|
377b71641b | ||
|
|
fb8a20a780 | ||
|
|
d158b9a478 | ||
|
|
54d12e95bd | ||
|
|
87d6cd2d4f | ||
|
|
32311bb933 | ||
|
|
0793ce767b | ||
|
|
eca8310ac8 | ||
|
|
4be483de6d | ||
|
|
67fa4aa7a3 | ||
|
|
d8ace59107 | ||
|
|
d47a2ba53a | ||
|
|
86d5b64ffa | ||
|
|
1a65176cee | ||
|
|
103272612a | ||
|
|
c3c899c365 | ||
|
|
618512cc92 | ||
|
|
21ee2bd432 | ||
|
|
ae05d45173 | ||
|
|
38b8665e9e | ||
|
|
79df949087 | ||
|
|
f551d4b14d | ||
|
|
3adb6c93fd | ||
|
|
f36429be69 | ||
|
|
e561bc770e | ||
|
|
9dcef8825f | ||
|
|
e088bd45a9 | ||
|
|
e2056fb057 | ||
|
|
5a5a9973c3 | ||
|
|
9da0b405db | ||
|
|
38d4108458 | ||
|
|
d973c0a9bb | ||
|
|
acc25b8c50 | ||
|
|
df68f5cf89 | ||
|
|
f198b23e1a | ||
|
|
469f770fe6 | ||
|
|
9d99cfbb7e | ||
|
|
e112429e81 | ||
|
|
44ca181a93 | ||
|
|
01fb7c5a96 | ||
|
|
b8d6623a3d | ||
|
|
0a529d5e64 | ||
|
|
3cf3095253 | ||
|
|
6b8680a2f7 | ||
|
|
1c17ff4c99 | ||
|
|
057470183f | ||
|
|
c04a480dd3 | ||
|
|
c5ea09b74d | ||
|
|
493cd196b7 | ||
|
|
dd6e9c7fcd | ||
|
|
216aae32b9 | ||
|
|
48dd25742a | ||
|
|
c78ff23e77 | ||
|
|
1fbd97aa04 | ||
|
|
e8f049cbb1 | ||
|
|
15ea1125e3 | ||
|
|
09a06e2a75 | ||
|
|
355150151f | ||
|
|
c1193fc29d | ||
|
|
1b992864ee | ||
|
|
a2c253c43b | ||
|
|
72958227ad | ||
|
|
00b68bfa16 | ||
|
|
eebdcdf365 | ||
|
|
c96b42c8f2 | ||
|
|
0ed2956757 | ||
|
|
f8f565c2b6 | ||
|
|
dea3058aa1 | ||
|
|
4b06db8e17 | ||
|
|
5f39522e69 | ||
|
|
bf3924b583 | ||
|
|
84f5724459 | ||
|
|
2c67a3aaa7 | ||
|
|
916e05bc24 | ||
|
|
41926421f9 | ||
|
|
f148db7ae0 | ||
|
|
2ecd33086f | ||
|
|
5e4ab1ec48 | ||
|
|
04407b4199 | ||
|
|
ca1d00741b | ||
|
|
c6d4b63785 | ||
|
|
298dbc50ca | ||
|
|
9cb069e7af | ||
|
|
0fac0e006e | ||
|
|
68a3d5adec | ||
|
|
96cb5cfc44 | ||
|
|
7415469c72 | ||
|
|
8c06f54d8b | ||
|
|
7259e23679 | ||
|
|
43745a9a59 | ||
|
|
052cf01a96 | ||
|
|
c767a3705f | ||
|
|
aefb1db4db | ||
|
|
ada4096d0b | ||
|
|
6050568e66 | ||
|
|
af0e241883 | ||
|
|
5a0d5116f4 | ||
|
|
b005b9a94d | ||
|
|
a7e729fd38 | ||
|
|
36e26c448f | ||
|
|
7130c92043 | ||
|
|
0da22db3af | ||
|
|
6833118338 | ||
|
|
2ff87d64dc | ||
|
|
4bc0aa730d | ||
|
|
b088b02adc | ||
|
|
1843717c57 | ||
|
|
83336dfab3 | ||
|
|
e668f4ad69 | ||
|
|
50f11d8248 | ||
|
|
a06e46677a | ||
|
|
456c6fde8b | ||
|
|
e94ce35608 | ||
|
|
c6db258e7d | ||
|
|
36aa65b791 | ||
|
|
2c3f0e8ccf | ||
|
|
a9fb9426f1 | ||
|
|
2d12a0a310 | ||
|
|
d385122bef | ||
|
|
1c6f4f48ab | ||
|
|
b5768efc96 | ||
|
|
a9cf9103ef | ||
|
|
ada99298b2 | ||
|
|
81453d7c8f | ||
|
|
8d6afee8fc | ||
|
|
f3ff8b1556 | ||
|
|
8a67c25f53 | ||
|
|
381f016f61 | ||
|
|
88896ae495 | ||
|
|
292f2dd960 | ||
|
|
2e9b7e5ddc | ||
|
|
252421354c | ||
|
|
e290a426a1 | ||
|
|
9401450402 | ||
|
|
07fb372398 | ||
|
|
0e97683460 | ||
|
|
5d334f4960 | ||
|
|
045430905a | ||
|
|
d276bd7395 | ||
|
|
dfeadd796a | ||
|
|
107c6dd265 | ||
|
|
aaed62cdd8 | ||
|
|
bf4a825530 | ||
|
|
5fbe8c26ba | ||
|
|
1843bab500 | ||
|
|
40e51ee9af | ||
|
|
feccaabc78 | ||
|
|
54e2edd1be | ||
|
|
47a2f48284 | ||
|
|
c02d5923fb | ||
|
|
f5fec75b0a | ||
|
|
616f1cdb1f | ||
|
|
a0c075b387 | ||
|
|
95f4443e35 | ||
|
|
023e0cacc5 | ||
|
|
663e082161 | ||
|
|
3aebb3362b | ||
|
|
2679713ec4 | ||
|
|
04ba6633f3 | ||
|
|
7afd7beddd | ||
|
|
cb9de43544 | ||
|
|
c1c7561b4e | ||
|
|
2e95a70c98 | ||
|
|
58b7fc447d | ||
|
|
f8d8667238 | ||
|
|
842a816385 | ||
|
|
34a67cb169 | ||
|
|
468fc49d0f | ||
|
|
e9e6c2231f | ||
|
|
58f9fec703 | ||
|
|
6e97f161c8 | ||
|
|
cc1606ff5c | ||
|
|
73727de391 | ||
|
|
14c2e506fa | ||
|
|
7c6499b8a8 | ||
|
|
e6e2b57022 | ||
|
|
fbef5dd7f0 | ||
|
|
55a9d204db | ||
|
|
cca1fd7c82 | ||
|
|
a933ca5ae6 | ||
|
|
eedcbfe138 | ||
|
|
176072dee4 | ||
|
|
0dffa062ea | ||
|
|
a5c59c6190 | ||
|
|
4654d71164 | ||
|
|
c32ab49547 | ||
|
|
2166c63e8f | ||
|
|
8f0ae83bf8 | ||
|
|
e8792efe0a | ||
|
|
f8a489be9d | ||
|
|
7370e6bfd3 | ||
|
|
c24e9c7847 | ||
|
|
e4a840380c | ||
|
|
d0a496826d | ||
|
|
ce7b02a310 | ||
|
|
802f2813e4 | ||
|
|
4b4cab0441 | ||
|
|
b8974e5aed | ||
|
|
c18faa5ff6 | ||
|
|
c4c0547a57 | ||
|
|
97beb1108d | ||
|
|
daa06599e4 | ||
|
|
62d07d5ea1 | ||
|
|
6b0f191643 | ||
|
|
84cbb788e2 | ||
|
|
3aa2b3a755 | ||
|
|
c8f319d94b | ||
|
|
b61ad7a959 | ||
|
|
dbc1f6ada0 | ||
|
|
76d49771d9 | ||
|
|
52a931bfa7 | ||
|
|
a55d40caf7 | ||
|
|
854b4f123f | ||
|
|
9fb024f8ec | ||
|
|
024656ba05 | ||
|
|
c64833c018 | ||
|
|
dc9794cdb0 | ||
|
|
6406549729 | ||
|
|
12f9b4e241 | ||
|
|
b38e144774 | ||
|
|
2770f13a73 | ||
|
|
1192c2d468 | ||
|
|
9051548c80 | ||
|
|
89b53a7e52 | ||
|
|
3ee6095c47 | ||
|
|
a20ab1b3dc | ||
|
|
fd7142e223 | ||
|
|
bec340af65 | ||
|
|
7cde242709 | ||
|
|
66e2075ebd | ||
|
|
791080485b | ||
|
|
bc16bde337 | ||
|
|
ec67a51185 | ||
|
|
631bf7822b | ||
|
|
8b1054cbdb | ||
|
|
e5c92be7db | ||
|
|
583d449e38 | ||
|
|
655258cf74 | ||
|
|
a4a9b8f406 | ||
|
|
2f5bf0c17f | ||
|
|
b5ee028536 | ||
|
|
cf7e0ae050 | ||
|
|
15e52fd862 | ||
|
|
e64706d7ea | ||
|
|
5b0fc3ef94 | ||
|
|
1bf8a56adc | ||
|
|
929062c86b | ||
|
|
710fe47b9b | ||
|
|
a2753bbaab | ||
|
|
1f51635bc7 | ||
|
|
88796ea618 | ||
|
|
fd6846bc88 | ||
|
|
ad254a8fe2 | ||
|
|
dccbca774a | ||
|
|
3cc795610b | ||
|
|
b9b729a3c9 | ||
|
|
e8afb9b135 | ||
|
|
8493f97e04 | ||
|
|
28073441c0 | ||
|
|
42c16b288c | ||
|
|
839e44595c | ||
|
|
81c04723f9 | ||
|
|
3fe6778ee7 | ||
|
|
318569a861 | ||
|
|
27322636ae | ||
|
|
02da50b05e | ||
|
|
be2e66c37c | ||
|
|
ec8687d57e | ||
|
|
d673ca79ea | ||
|
|
1a832ed018 | ||
|
|
d86f52c4bb | ||
|
|
a7dd2810ae | ||
|
|
68ca2bf457 | ||
|
|
f73adff238 | ||
|
|
fa344d5cc0 | ||
|
|
99bfdfed4c | ||
|
|
2f1d44eee2 | ||
|
|
d0e71b13a8 | ||
|
|
cd0c81165b | ||
|
|
e917b9513d | ||
|
|
f85086b153 | ||
|
|
2f08ccf0d5 | ||
|
|
ba5f9ac373 | ||
|
|
698e9ad094 | ||
|
|
efdda726bd | ||
|
|
37e726f100 | ||
|
|
f151b8ab42 | ||
|
|
388ebe127f | ||
|
|
ad4441ef2b | ||
|
|
cdb6b179d3 | ||
|
|
6347b436ff | ||
|
|
1009a897d8 | ||
|
|
b34681d662 | ||
|
|
97715cd215 | ||
|
|
048aab801a | ||
|
|
acd390f261 | ||
|
|
145da32419 | ||
|
|
b6c2a7bb85 | ||
|
|
6f414de058 | ||
|
|
ea96e2b2c8 | ||
|
|
3142b54cc1 | ||
|
|
30a9bb8b05 | ||
|
|
f73e036b80 | ||
|
|
1f7bce1ada | ||
|
|
5bb0e38f94 | ||
|
|
248f8efb36 | ||
|
|
b3e1ac34c7 | ||
|
|
5cd7ff8876 | ||
|
|
2c9a733cae | ||
|
|
01fbd0f5ef | ||
|
|
41e6cc5626 | ||
|
|
a64491e101 | ||
|
|
af1d0ee6da | ||
|
|
55c5b96323 | ||
|
|
85a50dbf91 | ||
|
|
9f24a19aa8 | ||
|
|
f022a57088 | ||
|
|
236b50d6db | ||
|
|
07fffc3bc8 | ||
|
|
f70b7e537c | ||
|
|
68a36788aa | ||
|
|
488b277e36 | ||
|
|
c57671a0d4 | ||
|
|
8c239d16aa | ||
|
|
1529bb83bf | ||
|
|
3cb806d011 | ||
|
|
de65258a7f | ||
|
|
7a276b6111 | ||
|
|
088aa3f04f | ||
|
|
eb7a7206a3 | ||
|
|
c2c2ab4299 | ||
|
|
c12f6e46c3 | ||
|
|
c2f1770cec | ||
|
|
d691fc4c9f | ||
|
|
c307963422 | ||
|
|
3e990e3525 | ||
|
|
73b157e4b1 | ||
|
|
d43c25ffa3 | ||
|
|
de706ef096 | ||
|
|
7838be4a7f | ||
|
|
63d0e213c3 | ||
|
|
6cee296d04 | ||
|
|
1381bf2168 | ||
|
|
351d021b92 | ||
|
|
4e42a9e3eb | ||
|
|
554905ac46 | ||
|
|
cf428f1188 | ||
|
|
69c0129cc7 | ||
|
|
16ff57a0ef | ||
|
|
edd633ff2f | ||
|
|
37a83f23f0 | ||
|
|
11d3bace31 | ||
|
|
624e3c1606 | ||
|
|
3d2dea913f | ||
|
|
a80947bfe8 | ||
|
|
c7570bd54a | ||
|
|
9de421ffd4 | ||
|
|
c32a438045 | ||
|
|
015134b2b7 | ||
|
|
657b6315fc | ||
|
|
95e6947f9c | ||
|
|
537ad9468a | ||
|
|
1c1ee7a5a4 | ||
|
|
cb7f9b6db2 | ||
|
|
603857371c | ||
|
|
48e9183957 | ||
|
|
288e8e3678 | ||
|
|
7b20dc2958 | ||
|
|
add7b7b881 | ||
|
|
afa79f2bd7 | ||
|
|
11771955b3 | ||
|
|
81c4a5ad6e | ||
|
|
811d7e5edb | ||
|
|
01b87ecc02 | ||
|
|
58860ccb15 | ||
|
|
82a6c4f20f | ||
|
|
c29c4a38a6 | ||
|
|
5afc2bdfad | ||
|
|
bf1145af1e | ||
|
|
264d21c65a | ||
|
|
5212e42ded | ||
|
|
40ee1a4ed6 | ||
|
|
b1d8ca83f2 | ||
|
|
78f844a357 | ||
|
|
17f5b7b11c | ||
|
|
2754c91048 | ||
|
|
0e44ad30db | ||
|
|
fc1d65b6e8 | ||
|
|
b0e8574969 | ||
|
|
a9a7b7a225 | ||
|
|
ce9e444740 | ||
|
|
80ae287b02 | ||
|
|
127d84854d | ||
|
|
a59de0d37e | ||
|
|
d2960d67ce | ||
|
|
36d5749991 | ||
|
|
fc64e84829 | ||
|
|
7a6a43046c | ||
|
|
50669cafa6 | ||
|
|
d42880acb1 | ||
|
|
250c0e4e59 | ||
|
|
e19fcb8daf | ||
|
|
abfc6709b0 | ||
|
|
e9d27aef5c | ||
|
|
591858cd1a | ||
|
|
6e2ed46cb4 | ||
|
|
30fd595df6 | ||
|
|
8f7accb135 | ||
|
|
1cff14a109 | ||
|
|
03e876aeaa | ||
|
|
6c0d5e4b65 | ||
|
|
83d81ea590 | ||
|
|
907555c849 | ||
|
|
1b1a5940ab | ||
|
|
aa60a8db1e | ||
|
|
8ca59cdebf | ||
|
|
b5a0640899 | ||
|
|
b5937c68bc | ||
|
|
0d9d42166a | ||
|
|
844139d52d | ||
|
|
d62c1e2418 | ||
|
|
4e8402e46f | ||
|
|
f126341342 | ||
|
|
5619a78ead | ||
|
|
04161f5e19 | ||
|
|
c586b4c06e | ||
|
|
19952de324 | ||
|
|
7c229abb05 | ||
|
|
276e1db70d | ||
|
|
162609d6d0 | ||
|
|
32dfeaaf6b | ||
|
|
cc4ff3a0cc | ||
|
|
0530f5a471 | ||
|
|
e964a37a3f | ||
|
|
606cdd3453 | ||
|
|
1187be0ad2 | ||
|
|
6a61b286b1 | ||
|
|
792c6c1475 | ||
|
|
1a504e6e64 | ||
|
|
8e6b9c8a49 | ||
|
|
8df32e87d6 | ||
|
|
45c6f376c4 | ||
|
|
2a5195f2d2 | ||
|
|
3f0953f9f4 | ||
|
|
dbc09a8bf0 | ||
|
|
42bb4df233 | ||
|
|
d9feb87286 | ||
|
|
661afae983 | ||
|
|
033969a0bf | ||
|
|
5a3ad93ab9 | ||
|
|
dc2a851b54 | ||
|
|
8eae2e3bbf | ||
|
|
4d7b58bac5 | ||
|
|
9c34f6c94b | ||
|
|
d6ffdbc8fb | ||
|
|
84a7b83eda | ||
|
|
de063f9252 | ||
|
|
b01f48836a | ||
|
|
3252573ed2 | ||
|
|
0f31ce23b9 | ||
|
|
869c875967 | ||
|
|
bd00af5a71 | ||
|
|
def1988b92 | ||
|
|
f13defa545 | ||
|
|
a7a9b65237 | ||
|
|
88b984a6e2 | ||
|
|
9aa7712c43 | ||
|
|
0d5acd8820 | ||
|
|
9de0045882 | ||
|
|
cce6451b63 | ||
|
|
a1d6c3d4af | ||
|
|
5488be0c8b | ||
|
|
9cf722a3aa | ||
|
|
096fbbf24a | ||
|
|
af342c3780 | ||
|
|
d7846dab9e | ||
|
|
b44a7642ed | ||
|
|
2cae86c783 | ||
|
|
620455a22c | ||
|
|
dec8d91dbc | ||
|
|
f4f5932d3f | ||
|
|
3902b3b03f | ||
|
|
c7a8815414 | ||
|
|
99bdf20c64 | ||
|
|
3b15bec803 | ||
|
|
c5e56141bd | ||
|
|
220f7c217a | ||
|
|
2f42260f98 | ||
|
|
a11a264933 | ||
|
|
c7537a171f | ||
|
|
65efe40a82 | ||
|
|
f65871e305 | ||
|
|
ab2bce93ea | ||
|
|
7b93343803 | ||
|
|
c579c0b403 | ||
|
|
c595efe440 | ||
|
|
cb1daf1567 | ||
|
|
2be75594d0 | ||
|
|
ed42cdc3a8 | ||
|
|
8e3b5ebc46 | ||
|
|
5d50c9beb9 | ||
|
|
9b6f6cdbb4 | ||
|
|
006c48c51c | ||
|
|
e71b1c80b4 | ||
|
|
548dc0fd99 | ||
|
|
3a7a724753 | ||
|
|
5960c628f3 |
@@ -0,0 +1,26 @@
|
||||
## Community Contribution License
|
||||
All community contributions in this pull request are licensed to the project maintainers
|
||||
under the terms of the [Apache 2 license](https://www.apache.org/licenses/LICENSE-2.0).
|
||||
By creating this pull request I represent that I have the right to license the
|
||||
contributions to the project maintainers under the Apache 2 license.
|
||||
|
||||
## Description
|
||||
|
||||
|
||||
## Motivation and Context
|
||||
|
||||
|
||||
## How to test this PR?
|
||||
|
||||
|
||||
## Types of changes
|
||||
- [ ] Bug fix (non-breaking change which fixes an issue)
|
||||
- [ ] New feature (non-breaking change which adds functionality)
|
||||
- [ ] Optimization (provides speedup with no functional changes)
|
||||
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
|
||||
|
||||
## Checklist:
|
||||
- [ ] Fixes a regression (If yes, please add `commit-id` or `PR #` here)
|
||||
- [ ] Unit tests added/updated
|
||||
- [ ] Internal documentation updated
|
||||
- [ ] Create a documentation update request [here](https://github.com/minio/docs/issues/new?label=doc-change,title=Doc+Updated+Needed+For+PR+github.com%2fminio%2fmc%2fpull%2fNNNNN)
|
||||
@@ -0,0 +1,39 @@
|
||||
name: Crosscompile
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
|
||||
# This ensures that previous jobs for the PR are canceled when the PR is
|
||||
# updated.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Tests with Go ${{ matrix.go-version }} on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.25.x]
|
||||
os: [ubuntu-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
check-latest: true
|
||||
- name: Build on ${{ matrix.os }}
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
GO111MODULE: on
|
||||
run: |
|
||||
sudo sysctl net.ipv6.conf.all.disable_ipv6=0
|
||||
sudo sysctl net.ipv6.conf.default.disable_ipv6=0
|
||||
make crosscompile
|
||||
@@ -3,7 +3,13 @@ name: Go
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- master
|
||||
|
||||
# This ensures that previous jobs for the PR are canceled when the PR is
|
||||
# updated.
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -13,17 +19,17 @@ jobs:
|
||||
GO111MODULE: on
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: [1.17.x]
|
||||
go-version: [1.25.x]
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
steps:
|
||||
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
|
||||
uses: actions/setup-go@v1
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
id: go
|
||||
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v1
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Build on ${{ matrix.os }}
|
||||
if: matrix.os == 'windows-latest'
|
||||
@@ -37,16 +43,24 @@ jobs:
|
||||
go test -v -race --timeout 30m ./...
|
||||
- name: Build on ${{ matrix.os }}
|
||||
if: matrix.os == 'ubuntu-latest'
|
||||
env:
|
||||
ACCESS_KEY: minioadmin
|
||||
SECRET_KEY: minioadmin
|
||||
ENABLE_HTTPS: 1
|
||||
MINIO_CI_CD: 1
|
||||
SERVER_ENDPOINT: localhost:9000
|
||||
MC_TEST_ENABLE_HTTPS: true
|
||||
MC_TEST_SKIP_INSECURE: true
|
||||
MC_TEST_SKIP_BUILD: true
|
||||
run: |
|
||||
wget https://dl.min.io/server/minio/release/linux-amd64/minio && chmod +x minio
|
||||
mkdir -p ~/.minio/certs/ && cp testdata/localhost.crt ~/.minio/certs/public.crt && cp testdata/localhost.key ~/.minio/certs/private.key
|
||||
sudo cp testdata/localhost.crt /usr/local/share/ca-certificates/ && sudo update-ca-certificates
|
||||
./minio server /tmp/test-xl/{1...4}/ & sleep 10
|
||||
export SERVER_ENDPOINT=localhost:9000 ACCESS_KEY=minioadmin SECRET_KEY=minioadmin ENABLE_HTTPS=1
|
||||
make
|
||||
make test-race
|
||||
make verify
|
||||
make crosscompile
|
||||
./functional-tests.sh
|
||||
vetchecks: # Run vet checks against one version.
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
@@ -55,10 +69,11 @@ jobs:
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.17.x
|
||||
go-version: 1.24.x
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Test 386
|
||||
run: GOOS=linux GOARCH=386 go test -short ./...
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# @format
|
||||
|
||||
name: Issue Workflow
|
||||
|
||||
on:
|
||||
issues:
|
||||
types:
|
||||
- opened
|
||||
|
||||
jobs:
|
||||
add-to-project:
|
||||
name: Add issue to project
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/add-to-project@v0.5.0
|
||||
with:
|
||||
project-url: https://github.com/orgs/miniohq/projects/2
|
||||
github-token: ${{ secrets.BOT_PAT }}
|
||||
@@ -0,0 +1,25 @@
|
||||
name: VulnCheck
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
vulncheck:
|
||||
name: Analysis
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.25.x
|
||||
- name: Get official govulncheck
|
||||
run: go install golang.org/x/vuln/cmd/govulncheck@latest
|
||||
shell: bash
|
||||
- name: Run govulncheck
|
||||
run: govulncheck ./...
|
||||
shell: bash
|
||||
@@ -11,3 +11,8 @@ stage/
|
||||
mc
|
||||
.run*
|
||||
.idea/
|
||||
mc.RELEASE*
|
||||
mc.gz
|
||||
.DS_Store
|
||||
.vscode/
|
||||
.bin/
|
||||
|
||||
+37
-37
@@ -1,42 +1,42 @@
|
||||
linters-settings:
|
||||
golint:
|
||||
min-confidence: 0
|
||||
|
||||
misspell:
|
||||
locale: US
|
||||
|
||||
version: "2"
|
||||
linters:
|
||||
disable-all: true
|
||||
default: none
|
||||
enable:
|
||||
- typecheck
|
||||
- goimports
|
||||
- misspell
|
||||
- govet
|
||||
- revive
|
||||
- ineffassign
|
||||
- deadcode
|
||||
- structcheck
|
||||
- gomodguard
|
||||
- gofmt
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- revive
|
||||
- staticcheck
|
||||
- unused
|
||||
- structcheck
|
||||
- varcheck
|
||||
settings:
|
||||
misspell:
|
||||
locale: US
|
||||
exclusions:
|
||||
generated: lax
|
||||
rules:
|
||||
- path: (.+)\.go$
|
||||
text: instead of using struct literal
|
||||
- path: (.+)\.go$
|
||||
text: should have a package comment
|
||||
- path: (.+)\.go$
|
||||
text: error strings should not be capitalized or end with punctuation or a newline
|
||||
- path: (.+)\.go$
|
||||
text: error strings should not end with punctuation or newlines
|
||||
- path: (.+)\.go$
|
||||
text: error strings should not be capitalized
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gofmt
|
||||
- gofumpt
|
||||
|
||||
linters-settings:
|
||||
gofumpt:
|
||||
lang-version: "1.17"
|
||||
|
||||
# Choose whether or not to use the extra rules that are disabled
|
||||
# by default
|
||||
extra-rules: false
|
||||
|
||||
issues:
|
||||
exclude-use-default: false
|
||||
exclude:
|
||||
- instead of using struct literal
|
||||
- should have a package comment
|
||||
- error strings should not be capitalized or end with punctuation or a newline
|
||||
|
||||
service:
|
||||
golangci-lint-version: 1.43.0 # use the fixed version to not introduce new linters unexpectedly
|
||||
- goimports
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ $ cd $GOPATH/src/github.com/minio
|
||||
$ git clone https://github.com/$USER_ID/mc
|
||||
$ cd mc
|
||||
$ make
|
||||
$ mc --help
|
||||
$ ./mc --help
|
||||
```
|
||||
|
||||
### Developer Guidelines
|
||||
|
||||
+11
-16
@@ -1,27 +1,22 @@
|
||||
FROM golang:1.17-alpine as builder
|
||||
FROM golang:1.22-alpine as build
|
||||
|
||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||
|
||||
ENV GOPATH /go
|
||||
ENV CGO_ENABLED 0
|
||||
ENV GO111MODULE on
|
||||
|
||||
RUN \
|
||||
apk add --no-cache git && \
|
||||
git clone https://github.com/minio/mc && cd mc && \
|
||||
go install -v -ldflags "$(go run buildscripts/gen-ldflags.go)"
|
||||
|
||||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
|
||||
RUN apk add -U --no-cache ca-certificates
|
||||
RUN apk add -U curl
|
||||
RUN curl -s -q https://raw.githubusercontent.com/minio/mc/master/LICENSE -o /go/LICENSE
|
||||
RUN curl -s -q https://raw.githubusercontent.com/minio/mc/master/CREDITS -o /go/CREDITS
|
||||
RUN go install -v -ldflags "$(go run buildscripts/gen-ldflags.go)" "github.com/minio/mc@latest"
|
||||
|
||||
ARG TARGETARCH
|
||||
FROM scratch
|
||||
|
||||
COPY --from=builder /go/bin/mc /usr/bin/mc
|
||||
COPY --from=builder /go/mc/CREDITS /licenses/CREDITS
|
||||
COPY --from=builder /go/mc/LICENSE /licenses/LICENSE
|
||||
|
||||
RUN \
|
||||
microdnf update --nodocs && \
|
||||
microdnf install ca-certificates --nodocs && \
|
||||
microdnf clean all
|
||||
COPY --from=build /go/bin/mc /usr/bin/mc
|
||||
COPY --from=build /go/CREDITS /licenses/CREDITS
|
||||
COPY --from=build /go/LICENSE /licenses/LICENSE
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
ENTRYPOINT ["mc"]
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
|
||||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8
|
||||
|
||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||
|
||||
@@ -7,8 +7,8 @@ COPY CREDITS /licenses/CREDITS
|
||||
COPY LICENSE /licenses/LICENSE
|
||||
|
||||
RUN \
|
||||
microdnf update --nodocs && \
|
||||
microdnf install ca-certificates --nodocs && \
|
||||
microdnf update --nodocs --assumeyes && \
|
||||
microdnf install ca-certificates --nodocs --assumeyes && \
|
||||
microdnf clean all
|
||||
|
||||
ENTRYPOINT ["mc"]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest as build
|
||||
|
||||
RUN microdnf update --nodocs --assumeyes && microdnf install ca-certificates --nodocs --assumeyes
|
||||
|
||||
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG RELEASE
|
||||
|
||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||
|
||||
# On RHEL the certificate bundle is located at:
|
||||
# - /etc/pki/tls/certs/ca-bundle.crt (RHEL 6)
|
||||
# - /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem (RHEL 7)
|
||||
COPY --from=build /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/ca-trust/extracted/pem/
|
||||
|
||||
COPY CREDITS /licenses/CREDITS
|
||||
COPY LICENSE /licenses/LICENSE
|
||||
|
||||
ADD https://dl.min.io/client/mc/hotfixes/linux-${TARGETARCH}/archive/mc.${RELEASE} /usr/bin/mc
|
||||
|
||||
RUN chmod +x /usr/bin/mc
|
||||
|
||||
ENTRYPOINT ["mc"]
|
||||
+13
-8
@@ -1,19 +1,24 @@
|
||||
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5
|
||||
FROM registry.access.redhat.com/ubi9/ubi-minimal:latest AS build
|
||||
|
||||
RUN microdnf update --nodocs --assumeyes && microdnf install ca-certificates --nodocs --assumeyes
|
||||
|
||||
FROM registry.access.redhat.com/ubi9/ubi-micro:latest
|
||||
|
||||
ARG TARGETARCH
|
||||
|
||||
ARG RELEASE
|
||||
|
||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||
|
||||
# On RHEL the certificate bundle is located at:
|
||||
# - /etc/pki/tls/certs/ca-bundle.crt (RHEL 6)
|
||||
# - /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem (RHEL 7)
|
||||
COPY --from=build /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/ca-trust/extracted/pem/
|
||||
|
||||
COPY CREDITS /licenses/CREDITS
|
||||
COPY LICENSE /licenses/LICENSE
|
||||
|
||||
RUN \
|
||||
microdnf update --nodocs && \
|
||||
microdnf install curl ca-certificates shadow-utils --nodocs && \
|
||||
microdnf clean all && \
|
||||
curl -s -q https://dl.minio.io/client/mc/release/linux-${TARGETARCH}/archive/mc.${RELEASE} -o /usr/bin/mc && \
|
||||
chmod +x /usr/bin/mc
|
||||
ADD https://dl.minio.io/client/mc/release/linux-${TARGETARCH}/archive/mc.${RELEASE} /usr/bin/mc
|
||||
|
||||
RUN chmod +x /usr/bin/mc
|
||||
|
||||
ENTRYPOINT ["mc"]
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest AS build
|
||||
|
||||
RUN microdnf update --nodocs --assumeyes && microdnf install ca-certificates --nodocs --assumeyes
|
||||
|
||||
FROM registry.access.redhat.com/ubi8/ubi-micro:latest
|
||||
|
||||
ARG TARGETARCH
|
||||
ARG RELEASE
|
||||
|
||||
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||
|
||||
# On RHEL the certificate bundle is located at:
|
||||
# - /etc/pki/tls/certs/ca-bundle.crt (RHEL 6)
|
||||
# - /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem (RHEL 7)
|
||||
COPY --from=build /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem /etc/pki/ca-trust/extracted/pem/
|
||||
|
||||
COPY CREDITS /licenses/CREDITS
|
||||
COPY LICENSE /licenses/LICENSE
|
||||
|
||||
ADD https://dl.minio.io/client/mc/release/linux-${TARGETARCH}/archive/mc.${RELEASE} /usr/bin/mc
|
||||
|
||||
RUN chmod +x /usr/bin/mc
|
||||
|
||||
ENTRYPOINT ["mc"]
|
||||
@@ -2,14 +2,14 @@ PWD := $(shell pwd)
|
||||
GOPATH := $(shell go env GOPATH)
|
||||
LDFLAGS := $(shell go run buildscripts/gen-ldflags.go)
|
||||
|
||||
GOARCH := $(shell go env GOARCH)
|
||||
GOOS := $(shell go env GOOS)
|
||||
|
||||
BUILD_LDFLAGS := '$(LDFLAGS)'
|
||||
TARGET_GOARCH ?= $(shell go env GOARCH)
|
||||
TARGET_GOOS ?= $(shell go env GOOS)
|
||||
|
||||
VERSION ?= $(shell git describe --tags)
|
||||
TAG ?= "minio/mc:$(VERSION)"
|
||||
|
||||
GOLANGCI = $(GOPATH)/bin/golangci-lint
|
||||
|
||||
all: build
|
||||
|
||||
checks:
|
||||
@@ -18,8 +18,7 @@ checks:
|
||||
|
||||
getdeps:
|
||||
@mkdir -p ${GOPATH}/bin
|
||||
@echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.43.0
|
||||
@echo "Installing stringer" && go install -v golang.org/x/tools/cmd/stringer@latest
|
||||
@echo "Installing tools" && go install tool
|
||||
|
||||
crosscompile:
|
||||
@(env bash $(PWD)/buildscripts/cross-compile.sh)
|
||||
@@ -33,9 +32,13 @@ vet:
|
||||
@echo "Running $@"
|
||||
@GO111MODULE=on go vet github.com/minio/mc/...
|
||||
|
||||
lint:
|
||||
lint-fix: getdeps ## runs golangci-lint suite of linters with automatic fixes
|
||||
@echo "Running $@ check"
|
||||
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
|
||||
@$(GOLANGCI) run --build-tags kqueue --timeout=10m --config ./.golangci.yml --fix
|
||||
|
||||
lint: getdeps
|
||||
@echo "Running $@ check"
|
||||
@$(GOLANGCI) run --build-tags kqueue --timeout=10m --config ./.golangci.yml
|
||||
|
||||
# Builds mc, runs the verifiers then runs the tests.
|
||||
check: test
|
||||
@@ -43,7 +46,7 @@ test: verifiers build
|
||||
@echo "Running unit tests"
|
||||
@GO111MODULE=on CGO_ENABLED=0 go test -tags kqueue ./... 1>/dev/null
|
||||
@echo "Running functional tests"
|
||||
@(env bash $(PWD)/functional-tests.sh)
|
||||
@GO111MODULE=on MC_TEST_RUN_FULL_SUITE=true go test -race -v --timeout 20m ./... -run Test_FullSuite
|
||||
|
||||
test-race: verifiers build
|
||||
@echo "Running unit tests under -race"
|
||||
@@ -54,12 +57,35 @@ verify:
|
||||
@echo "Verifying build with race"
|
||||
@GO111MODULE=on CGO_ENABLED=1 go build -race -tags kqueue -trimpath --ldflags "$(LDFLAGS)" -o $(PWD)/mc 1>/dev/null
|
||||
@echo "Running functional tests"
|
||||
@(env bash $(PWD)/functional-tests.sh)
|
||||
@GO111MODULE=on MC_TEST_RUN_FULL_SUITE=true go test -race -v --timeout 20m ./... -run Test_FullSuite
|
||||
|
||||
# Builds mc locally.
|
||||
build: checks
|
||||
@echo "Building mc binary to './mc'"
|
||||
@GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/mc
|
||||
@GO111MODULE=on GOOS=$(TARGET_GOOS) GOARCH=$(TARGET_GOARCH) CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags "$(LDFLAGS)" -o $(PWD)/mc
|
||||
|
||||
hotfix-vars:
|
||||
$(eval LDFLAGS := $(shell MC_RELEASE="RELEASE" MC_HOTFIX="hotfix.$(shell git rev-parse --short HEAD)" go run buildscripts/gen-ldflags.go $(shell git describe --tags --abbrev=0 | \
|
||||
sed 's#RELEASE\.\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)T\([0-9]\+\)-\([0-9]\+\)-\([0-9]\+\)Z#\1-\2-\3T\4:\5:\6Z#')))
|
||||
$(eval VERSION := $(shell git describe --tags --abbrev=0).hotfix.$(shell git rev-parse --short HEAD))
|
||||
$(eval TAG := "minio/mc:$(VERSION)")
|
||||
|
||||
hotfix: hotfix-vars install ## builds mc binary with hotfix tags
|
||||
@mv -f ./mc ./mc.$(VERSION)
|
||||
@minisign -qQSm ./mc.$(VERSION) -s "${CRED_DIR}/minisign.key" < "${CRED_DIR}/minisign-passphrase"
|
||||
@sha256sum < ./mc.$(VERSION) | sed 's, -,mc.$(VERSION),g' > mc.$(VERSION).sha256sum
|
||||
|
||||
hotfix-push: hotfix
|
||||
@scp -q -r mc.$(VERSION)* minio@dl-0.min.io:~/releases/client/mc/hotfixes/$(TARGET_GOOS)-$(TARGET_GOARCH)/archive/
|
||||
@scp -q -r mc.$(VERSION)* minio@dl-1.min.io:~/releases/client/mc/hotfixes/$(TARGET_GOOS)-$(TARGET_GOARCH)/archive/
|
||||
@echo "Published new hotfix binaries at https://dl.min.io/client/mc/hotfixes/$(TARGET_GOOS)-$(TARGET_GOARCH)/archive/mc.$(VERSION)"
|
||||
|
||||
docker-hotfix-push: docker-hotfix
|
||||
@docker push -q $(TAG) && echo "Published new container $(TAG)"
|
||||
|
||||
docker-hotfix: hotfix-push checks ## builds mc docker container with hotfix tags
|
||||
@echo "Building mc docker image '$(TAG)'"
|
||||
@docker build -q --no-cache -t $(TAG) --build-arg RELEASE=$(VERSION) . -f Dockerfile.hotfix
|
||||
|
||||
# Builds MinIO and installs it to $GOPATH/bin.
|
||||
install: build
|
||||
|
||||
@@ -1,40 +1,53 @@
|
||||
# MinIO Client Quickstart Guide
|
||||
[](https://slack.min.io) [](https://goreportcard.com/report/minio/mc) [](https://hub.docker.com/r/minio/mc/) [](https://github.com/minio/mc/blob/master/LICENSE)
|
||||
|
||||
# Documentation
|
||||
- [MC documentation](https://docs.min.io/community/minio-object-store/reference/minio-mc.html)
|
||||
|
||||
MinIO Client (mc) provides a modern alternative to UNIX commands like ls, cat, cp, mirror, diff, find etc. It supports filesystems and Amazon S3 compatible cloud storage service (AWS Signature v2 and v4).
|
||||
|
||||
```
|
||||
alias set, remove and list aliases in configuration file
|
||||
ls list buckets and objects
|
||||
mb make a bucket
|
||||
rb remove a bucket
|
||||
cp copy objects
|
||||
mirror synchronize object(s) to a remote site
|
||||
cat display object contents
|
||||
head display first 'n' lines of an object
|
||||
pipe stream STDIN to an object
|
||||
share generate URL for temporary access to an object
|
||||
find search for objects
|
||||
sql run sql queries on objects
|
||||
stat show object metadata
|
||||
mv move objects
|
||||
tree list buckets and objects in a tree format
|
||||
du summarize disk usage recursively
|
||||
retention set retention for object(s)
|
||||
legalhold set legal hold for object(s)
|
||||
diff list differences in object name, size, and date between two buckets
|
||||
rm remove objects
|
||||
encrypt manage bucket encryption config
|
||||
event manage object notifications
|
||||
watch listen for object notification events
|
||||
undo undo PUT/DELETE operations
|
||||
policy manage anonymous access to buckets and objects
|
||||
tag manage tags for bucket(s) and object(s)
|
||||
ilm manage bucket lifecycle
|
||||
version manage bucket versioning
|
||||
replicate configure server side bucket replication
|
||||
admin manage MinIO servers
|
||||
update update mc to latest release
|
||||
alias manage server credentials in configuration file
|
||||
admin manage MinIO servers
|
||||
anonymous manage anonymous access to buckets and objects
|
||||
batch manage batch jobs
|
||||
cp copy objects
|
||||
cat display object contents
|
||||
diff list differences in object name, size, and date between two buckets
|
||||
du summarize disk usage recursively
|
||||
encrypt manage bucket encryption config
|
||||
event manage object notifications
|
||||
find search for objects
|
||||
get get s3 object to local
|
||||
head display first 'n' lines of an object
|
||||
ilm manage bucket lifecycle
|
||||
idp manage MinIO IDentity Provider server configuration
|
||||
license license related commands
|
||||
legalhold manage legal hold for object(s)
|
||||
ls list buckets and objects
|
||||
mb make a bucket
|
||||
mv move objects
|
||||
mirror synchronize object(s) to a remote site
|
||||
od measure single stream upload and download
|
||||
ping perform liveness check
|
||||
pipe stream STDIN to an object
|
||||
put upload an object to a bucket
|
||||
quota manage bucket quota
|
||||
rm remove object(s)
|
||||
retention set retention for object(s)
|
||||
rb remove a bucket
|
||||
replicate configure server side bucket replication
|
||||
ready checks if the cluster is ready or not
|
||||
sql run sql queries on objects
|
||||
stat show object metadata
|
||||
support support related commands
|
||||
share generate URL for temporary access to an object
|
||||
tree list buckets and objects in a tree format
|
||||
tag manage tags for bucket and object(s)
|
||||
undo undo PUT/DELETE operations
|
||||
update update mc to latest release
|
||||
version manage bucket versioning
|
||||
watch listen for object notification events
|
||||
```
|
||||
|
||||
## Docker Container
|
||||
@@ -56,10 +69,10 @@ docker run minio/mc:edge ls play
|
||||
docker run -it --entrypoint=/bin/sh minio/mc
|
||||
```
|
||||
|
||||
then use the [`mc config` command](#add-a-cloud-storage-service).
|
||||
then use the [`mc alias` command](#add-a-cloud-storage-service).
|
||||
|
||||
### GitLab CI
|
||||
When using the Docker container in GitLab CI, you must [set the entrypoint to an empty string](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#overriding-the-entrypoint-of-an-image).
|
||||
When using the Docker container in GitLab CI, you must [set the entrypoint to an empty string](https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#override-the-entrypoint-of-an-image).
|
||||
|
||||
```
|
||||
deploy:
|
||||
@@ -87,7 +100,9 @@ mc --help
|
||||
| Platform | Architecture | URL |
|
||||
| ---------- | -------- |------|
|
||||
|GNU/Linux|64-bit Intel|https://dl.min.io/client/mc/release/linux-amd64/mc |
|
||||
||64-bit PPC|https://dl.min.io/client/mc/release/linux-ppc64le/mc |
|
||||
|GNU/Linux|64-bit PPC|https://dl.min.io/client/mc/release/linux-ppc64le/mc |
|
||||
|GNU/Linux|64-bit ARM|https://dl.min.io/client/mc/release/linux-arm64/mc |
|
||||
|Linux/s390x|S390X|https://dl.min.io/client/mc/release/linux-s390x/mc |
|
||||
|
||||
```
|
||||
wget https://dl.min.io/client/mc/release/linux-amd64/mc
|
||||
@@ -106,7 +121,7 @@ mc.exe --help
|
||||
```
|
||||
|
||||
## Install from Source
|
||||
Source installation is only intended for developers and advanced users. If you do not have a working Golang environment, please follow [How to install Golang](https://golang.org/doc/install). Minimum version required is [go1.17](https://golang.org/dl/#stable)
|
||||
Source installation is only intended for developers and advanced users. If you do not have a working Golang environment, please follow [How to install Golang](https://golang.org/doc/install). Minimum version required is [go1.22](https://golang.org/dl/#stable)
|
||||
|
||||
```sh
|
||||
go install github.com/minio/mc@latest
|
||||
@@ -173,9 +188,6 @@ Get your AccessKeyID and SecretAccessKey by following [Google Credentials Guide]
|
||||
mc alias set gcs https://storage.googleapis.com BKIKJAA5BMMU2RHO6IBB V8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||
```
|
||||
|
||||
### Example - IBM Cloud Object Storage
|
||||
See [the complete guide](docs/minio-client-complete-guide.md) for IBM instructions.
|
||||
|
||||
## Test Your Setup
|
||||
`mc` is pre-configured with https://play.min.io, aliased as "play". It is a hosted MinIO server for testing and development purpose. To test Amazon S3, simply replace "play" with "s3" or the alias you used at the time of setup.
|
||||
|
||||
@@ -233,11 +245,6 @@ admin config diff find ls mirror policy session sql
|
||||
cat cp event head mb pipe rm share stat version
|
||||
```
|
||||
|
||||
## Explore Further
|
||||
- [MinIO Client Complete Guide](https://docs.min.io/docs/minio-client-complete-guide)
|
||||
- [MinIO Quickstart Guide](https://docs.min.io/docs/minio-quickstart-guide)
|
||||
- [The MinIO documentation website](https://docs.min.io)
|
||||
|
||||
## Contribute to MinIO Project
|
||||
Please follow MinIO [Contributor's Guide](https://github.com/minio/mc/blob/master/CONTRIBUTING.md)
|
||||
|
||||
|
||||
+20
-20
@@ -5,23 +5,23 @@ MinIO Client (mc)为ls,cat,cp,mirror,diff,find等UNIX命令提供了
|
||||
|
||||
|
||||
```
|
||||
ls 列出文件和文件夹。
|
||||
mb 创建一个存储桶或一个文件夹。
|
||||
cat 显示文件和对象内容。
|
||||
pipe 将一个STDIN重定向到一个对象或者文件或者STDOUT。
|
||||
share 生成用于共享的URL。
|
||||
cp 拷贝文件和对象。
|
||||
mirror 给存储桶和文件夹做镜像。
|
||||
find 基于参数查找文件。
|
||||
diff 对两个文件夹或者存储桶比较差异。
|
||||
rm 删除文件和对象。
|
||||
events 管理对象通知。
|
||||
watch 监听文件和对象的事件。
|
||||
policy 管理访问策略。
|
||||
session 为cp命令管理保存的会话。
|
||||
config 管理mc配置文件。
|
||||
update 检查软件更新。
|
||||
version 输出版本信息。
|
||||
ls 列出文件和文件夹。
|
||||
mb 创建一个存储桶或一个文件夹。
|
||||
cat 显示文件和对象内容。
|
||||
pipe 将一个STDIN重定向到一个对象或者文件或者STDOUT。
|
||||
share 生成用于共享的URL。
|
||||
cp 拷贝文件和对象。
|
||||
mirror 给存储桶和文件夹做镜像。
|
||||
find 基于参数查找文件。
|
||||
diff 对两个文件夹或者存储桶比较差异。
|
||||
rm 删除文件和对象。
|
||||
events 管理对象通知。
|
||||
watch 监听文件和对象的事件。
|
||||
anonymous 管理访问策略。
|
||||
session 为cp命令管理保存的会话。
|
||||
config 管理mc配置文件。
|
||||
update 检查软件更新。
|
||||
version 输出版本信息。
|
||||
```
|
||||
|
||||
## Docker容器
|
||||
@@ -165,9 +165,9 @@ cat cp events mb pipe rm share version
|
||||
```
|
||||
|
||||
## 了解更多
|
||||
- [MinIO Client完全指南](https://docs.min.io/docs/minio-client-complete-guide)
|
||||
- [MinIO快速入门](https://docs.min.io/docs/minio-quickstart-guide)
|
||||
- [MinIO官方文档](https://docs.min.io)
|
||||
- [MinIO Client完全指南](https://docs.min.io/community/minio-object-store/reference/minio-mc.html?ref=gh)
|
||||
- [MinIO快速入门](https://docs.min.io/community/minio-object-store/operations/deployments/baremetal-deploy-minio-on-redhat-linux.html?ref=gh)
|
||||
- [MinIO官方文档](https://docs.min.io/community/minio-object-store/index.html?ref=gh)
|
||||
|
||||
## 贡献
|
||||
请遵守MinIO[贡献者指南](https://github.com/minio/mc/blob/master/docs/zh_CN/CONTRIBUTING.md)
|
||||
|
||||
@@ -70,11 +70,11 @@ readlink() {
|
||||
|
||||
assert_is_supported_arch() {
|
||||
case "${ARCH}" in
|
||||
x86_64 | amd64 | ppc64le | aarch64 | arm* | s390x )
|
||||
x86_64 | amd64 | ppc64le | aarch64 | arm* | s390x | loong64 | loongarch64 )
|
||||
return
|
||||
;;
|
||||
*)
|
||||
echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, ppc64le, aarch64, arm*, s390x]"
|
||||
echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, ppc64le, aarch64, arm*, s390x, loong64, loongarch64]"
|
||||
exit 1
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function _init() {
|
||||
export CGO_ENABLED=0
|
||||
|
||||
## List of architectures and OS to test coss compilation.
|
||||
SUPPORTED_OSARCH="linux/ppc64le linux/mips64 linux/arm64 linux/s390x darwin/arm64 darwin/amd64 freebsd/amd64 windows/amd64 linux/arm linux/386 netbsd/amd64 linux/mips openbsd/amd64"
|
||||
SUPPORTED_OSARCH="linux/ppc64le linux/s390x linux/mips64 linux/amd64 windows/amd64 darwin/amd64 darwin/arm64 linux/arm64 linux/arm"
|
||||
}
|
||||
|
||||
function _build() {
|
||||
|
||||
@@ -29,25 +29,44 @@ import (
|
||||
)
|
||||
|
||||
func genLDFlags(version string) string {
|
||||
releaseTag, date := releaseTag(version)
|
||||
copyrightYear := fmt.Sprintf("%d", date.Year())
|
||||
|
||||
var ldflagsStr string
|
||||
ldflagsStr = "-s -w -X github.com/minio/mc/cmd.Version=" + version + " "
|
||||
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.ReleaseTag=" + releaseTag(version) + " "
|
||||
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.CopyrightYear=" + copyrightYear + " "
|
||||
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.ReleaseTag=" + releaseTag + " "
|
||||
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.CommitID=" + commitID() + " "
|
||||
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.ShortCommitID=" + commitID()[:12]
|
||||
return ldflagsStr
|
||||
}
|
||||
|
||||
// genReleaseTag prints release tag to the console for easy git tagging.
|
||||
func releaseTag(version string) string {
|
||||
// releaseTag prints release tag to the console for easy git tagging.
|
||||
func releaseTag(version string) (string, time.Time) {
|
||||
relPrefix := "DEVELOPMENT"
|
||||
if prefix := os.Getenv("MC_RELEASE"); prefix != "" {
|
||||
relPrefix = prefix
|
||||
}
|
||||
|
||||
relTag := strings.Replace(version, " ", "-", -1)
|
||||
relTag = strings.Replace(relTag, ":", "-", -1)
|
||||
relTag = strings.Replace(relTag, ",", "", -1)
|
||||
return relPrefix + "." + relTag
|
||||
relSuffix := ""
|
||||
if hotfix := os.Getenv("MC_HOTFIX"); hotfix != "" {
|
||||
relSuffix = hotfix
|
||||
}
|
||||
|
||||
relTag := strings.ReplaceAll(version, " ", "-")
|
||||
relTag = strings.ReplaceAll(relTag, ":", "-")
|
||||
t, err := time.Parse("2006-01-02T15-04-05Z", relTag)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
relTag = strings.ReplaceAll(relTag, ",", "")
|
||||
relTag = relPrefix + "." + relTag
|
||||
if relSuffix != "" {
|
||||
relTag += "." + relSuffix
|
||||
}
|
||||
|
||||
return relTag, t
|
||||
}
|
||||
|
||||
// commitID returns the abbreviated commit-id hash of the last commit.
|
||||
@@ -67,6 +86,35 @@ func commitID() string {
|
||||
return strings.TrimSpace(string(commit))
|
||||
}
|
||||
|
||||
func commitTime() time.Time {
|
||||
// git log --format=%cD -n1
|
||||
var (
|
||||
commitUnix []byte
|
||||
err error
|
||||
)
|
||||
cmdName := "git"
|
||||
cmdArgs := []string{"log", "--format=%cI", "-n1"}
|
||||
if commitUnix, err = exec.Command(cmdName, cmdArgs...).Output(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error generating git commit-time: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
t, err := time.Parse(time.RFC3339, strings.TrimSpace(string(commitUnix)))
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error generating git commit-time: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
return t.UTC()
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(genLDFlags(time.Now().UTC().Format(time.RFC3339)))
|
||||
var version string
|
||||
if len(os.Args) > 1 {
|
||||
version = os.Args[1]
|
||||
} else {
|
||||
version = commitTime().Format(time.RFC3339)
|
||||
}
|
||||
|
||||
fmt.Println(genLDFlags(version))
|
||||
}
|
||||
|
||||
+32
-3
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -17,7 +17,12 @@
|
||||
|
||||
package cmd
|
||||
|
||||
import "path/filepath"
|
||||
import (
|
||||
"os"
|
||||
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/minio-go/v7/pkg/policy"
|
||||
)
|
||||
|
||||
// isValidAccessPERM - is provided access perm string supported.
|
||||
func (b accessPerms) isValidAccessPERM() bool {
|
||||
@@ -29,7 +34,31 @@ func (b accessPerms) isValidAccessPERM() bool {
|
||||
}
|
||||
|
||||
func (b accessPerms) isValidAccessFile() bool {
|
||||
return filepath.Ext(string(b)) == ".json"
|
||||
file, err := os.Open(string(b))
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var policy policy.BucketAccessPolicy
|
||||
if json.NewDecoder(file).Decode(&policy) != nil {
|
||||
fatalIf(errDummy().Trace(), "Unable to parse access file.")
|
||||
return false
|
||||
}
|
||||
|
||||
if policy.Version != "2012-10-17" {
|
||||
fatalIf(errDummy().Trace(), "Invalid policy version. Only 2012-10-17 is supported.")
|
||||
return false
|
||||
}
|
||||
|
||||
for _, statement := range policy.Statements {
|
||||
if statement.Effect != "Allow" && statement.Effect != "Deny" {
|
||||
fatalIf(errDummy().Trace(), "Invalid policy effect. Only Allow and Deny are supported.")
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// accessPerms - access level.
|
||||
|
||||
+56
-17
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,11 +18,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
@@ -32,7 +35,7 @@ import (
|
||||
type accounter struct {
|
||||
current int64
|
||||
|
||||
Total int64
|
||||
total int64
|
||||
startTime time.Time
|
||||
startValue int64
|
||||
refreshRate time.Duration
|
||||
@@ -44,7 +47,7 @@ type accounter struct {
|
||||
// Instantiate a new accounter.
|
||||
func newAccounter(total int64) *accounter {
|
||||
acct := &accounter{
|
||||
Total: total,
|
||||
total: total,
|
||||
startTime: time.Now(),
|
||||
startValue: 0,
|
||||
refreshRate: time.Millisecond * 200,
|
||||
@@ -56,14 +59,14 @@ func newAccounter(total int64) *accounter {
|
||||
}
|
||||
|
||||
// write calculate the final speed.
|
||||
func (a *accounter) write(current int64) float64 {
|
||||
func (a *accounter) write(current int64) (float64, time.Duration) {
|
||||
fromStart := time.Since(a.startTime)
|
||||
currentFromStart := current - a.startValue
|
||||
if currentFromStart > 0 {
|
||||
speed := float64(currentFromStart) / (float64(fromStart) / float64(time.Second))
|
||||
return speed
|
||||
return speed, fromStart
|
||||
}
|
||||
return 0.0
|
||||
return 0.0, 0
|
||||
}
|
||||
|
||||
// writer update new accounting data for a specified refreshRate.
|
||||
@@ -81,10 +84,11 @@ func (a *accounter) writer() {
|
||||
|
||||
// accountStat cantainer for current stats captured.
|
||||
type accountStat struct {
|
||||
Status string `json:"status"`
|
||||
Total int64 `json:"total"`
|
||||
Transferred int64 `json:"transferred"`
|
||||
Speed float64 `json:"speed"`
|
||||
Status string `json:"status"`
|
||||
Total int64 `json:"total"`
|
||||
Transferred int64 `json:"transferred"`
|
||||
Duration time.Duration `json:"duration"`
|
||||
Speed float64 `json:"speed"`
|
||||
}
|
||||
|
||||
func (c accountStat) JSON() string {
|
||||
@@ -96,15 +100,42 @@ func (c accountStat) JSON() string {
|
||||
}
|
||||
|
||||
func (c accountStat) String() string {
|
||||
dspOrder := []col{colGreen} // Header
|
||||
dspOrder = append(dspOrder, colGrey)
|
||||
var printColors []*color.Color
|
||||
for _, c := range dspOrder {
|
||||
printColors = append(printColors, getPrintCol(c))
|
||||
}
|
||||
|
||||
tbl := console.NewTable(printColors, []bool{false, false, false, false}, 0)
|
||||
|
||||
var builder strings.Builder
|
||||
cellText := make([][]string, 0, 2)
|
||||
cellText = append(cellText, []string{
|
||||
"Total",
|
||||
"Transferred",
|
||||
"Duration",
|
||||
"Speed",
|
||||
})
|
||||
|
||||
speedBox := pb.Format(int64(c.Speed)).To(pb.U_BYTES).String()
|
||||
if speedBox == "" {
|
||||
speedBox = "0 MB"
|
||||
} else {
|
||||
speedBox = speedBox + "/s"
|
||||
}
|
||||
message := fmt.Sprintf("Total: %s, Transferred: %s, Speed: %s", pb.Format(c.Total).To(pb.U_BYTES),
|
||||
pb.Format(c.Transferred).To(pb.U_BYTES), speedBox)
|
||||
return message
|
||||
|
||||
cellText = append(cellText, []string{
|
||||
pb.Format(c.Total).To(pb.U_BYTES).String(),
|
||||
pb.Format(c.Transferred).To(pb.U_BYTES).String(),
|
||||
pb.Format(int64(c.Duration)).To(pb.U_DURATION).String(),
|
||||
speedBox,
|
||||
})
|
||||
|
||||
e := tbl.PopulateTable(&builder, cellText)
|
||||
fatalIf(probe.NewError(e), "unable to populate the table")
|
||||
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Stat provides current stats captured.
|
||||
@@ -112,9 +143,9 @@ func (a *accounter) Stat() accountStat {
|
||||
var acntStat accountStat
|
||||
a.finishOnce.Do(func() {
|
||||
close(a.isFinished)
|
||||
acntStat.Total = a.Total
|
||||
acntStat.Total = a.total
|
||||
acntStat.Transferred = atomic.LoadInt64(&a.current)
|
||||
acntStat.Speed = a.write(atomic.LoadInt64(&a.current))
|
||||
acntStat.Speed, acntStat.Duration = a.write(atomic.LoadInt64(&a.current))
|
||||
})
|
||||
return acntStat
|
||||
}
|
||||
@@ -139,7 +170,8 @@ func (a *accounter) Get() int64 {
|
||||
return atomic.LoadInt64(&a.current)
|
||||
}
|
||||
|
||||
func (a *accounter) SetTotal(int64) {
|
||||
func (a *accounter) SetTotal(n int64) {
|
||||
atomic.StoreInt64(&a.total, n)
|
||||
}
|
||||
|
||||
// Add add to current value atomically.
|
||||
@@ -149,6 +181,13 @@ func (a *accounter) Add(n int64) int64 {
|
||||
|
||||
// Read implements Reader which internally updates current value.
|
||||
func (a *accounter) Read(p []byte) (n int, err error) {
|
||||
defer func() {
|
||||
// Upload retry can read one object twice; Avoid read to be greater than Total
|
||||
if n, t := a.Get(), atomic.LoadInt64(&a.total); t > 0 && n > t {
|
||||
a.Set(t)
|
||||
}
|
||||
}()
|
||||
|
||||
n = len(p)
|
||||
a.Add(int64(n))
|
||||
return
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminAccesskeyCreateFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "access-key",
|
||||
Usage: "set an access key for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "secret-key",
|
||||
Usage: "set a secret key for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "policy",
|
||||
Usage: "path to a JSON policy file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "friendly name for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry-duration",
|
||||
Usage: "duration before the access key expires",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry",
|
||||
Usage: "expiry date for the access key",
|
||||
},
|
||||
}
|
||||
|
||||
var adminAccesskeyCreateCmd = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "create access key pairs for users",
|
||||
Action: mainAdminAccesskeyCreate,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminAccesskeyCreateFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] [TARGET]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create a new access key pair with the same policy as the authenticated user
|
||||
{{.Prompt}} {{.HelpName}} myminio/
|
||||
|
||||
2. Create a new access key pair with custom access key and secret key
|
||||
{{.Prompt}} {{.HelpName}} myminio/ --access-key myaccesskey --secret-key mysecretkey
|
||||
|
||||
3. Create a new access key pair for user 'tester' that expires in 1 day
|
||||
{{.Prompt}} {{.HelpName}} myminio/ tester --expiry-duration 24h
|
||||
|
||||
4. Create a new access key pair for authenticated user that expires on 2025-01-01
|
||||
{{.Prompt}} {{.HelpName}} --expiry 2025-01-01
|
||||
|
||||
5. Create a new access key pair for user 'tester' with a custom policy
|
||||
{{.Prompt}} {{.HelpName}} myminio/ tester --policy /path/to/policy.json
|
||||
|
||||
6. Create a new access key pair for user 'tester' with a custom name and description
|
||||
{{.Prompt}} {{.HelpName}} myminio/ tester --name "Tester's Access Key" --description "Access key for tester"
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyCreate(ctx *cli.Context) error {
|
||||
return commonAccesskeyCreate(ctx, false)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminAccesskeyDisableCmd = cli.Command{
|
||||
Name: "disable",
|
||||
Usage: "disable an access key",
|
||||
Action: mainAdminAccesskeyDisable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] [TARGET]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Disable access key
|
||||
{{.Prompt}} {{.HelpName}} myminio myaccesskey
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyDisable(ctx *cli.Context) error {
|
||||
return enableDisableAccesskey(ctx, false)
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminAccesskeyEditFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "secret-key",
|
||||
Usage: "set a secret key for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "policy",
|
||||
Usage: "path to a JSON policy file",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "friendly name for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "description",
|
||||
Usage: "description for the account",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry-duration",
|
||||
Usage: "duration before the access key expires",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "expiry",
|
||||
Usage: "expiry date for the access key",
|
||||
},
|
||||
}
|
||||
|
||||
var adminAccesskeyEditCmd = cli.Command{
|
||||
Name: "edit",
|
||||
Usage: "edit existing access keys",
|
||||
Action: mainAdminAccesskeyEdit,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminAccesskeyEditFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] [TARGET]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Change the secret key for the access key "testkey"
|
||||
{{.Prompt}} {{.HelpName}} myminio/ testkey --secret-key 'xxxxxxx'
|
||||
2. Change the expiry duration for the access key "testkey"
|
||||
{{.Prompt}} {{.HelpName}} myminio/ testkey ---expiry-duration 24h
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyEdit(ctx *cli.Context) error {
|
||||
return commonAccesskeyEdit(ctx)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminAccesskeyEnableCmd = cli.Command{
|
||||
Name: "enable",
|
||||
Usage: "enable an access key",
|
||||
Action: mainAdminAccesskeyEnable,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] [TARGET]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Enable access key
|
||||
{{.Prompt}} {{.HelpName}} myminio myaccesskey
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyEnable(ctx *cli.Context) error {
|
||||
return enableDisableAccesskey(ctx, true)
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminAccesskeyInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "info about given access key pairs",
|
||||
Action: mainAdminAccesskeyInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET ACCESSKEY [ACCESSKEY...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get info for the access key "testkey"
|
||||
{{.Prompt}} {{.HelpName}} local/ testkey
|
||||
2. Get info for the access keys "testkey" and "testkey2"
|
||||
{{.Prompt}} {{.HelpName}} local/ testkey testkey2
|
||||
`,
|
||||
}
|
||||
|
||||
type accesskeyMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
AccessKey string `json:"accessKey"`
|
||||
SecretKey string `json:"secretKey,omitempty"`
|
||||
STS bool `json:"sts,omitempty"`
|
||||
ParentUser string `json:"parentUser,omitempty"`
|
||||
AccountStatus string `json:"accountStatus,omitempty"`
|
||||
ImpliedPolicy bool `json:"impliedPolicy,omitempty"`
|
||||
Policy json.RawMessage `json:"policy,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Expiration *time.Time `json:"expiration,omitempty"`
|
||||
Provider string `json:"provider,omitempty"`
|
||||
ProviderInfo providerInfo `json:"providerInfo,omitempty"`
|
||||
}
|
||||
|
||||
func (m accesskeyMessage) String() string {
|
||||
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575")) // green
|
||||
o := strings.Builder{}
|
||||
switch m.op {
|
||||
case "info":
|
||||
expirationStr := "NONE"
|
||||
if m.Expiration != nil && !m.Expiration.IsZero() && !m.Expiration.Equal(timeSentinel) {
|
||||
expirationStr = humanize.Time(*m.Expiration)
|
||||
}
|
||||
policyStr := "embedded"
|
||||
if m.ImpliedPolicy {
|
||||
policyStr = "implied"
|
||||
}
|
||||
statusStr := "enabled"
|
||||
if m.AccountStatus == "off" {
|
||||
statusStr = "disabled"
|
||||
}
|
||||
stsStr := "false"
|
||||
if m.STS {
|
||||
stsStr = "true"
|
||||
}
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Access Key:"), m.AccessKey))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Parent User:"), m.ParentUser))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Status:"), statusStr))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Policy:"), policyStr))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Name:"), m.Name))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Description:"), m.Description))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Expiration:"), expirationStr))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("STS:"), stsStr))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Provider:"), m.Provider))
|
||||
if m.ProviderInfo != nil {
|
||||
o.WriteString(iFmt(0, "%s\n", labelStyle.Render("Provider Specific Info:")))
|
||||
o.WriteString(m.ProviderInfo.String())
|
||||
}
|
||||
case "create":
|
||||
expirationStr := "NONE"
|
||||
if m.Expiration != nil && !m.Expiration.IsZero() && !m.Expiration.Equal(timeSentinel) {
|
||||
expirationStr = m.Expiration.String()
|
||||
}
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Access Key:"), m.AccessKey))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Secret Key:"), m.SecretKey))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Expiration:"), expirationStr))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Name:"), m.Name))
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render("Description:"), m.Description))
|
||||
case "remove":
|
||||
o.WriteString(labelStyle.Render(iFmt(0, "Successfully removed access key `%s`.", m.AccessKey)))
|
||||
case "edit":
|
||||
o.WriteString(labelStyle.Render(iFmt(0, "Successfully edited access key `%s`.", m.AccessKey)))
|
||||
case "enable":
|
||||
o.WriteString(labelStyle.Render(iFmt(0, "Successfully enabled access key `%s`.", m.AccessKey)))
|
||||
case "disable":
|
||||
o.WriteString(labelStyle.Render(iFmt(0, "Successfully disabled access key `%s`.", m.AccessKey)))
|
||||
}
|
||||
return o.String()
|
||||
}
|
||||
|
||||
func (m accesskeyMessage) JSON() string {
|
||||
m.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
type providerInfo interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyInfo(ctx *cli.Context) error {
|
||||
return commonAccesskeyInfo(ctx)
|
||||
}
|
||||
|
||||
func commonAccesskeyInfo(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
accessKeys := args.Tail()
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
for _, accessKey := range accessKeys {
|
||||
// Assume service account by default
|
||||
res, e := client.InfoAccessKey(globalContext, accessKey)
|
||||
fatalIf(probe.NewError(e), "Unable to get info for access key.")
|
||||
m := accesskeyMessage{
|
||||
op: "info",
|
||||
AccessKey: accessKey,
|
||||
ParentUser: res.ParentUser,
|
||||
AccountStatus: res.AccountStatus,
|
||||
ImpliedPolicy: res.ImpliedPolicy,
|
||||
Policy: json.RawMessage(res.Policy),
|
||||
Name: res.Name,
|
||||
Description: res.Description,
|
||||
Expiration: nilExpiry(res.Expiration),
|
||||
Provider: res.UserProvider,
|
||||
}
|
||||
|
||||
switch res.UserProvider {
|
||||
case madmin.LDAPProvider:
|
||||
info := res.LDAPSpecificInfo
|
||||
m.ProviderInfo = ldapAccessKeyInfo{
|
||||
Username: info.Username,
|
||||
}
|
||||
case madmin.OpenIDProvider:
|
||||
info := res.OpenIDSpecificInfo
|
||||
m.ProviderInfo = openIDAccessKeyInfo{
|
||||
ConfigName: info.ConfigName,
|
||||
UserID: info.UserID,
|
||||
UserIDClaim: info.UserIDClaim,
|
||||
DisplayName: info.DisplayName,
|
||||
DisplayNameClaim: info.DisplayNameClaim,
|
||||
}
|
||||
}
|
||||
printMsg(m)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func nilExpiry(expiry *time.Time) *time.Time {
|
||||
if expiry != nil && expiry.Equal(timeSentinel) {
|
||||
return nil
|
||||
}
|
||||
return expiry
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminAccesskeyListFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "users-only",
|
||||
Usage: "only list user DNs",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "temp-only",
|
||||
Usage: "only list temporary access keys",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "svcacc-only",
|
||||
Usage: "only list service account access keys",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "self",
|
||||
Usage: "list access keys for the authenticated user",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "all",
|
||||
Usage: "list all access keys for all builtin users",
|
||||
},
|
||||
}
|
||||
|
||||
var adminAccesskeyListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "list access key pairs for builtin users",
|
||||
Action: mainAdminAccesskeyList,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminAccesskeyListFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [DN...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get list of all builtin users and associated access keys in local server
|
||||
{{.Prompt}} {{.HelpName}} local/ --all
|
||||
|
||||
2. Get list of access keys for the authenticated user in local server
|
||||
{{.Prompt}} {{.HelpName}} local/ --self
|
||||
|
||||
3. Get list of builtin users in local server
|
||||
{{.Prompt}} {{.HelpName}} local/ --all --users-only
|
||||
|
||||
4. Get list of all builtin users and associated temporary access keys in play server (if admin)
|
||||
{{.Prompt}} {{.HelpName}} play/ --temp-only
|
||||
|
||||
5. Get list of access keys associated with user 'foobar'
|
||||
{{.Prompt}} {{.HelpName}} play/ foobar
|
||||
|
||||
6. Get list of access keys associated with users 'foobar' and 'tester'
|
||||
{{.Prompt}} {{.HelpName}} play/ foobar tester
|
||||
|
||||
7. Get all users and access keys if admin, else get authenticated user and associated access keys
|
||||
{{.Prompt}} {{.HelpName}} local/
|
||||
`,
|
||||
}
|
||||
|
||||
type userAccesskeyList struct {
|
||||
Status string `json:"status"`
|
||||
User string `json:"user"`
|
||||
STSKeys []madmin.ServiceAccountInfo `json:"stsKeys"`
|
||||
ServiceAccounts []madmin.ServiceAccountInfo `json:"svcaccs"`
|
||||
LDAP bool `json:"ldap,omitempty"`
|
||||
}
|
||||
|
||||
func (m userAccesskeyList) String() string {
|
||||
labelStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#04B575"))
|
||||
o := strings.Builder{}
|
||||
|
||||
userStr := "User"
|
||||
if m.LDAP {
|
||||
userStr = "DN"
|
||||
}
|
||||
o.WriteString(iFmt(0, "%s %s\n", labelStyle.Render(userStr+":"), m.User))
|
||||
if len(m.STSKeys) > 0 || len(m.ServiceAccounts) > 0 {
|
||||
o.WriteString(iFmt(2, "%s\n", labelStyle.Render("Access Keys:")))
|
||||
}
|
||||
for _, k := range m.STSKeys {
|
||||
expiration := "never"
|
||||
if nilExpiry(k.Expiration) != nil {
|
||||
expiration = humanize.Time(*k.Expiration)
|
||||
}
|
||||
o.WriteString(iFmt(4, "%s, expires: %s, sts: true\n", k.AccessKey, expiration))
|
||||
}
|
||||
for _, k := range m.ServiceAccounts {
|
||||
expiration := "never"
|
||||
if nilExpiry(k.Expiration) != nil {
|
||||
expiration = humanize.Time(*k.Expiration)
|
||||
}
|
||||
o.WriteString(iFmt(4, "%s, expires: %s, sts: false\n", k.AccessKey, expiration))
|
||||
}
|
||||
|
||||
return o.String()
|
||||
}
|
||||
|
||||
func (m userAccesskeyList) JSON() string {
|
||||
jsonMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyList(ctx *cli.Context) error {
|
||||
aliasedURL, tentativeAll, users, opts := commonAccesskeyList(ctx)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
accessKeysMap, e := client.ListAccessKeysBulk(globalContext, users, opts)
|
||||
if e != nil {
|
||||
if e.Error() == "Access Denied." && tentativeAll {
|
||||
// retry with self
|
||||
opts.All = false
|
||||
accessKeysMap, e = client.ListAccessKeysBulk(globalContext, users, opts)
|
||||
}
|
||||
fatalIf(probe.NewError(e), "Unable to list access keys.")
|
||||
}
|
||||
|
||||
for user, accessKeys := range accessKeysMap {
|
||||
m := userAccesskeyList{
|
||||
Status: "success",
|
||||
User: user,
|
||||
ServiceAccounts: accessKeys.ServiceAccounts,
|
||||
STSKeys: accessKeys.STSKeys,
|
||||
LDAP: false,
|
||||
}
|
||||
printMsg(m)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminAccesskeyRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "delete access key pairs for builtin users",
|
||||
Action: mainAdminAccesskeyRemove,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET ACCESSKEY
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove the access key "testkey" from local server
|
||||
{{.Prompt}} {{.HelpName}} local/ testkey
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminAccesskeyRemove(ctx *cli.Context) error {
|
||||
return commonAccesskeyRemove(ctx)
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) 2015-2025 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminAccesskeySTSRevokeFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "all",
|
||||
Usage: "revoke all STS accounts for the specified user",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "self",
|
||||
Usage: "revoke all STS accounts for the authenticated user",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "token-type",
|
||||
Usage: "specify the token type to revoke",
|
||||
},
|
||||
}
|
||||
|
||||
var adminAccesskeySTSRevokeCmd = cli.Command{
|
||||
Name: "sts-revoke",
|
||||
Usage: "revokes all STS accounts or specified types for the specified user",
|
||||
Action: mainAdminAccesskeySTSRevoke,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminAccesskeySTSRevokeFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} ALIAS USER [--all | --token-type TOKEN_TYPE]
|
||||
|
||||
Exactly one of --all or --token-type must be specified.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Revoke all STS accounts for user "user1"
|
||||
{{.Prompt}} {{.HelpName}} myminio user1 --all
|
||||
|
||||
2. Revoke STS accounts of a token type "app-1" for user "user1"
|
||||
{{.Prompt}} {{.HelpName}} myminio user1 --token-type app-1
|
||||
|
||||
3. Revoke all STS accounts for the authenticated user
|
||||
{{.Prompt}} {{.HelpName}} myminio --self
|
||||
|
||||
4. Revoke STS accounts of a token type "app-1" for the authenticated user
|
||||
{{.Prompt}} {{.HelpName}} myminio --self --token-type app-1
|
||||
`,
|
||||
}
|
||||
|
||||
type stsRevokeMessage struct {
|
||||
Status string `json:"status"`
|
||||
User string `json:"user"`
|
||||
TokenRevokeType string `json:"tokenRevokeType,omitempty"`
|
||||
}
|
||||
|
||||
func (m stsRevokeMessage) String() string {
|
||||
userString := "user " + m.User
|
||||
if m.User == "" {
|
||||
userString = "authenticated user"
|
||||
}
|
||||
if m.TokenRevokeType == "" {
|
||||
return "Successfully revoked all STS accounts for " + userString
|
||||
}
|
||||
return "Successfully revoked all STS accounts of type " + m.TokenRevokeType + " for " + userString
|
||||
}
|
||||
|
||||
func (m stsRevokeMessage) JSON() string {
|
||||
if m.Status == "" {
|
||||
m.Status = "success"
|
||||
}
|
||||
jsonMessageBytes, e := json.MarshalIndent(m, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
// checkSTSRevokeSyntax - validate all the passed arguments
|
||||
func checkSTSRevokeSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) > 2 || len(ctx.Args()) == 0 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
if !ctx.Bool("self") && ctx.Args().Get(1) == "" {
|
||||
fatalIf(errInvalidArgument().Trace(), "Must specify user or use --self flag.")
|
||||
}
|
||||
|
||||
if ctx.Bool("self") && ctx.Args().Get(1) != "" {
|
||||
fatalIf(errInvalidArgument().Trace(), "Cannot specify user with --self flag.")
|
||||
}
|
||||
|
||||
if (!ctx.Bool("all") && ctx.String("token-type") == "") || (ctx.Bool("all") && ctx.String("token-type") != "") {
|
||||
fatalIf(errDummy().Trace(), "Exactly one of --all or --token-type must be specified.")
|
||||
}
|
||||
}
|
||||
|
||||
// mainAdminAccesskeySTSRevoke is the handle for "mc admin accesskey sts-revoke" command.
|
||||
func mainAdminAccesskeySTSRevoke(ctx *cli.Context) error {
|
||||
checkSTSRevokeSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
user := args.Get(1) // will be empty if --self flag is set
|
||||
tokenRevokeType := ctx.String("token-type")
|
||||
fullRevoke := ctx.Bool("all")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
e := client.RevokeTokens(globalContext, madmin.RevokeTokensReq{
|
||||
User: user,
|
||||
TokenRevokeType: tokenRevokeType,
|
||||
FullRevoke: fullRevoke,
|
||||
})
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to revoke tokens for %s", user)
|
||||
|
||||
printMsg(stsRevokeMessage{
|
||||
User: user,
|
||||
TokenRevokeType: tokenRevokeType,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminAccesskeySubcommands = []cli.Command{
|
||||
adminAccesskeyListCmd,
|
||||
adminAccesskeyRemoveCmd,
|
||||
adminAccesskeyInfoCmd,
|
||||
adminAccesskeyCreateCmd,
|
||||
adminAccesskeyEditCmd,
|
||||
adminAccesskeyEnableCmd,
|
||||
adminAccesskeyDisableCmd,
|
||||
adminAccesskeySTSRevokeCmd,
|
||||
}
|
||||
|
||||
var adminAccesskeyCmd = cli.Command{
|
||||
Name: "accesskey",
|
||||
Usage: "manage access keys defined in the MinIO server",
|
||||
Action: mainAdminAccesskey,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminAccesskeySubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
func mainAdminAccesskey(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminAccesskeySubcommands)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminBucketInfoFlags = []cli.Flag{}
|
||||
|
||||
var adminBucketInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "display bucket information",
|
||||
Action: mainAdminBucketInfo,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminBucketInfoFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketInfo is the handler for "mc admin bucket info" command.
|
||||
func mainAdminBucketInfo(_ *cli.Context) error {
|
||||
deprecatedError("mc stat")
|
||||
return nil
|
||||
}
|
||||
+10
-130
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,15 +18,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminQuotaFlags = []cli.Flag{
|
||||
@@ -40,130 +32,18 @@ var adminQuotaFlags = []cli.Flag{
|
||||
},
|
||||
}
|
||||
|
||||
// quotaMessage container for content message structure
|
||||
type quotaMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
Bucket string `json:"bucket"`
|
||||
Quota uint64 `json:"quota,omitempty"`
|
||||
QuotaType string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
func (q quotaMessage) String() string {
|
||||
switch q.op {
|
||||
case "set":
|
||||
return console.Colorize("QuotaMessage",
|
||||
fmt.Sprintf("Successfully set bucket quota of %s with %s type on `%s`", humanize.IBytes(q.Quota), q.QuotaType, q.Bucket))
|
||||
case "unset":
|
||||
return console.Colorize("QuotaMessage",
|
||||
fmt.Sprintf("Successfully cleared bucket quota configured on `%s`", q.Bucket))
|
||||
default:
|
||||
return console.Colorize("QuotaInfo",
|
||||
fmt.Sprintf("Bucket `%s` has %s quota of %s", q.Bucket, q.QuotaType, humanize.IBytes(q.Quota)))
|
||||
}
|
||||
}
|
||||
|
||||
func (q quotaMessage) JSON() string {
|
||||
jsonMessageBytes, e := json.MarshalIndent(q, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
var adminBucketQuotaCmd = cli.Command{
|
||||
Name: "quota",
|
||||
Usage: "manage bucket quota",
|
||||
Action: mainAdminBucketQuota,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminQuotaFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET [--hard QUOTA | --clear]
|
||||
|
||||
QUOTA
|
||||
quota accepts human-readable case-insensitive number
|
||||
suffixes such as "k", "m", "g" and "t" referring to the metric units KB,
|
||||
MB, GB and TB respectively. Adding an "i" to these prefixes, uses the IEC
|
||||
units, so that "gi" refers to "gibibyte" or "GiB". A "b" at the end is
|
||||
also accepted. Without suffixes the unit is bytes.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Display bucket quota configured for "mybucket" on MinIO.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket
|
||||
|
||||
3. Set hard quota of 1gb for a bucket "mybucket" on MinIO.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --hard 1GB
|
||||
|
||||
4. Clear bucket quota configured for bucket "mybucket" on MinIO.
|
||||
{{.Prompt}} {{.HelpName}} myminio/mybucket --clear
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketQuotaSyntax - validate all the passed arguments
|
||||
func checkAdminBucketQuotaSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
}
|
||||
Name: "quota",
|
||||
Usage: "manage bucket quota",
|
||||
Action: mainAdminBucketQuota,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminQuotaFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketQuota is the handler for "mc admin bucket quota" command.
|
||||
func mainAdminBucketQuota(ctx *cli.Context) error {
|
||||
checkAdminBucketQuotaSyntax(ctx)
|
||||
|
||||
console.SetColor("QuotaMessage", color.New(color.FgGreen))
|
||||
console.SetColor("QuotaInfo", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
_, targetURL := url2Alias(args[0])
|
||||
if ctx.IsSet("hard") {
|
||||
qType := madmin.HardQuota
|
||||
quotaStr := ctx.String("hard")
|
||||
quota, e := humanize.ParseBytes(quotaStr)
|
||||
fatalIf(probe.NewError(e).Trace(quotaStr), "Unable to parse quota")
|
||||
if e = client.SetBucketQuota(globalContext, targetURL, &madmin.BucketQuota{Quota: quota, Type: qType}); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to set bucket quota")
|
||||
}
|
||||
printMsg(quotaMessage{
|
||||
op: "set",
|
||||
Bucket: targetURL,
|
||||
Quota: quota,
|
||||
QuotaType: string(qType),
|
||||
Status: "success",
|
||||
})
|
||||
} else if ctx.Bool("clear") {
|
||||
if err := client.SetBucketQuota(globalContext, targetURL, &madmin.BucketQuota{}); err != nil {
|
||||
fatalIf(probe.NewError(err).Trace(args...), "Unable to clear bucket quota config")
|
||||
}
|
||||
printMsg(quotaMessage{
|
||||
op: "unset",
|
||||
Bucket: targetURL,
|
||||
Status: "success",
|
||||
})
|
||||
|
||||
} else {
|
||||
qCfg, e := client.GetBucketQuota(globalContext, targetURL)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get bucket quota")
|
||||
printMsg(quotaMessage{
|
||||
op: "get",
|
||||
Bucket: targetURL,
|
||||
Quota: qCfg.Quota,
|
||||
QuotaType: string(qCfg.Type),
|
||||
Status: "success",
|
||||
})
|
||||
}
|
||||
|
||||
func mainAdminBucketQuota(_ *cli.Context) error {
|
||||
deprecatedError("mc quota")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,292 +18,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteAddFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "service",
|
||||
Usage: "type of service. Valid options are '[replication]'",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "region",
|
||||
Usage: "region of the destination bucket (optional)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Default is async",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check duration in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "disable-proxy",
|
||||
Usage: "disable proxying in active-active replication. If unset, default behavior is to proxy",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "add a new remote target",
|
||||
Action: mainAdminBucketRemoteAdd,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteAddFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET http(s)://ACCESSKEY:SECRETKEY@DEST_URL/DEST_BUCKET [--path | --region | --bandwidth] --service
|
||||
|
||||
TARGET:
|
||||
Also called as alias/sourcebucketname
|
||||
|
||||
DEST_BUCKET:
|
||||
Also called as remote target bucket.
|
||||
|
||||
DEST_URL:
|
||||
Also called as remote endpoint.
|
||||
|
||||
ACCESSKEY:
|
||||
Also called as username.
|
||||
|
||||
SECRETKEY:
|
||||
Also called as password.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Set a new remote replication target "targetbucket" in region "us-west-1" on https://minio.siteb.example.com for bucket 'sourcebucket'.
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--service "replication" --region "us-west-1"
|
||||
|
||||
2. Set a new remote replication target 'targetbucket' in region "us-west-1" on https://minio.siteb.example.com for
|
||||
bucket 'sourcebucket' with bandwidth set to 2 gigabits per second. Enable synchronous replication to the target
|
||||
and perform health check of target every 100 seconds
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket https://foobar:foo12345@minio.siteb.example.com/targetbucket \
|
||||
--service "replication" --region "us-west-1 --bandwidth "2G" --sync
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteAddSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteAddSyntax(ctx *cli.Context) {
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
}
|
||||
if argsNr > 2 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
|
||||
"Incorrect number of arguments for remote add command.")
|
||||
}
|
||||
}
|
||||
|
||||
// RemoteMessage container for content message structure
|
||||
type RemoteMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
AccessKey string `json:"accessKey,omitempty"`
|
||||
SecretKey string `json:"secretKey,omitempty"`
|
||||
SourceBucket string `json:"sourceBucket"`
|
||||
TargetURL string `json:"TargetURL,omitempty"`
|
||||
TargetBucket string `json:"TargetBucket,omitempty"`
|
||||
RemoteARN string `json:"RemoteARN,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Region string `json:"region,omitempty"`
|
||||
ServiceType string `json:"service"`
|
||||
Bandwidth int64 `json:"bandwidth"`
|
||||
ReplicationSync bool `json:"replicationSync"`
|
||||
Proxy bool `json:"proxy"`
|
||||
HealthCheckDuration time.Duration `json:"healthcheckDuration"`
|
||||
ResetID string `json:"resetID"`
|
||||
ResetBefore time.Time `json:"resetBeforeDate"`
|
||||
}
|
||||
|
||||
func (r RemoteMessage) String() string {
|
||||
switch r.op {
|
||||
case "ls":
|
||||
message := console.Colorize("TargetURL", fmt.Sprintf("%s ", r.TargetURL))
|
||||
message += console.Colorize("SourceBucket", r.SourceBucket)
|
||||
message += console.Colorize("Arrow", "->")
|
||||
message += console.Colorize("TargetBucket", r.TargetBucket)
|
||||
message += " "
|
||||
message += console.Colorize("ARN", r.RemoteARN)
|
||||
syncStr := " "
|
||||
if r.ReplicationSync && r.ServiceType == string(madmin.ReplicationService) {
|
||||
syncStr = "sync"
|
||||
}
|
||||
message += " " + console.Colorize("SyncLabel", syncStr)
|
||||
proxyStr := " "
|
||||
if r.Proxy && r.ServiceType == string(madmin.ReplicationService) {
|
||||
proxyStr = "proxy"
|
||||
}
|
||||
message += " "
|
||||
message += console.Colorize("ProxyLabel", proxyStr)
|
||||
return message
|
||||
case "rm":
|
||||
return console.Colorize("RemoteMessage", "Removed remote target for `"+r.SourceBucket+"` bucket successfully.")
|
||||
case "add":
|
||||
return console.Colorize("RemoteMessage", "Remote ARN = `"+r.RemoteARN+"`.")
|
||||
case "edit":
|
||||
return console.Colorize("RemoteMessage", "Remote target updated successfully for target with ARN:`"+r.RemoteARN+"`.")
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// JSON returns jsonified message
|
||||
func (r RemoteMessage) JSON() string {
|
||||
r.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(r, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
func extractCredentialURL(argURL string) (accessKey, secretKey string, u *url.URL) {
|
||||
var parsedURL string
|
||||
if hostKeyTokens.MatchString(argURL) {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "temporary tokens are not allowed for remote targets")
|
||||
}
|
||||
if hostKeys.MatchString(argURL) {
|
||||
parts := hostKeys.FindStringSubmatch(argURL)
|
||||
if len(parts) != 5 {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "Unsupported remote target format, please check --help")
|
||||
}
|
||||
accessKey = parts[2]
|
||||
secretKey = parts[3]
|
||||
parsedURL = fmt.Sprintf("%s%s", parts[1], parts[4])
|
||||
}
|
||||
var e error
|
||||
if parsedURL == "" {
|
||||
fatalIf(errInvalidArgument().Trace(argURL), "No valid credentials were detected")
|
||||
}
|
||||
u, e = url.Parse(parsedURL)
|
||||
if e != nil {
|
||||
fatalIf(errInvalidArgument().Trace(parsedURL), "Unsupported URL format %v", e)
|
||||
}
|
||||
|
||||
return accessKey, secretKey, u
|
||||
}
|
||||
|
||||
// fetchRemoteTarget - returns the dest bucket, dest endpoint, access and secret key
|
||||
func fetchRemoteTarget(cli *cli.Context) (sourceBucket string, bktTarget *madmin.BucketTarget) {
|
||||
args := cli.Args()
|
||||
argCount := len(args)
|
||||
if argCount < 2 {
|
||||
fatalIf(probe.NewError(fmt.Errorf("Missing Remote target configuration")), "Unable to parse remote target")
|
||||
}
|
||||
_, sourceBucket = url2Alias(args[0])
|
||||
p := cli.String("path")
|
||||
if !isValidPath(p) {
|
||||
fatalIf(errInvalidArgument().Trace(p),
|
||||
"Unrecognized bucket path style. Valid options are `[on,off, auto]`.")
|
||||
}
|
||||
|
||||
tgtURL := args[1]
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
|
||||
serviceType := cli.String("service")
|
||||
if !madmin.ServiceType(serviceType).IsValid() {
|
||||
fatalIf(errInvalidArgument().Trace(serviceType), "Invalid service type. Valid option is `[replication]`.")
|
||||
}
|
||||
if cli.IsSet("sync") && serviceType != string(madmin.ReplicationService) {
|
||||
fatalIf(errInvalidArgument(), "Invalid usage. --sync flag applies only to replication service")
|
||||
}
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
disableproxy := cli.Bool("disable-proxy")
|
||||
bktTarget = &madmin.BucketTarget{
|
||||
TargetBucket: tgtBucket,
|
||||
Secure: u.Scheme == "https",
|
||||
Credentials: creds,
|
||||
Endpoint: u.Host,
|
||||
Path: p,
|
||||
API: "s3v4",
|
||||
Type: madmin.ServiceType(serviceType),
|
||||
Region: cli.String("region"),
|
||||
BandwidthLimit: int64(bandwidth),
|
||||
ReplicationSync: cli.Bool("sync"),
|
||||
DisableProxy: disableproxy,
|
||||
HealthCheckDuration: time.Duration(cli.Uint("healthcheck-seconds")) * time.Second,
|
||||
}
|
||||
return sourceBucket, bktTarget
|
||||
}
|
||||
|
||||
func getBandwidthInBytes(bandwidthStr string) (bandwidth uint64, err error) {
|
||||
if bandwidthStr != "" {
|
||||
bandwidth, err = humanize.ParseBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
bandwidth = bandwidth / 8
|
||||
return
|
||||
Flags: globalFlags,
|
||||
HideHelp: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteAdd is the handle for "mc admin bucket remote set" command.
|
||||
func mainAdminBucketRemoteAdd(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteAddSyntax(ctx)
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
|
||||
sourceBucket, bktTarget := fetchRemoteTarget(ctx)
|
||||
arn, e := client.SetRemoteTarget(globalContext, sourceBucket, bktTarget)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to configure remote target")
|
||||
}
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
TargetURL: bktTarget.URL().String(),
|
||||
TargetBucket: bktTarget.TargetBucket,
|
||||
AccessKey: bktTarget.Credentials.AccessKey,
|
||||
SourceBucket: sourceBucket,
|
||||
RemoteARN: arn,
|
||||
ReplicationSync: bktTarget.ReplicationSync,
|
||||
Proxy: !bktTarget.DisableProxy,
|
||||
})
|
||||
|
||||
func mainAdminBucketRemoteAdd(_ *cli.Context) error {
|
||||
deprecatedError("mc replicate add")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -25,10 +25,10 @@ func TestGetBandwidthInBytes(t *testing.T) {
|
||||
type args struct {
|
||||
bandwidthStr string
|
||||
}
|
||||
f1 := 999.123457 * 1024 * 1024 / 8
|
||||
f2 := 10.123456790 * 1024 * 1024 * 1024 / 8
|
||||
f3 := 10000.123456790 * 1024 * 1024 * 1024 / 8
|
||||
f4 := (0.001*1024*1024*1024 + 1) / 8 // round up
|
||||
f1 := 999.1234567 * 1024 * 1024
|
||||
f2 := 10.123456789 * 1024 * 1024 * 1024
|
||||
f3 := 10000.123456789 * 1024 * 1024 * 1024
|
||||
f4 := 0.001 * 1024 * 1024 * 1024
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
@@ -39,66 +39,66 @@ func TestGetBandwidthInBytes(t *testing.T) {
|
||||
args: args{
|
||||
bandwidthStr: "1Mi",
|
||||
},
|
||||
want: 1024 * 1024 / 8,
|
||||
want: 1024 * 1024,
|
||||
},
|
||||
{
|
||||
name: "1MegaBit",
|
||||
args: args{
|
||||
bandwidthStr: "1M",
|
||||
},
|
||||
want: 1000000 / 8,
|
||||
},
|
||||
{
|
||||
name: "1GigaBit",
|
||||
args: args{
|
||||
bandwidthStr: "1G",
|
||||
},
|
||||
want: 1000000000 / 8,
|
||||
want: 1000000,
|
||||
},
|
||||
{
|
||||
name: "1GigaByte",
|
||||
args: args{
|
||||
bandwidthStr: "1G",
|
||||
},
|
||||
want: 1000000000,
|
||||
},
|
||||
{
|
||||
name: "1GibiByte",
|
||||
args: args{
|
||||
bandwidthStr: "1Gi",
|
||||
},
|
||||
want: 1024 * 1024 * 1024 / 8,
|
||||
},
|
||||
{
|
||||
name: "FractionalMegaBits",
|
||||
args: args{
|
||||
bandwidthStr: "999.123456789123456789M",
|
||||
},
|
||||
want: 999123457 / 8,
|
||||
},
|
||||
{
|
||||
name: "FractionalGigaBits",
|
||||
args: args{
|
||||
bandwidthStr: "10.123456789123456789123456G",
|
||||
},
|
||||
want: 10123456789 / 8,
|
||||
},
|
||||
{
|
||||
name: "FractionalBigGigaBits",
|
||||
args: args{
|
||||
bandwidthStr: "10000.123456789123456789123456G",
|
||||
},
|
||||
want: 10000123456789 / 8,
|
||||
want: 1024 * 1024 * 1024,
|
||||
},
|
||||
{
|
||||
name: "FractionalMegaBytes",
|
||||
args: args{
|
||||
bandwidthStr: "999.123456789123456789M",
|
||||
},
|
||||
want: 999123456,
|
||||
},
|
||||
{
|
||||
name: "FractionalGigaBytes",
|
||||
args: args{
|
||||
bandwidthStr: "10.123456789123456789123456G",
|
||||
},
|
||||
want: 10123456789,
|
||||
},
|
||||
{
|
||||
name: "FractionalBigGigaBytes",
|
||||
args: args{
|
||||
bandwidthStr: "10000.123456789123456789123456G",
|
||||
},
|
||||
want: 10000123456789,
|
||||
},
|
||||
{
|
||||
name: "FractionalMebiBytes",
|
||||
args: args{
|
||||
bandwidthStr: "999.123456789123456789Mi",
|
||||
},
|
||||
want: uint64(f1),
|
||||
},
|
||||
{
|
||||
name: "FractionalGigaBytes",
|
||||
name: "FractionalGibiBytes",
|
||||
args: args{
|
||||
bandwidthStr: "10.123456789123456789123456Gi",
|
||||
},
|
||||
want: uint64(f2),
|
||||
},
|
||||
{
|
||||
name: "FractionalBigGigaBytes",
|
||||
name: "FractionalBigGibiBytes",
|
||||
args: args{
|
||||
bandwidthStr: "10000.123456789123456789123456Gi",
|
||||
},
|
||||
@@ -116,12 +116,11 @@ func TestGetBandwidthInBytes(t *testing.T) {
|
||||
args: args{
|
||||
bandwidthStr: "1024Ki",
|
||||
},
|
||||
want: 1024 * 1024 / 8,
|
||||
want: 1024 * 1024,
|
||||
},
|
||||
}
|
||||
t.Parallel()
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got, err := getBandwidthInBytes(tt.args.bandwidthStr); err != nil || got != tt.want {
|
||||
t.Errorf("getBandwidthInBytes() = %v, want %v", got, tt.want)
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBandwidthInfoCmdFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "unit",
|
||||
Value: "b",
|
||||
Usage: "[b|bi|B|Bi] Display bandwidth in bits (IEC [bi] or SI [b]) or bytes (IEC [Bi] or SI [B])",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBwInfoCmd = cli.Command{
|
||||
Name: "bandwidth",
|
||||
Usage: "Show bandwidth info for buckets on the MinIO server in bits or bytes per second. Ki,Bi,Mi,Gi represent IEC units.",
|
||||
Action: mainAdminBwInfo,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: append(globalFlags, adminBandwidthInfoCmdFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} FLAGS TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Show the bandwidth usage for all the buckets in a MinIO server setup
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. Show the bandwidth usage for the bucket 'source-bucket' in a MinIO server setup
|
||||
{{.Prompt}} {{.HelpName}} play/source-bucket
|
||||
`,
|
||||
}
|
||||
|
||||
func printTable(report madmin.Report, bits bool, iec bool) {
|
||||
bucketMaxLength := 63
|
||||
bucketColLength := 6
|
||||
var bucketKeys []string
|
||||
for bucket := range report.Report.BucketStats {
|
||||
if len(bucket) <= bucketMaxLength && len(bucket) > bucketColLength {
|
||||
bucketColLength = len(bucket)
|
||||
}
|
||||
bucketKeys = append(bucketKeys, bucket)
|
||||
}
|
||||
sort.Strings(bucketKeys)
|
||||
dspOrder := []col{colGreen} // Header
|
||||
for i := 0; i < len(report.Report.BucketStats); i++ {
|
||||
dspOrder = append(dspOrder, colGrey)
|
||||
}
|
||||
var printColors []*color.Color
|
||||
for _, c := range dspOrder {
|
||||
printColors = append(printColors, getPrintCol(c))
|
||||
}
|
||||
|
||||
cellText := make([][]string, len(report.Report.BucketStats)+1) // 1 for the header
|
||||
tbl := console.NewTable(printColors, []bool{false, false, false}, 0)
|
||||
bucketTitle := fmt.Sprintf("%-16v", "Bucket")
|
||||
cellText[0] = []string{
|
||||
bucketTitle,
|
||||
"Configured Max Bandwidth",
|
||||
"Current Bandwidth",
|
||||
}
|
||||
tbl.HeaderRowSeparator = true
|
||||
index := 1
|
||||
|
||||
for _, bucket := range bucketKeys {
|
||||
values := report.Report.BucketStats[bucket]
|
||||
if len(bucket) > bucketMaxLength {
|
||||
bucket = bucket[:bucketMaxLength] + ".."
|
||||
}
|
||||
var mul uint64
|
||||
mul = 1
|
||||
if bits {
|
||||
mul = 8
|
||||
}
|
||||
limit := humanize.Bytes(uint64(values.LimitInBytesPerSecond) * mul)
|
||||
current := humanize.Bytes(uint64(values.CurrentBandwidthInBytesPerSecond) * mul)
|
||||
if iec {
|
||||
limit = humanize.IBytes(uint64(values.LimitInBytesPerSecond)*mul) + "/sec"
|
||||
current = humanize.IBytes(uint64(values.CurrentBandwidthInBytesPerSecond)*mul) + "/sec"
|
||||
}
|
||||
if bits {
|
||||
limit = strings.ToLower(limit) + "/sec"
|
||||
current = strings.ToLower(current) + "/sec"
|
||||
}
|
||||
if values.LimitInBytesPerSecond == 0 {
|
||||
limit = "N/A" // N/A means cluster bandwidth is not configured
|
||||
}
|
||||
cellText[index] = []string{
|
||||
bucket,
|
||||
limit,
|
||||
current,
|
||||
}
|
||||
index++
|
||||
}
|
||||
if len(report.Report.BucketStats) > 0 {
|
||||
err := tbl.DisplayTable(cellText)
|
||||
if err != nil {
|
||||
console.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkAdminBwInfoSyntax(ctx *cli.Context) {
|
||||
u := ctx.String("unit")
|
||||
if u != "bi" &&
|
||||
u != "b" &&
|
||||
u != "Bi" &&
|
||||
u != "B" &&
|
||||
u != "" {
|
||||
cli.ShowCommandHelpAndExit(ctx, "bandwidth", globalErrorExitStatus)
|
||||
}
|
||||
if len(ctx.Args()) > 1 || len(ctx.Args()) == 0 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "bandwidth", globalErrorExitStatus)
|
||||
}
|
||||
}
|
||||
|
||||
func mainAdminBwInfo(ctx *cli.Context) {
|
||||
checkAdminBwInfoSyntax(ctx)
|
||||
aliasURL, bucket := getAliasAndBucket(ctx)
|
||||
client := getClient(aliasURL)
|
||||
reportCh := client.GetBucketBandwidth(globalContext, bucket)
|
||||
firstPrint := true
|
||||
bandwidthUnitsString := ctx.String("unit")
|
||||
for {
|
||||
select {
|
||||
case report := <-reportCh:
|
||||
if len(report.Report.BucketStats) == 0 {
|
||||
continue
|
||||
}
|
||||
if report.Err != nil {
|
||||
if strings.Contains(report.Err.Error(), "EOF") {
|
||||
continue
|
||||
}
|
||||
console.Error(report.Err)
|
||||
}
|
||||
printBandwidth(report, firstPrint, bandwidthUnitsString == "bi" || bandwidthUnitsString == "b",
|
||||
bandwidthUnitsString == "bi" || bandwidthUnitsString == "Bi")
|
||||
firstPrint = false
|
||||
case <-globalContext.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printBandwidth(report madmin.Report, firstPrint bool, bits bool, iec bool) {
|
||||
rewindLines := len(report.Report.BucketStats) + 4
|
||||
if firstPrint {
|
||||
rewindLines = 0
|
||||
}
|
||||
if globalJSON {
|
||||
reportJSON, e := json.MarshalIndent(report, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON")
|
||||
console.Println(string(reportJSON))
|
||||
time.Sleep(1 * time.Second)
|
||||
return
|
||||
}
|
||||
if len(report.Report.BucketStats) > 0 {
|
||||
console.RewindLines(rewindLines)
|
||||
// For the next iteration, rewind lines
|
||||
printTable(report, bits, iec)
|
||||
}
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,233 +18,21 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/s3utils"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteEditFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "arn",
|
||||
Usage: "ARN of target",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "sync",
|
||||
Usage: "enable synchronous replication for this target. Valid values are enable,disable.Defaults to disable if unset",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "proxy",
|
||||
Usage: "enable proxying in active-active replication. Valid values are enable,disable.By default proxying is enabled.",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "bandwidth",
|
||||
Usage: "Set bandwidth limit in bits per second (K,B,G,T for metric and Ki,Bi,Gi,Ti for IEC units)",
|
||||
},
|
||||
cli.UintFlag{
|
||||
Name: "healthcheck-seconds",
|
||||
Usage: "health check duration in seconds",
|
||||
Value: 60,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "path",
|
||||
Value: "auto",
|
||||
Usage: "bucket path lookup supported by the server. Valid options are '[on,off,auto]'",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteEditCmd = cli.Command{
|
||||
Name: "edit",
|
||||
Usage: "edit remote target",
|
||||
Action: mainAdminBucketRemoteEdit,
|
||||
Before: setGlobalsFromContext,
|
||||
OnUsageError: onUsageError,
|
||||
Flags: append(globalFlags, adminBucketRemoteEditFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET http(s)://ACCESSKEY:SECRETKEY@DEST_URL/DEST_BUCKET --arn arn
|
||||
|
||||
TARGET:
|
||||
Also called as alias/sourcebucketname
|
||||
|
||||
DEST_BUCKET:
|
||||
Also called as remote target bucket.
|
||||
|
||||
DEST_URL:
|
||||
Also called as remote endpoint.
|
||||
|
||||
ACCESSKEY:
|
||||
Also called as username.
|
||||
|
||||
SECRETKEY:
|
||||
Also called as password.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Edit credentials for existing remote target with arn where a remote target has been configured between sourcebucket on sitea to targetbucket on siteb.
|
||||
{{.DisableHistory}}
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket \
|
||||
https://foobar:newpassword@minio.siteb.example.com/targetbucket \
|
||||
--arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
{{.EnableHistory}}
|
||||
|
||||
2. Edit remote target for sourceBucket on sitea with specified ARN to disable proxying and enable synchronous replication
|
||||
{{.Prompt}} {{.HelpName}} sitea/sourcebucket --sync "enable" --proxy "disable"
|
||||
--arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteEditSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteEditSyntax(ctx *cli.Context) {
|
||||
argsNr := len(ctx.Args())
|
||||
if argsNr > 2 || argsNr == 0 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
}
|
||||
if !ctx.IsSet("arn") {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "--arn flag needs to be set")
|
||||
}
|
||||
}
|
||||
|
||||
// modifyRemoteTarget - modifies the dest credentials or updates sync , disable-proxy settings
|
||||
func modifyRemoteTarget(cli *cli.Context, targets []madmin.BucketTarget) (*madmin.BucketTarget, []madmin.TargetUpdateType) {
|
||||
args := cli.Args()
|
||||
foundIdx := -1
|
||||
arn := cli.String("arn")
|
||||
for i, t := range targets {
|
||||
if t.Arn == arn {
|
||||
foundIdx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
if foundIdx < 0 {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "Unable to edit remote target - `"+arn+"` not found")
|
||||
}
|
||||
var ops []madmin.TargetUpdateType
|
||||
bktTarget := targets[foundIdx].Clone()
|
||||
if cli.IsSet("sync") {
|
||||
syncState := strings.ToLower(cli.String("sync"))
|
||||
switch syncState {
|
||||
case "enable", "disable":
|
||||
bktTarget.ReplicationSync = syncState == "enable"
|
||||
ops = append(ops, madmin.SyncUpdateType)
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--sync can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
if cli.IsSet("proxy") {
|
||||
proxyState := strings.ToLower(cli.String("proxy"))
|
||||
switch proxyState {
|
||||
case "enable", "disable":
|
||||
bktTarget.DisableProxy = proxyState == "disable"
|
||||
ops = append(ops, madmin.ProxyUpdateType)
|
||||
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(args...), "--proxy can be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
|
||||
if len(args) == 2 {
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
|
||||
tgtURL := args[1]
|
||||
accessKey, secretKey, u := extractCredentialURL(tgtURL)
|
||||
var tgtBucket string
|
||||
if u.Path != "" {
|
||||
tgtBucket = path.Clean(u.Path[1:])
|
||||
}
|
||||
if e := s3utils.CheckValidBucketName(tgtBucket); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(tgtURL), "Invalid target bucket specified")
|
||||
}
|
||||
secure := u.Scheme == "https"
|
||||
host := u.Host
|
||||
if u.Port() == "" {
|
||||
port := 80
|
||||
if secure {
|
||||
port = 443
|
||||
}
|
||||
host = host + ":" + strconv.Itoa(port)
|
||||
}
|
||||
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
if host != bktTarget.Endpoint {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured Endpoint `"+host+"` does not match "+bktTarget.Endpoint+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
if tgtBucket != bktTarget.TargetBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured remote target bucket `"+tgtBucket+"` does not match "+bktTarget.TargetBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
if sourceBucket != bktTarget.SourceBucket {
|
||||
fatalIf(errInvalidArgument().Trace(args...), "configured source bucket `"+sourceBucket+"` does not match "+bktTarget.SourceBucket+"` for this ARN `"+bktTarget.Arn+"`")
|
||||
}
|
||||
bktTarget.TargetBucket = tgtBucket
|
||||
bktTarget.Secure = secure
|
||||
bktTarget.Credentials = creds
|
||||
bktTarget.Endpoint = host
|
||||
ops = append(ops, madmin.CredentialsUpdateType)
|
||||
}
|
||||
if cli.IsSet("bandwidth") {
|
||||
bandwidthStr := cli.String("bandwidth")
|
||||
bandwidth, err := getBandwidthInBytes(bandwidthStr)
|
||||
if err != nil {
|
||||
fatalIf(errInvalidArgument().Trace(bandwidthStr), "Invalid bandwidth number")
|
||||
}
|
||||
bktTarget.BandwidthLimit = int64(bandwidth)
|
||||
ops = append(ops, madmin.BandwidthLimitUpdateType)
|
||||
|
||||
}
|
||||
if cli.IsSet("healthcheck-seconds") {
|
||||
bktTarget.HealthCheckDuration = time.Duration(cli.Uint("healthcheck-seconds")) * time.Second
|
||||
ops = append(ops, madmin.HealthCheckDurationUpdateType)
|
||||
}
|
||||
if cli.IsSet("path") {
|
||||
bktTarget.Path = cli.String("path")
|
||||
ops = append(ops, madmin.PathUpdateType)
|
||||
}
|
||||
return &bktTarget, ops
|
||||
Flags: globalFlags,
|
||||
HideHelp: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteEdit is the handle for "mc admin bucket remote edit" command.
|
||||
func mainAdminBucketRemoteEdit(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteEditSyntax(ctx)
|
||||
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr, "Unable to initialize admin connection.")
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
|
||||
targets, e := client.ListRemoteTargets(globalContext, sourceBucket, "")
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch remote target.")
|
||||
|
||||
bktTarget, ops := modifyRemoteTarget(ctx, targets)
|
||||
|
||||
arn, e := client.UpdateRemoteTarget(globalContext, bktTarget, ops...)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to update remote target `"+bktTarget.Endpoint+"` from `"+bktTarget.SourceBucket+"` -> `"+bktTarget.TargetBucket+"`")
|
||||
}
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
TargetURL: bktTarget.URL().String(),
|
||||
TargetBucket: bktTarget.TargetBucket,
|
||||
AccessKey: bktTarget.Credentials.AccessKey,
|
||||
SourceBucket: bktTarget.SourceBucket,
|
||||
RemoteARN: arn,
|
||||
})
|
||||
|
||||
func mainAdminBucketRemoteEdit(_ *cli.Context) error {
|
||||
deprecatedError("mc replicate update")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteListFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "service",
|
||||
Usage: "type of service. valid options are '[replication]'",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteListCmd = cli.Command{
|
||||
Name: "ls",
|
||||
Usage: "list remote target ARN(s)",
|
||||
Action: mainAdminBucketRemoteList,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteListFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get remote bucket target for replication on MinIO server for bucket 'srcbucket'.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket --service "replication"
|
||||
|
||||
2. List all remote bucket target(s) on MinIO server for bucket 'srcbucket'.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket
|
||||
|
||||
3. List all remote bucket target(s) on MinIO tenant.
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteListSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteListSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteList is the handle for "mc admin bucket remote list" command.
|
||||
func mainAdminBucketRemoteList(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteListSyntax(ctx)
|
||||
|
||||
// Additional command specific theme customization.
|
||||
console.SetColor("RemoteListMessage", color.New(color.Bold, color.FgHiGreen))
|
||||
console.SetColor("RemoteListEmpty", color.New(color.FgYellow))
|
||||
console.SetColor("SourceBucket", color.New(color.FgYellow))
|
||||
console.SetColor("TargetBucket", color.New(color.FgYellow))
|
||||
console.SetColor("TargetURL", color.New(color.FgHiWhite))
|
||||
console.SetColor("ARN", color.New(color.FgCyan))
|
||||
console.SetColor("Arrow", color.New(color.FgHiWhite))
|
||||
console.SetColor("SyncLabel", color.New(color.FgHiYellow))
|
||||
console.SetColor("ProxyLabel", color.New(color.FgHiYellow))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
_, sourceBucket := url2Alias(aliasedURL)
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
targets, e := client.ListRemoteTargets(globalContext, sourceBucket, ctx.String("service"))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list remote target")
|
||||
printRemotes(ctx, aliasedURL, targets)
|
||||
return nil
|
||||
}
|
||||
|
||||
func printRemotes(ctx *cli.Context, urlStr string, targets []madmin.BucketTarget) {
|
||||
maxURLLen := 10
|
||||
maxTgtLen := 6
|
||||
maxSrcLen := 6
|
||||
maxArnLen := 3
|
||||
|
||||
if !globalJSON {
|
||||
if len(targets) == 0 {
|
||||
console.Print(console.Colorize("RemoteListEmpty", fmt.Sprintf("No remote targets found for `%s`. \n", urlStr)))
|
||||
return
|
||||
}
|
||||
for _, t := range targets {
|
||||
l := len(t.Endpoint)
|
||||
if l > maxURLLen {
|
||||
maxURLLen = l
|
||||
}
|
||||
if len(t.TargetBucket) > maxTgtLen {
|
||||
maxTgtLen = len(t.TargetBucket)
|
||||
}
|
||||
if len(t.SourceBucket) > maxSrcLen {
|
||||
maxSrcLen = len(t.SourceBucket)
|
||||
}
|
||||
if len(t.Arn) > maxArnLen {
|
||||
maxArnLen = len(t.Arn)
|
||||
}
|
||||
}
|
||||
if maxURLLen > 0 {
|
||||
console.Println(console.Colorize("RemoteListMessage", fmt.Sprintf("%-*.*s %-*.*s->%-*.*s %-*.*s %s %s", maxURLLen+8, maxURLLen+8, "Remote URL", maxSrcLen, maxSrcLen, "Source", maxTgtLen, maxTgtLen, "Target", maxArnLen, maxArnLen, "ARN", "SYNC", "PROXY")))
|
||||
}
|
||||
}
|
||||
for _, target := range targets {
|
||||
targetURL := target.URL().String()
|
||||
if !globalJSON {
|
||||
if maxURLLen > 0 {
|
||||
targetURL = fmt.Sprintf("%-*.*s", maxURLLen+8, maxURLLen+8, target.URL().String())
|
||||
}
|
||||
if maxTgtLen > 0 {
|
||||
target.TargetBucket = fmt.Sprintf("%-*.*s", maxTgtLen, maxTgtLen, target.TargetBucket)
|
||||
}
|
||||
|
||||
if maxSrcLen > 0 {
|
||||
target.SourceBucket = fmt.Sprintf("%-*.*s", maxSrcLen, maxSrcLen, target.SourceBucket)
|
||||
}
|
||||
if maxArnLen > 0 {
|
||||
target.Arn = fmt.Sprintf("%-*.*s", maxArnLen, maxArnLen, target.Arn)
|
||||
}
|
||||
}
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
AccessKey: target.Credentials.AccessKey,
|
||||
TargetBucket: target.TargetBucket,
|
||||
TargetURL: targetURL,
|
||||
SourceBucket: target.SourceBucket,
|
||||
RemoteARN: target.Arn,
|
||||
ServiceType: string(target.Type),
|
||||
ReplicationSync: target.ReplicationSync,
|
||||
Bandwidth: target.BandwidthLimit,
|
||||
Proxy: !target.DisableProxy,
|
||||
ResetID: target.ResetID,
|
||||
ResetBefore: target.ResetBeforeDate,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -22,9 +22,7 @@ import "github.com/minio/cli"
|
||||
var adminBucketRemoteSubcommands = []cli.Command{
|
||||
adminBucketRemoteAddCmd,
|
||||
adminBucketRemoteEditCmd,
|
||||
adminBucketRemoteListCmd,
|
||||
adminBucketRemoteRmCmd,
|
||||
adminBwInfoCmd,
|
||||
}
|
||||
|
||||
var adminBucketRemoteCmd = cli.Command{
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminBucketRemoteRmCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove configured remote target",
|
||||
Action: mainAdminBucketRemoteRemove,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelp: true,
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteRemove is the handle for "mc admin bucket remote rm" command.
|
||||
func mainAdminBucketRemoteRemove(_ *cli.Context) error {
|
||||
deprecatedError("mc replicate rm")
|
||||
return nil
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminBucketRemoteRmFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "arn",
|
||||
Usage: "ARN to be removed",
|
||||
},
|
||||
}
|
||||
|
||||
var adminBucketRemoteRmCmd = cli.Command{
|
||||
Name: "rm",
|
||||
Usage: "remove configured remote target",
|
||||
Action: mainAdminBucketRemoteRemove,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(globalFlags, adminBucketRemoteRmFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Remove existing remote target with arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
for bucket srcbucket on MinIO server.
|
||||
{{.Prompt}} {{.HelpName}} myminio/srcbucket --arn "arn:minio:replication:us-west-1:993bc6b6-accd-45e3-884f-5f3e652aed2a:dest1"
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminBucketRemoteRemoveSyntax - validate all the passed arguments
|
||||
func checkAdminBucketRemoteRemoveSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainAdminBucketRemoteRemove is the handle for "mc admin bucket remote rm" command.
|
||||
func mainAdminBucketRemoteRemove(ctx *cli.Context) error {
|
||||
checkAdminBucketRemoteRemoveSyntax(ctx)
|
||||
|
||||
console.SetColor("RemoteMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
// Create a new MinIO Admin Client
|
||||
client, cerr := newAdminClient(aliasedURL)
|
||||
fatalIf(cerr.Trace(aliasedURL), "Unable to initialize admin connection.")
|
||||
_, sourceBucket := url2Alias(args[0])
|
||||
if sourceBucket == "" {
|
||||
fatalIf(errInvalidArgument(), "Source bucket not specified in `"+args[0]+"`.")
|
||||
}
|
||||
arn := ctx.String("arn")
|
||||
if arn == "" {
|
||||
fatalIf(errInvalidArgument(), "ARN needs to be specified.")
|
||||
}
|
||||
fatalIf(probe.NewError(client.RemoveRemoteTarget(globalContext, sourceBucket, arn)).Trace(args...), "Unable to remove remote target")
|
||||
|
||||
printMsg(RemoteMessage{
|
||||
op: ctx.Command.Name,
|
||||
SourceBucket: sourceBucket,
|
||||
RemoteARN: arn,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
+3
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -22,6 +22,7 @@ import "github.com/minio/cli"
|
||||
var adminBucketSubcommands = []cli.Command{
|
||||
adminBucketRemoteCmd,
|
||||
adminBucketQuotaCmd,
|
||||
adminBucketInfoCmd,
|
||||
}
|
||||
|
||||
var adminBucketCmd = cli.Command{
|
||||
@@ -32,6 +33,7 @@ var adminBucketCmd = cli.Command{
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminBucketSubcommands,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
// mainAdminBucket is the handle for "mc admin bucket" command.
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminClusterBucketExportCmd = cli.Command{
|
||||
Name: "export",
|
||||
Usage: "backup bucket metadata to a zip file",
|
||||
Action: mainClusterBucketExport,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET/[BUCKET]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Save metadata of all buckets to a zip file.
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
`,
|
||||
}
|
||||
|
||||
func checkBucketExportSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainClusterBucketExport - metadata export command
|
||||
func mainClusterBucketExport(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkBucketExportSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
console.SetColor("File", color.New(color.FgWhite, color.Bold))
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compute bucket and object from the aliased URL
|
||||
aliasedURL = filepath.ToSlash(aliasedURL)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
_, bucket := url2Alias(aliasedURL)
|
||||
r, e := client.ExportBucketMetadata(context.Background(), bucket)
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to export bucket metadata.")
|
||||
|
||||
if bucket == "" {
|
||||
bucket = "bucket"
|
||||
}
|
||||
// Create bucket metadata zip file
|
||||
tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-%s-metadata-", strings.ReplaceAll(aliasedURL, "/", "-"), bucket))
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
ext := "zip"
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, r)
|
||||
fatalIf(probe.NewError(e), "Unable to download bucket metadata.")
|
||||
// Close everything
|
||||
r.Close()
|
||||
tmpFile.Close()
|
||||
// We use 4 bytes of the 32 bytes to identify the file.
|
||||
downloadPath := fmt.Sprintf("%s-%s-metadata.%s", aliasedURL, bucket, ext)
|
||||
// Create necessary directories.
|
||||
dir := filepath.Dir(downloadPath)
|
||||
if e := os.MkdirAll(dir, 0o755); e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(dir), "Unable to create download directory")
|
||||
}
|
||||
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
fatalIf(probe.NewError(e), "Unable to create a backup of "+downloadPath)
|
||||
} else {
|
||||
if !os.IsNotExist(e) {
|
||||
fatal(probe.NewError(e), "Unable to download file data")
|
||||
}
|
||||
}
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to rename downloaded data, file exists at %s", tmpFile.Name())
|
||||
|
||||
// Explicitly set permissions to 0o600 and override umask
|
||||
// to ensure that the file is not world-readable.
|
||||
e = os.Chmod(downloadPath, 0o600)
|
||||
fatalIf(probe.NewError(e), "Unable to set file permissions for "+downloadPath)
|
||||
|
||||
if !globalJSON {
|
||||
console.Infof("Bucket metadata successfully downloaded as %s\n", downloadPath)
|
||||
return nil
|
||||
}
|
||||
v := struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}{
|
||||
File: downloadPath,
|
||||
}
|
||||
b, e := json.Marshal(v)
|
||||
fatalIf(probe.NewError(e), "Unable to serialize data")
|
||||
console.Println(string(b))
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,242 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/klauspost/compress/zip"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminClusterBucketImportCmd = cli.Command{
|
||||
Name: "import",
|
||||
Usage: "restore bucket metadata from a zip file",
|
||||
Action: mainClusterBucketImport,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET/[BUCKET] /path/to/backups/bucket-metadata.zip
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Recover bucket metadata for all buckets from previously saved bucket metadata backup.
|
||||
{{.Prompt}} {{.HelpName}} myminio /backups/myminio-bucket-metadata.zip
|
||||
`,
|
||||
}
|
||||
|
||||
func checkBucketImportSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainClusterBucketImport - bucket metadata import command
|
||||
func mainClusterBucketImport(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkBucketImportSyntax(ctx)
|
||||
console.SetColor("Name", color.New(color.Bold, color.FgCyan))
|
||||
console.SetColor("success", color.New(color.Bold, color.FgGreen))
|
||||
console.SetColor("warning", color.New(color.Bold, color.FgYellow))
|
||||
console.SetColor("errors", color.New(color.Bold, color.FgRed))
|
||||
console.SetColor("statusMsg", color.New(color.Bold, color.FgHiWhite))
|
||||
console.SetColor("failCell", color.New(color.FgRed))
|
||||
console.SetColor("passCell", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
var r io.Reader
|
||||
var sz int64
|
||||
f, e := os.Open(args.Get(1))
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get bucket metadata")
|
||||
}
|
||||
if st, e := f.Stat(); e == nil {
|
||||
sz = st.Size()
|
||||
}
|
||||
defer f.Close()
|
||||
r = f
|
||||
|
||||
_, e = zip.NewReader(r.(io.ReaderAt), sz)
|
||||
fatalIf(probe.NewError(e).Trace(args...), fmt.Sprintf("Unable to read zip file %s", args.Get(1)))
|
||||
|
||||
f, e = os.Open(args.Get(1))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get bucket metadata")
|
||||
defer f.Close()
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compute bucket and object from the aliased URL
|
||||
aliasedURL = filepath.ToSlash(aliasedURL)
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
_, bucket := url2Alias(aliasedURL)
|
||||
|
||||
rpt, e := client.ImportBucketMetadata(context.Background(), bucket, f)
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to import bucket metadata.")
|
||||
|
||||
printMsg(importMetaMsg{
|
||||
BucketMetaImportErrs: rpt,
|
||||
Status: "success",
|
||||
URL: aliasedURL,
|
||||
Op: ctx.Command.Name,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type importMetaMsg struct {
|
||||
madmin.BucketMetaImportErrs
|
||||
Op string
|
||||
URL string `json:"url"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
func statusTick(s madmin.MetaStatus) string {
|
||||
switch {
|
||||
case s.Err != "":
|
||||
return console.Colorize("failCell", crossTickCell)
|
||||
case !s.IsSet:
|
||||
return blankCell
|
||||
default:
|
||||
return console.Colorize("passCell", tickCell)
|
||||
}
|
||||
}
|
||||
|
||||
func (i importMetaMsg) String() string {
|
||||
m := i.Buckets
|
||||
totBuckets := len(m)
|
||||
totErrs := 0
|
||||
for _, st := range m {
|
||||
if st.ObjectLock.Err != "" || st.Versioning.Err != "" ||
|
||||
st.SSEConfig.Err != "" || st.Tagging.Err != "" ||
|
||||
st.Lifecycle.Err != "" || st.Quota.Err != "" ||
|
||||
st.Policy.Err != "" || st.Notification.Err != "" ||
|
||||
st.Cors.Err != "" || st.Err != "" {
|
||||
totErrs++
|
||||
}
|
||||
}
|
||||
var b strings.Builder
|
||||
numSch := "success"
|
||||
if totErrs > 0 {
|
||||
numSch = "warning"
|
||||
}
|
||||
msg := "\n" + console.Colorize(numSch, totBuckets-totErrs) +
|
||||
console.Colorize("statusMsg", "/") +
|
||||
console.Colorize("success", totBuckets) +
|
||||
console.Colorize("statusMsg", " buckets were imported successfully.")
|
||||
fmt.Fprintln(&b, msg)
|
||||
if totErrs > 0 {
|
||||
fmt.Fprintln(&b, console.Colorize("errors", "Errors: \n"))
|
||||
for bucket, st := range m {
|
||||
if st.ObjectLock.Err != "" || st.Versioning.Err != "" ||
|
||||
st.SSEConfig.Err != "" || st.Tagging.Err != "" ||
|
||||
st.Lifecycle.Err != "" || st.Quota.Err != "" ||
|
||||
st.Policy.Err != "" || st.Notification.Err != "" ||
|
||||
st.Cors.Err != "" || st.Err != "" {
|
||||
fmt.Fprintln(&b, printImportErrs(bucket, st))
|
||||
}
|
||||
}
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (i importMetaMsg) JSON() string {
|
||||
buf := &bytes.Buffer{}
|
||||
enc := json.NewEncoder(buf)
|
||||
enc.SetIndent("", " ")
|
||||
// Disable escaping special chars to display XML tags correctly
|
||||
enc.SetEscapeHTML(false)
|
||||
|
||||
fatalIf(probe.NewError(enc.Encode(i.Buckets)), "Unable to marshal into JSON.")
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// pretty print import errors
|
||||
func printImportErrs(bucket string, r madmin.BucketStatus) string {
|
||||
var b strings.Builder
|
||||
placeHolder := ""
|
||||
key := fmt.Sprintf("%-10s: %s", "Name", bucket)
|
||||
fmt.Fprintln(&b, console.Colorize("Name", key))
|
||||
|
||||
if r.Err != "" {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, console.Colorize("errors", "Error: "), r.Err)
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.ObjectLock.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Object lock: ", statusTick(r.ObjectLock))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Versioning.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Versioning: ", statusTick(r.Versioning))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
|
||||
if r.SSEConfig.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Encryption: ", statusTick(r.SSEConfig))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Lifecycle.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Lifecycle: ", statusTick(r.Lifecycle))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Notification.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Notification: ", statusTick(r.Notification))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Quota.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Quota: ", statusTick(r.Quota))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Policy.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Policy: ", statusTick(r.Policy))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Tagging.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "Tagging: ", statusTick(r.Tagging))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
if r.Cors.IsSet {
|
||||
fmt.Fprintf(&b, "%2s%s %s", placeHolder, "CORS: ", statusTick(r.Cors))
|
||||
fmt.Fprintln(&b)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminClusterBucketSubcommands = []cli.Command{
|
||||
adminClusterBucketImportCmd,
|
||||
adminClusterBucketExportCmd,
|
||||
}
|
||||
|
||||
var adminClusterBucketCmd = cli.Command{
|
||||
Name: "bucket",
|
||||
Usage: "manage bucket metadata on MinIO cluster",
|
||||
Action: mainAdminClusterBucket,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminClusterBucketSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainAdminClusterBucket is the handle for "mc admin cluster bucket" command.
|
||||
func mainAdminClusterBucket(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminClusterBucketSubcommands)
|
||||
return nil
|
||||
// Sub-commands like "export", "import" have their own main.
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
// iam export specific flags.
|
||||
var (
|
||||
iamExportFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "output,o",
|
||||
Usage: "output iam export to a custom file path",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
var adminClusterIAMExportCmd = cli.Command{
|
||||
Name: "export",
|
||||
Usage: "exports IAM info to zipped file",
|
||||
Action: mainClusterIAMExport,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(iamExportFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Download all IAM metadata for cluster into zip file.
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
|
||||
2. Download all IAM metadata to a custom file.
|
||||
{{.Prompt}} {{.HelpName}} myminio --output /tmp/myminio-iam.zip
|
||||
`,
|
||||
}
|
||||
|
||||
func checkIAMExportSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainClusterIAMExport - metadata export command
|
||||
func mainClusterIAMExport(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkIAMExportSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := filepath.ToSlash(args.Get(0))
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
|
||||
console.SetColor("File", color.New(color.FgWhite, color.Bold))
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
r, e := client.ExportIAM(context.Background())
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to export IAM info.")
|
||||
|
||||
// Create iam info zip file
|
||||
tmpFile, e := os.CreateTemp("", fmt.Sprintf("%s-iam-info", aliasedURL))
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
ext := "zip"
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, r)
|
||||
fatalIf(probe.NewError(e), "Unable to download IAM info.")
|
||||
|
||||
// Close everything
|
||||
r.Close()
|
||||
tmpFile.Close()
|
||||
|
||||
downloadPath := fmt.Sprintf("%s-iam-info.%s", aliasedURL, ext)
|
||||
if ctx.String("output") != "" {
|
||||
downloadPath = ctx.String("output")
|
||||
}
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
fatalIf(probe.NewError(e), "Unable to create a backup of "+downloadPath)
|
||||
} else {
|
||||
if !os.IsNotExist(e) {
|
||||
fatal(probe.NewError(e), "Unable to download file data")
|
||||
}
|
||||
}
|
||||
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to rename downloaded data, file exists at %s", tmpFile.Name())
|
||||
|
||||
// Explicitly set permissions to 0o600 and override umask
|
||||
// to ensure that the file is not world-readable.
|
||||
e = os.Chmod(downloadPath, 0o600)
|
||||
fatalIf(probe.NewError(e), "Unable to set file permissions for "+downloadPath)
|
||||
|
||||
if !globalJSON {
|
||||
console.Infof("IAM info successfully downloaded as %s\n", downloadPath)
|
||||
return nil
|
||||
}
|
||||
|
||||
v := struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}{
|
||||
File: downloadPath,
|
||||
}
|
||||
b, e := json.Marshal(v)
|
||||
fatalIf(probe.NewError(e), "Unable to serialize data")
|
||||
console.Println(string(b))
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/klauspost/compress/zip"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminClusterIAMImportCmd = cli.Command{
|
||||
Name: "import",
|
||||
Usage: "imports IAM info from zipped file",
|
||||
Action: mainClusterIAMImport,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET/BUCKET /path/to/myminio-iam-info.zip
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Set IAM info from previously exported metadata zip file.
|
||||
{{.Prompt}} {{.HelpName}} myminio /tmp/myminio-iam-info.zip
|
||||
|
||||
`,
|
||||
}
|
||||
|
||||
type iamImportInfo madmin.ImportIAMResult
|
||||
|
||||
func (i iamImportInfo) JSON() string {
|
||||
bs, e := json.MarshalIndent(madmin.ImportIAMResult(i), "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
return string(bs)
|
||||
}
|
||||
|
||||
func (i iamImportInfo) String() string {
|
||||
var messages []string
|
||||
info := madmin.ImportIAMResult(i)
|
||||
messages = append(messages, processIAMEntities(info.Skipped, "Skipped")...)
|
||||
messages = append(messages, processIAMEntities(info.Removed, "Removed")...)
|
||||
messages = append(messages, processIAMEntities(info.Added, "Added")...)
|
||||
messages = append(messages, processErrIAMEntities(info.Failed)...)
|
||||
return strings.Join(messages, "\n")
|
||||
}
|
||||
|
||||
func processIAMEntities(entities madmin.IAMEntities, action string) []string {
|
||||
var messages []string
|
||||
if len(entities.Policies) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s policies: %v", action, strings.Join(entities.Policies, ", ")))
|
||||
}
|
||||
if len(entities.Users) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s users: %v", action, strings.Join(entities.Users, ", ")))
|
||||
}
|
||||
if len(entities.Groups) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s groups: %v", action, strings.Join(entities.Groups, ", ")))
|
||||
}
|
||||
if len(entities.ServiceAccounts) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s service accounts: %v", action, strings.Join(entities.ServiceAccounts, ", ")))
|
||||
}
|
||||
var users []string
|
||||
for _, pol := range entities.UserPolicies {
|
||||
for name := range pol {
|
||||
users = append(users, name)
|
||||
}
|
||||
}
|
||||
if len(users) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s policies for users: %v", action, strings.Join(users, ", ")))
|
||||
}
|
||||
var groups []string
|
||||
for _, pol := range entities.GroupPolicies {
|
||||
for name := range pol {
|
||||
groups = append(groups, name)
|
||||
}
|
||||
}
|
||||
if len(groups) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s policies for groups: %v", action, strings.Join(groups, ", ")))
|
||||
}
|
||||
var stsarr []string
|
||||
for _, pol := range entities.STSPolicies {
|
||||
for name := range pol {
|
||||
stsarr = append(stsarr, name)
|
||||
}
|
||||
}
|
||||
if len(stsarr) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("%s policies for sts: %v", action, strings.Join(stsarr, ", ")))
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func processErrIAMEntities(entities madmin.IAMErrEntities) []string {
|
||||
var messages []string
|
||||
|
||||
var policies []string
|
||||
for _, entry := range entities.Policies {
|
||||
policies = append(policies, entry.Name)
|
||||
}
|
||||
if len(policies) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add policies: %v", strings.Join(policies, ", ")))
|
||||
}
|
||||
var users []string
|
||||
for _, entry := range entities.Users {
|
||||
users = append(users, entry.Name)
|
||||
}
|
||||
if len(users) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add users: %v", strings.Join(users, ", ")))
|
||||
}
|
||||
var groups []string
|
||||
for _, entry := range entities.Groups {
|
||||
groups = append(groups, entry.Name)
|
||||
}
|
||||
if len(groups) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add groups: %v", strings.Join(groups, ", ")))
|
||||
}
|
||||
var sas []string
|
||||
for _, entry := range entities.ServiceAccounts {
|
||||
sas = append(sas, entry.Name)
|
||||
}
|
||||
if len(sas) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add service accounts: %v", strings.Join(sas, ", ")))
|
||||
}
|
||||
var polusers []string
|
||||
for _, pol := range entities.UserPolicies {
|
||||
polusers = append(polusers, pol.Name)
|
||||
}
|
||||
if len(polusers) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add policies for users: %v", strings.Join(polusers, ", ")))
|
||||
}
|
||||
var polgroups []string
|
||||
for _, pol := range entities.GroupPolicies {
|
||||
polgroups = append(polgroups, pol.Name)
|
||||
}
|
||||
if len(polgroups) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add policies for groups: %v", strings.Join(polgroups, ", ")))
|
||||
}
|
||||
var polsts []string
|
||||
for _, pol := range entities.STSPolicies {
|
||||
polsts = append(polsts, pol.Name)
|
||||
}
|
||||
if len(polsts) > 0 {
|
||||
messages = append(messages, fmt.Sprintf("Failed to add policies for sts: %v", strings.Join(polsts, ", ")))
|
||||
}
|
||||
return messages
|
||||
}
|
||||
|
||||
func checkIAMImportSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// mainClusterIAMImport - iam info import command
|
||||
func mainClusterIAMImport(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkIAMImportSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := filepath.ToSlash(args.Get(0))
|
||||
aliasedURL = filepath.Clean(aliasedURL)
|
||||
|
||||
var r io.Reader
|
||||
var sz int64
|
||||
f, e := os.Open(args.Get(1))
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get IAM info")
|
||||
}
|
||||
if st, e := f.Stat(); e == nil {
|
||||
sz = st.Size()
|
||||
}
|
||||
defer f.Close()
|
||||
r = f
|
||||
|
||||
_, e = zip.NewReader(r.(io.ReaderAt), sz)
|
||||
fatalIf(probe.NewError(e).Trace(args...), fmt.Sprintf("Unable to read zip file %s", args.Get(1)))
|
||||
|
||||
f, e = os.Open(args.Get(1))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get IAM info")
|
||||
defer f.Close()
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
iamr, e := client.ImportIAMV2(context.Background(), f)
|
||||
if e != nil {
|
||||
f.Seek(0, 0)
|
||||
e = client.ImportIAM(context.Background(), f)
|
||||
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to import IAM info.")
|
||||
if !globalJSON {
|
||||
console.Infof("IAM info imported to %s from %s\n", aliasedURL, args.Get(1))
|
||||
}
|
||||
} else {
|
||||
printMsg(iamImportInfo(iamr))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminClusterIAMSubcommands = []cli.Command{
|
||||
adminClusterIAMImportCmd,
|
||||
adminClusterIAMExportCmd,
|
||||
}
|
||||
|
||||
var adminClusterIAMCmd = cli.Command{
|
||||
Name: "iam",
|
||||
Usage: "manage IAM info on MinIO cluster",
|
||||
Action: mainadminClusterIAM,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminClusterIAMSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainadminClusterIAM is the handle for "mc admin cluster bucket" command.
|
||||
func mainadminClusterIAM(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminClusterIAMSubcommands)
|
||||
return nil
|
||||
// Sub-commands like "export", "import" have their own main.
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminClusterSubcommands = []cli.Command{
|
||||
adminClusterBucketCmd,
|
||||
adminClusterIAMCmd,
|
||||
}
|
||||
|
||||
var adminClusterCmd = cli.Command{
|
||||
Name: "cluster",
|
||||
Usage: "manage MinIO cluster metadata",
|
||||
Action: mainAdminCluster,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminClusterSubcommands,
|
||||
HideHelpCommand: true,
|
||||
}
|
||||
|
||||
// mainAdminCluster is the handle for "mc admin cluster" command.
|
||||
func mainAdminCluster(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminClusterSubcommands)
|
||||
return nil
|
||||
// Sub-commands like "bucket", "iam" have their own main.
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,9 +18,17 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigExportCmd = cli.Command{
|
||||
@@ -40,6 +48,8 @@ FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
The output includes environment variables set on the server. These cannot be overridden from the client.
|
||||
|
||||
1. Export the current config from MinIO server
|
||||
{{.Prompt}} {{.HelpName}} play/ > config.txt
|
||||
`,
|
||||
@@ -53,7 +63,26 @@ type configExportMessage struct {
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configExportMessage) String() string {
|
||||
return string(u.Value)
|
||||
console.SetColor("EnvVar", color.New(color.FgYellow))
|
||||
bio := bufio.NewReader(bytes.NewReader(u.Value))
|
||||
var lines []string
|
||||
for {
|
||||
s, e := bio.ReadString('\n')
|
||||
// Make lines displaying environment variables bold.
|
||||
if strings.HasPrefix(s, "# MINIO_") {
|
||||
s = strings.TrimPrefix(s, "# ")
|
||||
parts := strings.SplitN(s, "=", 2)
|
||||
s = fmt.Sprintf("# %s=%s", console.Colorize("EnvVar", parts[0]), parts[1])
|
||||
lines = append(lines, s)
|
||||
} else {
|
||||
lines = append(lines, s)
|
||||
}
|
||||
if e == io.EOF {
|
||||
break
|
||||
}
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to string.")
|
||||
}
|
||||
return strings.Join(lines, "")
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
@@ -68,7 +97,7 @@ func (u configExportMessage) JSON() string {
|
||||
// checkAdminConfigExportSyntax - validate all the passed arguments
|
||||
func checkAdminConfigExportSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "export", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-14
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,12 +18,18 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigGetCmd = cli.Command{
|
||||
@@ -43,6 +49,8 @@ FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
The output includes environment variables set on the server. These cannot be overridden from the client.
|
||||
|
||||
1. Get the current region setting on MinIO server.
|
||||
{{.Prompt}} {{.HelpName}} play/ region
|
||||
region name=us-east-1
|
||||
@@ -57,21 +65,43 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
// configGetMessage container to hold locks information.
|
||||
type configGetMessage struct {
|
||||
Status string `json:"status"`
|
||||
Value *madmin.Target `json:"value"`
|
||||
Status string `json:"status"`
|
||||
Config []madmin.SubsysConfig `json:"config"`
|
||||
value []byte
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configGetMessage) String() string {
|
||||
return string(u.value)
|
||||
console.SetColor("EnvVar", color.New(color.FgYellow))
|
||||
bio := bufio.NewReader(bytes.NewReader(u.value))
|
||||
var lines []string
|
||||
for {
|
||||
s, e := bio.ReadString('\n')
|
||||
// Make lines displaying environment variables bold.
|
||||
if strings.HasPrefix(s, "# MINIO_") {
|
||||
s = strings.TrimPrefix(s, "# ")
|
||||
parts := strings.SplitN(s, "=", 2)
|
||||
s = fmt.Sprintf("# %s=%s", console.Colorize("EnvVar", parts[0]), parts[1])
|
||||
lines = append(lines, s)
|
||||
} else {
|
||||
lines = append(lines, s)
|
||||
}
|
||||
if e == io.EOF {
|
||||
break
|
||||
}
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to string.")
|
||||
}
|
||||
return strings.Join(lines, "")
|
||||
}
|
||||
|
||||
// JSON jsonified service status Message message.
|
||||
func (u configGetMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
var err error
|
||||
u.Config, err = madmin.ParseServerConfigOutput(string(u.value))
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -81,7 +111,7 @@ func (u configGetMessage) JSON() string {
|
||||
// checkAdminConfigGetSyntax - validate all the passed arguments
|
||||
func checkAdminConfigGetSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) < 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "get", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,14 +147,7 @@ func mainAdminConfigGet(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(e), "Unable to get server '%s' config", args.Tail())
|
||||
|
||||
if globalJSON {
|
||||
hr, e := client.HelpConfigKV(globalContext, subSys, "", false)
|
||||
fatalIf(probe.NewError(e), "Unable to get help for "+subSys+" the sub-system")
|
||||
|
||||
tgt, e := madmin.ParseSubSysTarget(buf, hr)
|
||||
fatalIf(probe.NewError(e), "Unable to parse sub-system target "+subSys)
|
||||
|
||||
printMsg(configGetMessage{
|
||||
Value: tgt,
|
||||
value: buf,
|
||||
})
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var historyListFlags = []cli.Flag{
|
||||
@@ -109,7 +109,7 @@ func (u configHistoryMessage) JSON() string {
|
||||
// checkAdminConfigHistorySyntax - validate all the passed arguments
|
||||
func checkAdminConfigHistorySyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "history", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func mainAdminConfigHistory(ctx *cli.Context) error {
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
if ctx.IsSet("clear") {
|
||||
if ctx.Bool("clear") {
|
||||
fatalIf(probe.NewError(client.ClearConfigHistoryKV(globalContext, "all")), "Unable to clear server configuration.")
|
||||
|
||||
// Print
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigImportCmd = cli.Command{
|
||||
@@ -78,7 +78,7 @@ func (u configImportMessage) JSON() string {
|
||||
// checkAdminConfigImportSyntax - validate all the passed arguments
|
||||
func checkAdminConfigImportSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "import", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-10
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigEnvFlags = []cli.Flag{
|
||||
@@ -46,7 +46,7 @@ var adminConfigResetCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
{{.HelpName}} TARGET [CONFIG-KEY...]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
@@ -54,6 +54,10 @@ FLAGS:
|
||||
EXAMPLES:
|
||||
1. Reset MQTT notifcation target 'name1' settings to default values.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ notify_mqtt:name1
|
||||
2. Reset compression's 'extensions' setting to default value.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ compression extensions
|
||||
3. Reset site name and site region to default values.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ site name region
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -61,17 +65,18 @@ EXAMPLES:
|
||||
type configResetMessage struct {
|
||||
Status string `json:"status"`
|
||||
targetAlias string
|
||||
key string
|
||||
restart bool
|
||||
}
|
||||
|
||||
// String colorized service status message.
|
||||
func (u configResetMessage) String() (msg string) {
|
||||
msg += console.Colorize("ResetConfigSuccess",
|
||||
"Key is successfully reset.\n")
|
||||
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||
fmt.Sprintf("'%s' is successfully reset.", u.key))
|
||||
if u.restart {
|
||||
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||
msg += console.Colorize("ResetConfigSuccess",
|
||||
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||
fmt.Sprintf("\nPlease restart your server with `%s`.", suggestion))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -88,7 +93,7 @@ func (u configResetMessage) JSON() string {
|
||||
// checkAdminConfigResetSyntax - validate all the passed arguments
|
||||
func checkAdminConfigResetSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() {
|
||||
cli.ShowCommandHelpAndExit(ctx, "reset", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,20 +116,28 @@ func mainAdminConfigReset(ctx *cli.Context) error {
|
||||
|
||||
if len(ctx.Args()) == 1 {
|
||||
// Call get config API
|
||||
hr, e := client.HelpConfigKV(globalContext, "", "", ctx.IsSet("env"))
|
||||
hr, e := client.HelpConfigKV(globalContext, "", "", ctx.Bool("env"))
|
||||
fatalIf(probe.NewError(e), "Unable to get help for the sub-system")
|
||||
|
||||
// Print
|
||||
printMsg(configHelpMessage{
|
||||
Value: hr,
|
||||
envOnly: ctx.IsSet("env"),
|
||||
envOnly: ctx.Bool("env"),
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Call reset config API
|
||||
input := strings.Join(args.Tail(), " ")
|
||||
// Check if user has attempted to set values
|
||||
for _, k := range args.Tail() {
|
||||
if strings.Contains(k, "=") {
|
||||
e := fmt.Errorf("new settings may not be provided for sub-system keys")
|
||||
fatalIf(probe.NewError(e), "Unable to reset '%s' on the server", args.Tail()[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Call reset config API
|
||||
restart, e := client.DelConfigKV(globalContext, input)
|
||||
fatalIf(probe.NewError(e), "Unable to reset '%s' on the server", input)
|
||||
|
||||
@@ -132,6 +145,7 @@ func mainAdminConfigReset(ctx *cli.Context) error {
|
||||
printMsg(configResetMessage{
|
||||
targetAlias: aliasedURL,
|
||||
restart: restart,
|
||||
key: input,
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigRestoreCmd = cli.Command{
|
||||
@@ -77,7 +77,7 @@ func (u configRestoreMessage) JSON() string {
|
||||
// checkAdminConfigRestoreSyntax - validate all the passed arguments
|
||||
func checkAdminConfigRestoreSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() || len(ctx.Args()) > 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "restore", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,9 +24,9 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminConfigSetCmd = cli.Command{
|
||||
@@ -88,7 +88,7 @@ func (u configSetMessage) JSON() string {
|
||||
// checkAdminConfigSetSyntax - validate all the passed arguments
|
||||
func checkAdminConfigSetSyntax(ctx *cli.Context) {
|
||||
if !ctx.Args().Present() && len(ctx.Args()) < 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "set", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,13 +112,13 @@ func mainAdminConfigSet(ctx *cli.Context) error {
|
||||
|
||||
if !strings.Contains(input, madmin.KvSeparator) {
|
||||
// Call get config API
|
||||
hr, e := client.HelpConfigKV(globalContext, args.Get(1), args.Get(2), ctx.IsSet("env"))
|
||||
hr, e := client.HelpConfigKV(globalContext, args.Get(1), args.Get(2), ctx.Bool("env"))
|
||||
fatalIf(probe.NewError(e), "Unable to get help for the sub-system")
|
||||
|
||||
// Print
|
||||
printMsg(configHelpMessage{
|
||||
Value: hr,
|
||||
envOnly: ctx.IsSet("env"),
|
||||
envOnly: ctx.Bool("env"),
|
||||
})
|
||||
|
||||
return nil
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
|
||||
+22
-170
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,21 +18,12 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
const logTimeFormat string = "15:04:05 MST 01/02/2006"
|
||||
|
||||
var adminConsoleFlags = []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "limit, l",
|
||||
@@ -47,173 +38,34 @@ var adminConsoleFlags = []cli.Flag{
|
||||
}
|
||||
|
||||
var adminConsoleCmd = cli.Command{
|
||||
Name: "console",
|
||||
Usage: "show console logs for MinIO server",
|
||||
Action: mainAdminConsole,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminConsoleFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [NODENAME]
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Show console logs for a MinIO server with alias 'play'
|
||||
{{.Prompt}} {{.HelpName}} play
|
||||
|
||||
2. Show last 5 log entries for node 'node1' on MinIO server with alias 'cluster1'
|
||||
{{.Prompt}} {{.HelpName}} --limit 5 cluster1 node1
|
||||
|
||||
3. Show application error logs on MinIO server with alias 'play'
|
||||
{{.Prompt}} {{.HelpName}} --type application play
|
||||
`,
|
||||
}
|
||||
|
||||
func checkAdminLogSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "console", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// Extend madmin.LogInfo to add String() and JSON() methods
|
||||
type logMessage struct {
|
||||
Status string `json:"status"`
|
||||
madmin.LogInfo
|
||||
}
|
||||
|
||||
// JSON - jsonify loginfo
|
||||
func (l logMessage) JSON() string {
|
||||
l.Status = "success"
|
||||
logJSON, err := json.MarshalIndent(&l, "", " ")
|
||||
fatalIf(probe.NewError(err), "Unable to marshal into JSON.")
|
||||
|
||||
return string(logJSON)
|
||||
}
|
||||
|
||||
func getLogTime(lt string) string {
|
||||
tm, err := time.Parse(time.RFC3339Nano, lt)
|
||||
if err != nil {
|
||||
return lt
|
||||
}
|
||||
return tm.Format(logTimeFormat)
|
||||
}
|
||||
|
||||
// String - return colorized loginfo as string.
|
||||
func (l logMessage) String() string {
|
||||
var hostStr string
|
||||
b := &strings.Builder{}
|
||||
if l.NodeName != "" {
|
||||
hostStr = fmt.Sprintf("%s ", colorizedNodeName(l.NodeName))
|
||||
}
|
||||
log := l.LogInfo
|
||||
if log.ConsoleMsg != "" {
|
||||
if strings.HasPrefix(log.ConsoleMsg, "\n") {
|
||||
fmt.Fprintf(b, "%s\n", hostStr)
|
||||
log.ConsoleMsg = strings.TrimPrefix(log.ConsoleMsg, "\n")
|
||||
}
|
||||
fmt.Fprintf(b, "%s %s", hostStr, log.ConsoleMsg)
|
||||
return b.String()
|
||||
}
|
||||
if l.API != nil {
|
||||
apiString := "API: " + l.API.Name + "("
|
||||
if l.API.Args != nil && l.API.Args.Bucket != "" {
|
||||
apiString = apiString + "bucket=" + l.API.Args.Bucket
|
||||
}
|
||||
if l.API.Args != nil && l.API.Args.Object != "" {
|
||||
apiString = apiString + ", object=" + l.API.Args.Object
|
||||
}
|
||||
apiString += ")"
|
||||
fmt.Fprintf(b, "\n%s %s", hostStr, console.Colorize("API", apiString))
|
||||
}
|
||||
if l.Time != "" {
|
||||
fmt.Fprintf(b, "\n%s Time: %s", hostStr, getLogTime(l.Time))
|
||||
}
|
||||
if l.DeploymentID != "" {
|
||||
fmt.Fprintf(b, "\n%s DeploymentID: %s", hostStr, l.DeploymentID)
|
||||
}
|
||||
if l.RequestID != "" {
|
||||
fmt.Fprintf(b, "\n%s RequestID: %s", hostStr, l.RequestID)
|
||||
}
|
||||
if l.RemoteHost != "" {
|
||||
fmt.Fprintf(b, "\n%s RemoteHost: %s", hostStr, l.RemoteHost)
|
||||
}
|
||||
if l.UserAgent != "" {
|
||||
fmt.Fprintf(b, "\n%s UserAgent: %s", hostStr, l.UserAgent)
|
||||
}
|
||||
if l.Trace != nil {
|
||||
if l.Trace.Message != "" {
|
||||
fmt.Fprintf(b, "\n%s Error: %s", hostStr, console.Colorize("LogMessage", l.Trace.Message))
|
||||
}
|
||||
if l.Trace.Variables != nil {
|
||||
for key, value := range l.Trace.Variables {
|
||||
if value != "" {
|
||||
fmt.Fprintf(b, "\n%s %s=%s", hostStr, key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
if l.Trace.Source != nil {
|
||||
traceLength := len(l.Trace.Source)
|
||||
for i, element := range l.Trace.Source {
|
||||
fmt.Fprintf(b, "\n%s %8v: %s", hostStr, traceLength-i, element)
|
||||
}
|
||||
}
|
||||
}
|
||||
logMsg := strings.TrimPrefix(b.String(), "\n")
|
||||
return fmt.Sprintf("%s\n", logMsg)
|
||||
Name: "console",
|
||||
Usage: "show MinIO logs",
|
||||
Action: mainAdminConsole,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminConsoleFlags, globalFlags...),
|
||||
Hidden: true,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: "This command is not supported now and replaced by 'admin logs' command. Please use 'mc admin logs'.\n",
|
||||
}
|
||||
|
||||
// mainAdminConsole - the entry function of console command
|
||||
func mainAdminConsole(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminLogSyntax(ctx)
|
||||
console.SetColor("LogMessage", color.New(color.Bold, color.FgRed))
|
||||
console.SetColor("Api", color.New(color.Bold, color.FgWhite))
|
||||
for _, c := range colors {
|
||||
console.SetColor(fmt.Sprintf("Node%d", c), color.New(c))
|
||||
}
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
var node string
|
||||
if len(ctx.Args()) > 1 {
|
||||
node = ctx.Args().Get(1)
|
||||
}
|
||||
var limit int
|
||||
newCmd := []string{"mc admin logs"}
|
||||
|
||||
var flgStr string
|
||||
|
||||
if ctx.IsSet("limit") {
|
||||
limit = ctx.Int("limit")
|
||||
if limit <= 0 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "please set a proper limit, for example: '--limit 5' to display last 5 logs, omit this flag to display all available logs")
|
||||
}
|
||||
}
|
||||
logType := strings.ToLower(ctx.String("type"))
|
||||
if logType != "minio" && logType != "application" && logType != "all" {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "Invalid value for --type flag. Valid options are [minio, application, all]")
|
||||
}
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
flgStr = fmt.Sprintf("%s %d", "--last", ctx.Int("limit"))
|
||||
newCmd = append(newCmd, flgStr)
|
||||
}
|
||||
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
// Start listening on all console log activity.
|
||||
logCh := client.GetLogs(ctxt, node, limit, logType)
|
||||
for logInfo := range logCh {
|
||||
if logInfo.Err != nil {
|
||||
fatalIf(probe.NewError(logInfo.Err), "Unable to listen to console logs")
|
||||
}
|
||||
// drop nodeName from output if specified as cli arg
|
||||
if node != "" {
|
||||
logInfo.NodeName = ""
|
||||
}
|
||||
printMsg(logMessage{LogInfo: logInfo})
|
||||
if ctx.IsSet("type") {
|
||||
flgStr = fmt.Sprintf("%s %s", "--type", strings.ToLower(ctx.String("type")))
|
||||
newCmd = append(newCmd, flgStr)
|
||||
}
|
||||
newCmd = append(newCmd, ctx.Args()...)
|
||||
|
||||
deprecatedError(strings.Join(newCmd, " "))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminDecommissionCancelCmd = cli.Command{
|
||||
@@ -48,7 +48,7 @@ EXAMPLES:
|
||||
1. Cancel an ongoing decommissioning of a pool.
|
||||
{{.Prompt}} {{.HelpName}} myminio/ http://server{5...8}/disk{1...4}
|
||||
|
||||
2. List all ongoing decommissioning of pools.
|
||||
2. Cancel all ongoing decommissioning of pools.
|
||||
{{.Prompt}} {{.HelpName}} myminio/
|
||||
`,
|
||||
}
|
||||
@@ -56,7 +56,7 @@ EXAMPLES:
|
||||
// checkAdminDecommissionCancelSyntax - validate all the passed arguments
|
||||
func checkAdminDecommissionCancelSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) > 2 || len(ctx.Args()) == 0 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminDecommissionStartCmd = cli.Command{
|
||||
@@ -52,7 +52,7 @@ EXAMPLES:
|
||||
// checkAdminDecommissionStartSyntax - validate all the passed arguments
|
||||
func checkAdminDecommissionStartSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
-10
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -25,8 +25,9 @@ import (
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminDecommissionStatusCmd = cli.Command{
|
||||
@@ -56,7 +57,7 @@ EXAMPLES:
|
||||
// checkAdminDecommissionStatusSyntax - validate all the passed arguments
|
||||
func checkAdminDecommissionStatusSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) > 2 || len(ctx.Args()) == 0 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +78,13 @@ func mainAdminDecommissionStatus(ctx *cli.Context) error {
|
||||
poolStatus, e := client.StatusPool(globalContext, pool)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get status per pool")
|
||||
|
||||
if globalJSON {
|
||||
statusJSONBytes, e := json.MarshalIndent(poolStatus, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
console.Println(string(statusJSONBytes))
|
||||
return nil
|
||||
}
|
||||
|
||||
var msg string
|
||||
if poolStatus.Decommission.Complete {
|
||||
msg = color.GreenString(fmt.Sprintf("Decommission of pool %s is complete, you may now remove it from server command line", poolStatus.CmdLine))
|
||||
@@ -88,10 +96,10 @@ func mainAdminDecommissionStatus(ctx *cli.Context) error {
|
||||
usedStart := (poolStatus.Decommission.TotalSize - poolStatus.Decommission.StartSize)
|
||||
usedCurrent := (poolStatus.Decommission.TotalSize - poolStatus.Decommission.CurrentSize)
|
||||
|
||||
if usedStart > usedCurrent {
|
||||
duration := uint64(time.Since(poolStatus.Decommission.StartTime).Seconds())
|
||||
duration := float64(time.Since(poolStatus.Decommission.StartTime)) / float64(time.Second)
|
||||
if usedStart > usedCurrent && duration > 10 {
|
||||
copied := uint64(usedStart - usedCurrent)
|
||||
speed := copied / duration
|
||||
speed := uint64(float64(copied) / duration)
|
||||
msg = "Decommissioning rate at " + humanize.IBytes(speed) + "/sec " + "[" + humanize.IBytes(
|
||||
uint64(usedCurrent)) + "/" + humanize.IBytes(uint64(poolStatus.Decommission.TotalSize)) + "]"
|
||||
msg += "\nStarted: " + humanize.RelTime(time.Now().UTC(), poolStatus.Decommission.StartTime, "", "ago")
|
||||
@@ -109,8 +117,15 @@ func mainAdminDecommissionStatus(ctx *cli.Context) error {
|
||||
poolStatuses, e := client.ListPoolsStatus(globalContext)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get status for all pools")
|
||||
|
||||
if globalJSON {
|
||||
statusJSONBytes, e := json.MarshalIndent(poolStatuses, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
console.Println(string(statusJSONBytes))
|
||||
return nil
|
||||
}
|
||||
|
||||
dspOrder := []col{colGreen} // Header
|
||||
for i := 0; i < len(poolStatuses); i++ {
|
||||
for range poolStatuses {
|
||||
dspOrder = append(dspOrder, colGrey)
|
||||
}
|
||||
var printColors []*color.Color
|
||||
@@ -124,14 +139,19 @@ func mainAdminDecommissionStatus(ctx *cli.Context) error {
|
||||
cellText[0] = []string{
|
||||
"ID",
|
||||
"Pools",
|
||||
"Capacity",
|
||||
"Drives Usage",
|
||||
"Status",
|
||||
}
|
||||
for idx, pool := range poolStatuses {
|
||||
idx++
|
||||
totalSize := uint64(pool.Decommission.TotalSize)
|
||||
currentSize := uint64(pool.Decommission.CurrentSize)
|
||||
capacity := humanize.IBytes(totalSize-currentSize) + " (used) / " + humanize.IBytes(totalSize) + " (total)"
|
||||
usedCurrent := uint64(pool.Decommission.TotalSize - pool.Decommission.CurrentSize)
|
||||
var capacity string
|
||||
if totalSize == 0 {
|
||||
capacity = "0% (total: 0B)"
|
||||
} else {
|
||||
capacity = fmt.Sprintf("%.1f%% (total: %s)", 100*float64(usedCurrent)/float64(totalSize), humanize.IBytes(totalSize))
|
||||
}
|
||||
status := "Active"
|
||||
if pool.Decommission != nil {
|
||||
if pool.Decommission.Complete {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
|
||||
+11
-7
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,9 +24,9 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminGroupAddCmd = cli.Command{
|
||||
@@ -48,13 +48,17 @@ FLAGS:
|
||||
EXAMPLES:
|
||||
1. Add users 'fivecent' and 'tencent' to the group 'allcents':
|
||||
{{.Prompt}} {{.HelpName}} myminio allcents fivecent tencent
|
||||
|
||||
2. Add user "james" to group "staff", then add the "readwrite" policy to the group "staff".
|
||||
{{.Prompt}} {{.HelpName}} myminio staff james
|
||||
{{.Prompt}} mc admin policy attach myminio readwrite --group staff
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminGroupAddSyntax - validate all the passed arguments
|
||||
func checkAdminGroupAddSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "add", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,8 +86,8 @@ func (u groupMessage) String() string {
|
||||
case "enable":
|
||||
return console.Colorize("GroupMessage", "Enabled group `"+u.GroupName+"` successfully.")
|
||||
case "add":
|
||||
membersStr := fmt.Sprintf("{%s}", strings.Join(u.Members, ","))
|
||||
return console.Colorize("GroupMessage", "Added members "+membersStr+" to group "+u.GroupName+" successfully.")
|
||||
membersStr := fmt.Sprintf("`%s`", strings.Join(u.Members, ","))
|
||||
return console.Colorize("GroupMessage", "Added members "+membersStr+" to group `"+u.GroupName+"` successfully.")
|
||||
case "remove":
|
||||
if len(u.Members) > 0 {
|
||||
membersStr := fmt.Sprintf("{%s}", strings.Join(u.Members, ","))
|
||||
@@ -136,7 +140,7 @@ func mainAdminGroupAdd(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(client.UpdateGroupMembers(globalContext, gAddRemove)).Trace(args...), "Unable to add new group")
|
||||
|
||||
printMsg(groupMessage{
|
||||
op: "add",
|
||||
op: ctx.Command.Name,
|
||||
GroupName: args.Get(1),
|
||||
Members: members,
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
|
||||
+11
-14
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,13 +18,11 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminGroupEnableCmd = cli.Command{
|
||||
@@ -52,7 +50,7 @@ EXAMPLES:
|
||||
// checkAdminGroupEnableSyntax - validate all the passed arguments
|
||||
func checkAdminGroupEnableSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, ctx.Command.Name, 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,18 +69,17 @@ func mainAdminGroupEnableDisable(ctx *cli.Context) error {
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
group := args.Get(1)
|
||||
var err1 error
|
||||
var status madmin.GroupStatus
|
||||
if ctx.Command.Name == "enable" {
|
||||
switch ctx.Command.Name {
|
||||
case "enable":
|
||||
status = madmin.GroupEnabled
|
||||
} else if ctx.Command.Name == "disable" {
|
||||
case "disable":
|
||||
status = madmin.GroupDisabled
|
||||
} else {
|
||||
err1 = errors.New("cannot happen")
|
||||
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Command.Name), "Invalid group status name")
|
||||
}
|
||||
err1 = client.SetGroupStatus(globalContext, group, status)
|
||||
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")
|
||||
e := client.SetGroupStatus(globalContext, group, status)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable set group status")
|
||||
|
||||
printMsg(groupMessage{
|
||||
op: ctx.Command.Name,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminGroupInfoCmd = cli.Command{
|
||||
@@ -49,7 +49,7 @@ EXAMPLES:
|
||||
// checkAdminGroupInfoSyntax - validate all the passed arguments
|
||||
func checkAdminGroupInfoSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ func mainAdminGroupInfo(ctx *cli.Context) error {
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
group := args.Get(1)
|
||||
gd, err1 := client.GetGroupDescription(globalContext, group)
|
||||
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group info")
|
||||
gd, e := client.GetGroupDescription(globalContext, group)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to fetch group info")
|
||||
|
||||
printMsg(groupMessage{
|
||||
op: "info",
|
||||
op: ctx.Command.Name,
|
||||
GroupName: group,
|
||||
GroupStatus: gd.Status,
|
||||
GroupPolicy: gd.Policy,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -21,11 +21,12 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminGroupListCmd = cli.Command{
|
||||
Name: "list",
|
||||
ShortName: "ls",
|
||||
Usage: "display list of groups",
|
||||
Action: mainAdminGroupList,
|
||||
OnUsageError: onUsageError,
|
||||
@@ -49,7 +50,7 @@ EXAMPLES:
|
||||
// checkAdminGroupListSyntax - validate all the passed arguments
|
||||
func checkAdminGroupListSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,11 +68,11 @@ func mainAdminGroupList(ctx *cli.Context) error {
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
gs, err1 := client.ListGroups(globalContext)
|
||||
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group list")
|
||||
gs, e := client.ListGroups(globalContext)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list groups")
|
||||
|
||||
printMsg(groupMessage{
|
||||
op: "list",
|
||||
op: ctx.Command.Name,
|
||||
Groups: gs,
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -20,13 +20,14 @@ package cmd
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminGroupRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
ShortName: "rm",
|
||||
Usage: "remove group or members from a group",
|
||||
Action: mainAdminGroupRemove,
|
||||
OnUsageError: onUsageError,
|
||||
@@ -53,7 +54,7 @@ EXAMPLES:
|
||||
// checkAdminGroupRemoveSyntax - validate all the passed arguments
|
||||
func checkAdminGroupRemoveSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) < 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ func mainAdminGroupRemove(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Could not perform remove operation")
|
||||
|
||||
printMsg(groupMessage{
|
||||
op: "remove",
|
||||
op: ctx.Command.Name,
|
||||
GroupName: args.Get(1),
|
||||
Members: members,
|
||||
})
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,9 +18,10 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
)
|
||||
|
||||
type hri struct {
|
||||
@@ -49,21 +50,70 @@ func (h hri) getObjectHCCChange() (b, a col, err error) {
|
||||
}
|
||||
a, err = getHColCode(surplusShardsAfterHeal, parityShards)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("%w: surplusShardsBeforeHeal: %d, parityShards: %d",
|
||||
err = fmt.Errorf("%w: surplusShardsAfterHeal: %d, parityShards: %d",
|
||||
err, surplusShardsAfterHeal, parityShards)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// getBucketHCCChange - fetches health color code for bucket healing
|
||||
// this does not return a Grey color since it does not have any meaning
|
||||
// for a bucket healing. Return green if the bucket is found in a drive,
|
||||
// yellow for missing, and red for everything else, grey for weird situations
|
||||
func (h hri) getBucketHCCChange() (b, a col, err error) {
|
||||
if h.HealResultItem == nil {
|
||||
return colGrey, colGrey, errors.New("empty result")
|
||||
}
|
||||
|
||||
getColCode := func(drives []madmin.HealDriveInfo) (c col) {
|
||||
var missing, unavailable int
|
||||
for i := range drives {
|
||||
switch drives[i].State {
|
||||
case madmin.DriveStateOk:
|
||||
case madmin.DriveStateMissing:
|
||||
missing++
|
||||
default:
|
||||
unavailable++
|
||||
}
|
||||
}
|
||||
if unavailable > 0 {
|
||||
return colRed
|
||||
}
|
||||
if missing > 0 {
|
||||
return colYellow
|
||||
}
|
||||
return colGreen
|
||||
}
|
||||
|
||||
a, b = colGrey, colGrey
|
||||
|
||||
if len(h.Before.Drives) > 0 {
|
||||
b = getColCode(h.Before.Drives)
|
||||
}
|
||||
if len(h.After.Drives) > 0 {
|
||||
a = getColCode(h.After.Drives)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// getReplicatedFileHCCChange - fetches health color code for metadata
|
||||
// files that are replicated.
|
||||
func (h hri) getReplicatedFileHCCChange() (b, a col, err error) {
|
||||
getColCode := func(numAvail int) (c col, err error) {
|
||||
// calculate color code for replicated object similar
|
||||
// to erasure coded objects
|
||||
quorum := h.DiskCount/h.SetCount/2 + 1
|
||||
surplus := numAvail/h.SetCount - quorum
|
||||
parity := h.DiskCount/h.SetCount - quorum
|
||||
var quorum, surplus, parity int
|
||||
if h.SetCount > 0 {
|
||||
quorum = h.DiskCount/h.SetCount/2 + 1
|
||||
surplus = numAvail/h.SetCount - quorum
|
||||
parity = h.DiskCount/h.SetCount - quorum
|
||||
} else {
|
||||
// in case of bucket healing, disk count is for the node
|
||||
// also explicitly set count would be set to invalid value of -1
|
||||
quorum = h.DiskCount/2 + 1
|
||||
surplus = numAvail - quorum
|
||||
parity = h.DiskCount - quorum
|
||||
}
|
||||
c, err = getHColCode(surplus, parity)
|
||||
return
|
||||
}
|
||||
|
||||
+36
-26
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -27,9 +27,9 @@ import (
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -52,7 +52,7 @@ var (
|
||||
|
||||
func getHColCode(surplusShards, parityShards int) (c col, err error) {
|
||||
if parityShards < 1 || parityShards > 8 || surplusShards > parityShards {
|
||||
return c, fmt.Errorf("Invalid parity shard count/surplus shard count given")
|
||||
return c, errors.New("Invalid parity shard count/surplus shard count given")
|
||||
}
|
||||
if surplusShards < 0 {
|
||||
return colGrey, err
|
||||
@@ -63,7 +63,7 @@ func getHColCode(surplusShards, parityShards int) (c col, err error) {
|
||||
return hColOrder[index], err
|
||||
}
|
||||
}
|
||||
return c, fmt.Errorf("cannot get a heal color code")
|
||||
return c, errors.New("cannot get a heal color code")
|
||||
}
|
||||
|
||||
type uiData struct {
|
||||
@@ -127,7 +127,9 @@ func (ui *uiData) updateStats(i madmin.HealResultItem) error {
|
||||
var afterCol col
|
||||
h := newHRI(&i)
|
||||
switch h.Type {
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||
case madmin.HealItemBucket:
|
||||
_, afterCol, err = h.getBucketHCCChange()
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||
_, afterCol, err = h.getReplicatedFileHCCChange()
|
||||
default:
|
||||
_, afterCol, err = h.getObjectHCCChange()
|
||||
@@ -205,17 +207,24 @@ func (ui *uiData) printItemsQuietly(s *madmin.HealTaskStatus) (err error) {
|
||||
var b, a col
|
||||
for _, item := range s.Items {
|
||||
h := newHRI(&item)
|
||||
hrStr := h.getHealResultStr()
|
||||
switch h.Type {
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||
case madmin.HealItemBucket:
|
||||
b, a, err = h.getBucketHCCChange()
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||
b, a, err = h.getReplicatedFileHCCChange()
|
||||
default:
|
||||
b, a, err = h.getObjectHCCChange()
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
errMsg := err.Error()
|
||||
if h.Detail != "" {
|
||||
errMsg = h.Detail
|
||||
}
|
||||
console.PrintC("[ERROR] ** ", hrStr, " **", ": ", errMsg, "\n")
|
||||
continue
|
||||
}
|
||||
printColStr(b, a)
|
||||
hrStr := h.getHealResultStr()
|
||||
switch h.Type {
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||
console.PrintC(fmt.Sprintln("**", hrStr, "**"))
|
||||
@@ -226,7 +235,7 @@ func (ui *uiData) printItemsQuietly(s *madmin.HealTaskStatus) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ui *uiData) printStatsQuietly(s *madmin.HealTaskStatus) {
|
||||
func (ui *uiData) printStatsQuietly() {
|
||||
totalObjects, totalSize, totalTime := ui.getProgress()
|
||||
|
||||
healedStr := fmt.Sprintf("Healed:\t%s/%s objects; %s in %s\n",
|
||||
@@ -240,6 +249,7 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||
type healRec struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Detail string `json:"detail,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Before struct {
|
||||
@@ -267,7 +277,9 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||
var b, a col
|
||||
var err error
|
||||
switch h.Type {
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||
case madmin.HealItemBucket:
|
||||
b, a, err = h.getBucketHCCChange()
|
||||
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||
b, a, err = h.getReplicatedFileHCCChange()
|
||||
default:
|
||||
if h.Type == madmin.HealItemObject {
|
||||
@@ -278,6 +290,7 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||
if err != nil {
|
||||
r.Error = err.Error()
|
||||
}
|
||||
r.Detail = h.Detail
|
||||
r.Before.Color = strings.ToLower(string(b))
|
||||
r.After.Color = strings.ToLower(string(a))
|
||||
r.Before.Online, r.After.Online = h.GetOnlineCounts()
|
||||
@@ -291,14 +304,14 @@ func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||
|
||||
for _, item := range s.Items {
|
||||
h := newHRI(&item)
|
||||
jsonBytes, err := json.MarshalIndent(makeHR(h), "", " ")
|
||||
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
|
||||
jsonBytes, e := json.MarshalIndent(makeHR(h), "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON.")
|
||||
console.Println(string(jsonBytes))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ui *uiData) printStatsJSON(s *madmin.HealTaskStatus) {
|
||||
func (ui *uiData) printStatsJSON(_ *madmin.HealTaskStatus) {
|
||||
var summary struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
@@ -321,8 +334,8 @@ func (ui *uiData) printStatsJSON(s *madmin.HealTaskStatus) {
|
||||
summary.Size = ui.BytesScanned
|
||||
summary.ElapsedTime = int64(ui.HealDuration.Round(time.Second).Seconds())
|
||||
|
||||
jBytes, err := json.MarshalIndent(summary, "", " ")
|
||||
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
|
||||
jBytes, e := json.MarshalIndent(summary, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON.")
|
||||
console.Println(string(jBytes))
|
||||
}
|
||||
|
||||
@@ -369,7 +382,7 @@ func (ui *uiData) updateUI(s *madmin.HealTaskStatus) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) (err error) {
|
||||
func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) {
|
||||
// Update state
|
||||
ui.updateDuration(s)
|
||||
for _, i := range s.Items {
|
||||
@@ -379,13 +392,12 @@ func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) (err error) {
|
||||
// Update display
|
||||
switch {
|
||||
case globalJSON:
|
||||
err = ui.printItemsJSON(s)
|
||||
ui.printItemsJSON(s)
|
||||
case globalQuiet:
|
||||
err = ui.printItemsQuietly(s)
|
||||
ui.printItemsQuietly(s)
|
||||
default:
|
||||
err = ui.updateUI(s)
|
||||
ui.updateUI(s)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (ui *uiData) healResumeMsg(aliasedURL string) string {
|
||||
@@ -420,16 +432,14 @@ func (ui *uiData) DisplayAndFollowHealStatus(aliasedURL string) (res madmin.Heal
|
||||
console.RewindLines(8)
|
||||
}
|
||||
}
|
||||
err = ui.UpdateDisplay(&res)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
ui.UpdateDisplay(&res)
|
||||
|
||||
if res.Summary == "finished" {
|
||||
if globalJSON {
|
||||
ui.printStatsJSON(&res)
|
||||
} else if globalQuiet {
|
||||
ui.printStatsQuietly(&res)
|
||||
ui.printStatsQuietly()
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
||||
+265
-178
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,20 +18,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -40,44 +43,74 @@ const (
|
||||
)
|
||||
|
||||
var adminHealFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "scan",
|
||||
Usage: "select the healing scan mode (normal/deep)",
|
||||
Value: scanNormalMode,
|
||||
cli.IntFlag{
|
||||
Name: "pool",
|
||||
Usage: "heal only the given pool",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "recursive, r",
|
||||
Usage: "heal recursively",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "dry-run, n",
|
||||
Usage: "only inspect data, but do not mutate",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-start, f",
|
||||
Usage: "force start a new heal sequence",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-stop, s",
|
||||
Usage: "force stop a running heal sequence",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "remove",
|
||||
Usage: "remove dangling objects in heal sequence",
|
||||
cli.IntFlag{
|
||||
Name: "set",
|
||||
Usage: "heal only the given set",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "storage-class",
|
||||
Usage: "show server/disks failure tolerance with the given storage class",
|
||||
Name: "scan",
|
||||
Usage: "select the healing scan mode (normal/deep)",
|
||||
Value: scanNormalMode,
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "recursive, r",
|
||||
Usage: "heal recursively",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "dry-run, n",
|
||||
Usage: "only inspect data, but do not mutate",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-start, f",
|
||||
Usage: "force start a new heal sequence",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force-stop, s",
|
||||
Usage: "force stop a running heal sequence",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "force",
|
||||
Usage: "avoid showing a warning prompt",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "remove",
|
||||
Usage: "remove dangling objects in heal sequence",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "storage-class",
|
||||
Usage: "show server/drives failure tolerance with the given storage class",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "rewrite",
|
||||
Usage: "rewrite objects from older to newer format",
|
||||
Hidden: true,
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "verbose, v",
|
||||
Usage: "show verbose information",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "all-drives, a",
|
||||
Usage: "select all drives for verbose printing",
|
||||
},
|
||||
}
|
||||
|
||||
var adminHealCmd = cli.Command{
|
||||
Name: "heal",
|
||||
Usage: "heal disks, buckets and objects on MinIO server",
|
||||
Usage: "monitor healing for bucket(s) and object(s) on MinIO server",
|
||||
Action: mainAdminHeal,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -100,14 +133,14 @@ EXAMPLES:
|
||||
|
||||
func checkAdminHealSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "heal", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
|
||||
// Check for scan argument
|
||||
scanArg := ctx.String("scan")
|
||||
scanArg = strings.ToLower(scanArg)
|
||||
if scanArg != scanNormalMode && scanArg != scanDeepMode {
|
||||
cli.ShowCommandHelpAndExit(ctx, "heal", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,61 +167,39 @@ type setIndex struct {
|
||||
pool, set int
|
||||
}
|
||||
|
||||
type healingStatus struct {
|
||||
started time.Time
|
||||
totalObjects uint64
|
||||
totalHealed uint64
|
||||
}
|
||||
|
||||
// Estimation of when the healing will finish
|
||||
func (h healingStatus) ETA() time.Time {
|
||||
if !h.started.IsZero() && h.totalObjects > h.totalHealed {
|
||||
objScanSpeed := float64(time.Now().UTC().Sub(h.started)) / float64(h.totalHealed)
|
||||
remainingDuration := float64(h.totalObjects-h.totalHealed) * objScanSpeed
|
||||
return time.Now().UTC().Add(time.Duration(remainingDuration))
|
||||
}
|
||||
return time.Time{}
|
||||
}
|
||||
|
||||
type poolInfo struct {
|
||||
tolerance int
|
||||
endpoints []string
|
||||
}
|
||||
|
||||
type diskInfo struct {
|
||||
set setIndex
|
||||
path string
|
||||
state string
|
||||
healing bool
|
||||
|
||||
usedSpace, totalSpace uint64
|
||||
}
|
||||
|
||||
type setInfo struct {
|
||||
healingStatus healingStatus
|
||||
totalDisks int
|
||||
totalDisks int
|
||||
|
||||
readyDisksCount int // disks online and not in healing state
|
||||
readyDisksUsedSpace uint64 // the total used space of ready disks
|
||||
|
||||
incapableDisks int
|
||||
}
|
||||
|
||||
type serverInfo struct {
|
||||
pool int
|
||||
disks []diskInfo
|
||||
disks []madmin.Disk
|
||||
}
|
||||
|
||||
func (s serverInfo) onlineDisksForSet(index setIndex) (setFound bool, count int) {
|
||||
for _, disk := range s.disks {
|
||||
if disk.set != index {
|
||||
if disk.PoolIndex != index.pool || disk.SetIndex != index.set {
|
||||
continue
|
||||
}
|
||||
setFound = true
|
||||
if disk.state == "ok" && !disk.healing {
|
||||
if disk.State == "ok" && !disk.Healing {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Get all disks from set statuses
|
||||
// Get all drives from set statuses
|
||||
func getAllDisks(sets []madmin.SetStatus) []madmin.Disk {
|
||||
var disks []madmin.Disk
|
||||
for _, set := range sets {
|
||||
@@ -197,7 +208,7 @@ func getAllDisks(sets []madmin.SetStatus) []madmin.Disk {
|
||||
return disks
|
||||
}
|
||||
|
||||
// Get all pools id from all disks
|
||||
// Get all pools id from all drives
|
||||
func getPoolsIndexes(disks []madmin.Disk) []int {
|
||||
m := make(map[int]struct{})
|
||||
for _, d := range disks {
|
||||
@@ -223,11 +234,9 @@ func generateSetsStatus(disks []madmin.Disk) map[setIndex]setInfo {
|
||||
setSt.totalDisks++
|
||||
if d.State != "ok" || d.Healing {
|
||||
setSt.incapableDisks++
|
||||
}
|
||||
if d.Healing && d.HealInfo != nil {
|
||||
setSt.healingStatus.started = d.HealInfo.Started
|
||||
setSt.healingStatus.totalObjects = d.HealInfo.ObjectsTotalCount
|
||||
setSt.healingStatus.totalHealed = d.HealInfo.ObjectsHealed
|
||||
} else {
|
||||
setSt.readyDisksCount++
|
||||
setSt.readyDisksUsedSpace += d.UsedSpace
|
||||
}
|
||||
m[idx] = setSt
|
||||
}
|
||||
@@ -238,8 +247,8 @@ func generateSetsStatus(disks []madmin.Disk) map[setIndex]setInfo {
|
||||
func generateServersStatus(disks []madmin.Disk) map[string]serverInfo {
|
||||
m := make(map[string]serverInfo)
|
||||
for _, d := range disks {
|
||||
u, err := url.Parse(d.Endpoint)
|
||||
if err != nil {
|
||||
u, e := url.Parse(d.Endpoint)
|
||||
if e != nil {
|
||||
continue
|
||||
}
|
||||
endpoint := u.Host
|
||||
@@ -252,15 +261,7 @@ func generateServersStatus(disks []madmin.Disk) map[string]serverInfo {
|
||||
pool: d.PoolIndex,
|
||||
}
|
||||
}
|
||||
setIndex := setIndex{pool: d.PoolIndex, set: d.SetIndex}
|
||||
serverSt.disks = append(serverSt.disks, diskInfo{
|
||||
set: setIndex,
|
||||
path: u.Path,
|
||||
state: d.State,
|
||||
healing: d.Healing,
|
||||
usedSpace: d.UsedSpace,
|
||||
totalSpace: d.TotalSpace,
|
||||
})
|
||||
serverSt.disks = append(serverSt.disks, d)
|
||||
m[endpoint] = serverSt
|
||||
}
|
||||
return m
|
||||
@@ -340,6 +341,8 @@ type verboseBackgroundHealStatusMessage struct {
|
||||
Status string `json:"status"`
|
||||
HealInfo madmin.BgHealState
|
||||
|
||||
allDrives bool
|
||||
|
||||
// Specify storage class to show servers/disks tolerance
|
||||
ToleranceForSC string `json:"-"`
|
||||
}
|
||||
@@ -384,47 +387,73 @@ func (s verboseBackgroundHealStatusMessage) String() string {
|
||||
_, ok := offlineEndpoints[endpoint]
|
||||
if ok {
|
||||
stateText := console.Colorize("NodeFailed", "OFFLINE")
|
||||
fmt.Fprintf(&msg, fmt.Sprintf(" %s: %s\n", endpoint, stateText))
|
||||
fmt.Fprintf(&msg, " %s: %s\n", endpoint, stateText)
|
||||
continue
|
||||
}
|
||||
var serverHeader strings.Builder
|
||||
var serverHeaderPrinted bool
|
||||
serverStatus := serversStatus[endpoint]
|
||||
switch {
|
||||
case showTolerance:
|
||||
serverHeader := " %s: (Tolerance: %d server(s))\n"
|
||||
fmt.Fprintf(&msg, fmt.Sprintf(serverHeader, endpoint, poolsInfo[serverStatus.pool].tolerance))
|
||||
hdr := " %s: (Tolerance: %d server(s))\n"
|
||||
fmt.Fprintf(&serverHeader, hdr, endpoint, poolsInfo[serverStatus.pool].tolerance)
|
||||
default:
|
||||
serverHeader := " %s:\n"
|
||||
fmt.Fprintf(&msg, fmt.Sprintf(serverHeader, endpoint))
|
||||
hdr := " %s:\n"
|
||||
fmt.Fprintf(&serverHeader, hdr, endpoint)
|
||||
}
|
||||
|
||||
for _, d := range serverStatus.disks {
|
||||
if d.set.pool != pool {
|
||||
if d.PoolIndex != pool {
|
||||
continue
|
||||
}
|
||||
stateText := ""
|
||||
switch {
|
||||
case d.state == "ok" && d.healing:
|
||||
case d.State == "ok" && d.Healing:
|
||||
stateText = console.Colorize("DiskHealing", "HEALING")
|
||||
case d.state == "ok":
|
||||
case d.State == "ok":
|
||||
if !s.allDrives {
|
||||
continue
|
||||
}
|
||||
stateText = console.Colorize("DiskOK", "OK")
|
||||
default:
|
||||
stateText = console.Colorize("DiskFailed", d.state)
|
||||
stateText = console.Colorize("DiskFailed", d.State)
|
||||
}
|
||||
fmt.Fprintf(&msg, " + %s : %s\n", d.path, stateText)
|
||||
if d.healing {
|
||||
estimationText := "Calculating..."
|
||||
if eta := setsStatus[d.set].healingStatus.ETA(); !eta.IsZero() {
|
||||
estimationText = humanize.RelTime(time.Now().UTC(), eta, "", "")
|
||||
if !serverHeaderPrinted {
|
||||
serverHeaderPrinted = true
|
||||
fmt.Fprint(&msg, serverHeader.String())
|
||||
}
|
||||
drivePath := d.DrivePath
|
||||
if drivePath == "" {
|
||||
if u, e := url.Parse(d.Endpoint); e == nil {
|
||||
drivePath = u.Path
|
||||
}
|
||||
fmt.Fprintf(&msg, " |__ Estimated: %s\n", estimationText)
|
||||
}
|
||||
fmt.Fprintf(&msg, " |__ Capacity: %s/%s\n", humanize.IBytes(d.usedSpace), humanize.IBytes(d.totalSpace))
|
||||
fmt.Fprintf(&msg, " + %s : %s\n", drivePath, stateText)
|
||||
|
||||
thisSet := setsStatus[setIndex{d.PoolIndex, d.SetIndex}]
|
||||
if d.Healing && d.HealInfo != nil && !d.HealInfo.Finished {
|
||||
refUsedSpace := uint64(math.MaxUint64)
|
||||
if thisSet.readyDisksCount > 0 { // to avoid crashing
|
||||
refUsedSpace = thisSet.readyDisksUsedSpace / uint64(thisSet.readyDisksCount)
|
||||
}
|
||||
if refUsedSpace < d.UsedSpace { // normalize
|
||||
refUsedSpace = d.UsedSpace
|
||||
}
|
||||
fmt.Fprintf(&msg, " |__ Progress: %d%%\n", 100*d.UsedSpace/refUsedSpace)
|
||||
fmt.Fprintf(&msg, " |__ Started: %s\n", humanize.Time(d.HealInfo.Started))
|
||||
if d.HealInfo.RetryAttempts > 0 {
|
||||
fmt.Fprintf(&msg, " |__ Retries: %d\n", d.HealInfo.RetryAttempts)
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(&msg, " |__ Capacity: %s/%s\n", humanize.IBytes(d.UsedSpace), humanize.IBytes(d.TotalSpace))
|
||||
if showTolerance {
|
||||
fmt.Fprintf(&msg, " |__ Tolerance: %d disk(s)\n", parity-setsStatus[d.set].incapableDisks)
|
||||
fmt.Fprintf(&msg, " |__ Tolerance: %d drive(s)\n", parity-thisSet.incapableDisks)
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
if serverHeaderPrinted {
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,11 +474,11 @@ func (s verboseBackgroundHealStatusMessage) String() string {
|
||||
|
||||
summary := shortBackgroundHealStatusMessage{HealInfo: s.HealInfo}
|
||||
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
fmt.Fprintf(&msg, "Summary:\n")
|
||||
fmt.Fprintf(&msg, "=======\n")
|
||||
fmt.Fprintf(&msg, summary.String())
|
||||
fmt.Fprintf(&msg, "\n")
|
||||
fmt.Fprint(&msg, "\n")
|
||||
fmt.Fprint(&msg, "Summary:\n")
|
||||
fmt.Fprint(&msg, "=======\n")
|
||||
fmt.Fprint(&msg, summary.String())
|
||||
fmt.Fprint(&msg, "\n")
|
||||
|
||||
return msg.String()
|
||||
}
|
||||
@@ -472,98 +501,133 @@ type shortBackgroundHealStatusMessage struct {
|
||||
func (s shortBackgroundHealStatusMessage) String() string {
|
||||
healPrettyMsg := ""
|
||||
var (
|
||||
totalItems uint64
|
||||
totalBytes uint64
|
||||
itemsHealed uint64
|
||||
bytesHealed uint64
|
||||
startedAt time.Time
|
||||
itemsHealed uint64
|
||||
bytesHealed uint64
|
||||
itemsFailed uint64
|
||||
bytesFailed uint64
|
||||
itemsHealedPerSec float64
|
||||
bytesHealedPerSec float64
|
||||
startedAt time.Time
|
||||
setsExceedsStd int
|
||||
setsExceedsReduced int
|
||||
|
||||
// The addition of Elapsed time of each parallel healing operation
|
||||
// this is needed to calculate the rate of healing
|
||||
accumulatedElapsedTime time.Duration
|
||||
)
|
||||
|
||||
type setInfo struct {
|
||||
pool, set int
|
||||
}
|
||||
|
||||
dedup := make(map[setInfo]struct{})
|
||||
var problematicDisks int
|
||||
leastPct := 100.0
|
||||
|
||||
for _, set := range s.HealInfo.Sets {
|
||||
setsStatus := generateSetsStatus(set.Disks)
|
||||
// Furthest along disk...
|
||||
var furthestHealingDisk *madmin.Disk
|
||||
missingInSet := 0
|
||||
for _, disk := range set.Disks {
|
||||
if disk.HealInfo != nil {
|
||||
// Avoid counting two disks beloning to the same pool/set
|
||||
diskLocation := setInfo{pool: disk.PoolIndex, set: disk.SetIndex}
|
||||
_, found := dedup[diskLocation]
|
||||
if found {
|
||||
// Ignore disk with non 'ok' status
|
||||
if disk.State != madmin.DriveStateOk {
|
||||
if disk.State != madmin.DriveStateUnformatted {
|
||||
missingInSet++
|
||||
problematicDisks++
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if disk.HealInfo != nil && !disk.HealInfo.Finished {
|
||||
missingInSet++
|
||||
|
||||
thisSet := setsStatus[setIndex{pool: disk.PoolIndex, set: disk.SetIndex}]
|
||||
refUsedSpace := uint64(math.MaxUint64)
|
||||
if thisSet.readyDisksCount > 0 {
|
||||
refUsedSpace = thisSet.readyDisksUsedSpace / uint64(thisSet.readyDisksCount)
|
||||
}
|
||||
if refUsedSpace < disk.UsedSpace {
|
||||
refUsedSpace = disk.UsedSpace
|
||||
}
|
||||
if refUsedSpace > 0 {
|
||||
if pct := float64(disk.UsedSpace) / float64(refUsedSpace); pct < leastPct {
|
||||
leastPct = pct
|
||||
}
|
||||
} else {
|
||||
// Unlikely to have max used space in an erasure set to be zero, but still set this to zero
|
||||
leastPct = 0
|
||||
}
|
||||
|
||||
disk := disk
|
||||
if furthestHealingDisk == nil {
|
||||
furthestHealingDisk = &disk
|
||||
continue
|
||||
}
|
||||
dedup[diskLocation] = struct{}{}
|
||||
|
||||
// Approximate values
|
||||
totalItems += disk.HealInfo.ObjectsTotalCount
|
||||
totalBytes += disk.HealInfo.ObjectsTotalSize
|
||||
itemsHealed += disk.HealInfo.ItemsHealed
|
||||
bytesHealed += disk.HealInfo.BytesDone
|
||||
|
||||
if !disk.HealInfo.Started.IsZero() && !disk.HealInfo.Started.Before(startedAt) {
|
||||
startedAt = disk.HealInfo.Started
|
||||
}
|
||||
|
||||
if !disk.HealInfo.Started.IsZero() && !disk.HealInfo.LastUpdate.IsZero() {
|
||||
accumulatedElapsedTime += disk.HealInfo.LastUpdate.Sub(disk.HealInfo.Started)
|
||||
if disk.HealInfo.ItemsHealed+disk.HealInfo.ItemsFailed > furthestHealingDisk.HealInfo.ItemsHealed+furthestHealingDisk.HealInfo.ItemsFailed {
|
||||
furthestHealingDisk = &disk
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
if furthestHealingDisk != nil {
|
||||
disk := furthestHealingDisk
|
||||
|
||||
for _, mrf := range s.HealInfo.MRF {
|
||||
totalItems += mrf.TotalItems
|
||||
totalBytes += mrf.TotalBytes
|
||||
bytesHealed += mrf.BytesHealed
|
||||
itemsHealed += mrf.ItemsHealed
|
||||
// Approximate values
|
||||
itemsHealed += disk.HealInfo.ItemsHealed
|
||||
bytesHealed += disk.HealInfo.BytesDone
|
||||
bytesFailed += disk.HealInfo.BytesFailed
|
||||
itemsFailed += disk.HealInfo.ItemsFailed
|
||||
|
||||
if !disk.HealInfo.Started.IsZero() {
|
||||
if !disk.HealInfo.Started.Before(startedAt) {
|
||||
startedAt = disk.HealInfo.Started
|
||||
}
|
||||
|
||||
if !disk.HealInfo.LastUpdate.IsZero() {
|
||||
accumulatedElapsedTime += disk.HealInfo.LastUpdate.Sub(disk.HealInfo.Started)
|
||||
}
|
||||
|
||||
bytesHealedPerSec += float64(time.Second) * float64(disk.HealInfo.BytesDone) / float64(disk.HealInfo.LastUpdate.Sub(disk.HealInfo.Started))
|
||||
itemsHealedPerSec += float64(time.Second) * float64(disk.HealInfo.ItemsHealed+disk.HealInfo.ItemsFailed) / float64(disk.HealInfo.LastUpdate.Sub(disk.HealInfo.Started))
|
||||
|
||||
if !mrf.Started.IsZero() {
|
||||
if startedAt.IsZero() || mrf.Started.Before(startedAt) {
|
||||
startedAt = mrf.Started
|
||||
}
|
||||
|
||||
accumulatedElapsedTime += now.Sub(mrf.Started)
|
||||
if n, ok := s.HealInfo.SCParity["STANDARD"]; ok && missingInSet > n {
|
||||
setsExceedsStd++
|
||||
}
|
||||
if n, ok := s.HealInfo.SCParity["REDUCED_REDUNDANCY"]; ok && missingInSet > n {
|
||||
setsExceedsReduced++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if startedAt.IsZero() && itemsHealed == 0 {
|
||||
healPrettyMsg += "No active healing in progress."
|
||||
healPrettyMsg += "No active healing is detected for new disks"
|
||||
if problematicDisks > 0 {
|
||||
healPrettyMsg += fmt.Sprintf(", though %d offline disk(s) found.", problematicDisks)
|
||||
} else {
|
||||
healPrettyMsg += "."
|
||||
}
|
||||
return healPrettyMsg
|
||||
}
|
||||
|
||||
if totalItems > 0 && totalBytes > 0 {
|
||||
// Objects healed information
|
||||
itemsPct := 100 * float64(itemsHealed) / float64(totalItems)
|
||||
bytesPct := 100 * float64(bytesHealed) / float64(totalBytes)
|
||||
|
||||
healPrettyMsg += fmt.Sprintf("Objects Healed: %s/%s (%s), %s/%s (%s)\n",
|
||||
humanize.Comma(int64(itemsHealed)), humanize.Comma(int64(totalItems)), humanize.CommafWithDigits(itemsPct, 1)+"%%",
|
||||
humanize.Bytes(bytesHealed), humanize.Bytes(totalBytes), humanize.CommafWithDigits(bytesPct, 1)+"%%")
|
||||
} else {
|
||||
healPrettyMsg += fmt.Sprintf("Objects Healed: %s, %s\n", humanize.Comma(int64(itemsHealed)), humanize.Bytes(bytesHealed))
|
||||
}
|
||||
// Objects healed information
|
||||
healPrettyMsg += fmt.Sprintf("Objects Healed: %s, %s (%s)\n",
|
||||
humanize.Comma(int64(itemsHealed)), humanize.IBytes(bytesHealed), humanize.CommafWithDigits(leastPct*100, 1)+"%")
|
||||
healPrettyMsg += fmt.Sprintf("Objects Failed: %s\n", humanize.Comma(int64(itemsFailed)))
|
||||
|
||||
if accumulatedElapsedTime > 0 {
|
||||
bytesHealedPerSec := float64(uint64(time.Second)*bytesHealed) / float64(accumulatedElapsedTime)
|
||||
itemsHealedPerSec := float64(uint64(time.Second)*itemsHealed) / float64(accumulatedElapsedTime)
|
||||
healPrettyMsg += fmt.Sprintf("Heal rate: %d obj/s, %s/s\n", int64(itemsHealedPerSec), humanize.IBytes(uint64(bytesHealedPerSec)))
|
||||
}
|
||||
|
||||
if totalItems > 0 && totalBytes > 0 && !startedAt.IsZero() {
|
||||
// Estimation completion
|
||||
avgTimePerObject := float64(accumulatedElapsedTime) / float64(itemsHealed)
|
||||
estimatedDuration := time.Duration(avgTimePerObject * float64(totalItems))
|
||||
estimatedFinishTime := startedAt.Add(estimatedDuration)
|
||||
healPrettyMsg += fmt.Sprintf("Estimated Completion: %s\n", humanize.RelTime(now, estimatedFinishTime, "", ""))
|
||||
if problematicDisks > 0 {
|
||||
healPrettyMsg += "\n"
|
||||
healPrettyMsg += fmt.Sprintf("%d offline disk(s) found.", problematicDisks)
|
||||
}
|
||||
if setsExceedsStd > 0 {
|
||||
healPrettyMsg += "\n"
|
||||
healPrettyMsg += fmt.Sprintf("%d of %d sets exceeds standard parity count EC:%d lost/offline disks", setsExceedsStd, len(s.HealInfo.Sets), s.HealInfo.SCParity["STANDARD"])
|
||||
}
|
||||
if setsExceedsReduced > 0 {
|
||||
healPrettyMsg += "\n"
|
||||
healPrettyMsg += fmt.Sprintf("%d of %d sets exceeds reduced parity count EC:%d lost/offline disks", setsExceedsReduced, len(s.HealInfo.Sets), s.HealInfo.SCParity["REDUCED_REDUNDANCY"])
|
||||
}
|
||||
|
||||
return healPrettyMsg
|
||||
}
|
||||
|
||||
@@ -625,12 +689,13 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
// Return the background heal status when the user
|
||||
// doesn't pass a bucket or --recursive flag.
|
||||
if bucket == "" && !ctx.Bool("recursive") {
|
||||
bgHealStatus, berr := adminClnt.BackgroundHealStatus(globalContext)
|
||||
fatalIf(probe.NewError(berr), "Failed to get the status of the background heal.")
|
||||
bgHealStatus, e := adminClnt.BackgroundHealStatus(globalContext)
|
||||
fatalIf(probe.NewError(e), "Unable to get background heal status.")
|
||||
if ctx.Bool("verbose") {
|
||||
printMsg(verboseBackgroundHealStatusMessage{
|
||||
Status: "success",
|
||||
HealInfo: bgHealStatus,
|
||||
allDrives: ctx.Bool("all-drives"),
|
||||
ToleranceForSC: strings.ToUpper(ctx.String("storage-class")),
|
||||
})
|
||||
} else {
|
||||
@@ -642,31 +707,53 @@ func mainAdminHeal(ctx *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
for content := range clnt.List(globalContext, ListOptions{Recursive: false, ShowDir: DirNone}) {
|
||||
if content.Err != nil {
|
||||
fatalIf(content.Err.Trace(clnt.GetURL().String()), "Unable to heal bucket `"+bucket+"`.")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
opts := madmin.HealOpts{
|
||||
ScanMode: transformScanArg(ctx.String("scan")),
|
||||
Remove: ctx.Bool("remove"),
|
||||
Recursive: ctx.Bool("recursive"),
|
||||
DryRun: ctx.Bool("dry-run"),
|
||||
Recreate: ctx.Bool("rewrite"),
|
||||
}
|
||||
|
||||
if ctx.IsSet("pool") {
|
||||
p := ctx.Int("pool")
|
||||
if p < 1 {
|
||||
fatalIf(errInvalidArgument(), "--pool takes a non zero positive number.")
|
||||
}
|
||||
p--
|
||||
opts.Pool = &p
|
||||
}
|
||||
|
||||
if ctx.IsSet("set") {
|
||||
s := ctx.Int("set")
|
||||
if s < 1 {
|
||||
fatalIf(errInvalidArgument(), "--set takes a non zero positive number.")
|
||||
}
|
||||
s--
|
||||
opts.Set = &s
|
||||
}
|
||||
|
||||
forceStart := ctx.Bool("force-start")
|
||||
forceStop := ctx.Bool("force-stop")
|
||||
if forceStop {
|
||||
_, _, herr := adminClnt.Heal(globalContext, bucket, prefix, opts, "", forceStart, forceStop)
|
||||
fatalIf(probe.NewError(herr), "Failed to stop heal sequence.")
|
||||
_, _, e := adminClnt.Heal(globalContext, bucket, prefix, opts, "", forceStart, forceStop)
|
||||
fatalIf(probe.NewError(e), "Unable to stop healing.")
|
||||
printMsg(stopHealMessage{Status: "success", Alias: aliasedURL})
|
||||
return nil
|
||||
}
|
||||
|
||||
healStart, _, herr := adminClnt.Heal(globalContext, bucket, prefix, opts, "", forceStart, false)
|
||||
fatalIf(probe.NewError(herr), "Failed to start heal sequence.")
|
||||
if opts.Recursive && opts.Pool == nil && opts.Set == nil && isTerminal() && !ctx.Bool("force") {
|
||||
fmt.Printf("You are about to scan and heal the whole namespace in all pools and sets, please confirm [y/N]: ")
|
||||
answer, e := bufio.NewReader(os.Stdin).ReadString('\n')
|
||||
fatalIf(probe.NewError(e), "Unable to parse user input.")
|
||||
if answer = strings.TrimSpace(strings.ToLower(answer)); answer != "y" && answer != "yes" {
|
||||
fmt.Println("Heal aborted!")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
healStart, _, e := adminClnt.Heal(globalContext, bucket, prefix, opts, "", forceStart, false)
|
||||
fatalIf(probe.NewError(e), "Unable to start healing.")
|
||||
|
||||
ui := uiData{
|
||||
Bucket: bucket,
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminIDPCmd = cli.Command{
|
||||
Name: "idp",
|
||||
Usage: "manage MinIO IDentity Provider server configuration",
|
||||
Action: mainAdminIDP,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `This command's functionality has moved and this command is DEPRECATED.
|
||||
|
||||
Please use commands under 'mc idp ldap|openid' instead.
|
||||
`,
|
||||
}
|
||||
|
||||
func mainAdminIDP(_ *cli.Context) error {
|
||||
deprecatedError("mc idp ldap|openid")
|
||||
return nil
|
||||
}
|
||||
+197
-89
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -25,23 +25,31 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/dustin/go-humanize/english"
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/minio-go/v7/pkg/set"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminInfoFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "offline",
|
||||
Usage: "show only offline nodes/drives",
|
||||
},
|
||||
}
|
||||
|
||||
var adminInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "display MinIO server information",
|
||||
Action: mainAdminInfo,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
Flags: append(globalFlags, adminInfoFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
@@ -57,65 +65,100 @@ EXAMPLES:
|
||||
`,
|
||||
}
|
||||
|
||||
type poolSummary struct {
|
||||
index int
|
||||
setsCount int
|
||||
drivesPerSet int
|
||||
driveTolerance int
|
||||
drivesTotalFreeSpace uint64
|
||||
drivesTotalUsableSpace uint64
|
||||
endpoints set.StringSet
|
||||
}
|
||||
|
||||
type clusterInfo map[int]*poolSummary
|
||||
|
||||
func clusterSummaryInfo(info madmin.InfoMessage) clusterInfo {
|
||||
summary := make(clusterInfo)
|
||||
|
||||
for _, srv := range info.Servers {
|
||||
for _, disk := range srv.Disks {
|
||||
if disk.PoolIndex < 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
pool := summary[disk.PoolIndex]
|
||||
if pool == nil {
|
||||
pool = &poolSummary{
|
||||
index: disk.PoolIndex,
|
||||
endpoints: set.NewStringSet(),
|
||||
driveTolerance: info.StandardParity(),
|
||||
}
|
||||
}
|
||||
|
||||
if len(info.Backend.DrivesPerSet) > 0 {
|
||||
if disk.DiskIndex < (info.Backend.DrivesPerSet[disk.PoolIndex] - info.Backend.StandardSCParity) {
|
||||
pool.drivesTotalFreeSpace += disk.AvailableSpace
|
||||
pool.drivesTotalUsableSpace += disk.TotalSpace
|
||||
}
|
||||
}
|
||||
|
||||
pool.endpoints.Add(srv.Endpoint)
|
||||
summary[disk.PoolIndex] = pool
|
||||
}
|
||||
}
|
||||
|
||||
for idx := range info.Backend.TotalSets {
|
||||
pool := summary[idx]
|
||||
if pool != nil {
|
||||
pool.setsCount = info.Backend.TotalSets[idx]
|
||||
pool.drivesPerSet = info.Backend.DrivesPerSet[idx]
|
||||
summary[idx] = pool
|
||||
}
|
||||
}
|
||||
|
||||
return summary
|
||||
}
|
||||
|
||||
func endpointToPools(endpoint string, c clusterInfo) (pools []int) {
|
||||
for poolNumber, poolSummary := range c {
|
||||
if poolSummary.endpoints.Contains(endpoint) {
|
||||
pools = append(pools, poolNumber)
|
||||
}
|
||||
}
|
||||
sort.Ints(pools)
|
||||
return
|
||||
}
|
||||
|
||||
// Wrap "Info" message together with fields "Status" and "Error"
|
||||
type clusterStruct struct {
|
||||
Status string `json:"status"`
|
||||
Error string `json:"error,omitempty"`
|
||||
Info madmin.InfoMessage `json:"info,omitempty"`
|
||||
|
||||
onlyOffline bool
|
||||
}
|
||||
|
||||
// String provides colorized info messages depending on the type of a server
|
||||
// FS server non-FS server
|
||||
// ============================== ===================================
|
||||
// ● <ip>:<port> ● <ip>:<port>
|
||||
// Uptime: xxx Uptime: xxx
|
||||
// Version: xxx Version: xxx
|
||||
// Network: X/Y OK Network: X/Y OK
|
||||
//
|
||||
// U Used, B Buckets, O Objects Drives: N/N OK
|
||||
//
|
||||
// U Used, B Buckets, O Objects
|
||||
// N drives online, K drives offline
|
||||
//
|
||||
// String provides colorized info messages
|
||||
func (u clusterStruct) String() (msg string) {
|
||||
// Check cluster level "Status" field for error
|
||||
if u.Status == "error" {
|
||||
fatal(probe.NewError(errors.New(u.Error)), "Unable to get service status")
|
||||
fatal(probe.NewError(errors.New(u.Error)), "Unable to get service info")
|
||||
}
|
||||
|
||||
// If nothing has been collected, error out
|
||||
if u.Info.Servers == nil {
|
||||
fatal(probe.NewError(errors.New("Unable to get service status")), "")
|
||||
fatal(probe.NewError(errors.New("Unable to get service info")), "")
|
||||
}
|
||||
|
||||
// Initialization
|
||||
var totalOnlineDisksCluster int
|
||||
var totalOfflineDisksCluster int
|
||||
var totalOfflineNodes int
|
||||
|
||||
// Color palette initialization
|
||||
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
|
||||
console.SetColor("InfoWarning", color.New(color.FgYellow, color.Bold))
|
||||
|
||||
// MinIO server type default
|
||||
backendType := madmin.Unknown
|
||||
|
||||
// Set the type of MinIO server ("FS", "Erasure", "Unknown")
|
||||
switch v := u.Info.Backend.(type) {
|
||||
case madmin.FSBackend:
|
||||
backendType = madmin.FS
|
||||
case madmin.ErasureBackend:
|
||||
backendType = madmin.Erasure
|
||||
case map[string]interface{}:
|
||||
vt, ok := v["backendType"]
|
||||
if ok {
|
||||
backendTypeS, _ := vt.(string)
|
||||
switch backendTypeS {
|
||||
case "Erasure":
|
||||
backendType = madmin.Erasure
|
||||
}
|
||||
}
|
||||
}
|
||||
backendType := u.Info.BackendType()
|
||||
|
||||
coloredDot := console.Colorize("Info", dot)
|
||||
if madmin.ItemState(u.Info.Mode) == madmin.ItemInitializing {
|
||||
@@ -126,36 +169,35 @@ func (u clusterStruct) String() (msg string) {
|
||||
return u.Info.Servers[i].Endpoint < u.Info.Servers[j].Endpoint
|
||||
})
|
||||
|
||||
poolIdx := -1
|
||||
clusterSummary := clusterSummaryInfo(u.Info)
|
||||
|
||||
// Loop through each server and put together info for each one
|
||||
for _, srv := range u.Info.Servers {
|
||||
// Check if MinIO server is offline ("Mode" field),
|
||||
// If offline, error out
|
||||
if srv.State == "offline" {
|
||||
// Check if MinIO server is not online ("Mode" field),
|
||||
if srv.State != string(madmin.ItemOnline) {
|
||||
totalOfflineNodes++
|
||||
// "PrintB" is color blue in console library package
|
||||
msg += fmt.Sprintf("%s %s\n", console.Colorize("InfoFail", dot), console.Colorize("PrintB", srv.Endpoint))
|
||||
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("InfoFail", "offline"))
|
||||
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("InfoFail", srv.State))
|
||||
|
||||
if backendType == madmin.Erasure {
|
||||
// Info about drives on a server, only available for non-FS types
|
||||
var OffDisks int
|
||||
var OnDisks int
|
||||
var dispNoOfDisks string
|
||||
var OffDrives int
|
||||
var OnDrives int
|
||||
var dispNoOfDrives string
|
||||
for _, disk := range srv.Disks {
|
||||
switch disk.State {
|
||||
case madmin.DriveStateOk, madmin.DriveStateUnformatted:
|
||||
OnDisks++
|
||||
OnDrives++
|
||||
default:
|
||||
OffDisks++
|
||||
OffDrives++
|
||||
}
|
||||
}
|
||||
|
||||
totalDisksPerServer := OnDisks + OffDisks
|
||||
totalOnlineDisksCluster += OnDisks
|
||||
totalOfflineDisksCluster += OffDisks
|
||||
totalDrivesPerServer := OnDrives + OffDrives
|
||||
|
||||
dispNoOfDisks = strconv.Itoa(OnDisks) + "/" + strconv.Itoa(totalDisksPerServer)
|
||||
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDisks, console.Colorize("InfoFail", "OK "))
|
||||
dispNoOfDrives = strconv.Itoa(OnDrives) + "/" + strconv.Itoa(totalDrivesPerServer)
|
||||
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDrives, console.Colorize("InfoFail", "OK "))
|
||||
}
|
||||
|
||||
msg += "\n"
|
||||
@@ -164,6 +206,10 @@ func (u clusterStruct) String() (msg string) {
|
||||
continue
|
||||
}
|
||||
|
||||
if u.onlyOffline {
|
||||
continue
|
||||
}
|
||||
|
||||
// Print server title
|
||||
msg += fmt.Sprintf("%s %s\n", coloredDot, console.Colorize("PrintB", srv.Endpoint))
|
||||
|
||||
@@ -173,14 +219,14 @@ func (u clusterStruct) String() (msg string) {
|
||||
|
||||
// Version
|
||||
version := srv.Version
|
||||
if srv.Version == "DEVELOPMENT.GOGET" {
|
||||
if strings.Contains(srv.Version, "DEVELOPMENT") {
|
||||
version = "<development>"
|
||||
}
|
||||
msg += fmt.Sprintf(" Version: %s\n", version)
|
||||
// Network info, only available for non-FS types
|
||||
connectionAlive := 0
|
||||
totalNodes := len(srv.Network)
|
||||
if srv.Network != nil {
|
||||
if srv.Network != nil && backendType == madmin.Erasure {
|
||||
for _, v := range srv.Network {
|
||||
if v == "online" {
|
||||
connectionAlive++
|
||||
@@ -196,59 +242,117 @@ func (u clusterStruct) String() (msg string) {
|
||||
|
||||
if backendType == madmin.Erasure {
|
||||
// Info about drives on a server, only available for non-FS types
|
||||
var OffDisks int
|
||||
var OnDisks int
|
||||
var dispNoOfDisks string
|
||||
var OffDrives int
|
||||
var OnDrives int
|
||||
var dispNoOfDrives string
|
||||
for _, disk := range srv.Disks {
|
||||
if poolIdx == -1 {
|
||||
poolIdx = disk.PoolIndex
|
||||
}
|
||||
switch disk.State {
|
||||
case madmin.DriveStateOk, madmin.DriveStateUnformatted:
|
||||
OnDisks++
|
||||
OnDrives++
|
||||
default:
|
||||
OffDisks++
|
||||
OffDrives++
|
||||
}
|
||||
}
|
||||
|
||||
totalDisksPerServer := OnDisks + OffDisks
|
||||
totalOnlineDisksCluster += OnDisks
|
||||
totalOfflineDisksCluster += OffDisks
|
||||
totalDrivesPerServer := OnDrives + OffDrives
|
||||
clr := "Info"
|
||||
if OnDisks != totalDisksPerServer {
|
||||
if OnDrives != totalDrivesPerServer {
|
||||
clr = "InfoWarning"
|
||||
}
|
||||
dispNoOfDisks = strconv.Itoa(OnDisks) + "/" + strconv.Itoa(totalDisksPerServer)
|
||||
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDisks, console.Colorize(clr, "OK "))
|
||||
dispNoOfDrives = strconv.Itoa(OnDrives) + "/" + strconv.Itoa(totalDrivesPerServer)
|
||||
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDrives, console.Colorize(clr, "OK "))
|
||||
|
||||
// Print pools belonging to this server
|
||||
var prettyPools []string
|
||||
for _, pool := range endpointToPools(srv.Endpoint, clusterSummary) {
|
||||
prettyPools = append(prettyPools, strconv.Itoa(pool+1))
|
||||
}
|
||||
msg += fmt.Sprintf(" Pool: %s\n", console.Colorize("Info", fmt.Sprintf("%+v", strings.Join(prettyPools, ", "))))
|
||||
}
|
||||
|
||||
if poolIdx != -1 {
|
||||
msg += fmt.Sprintf(" Pool: %s\n", console.Colorize("Info", humanize.Ordinal(poolIdx+1)))
|
||||
}
|
||||
msg += "\n"
|
||||
}
|
||||
|
||||
if backendType == madmin.Erasure {
|
||||
dspOrder := []col{colGreen} // Header
|
||||
for i := 0; i < len(clusterSummary); i++ {
|
||||
dspOrder = append(dspOrder, colGrey)
|
||||
}
|
||||
var printColors []*color.Color
|
||||
for _, c := range dspOrder {
|
||||
printColors = append(printColors, getPrintCol(c))
|
||||
}
|
||||
|
||||
tbl := console.NewTable(printColors, []bool{false, false, false, false}, 0)
|
||||
|
||||
var builder strings.Builder
|
||||
cellText := make([][]string, 0, len(clusterSummary)+1)
|
||||
cellText = append(cellText, []string{
|
||||
"Pool",
|
||||
"Drives Usage",
|
||||
"Erasure stripe size",
|
||||
"Erasure sets",
|
||||
})
|
||||
|
||||
var printSummary bool
|
||||
// Keep the pool order while printing the output
|
||||
for poolIdx := 0; poolIdx < len(clusterSummary); poolIdx++ {
|
||||
summary := clusterSummary[poolIdx]
|
||||
if summary == nil {
|
||||
break
|
||||
}
|
||||
totalSize := summary.drivesTotalUsableSpace
|
||||
usedCurrent := summary.drivesTotalUsableSpace - summary.drivesTotalFreeSpace
|
||||
var capacity string
|
||||
if totalSize > 0 {
|
||||
capacity = fmt.Sprintf("%.1f%% (total: %s)", 100*float64(usedCurrent)/float64(totalSize), humanize.IBytes(totalSize))
|
||||
}
|
||||
|
||||
if summary.drivesPerSet > 0 {
|
||||
printSummary = true
|
||||
}
|
||||
|
||||
cellText = append(cellText, []string{
|
||||
humanize.Ordinal(poolIdx + 1),
|
||||
capacity,
|
||||
strconv.Itoa(summary.drivesPerSet),
|
||||
strconv.Itoa(summary.setsCount),
|
||||
})
|
||||
}
|
||||
|
||||
if printSummary {
|
||||
e := tbl.PopulateTable(&builder, cellText)
|
||||
fatalIf(probe.NewError(e), "unable to populate the table")
|
||||
|
||||
msg += builder.String() + "\n"
|
||||
}
|
||||
}
|
||||
|
||||
// Summary on used space, total no of buckets and
|
||||
// total no of objects at the Cluster level
|
||||
usedTotal := humanize.IBytes(u.Info.Usage.Size)
|
||||
if u.Info.Buckets.Count > 0 {
|
||||
msg += fmt.Sprintf("%s Used, %s, %s\n", usedTotal,
|
||||
msg += fmt.Sprintf("%s Used, %s, %s", usedTotal,
|
||||
english.Plural(int(u.Info.Buckets.Count), "Bucket", ""),
|
||||
english.Plural(int(u.Info.Objects.Count), "Object", ""))
|
||||
if u.Info.Versions.Count > 0 {
|
||||
msg += ", " + english.Plural(int(u.Info.Versions.Count), "Version", "")
|
||||
}
|
||||
if u.Info.DeleteMarkers.Count > 0 {
|
||||
msg += ", " + english.Plural(int(u.Info.DeleteMarkers.Count), "Delete Marker", "")
|
||||
}
|
||||
msg += "\n"
|
||||
}
|
||||
if backendType == madmin.Erasure {
|
||||
// Summary on total no of online and total
|
||||
// number of offline disks at the Cluster level
|
||||
bkInfo, ok := u.Info.Backend.(madmin.ErasureBackend)
|
||||
if ok {
|
||||
msg += fmt.Sprintf("%s online, %s offline\n",
|
||||
english.Plural(bkInfo.OnlineDisks, "drive", ""),
|
||||
english.Plural(bkInfo.OfflineDisks, "drive", ""))
|
||||
} else {
|
||||
msg += fmt.Sprintf("%s online, %s offline\n",
|
||||
english.Plural(totalOnlineDisksCluster, "drive", ""),
|
||||
english.Plural(totalOfflineDisksCluster, "drive", ""))
|
||||
if totalOfflineNodes != 0 {
|
||||
msg += fmt.Sprintf("%s offline, ", english.Plural(totalOfflineNodes, "node", ""))
|
||||
}
|
||||
// Summary on total no of online and total
|
||||
// number of offline drives at the Cluster level
|
||||
msg += fmt.Sprintf("%s online, %s offline, EC:%d\n",
|
||||
english.Plural(u.Info.Backend.OnlineDisks, "drive", ""),
|
||||
english.Plural(u.Info.Backend.OfflineDisks, "drive", ""),
|
||||
u.Info.Backend.StandardSCParity)
|
||||
}
|
||||
|
||||
// Remove the last new line if any
|
||||
@@ -268,7 +372,7 @@ func (u clusterStruct) JSON() string {
|
||||
// checkAdminInfoSyntax - validate arguments passed by a user
|
||||
func checkAdminInfoSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +387,10 @@ func mainAdminInfo(ctx *cli.Context) error {
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
var clusterInfo clusterStruct
|
||||
clusterInfo := clusterStruct{
|
||||
onlyOffline: ctx.Bool("offline"),
|
||||
}
|
||||
|
||||
// Fetch info of all servers (cluster or single server)
|
||||
admInfo, e := client.ServerInfo(globalContext)
|
||||
if e != nil {
|
||||
@@ -293,6 +400,7 @@ func mainAdminInfo(ctx *cli.Context) error {
|
||||
clusterInfo.Status = "success"
|
||||
clusterInfo.Error = ""
|
||||
}
|
||||
|
||||
clusterInfo.Info = admInfo
|
||||
printMsg(clusterInfo)
|
||||
|
||||
|
||||
+11
-165
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,176 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash/crc32"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/secure-io/sio-go"
|
||||
)
|
||||
|
||||
var adminInspectFlags = []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "encrypt",
|
||||
Usage: "Encrypt content with one time key for confidential data",
|
||||
},
|
||||
}
|
||||
|
||||
var adminInspectCmd = cli.Command{
|
||||
Name: "inspect",
|
||||
Usage: "inspect files on MinIO server",
|
||||
Action: mainAdminInspect,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminInspectFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Download 'xl.meta' for a specific object from all the drives in a zip file.
|
||||
{{.Prompt}} {{.HelpName}} myminio/bucket/test*/xl.meta
|
||||
|
||||
2. Download all constituent parts for a specific object, and optionally encrypt the downloaded zip.
|
||||
{{.Prompt}} {{.HelpName}} --encrypt myminio/bucket/test*/*/part.*
|
||||
|
||||
3. Download recursively all objects at a prefix. NOTE: This can be an expensive operation use it with caution.
|
||||
{{.Prompt}} {{.HelpName}} myminio/bucket/test/**
|
||||
`,
|
||||
}
|
||||
|
||||
func checkAdminInspectSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "inspect", 1) // last argument is exit code
|
||||
}
|
||||
Name: "inspect",
|
||||
Usage: "inspect files on MinIO server",
|
||||
Action: mainAdminInspect,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: "Please use 'mc support inspect'",
|
||||
}
|
||||
|
||||
// mainAdminHeal - the entry function of heal command
|
||||
func mainAdminInspect(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminInspectSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
encrypt := ctx.Bool("encrypt")
|
||||
|
||||
console.SetColor("File", color.New(color.FgWhite, color.Bold))
|
||||
console.SetColor("Key", color.New(color.FgHiRed, color.Bold))
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Compute bucket and object from the aliased URL
|
||||
aliasedURL = filepath.ToSlash(aliasedURL)
|
||||
splits := splitStr(aliasedURL, "/", 3)
|
||||
bucket, prefix := splits[1], splits[2]
|
||||
|
||||
shellName, _ := getShellName()
|
||||
if runtime.GOOS != "windows" && shellName != "bash" && strings.Contains(prefix, "*") {
|
||||
console.Infoln("Your shell is auto determined as '" + shellName + "', wildcard patterns are only supported with 'bash' SHELL.")
|
||||
}
|
||||
|
||||
key, r, ierr := client.Inspect(context.Background(), madmin.InspectOptions{
|
||||
Volume: bucket,
|
||||
File: prefix,
|
||||
})
|
||||
fatalIf(probe.NewError(ierr).Trace(aliasedURL), "Unable to inspect file.")
|
||||
|
||||
// Create profile zip file
|
||||
tmpFile, e := ioutil.TempFile("", "mc-inspect-")
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
ext := "enc"
|
||||
if !encrypt {
|
||||
ext = "zip"
|
||||
r = decryptInspect(key, r)
|
||||
}
|
||||
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, r)
|
||||
fatalIf(probe.NewError(e), "Unable to download file data.")
|
||||
|
||||
// Close everything
|
||||
r.Close()
|
||||
tmpFile.Close()
|
||||
|
||||
// Create an id that is also crc.
|
||||
var id [4]byte
|
||||
binary.LittleEndian.PutUint32(id[:], crc32.ChecksumIEEE(key[:]))
|
||||
|
||||
// We use 4 bytes of the 32 bytes to identify they file.
|
||||
downloadPath := fmt.Sprintf("inspect.%s.%s", hex.EncodeToString(id[:]), ext)
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
fatalIf(probe.NewError(e), "Unable to create a backup of "+downloadPath)
|
||||
} else {
|
||||
if !os.IsNotExist(e) {
|
||||
fatal(probe.NewError(e), "Unable to download file data.")
|
||||
}
|
||||
}
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to download file data.")
|
||||
hexKey := hex.EncodeToString(id[:]) + hex.EncodeToString(key[:])
|
||||
if !globalJSON {
|
||||
if !encrypt {
|
||||
console.Infof("File data successfully downloaded as %s\n", console.Colorize("File", downloadPath))
|
||||
return nil
|
||||
}
|
||||
console.Infof("Encrypted file data successfully downloaded as %s\n", console.Colorize("File", downloadPath))
|
||||
console.Infof("Decryption key: %s\n\n", console.Colorize("Key", hexKey))
|
||||
|
||||
console.Info("The decryption key will ONLY be shown here. It cannot be recovered.\n")
|
||||
console.Info("The encrypted file can safely be shared without the decryption key.\n")
|
||||
console.Info("Even with the decryption key, data stored with encryption cannot be accessed.\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
v := struct {
|
||||
File string `json:"file"`
|
||||
Key string `json:"key,omitempty"`
|
||||
}{
|
||||
File: downloadPath,
|
||||
Key: hexKey,
|
||||
}
|
||||
if !encrypt {
|
||||
v.Key = ""
|
||||
}
|
||||
b, e := json.Marshal(v)
|
||||
fatalIf(probe.NewError(e), "Unable to serialize data")
|
||||
console.Println(string(b))
|
||||
func mainAdminInspect(_ *cli.Context) error {
|
||||
deprecatedError("mc support inspect")
|
||||
return nil
|
||||
}
|
||||
|
||||
func decryptInspect(key [32]byte, r io.Reader) io.ReadCloser {
|
||||
stream, err := sio.AES_256_GCM.Stream(key[:])
|
||||
fatalIf(probe.NewError(err), "Unable to initiate decryption")
|
||||
|
||||
// Zero nonce, we only use each key once, and 32 bytes is plenty.
|
||||
nonce := make([]byte, stream.NonceSize())
|
||||
return ioutil.NopCloser(stream.DecryptReader(r, nonce, nil))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,13 +24,13 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
var adminKMSCreateKeyCmd = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "creates a new master key at the KMS",
|
||||
Usage: "creates a new master KMS key",
|
||||
Action: mainAdminKMSCreateKey,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -53,7 +53,7 @@ EXAMPLES:
|
||||
// adminKMSCreateKeyCmd is the handler for the "mc admin kms key create" command.
|
||||
func mainAdminKMSCreateKey(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "create", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
|
||||
client, err := newAdminClient(ctx.Args().Get(0))
|
||||
@@ -63,7 +63,7 @@ func mainAdminKMSCreateKey(ctx *cli.Context) error {
|
||||
e := client.CreateKey(globalContext, keyID)
|
||||
fatalIf(probe.NewError(e), "Failed to create master key")
|
||||
|
||||
if terminal.IsTerminal(int(os.Stdout.Fd())) {
|
||||
if term.IsTerminal(int(os.Stdout.Fd())) {
|
||||
console.Println(color.GreenString(fmt.Sprintf("Created master key `%s` successfully", keyID)))
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// Copyright (c) 2015-2023 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/jedib0t/go-pretty/v6/table"
|
||||
"github.com/jedib0t/go-pretty/v6/text"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminKMSKeyListCmd = cli.Command{
|
||||
Name: "list",
|
||||
Usage: "request list of KMS master keys",
|
||||
Action: mainAdminKMSKeyList,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Get list of master keys from a MinIO server/cluster.
|
||||
$ {{.HelpName}} play
|
||||
`,
|
||||
}
|
||||
|
||||
// adminKMSKeyCmd is the handle for the "mc admin kms key" command.
|
||||
func mainAdminKMSKeyList(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
|
||||
console.SetColor("KeyName", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
keys, e := client.ListKeys(globalContext, "*")
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to list KMS keys")
|
||||
|
||||
var rows []table.Row
|
||||
kmsKeys := []string{}
|
||||
for idx, k := range keys {
|
||||
rows = append(rows, table.Row{idx + 1, k.Name})
|
||||
kmsKeys = append(kmsKeys, k.Name)
|
||||
}
|
||||
|
||||
if globalJSON {
|
||||
printMsg(kmsKeysMsg{
|
||||
Status: "success",
|
||||
Target: aliasedURL,
|
||||
Keys: kmsKeys,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
t := table.NewWriter()
|
||||
t.SetOutputMirror(os.Stdout)
|
||||
t.SetColumnConfigs([]table.ColumnConfig{{Align: text.AlignCenter}})
|
||||
t.SetTitle("KMS Keys")
|
||||
t.AppendHeader(table.Row{"S N", "Name"})
|
||||
t.AppendRows(rows)
|
||||
t.SetStyle(table.StyleLight)
|
||||
t.Render()
|
||||
return nil
|
||||
}
|
||||
|
||||
type kmsKeysMsg struct {
|
||||
Status string `json:"status"`
|
||||
Target string `json:"target"`
|
||||
Keys []string `json:"keys"`
|
||||
}
|
||||
|
||||
func (k kmsKeysMsg) JSON() string {
|
||||
kmsBytes, e := json.MarshalIndent(k, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(kmsBytes)
|
||||
}
|
||||
|
||||
func (k kmsKeysMsg) String() string {
|
||||
return fmt.Sprintf("Keys: %s\n", k.Keys)
|
||||
}
|
||||
+22
-19
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminKMSKeyStatusCmd = cli.Command{
|
||||
@@ -54,11 +54,12 @@ EXAMPLES:
|
||||
// adminKMSKeyCmd is the handle for the "mc admin kms key" command.
|
||||
func mainAdminKMSKeyStatus(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "status", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
|
||||
console.SetColor("StatusSuccess", color.New(color.FgGreen, color.Bold))
|
||||
console.SetColor("StatusError", color.New(color.FgRed, color.Bold))
|
||||
console.SetColor("StatusUnknown", color.New(color.FgYellow, color.Bold))
|
||||
|
||||
client, err := newAdminClient(ctx.Args().Get(0))
|
||||
fatalIf(err, "Unable to get a configured admin connection.")
|
||||
@@ -72,8 +73,6 @@ func mainAdminKMSKeyStatus(ctx *cli.Context) error {
|
||||
|
||||
printMsg(kmsKeyStatusMsg{
|
||||
KeyID: status.KeyID,
|
||||
Encryption: status.EncryptionErr == "",
|
||||
Decryption: status.DecryptionErr == "",
|
||||
EncryptionErr: status.EncryptionErr,
|
||||
DecryptionErr: status.DecryptionErr,
|
||||
})
|
||||
@@ -82,8 +81,6 @@ func mainAdminKMSKeyStatus(ctx *cli.Context) error {
|
||||
|
||||
type kmsKeyStatusMsg struct {
|
||||
KeyID string `json:"keyId"`
|
||||
Encryption bool `json:"encryption"`
|
||||
Decryption bool `json:"decryption"`
|
||||
EncryptionErr string `json:"encryptionError,omitempty"`
|
||||
DecryptionErr string `json:"decryptionError,omitempty"`
|
||||
Status string `json:"status"`
|
||||
@@ -91,9 +88,6 @@ type kmsKeyStatusMsg struct {
|
||||
|
||||
func (s kmsKeyStatusMsg) JSON() string {
|
||||
s.Status = "success"
|
||||
if !s.Encryption && !s.Decryption {
|
||||
s.Status = "error"
|
||||
}
|
||||
kmsBytes, e := json.MarshalIndent(s, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
@@ -102,16 +96,25 @@ func (s kmsKeyStatusMsg) JSON() string {
|
||||
|
||||
func (s kmsKeyStatusMsg) String() string {
|
||||
msg := fmt.Sprintf("Key: %s\n", s.KeyID)
|
||||
if s.Encryption {
|
||||
msg += " - Encryption " + console.Colorize("StatusSuccess", "✔") + "\n"
|
||||
} else {
|
||||
msg += fmt.Sprintf(" - Encryption %s (%s)\n", console.Colorize("StatusError", "✗"), s.EncryptionErr)
|
||||
|
||||
success := console.Colorize("StatusSuccess", "✔")
|
||||
failure := console.Colorize("StatusError", "✗")
|
||||
dunno := console.Colorize("StatusUnknown", "?")
|
||||
|
||||
formatStatus := func(name string, unknown bool, err string) string {
|
||||
st := ""
|
||||
switch {
|
||||
case !unknown && err == "":
|
||||
st = success
|
||||
case unknown:
|
||||
st = dunno
|
||||
case err != "":
|
||||
st = fmt.Sprintf("%s (%s)", failure, err)
|
||||
}
|
||||
return fmt.Sprintf(" - %s %s\n", name, st)
|
||||
}
|
||||
|
||||
if s.Decryption {
|
||||
msg += " - Decryption " + console.Colorize("StatusSuccess", "✔") + "\n"
|
||||
} else {
|
||||
msg += fmt.Sprintf(" - Decryption %s (%s)\n", console.Colorize("StatusError", "✗"), s.DecryptionErr)
|
||||
}
|
||||
msg += formatStatus("Encryption", false, s.EncryptionErr)
|
||||
msg += formatStatus("Decryption", s.EncryptionErr != "", s.DecryptionErr)
|
||||
return msg
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -22,6 +22,7 @@ import "github.com/minio/cli"
|
||||
var adminKMSKeySubcommands = []cli.Command{
|
||||
adminKMSCreateKeyCmd,
|
||||
adminKMSKeyStatusCmd,
|
||||
adminKMSKeyListCmd,
|
||||
}
|
||||
|
||||
var adminKMSKeyCmd = cli.Command{
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
const logTimeFormat string = "15:04:05 MST 01/02/2006"
|
||||
|
||||
var logsShowFlags = []cli.Flag{
|
||||
cli.IntFlag{
|
||||
Name: "last, l",
|
||||
Usage: "show last n log entries",
|
||||
Value: 10,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "type, t",
|
||||
Usage: "list error logs by type. Valid options are '[minio, application, all]'",
|
||||
Value: "all",
|
||||
},
|
||||
}
|
||||
|
||||
var adminLogsCmd = cli.Command{
|
||||
Name: "logs",
|
||||
Usage: "show MinIO logs",
|
||||
OnUsageError: onUsageError,
|
||||
Action: mainAdminLogs,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(logsShowFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET [NODENAME]
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Show logs for a MinIO server with alias 'myminio'
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
2. Show last 5 log entries for node 'node1' for a MinIO server with alias 'myminio'
|
||||
{{.Prompt}} {{.HelpName}} --last 5 myminio node1
|
||||
3. Show application errors in logs for a MinIO server with alias 'myminio'
|
||||
{{.Prompt}} {{.HelpName}} --type application myminio
|
||||
`,
|
||||
}
|
||||
|
||||
func checkLogsShowSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 3 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// Extend madmin.LogInfo to add String() and JSON() methods
|
||||
type logMessage struct {
|
||||
Status string `json:"status"`
|
||||
madmin.LogInfo
|
||||
}
|
||||
|
||||
// JSON - jsonify loginfo
|
||||
func (l logMessage) JSON() string {
|
||||
l.Status = "success"
|
||||
logJSON, e := json.MarshalIndent(&l, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(logJSON)
|
||||
}
|
||||
|
||||
func getLogTime(lt string) string {
|
||||
tm, e := time.Parse(time.RFC3339Nano, lt)
|
||||
if e != nil {
|
||||
return lt
|
||||
}
|
||||
return tm.Format(logTimeFormat)
|
||||
}
|
||||
|
||||
// String - return colorized loginfo as string.
|
||||
func (l logMessage) String() string {
|
||||
var hostStr string
|
||||
b := &strings.Builder{}
|
||||
if l.NodeName != "" {
|
||||
hostStr = fmt.Sprintf("%s ", colorizedNodeName(l.NodeName))
|
||||
}
|
||||
if l.API != nil {
|
||||
apiString := "API: " + l.API.Name + "("
|
||||
if l.API.Args != nil && l.API.Args.Bucket != "" {
|
||||
apiString = apiString + "bucket=" + l.API.Args.Bucket
|
||||
}
|
||||
if l.API.Args != nil && l.API.Args.Object != "" {
|
||||
apiString = apiString + ", object=" + l.API.Args.Object
|
||||
}
|
||||
apiString += ")"
|
||||
fmt.Fprintf(b, "\n%s %s", hostStr, console.Colorize("API", apiString))
|
||||
}
|
||||
if l.Time != "" {
|
||||
fmt.Fprintf(b, "\n%s Time: %s", hostStr, getLogTime(l.Time))
|
||||
}
|
||||
if l.DeploymentID != "" {
|
||||
fmt.Fprintf(b, "\n%s DeploymentID: %s", hostStr, l.DeploymentID)
|
||||
}
|
||||
if l.RequestID != "" {
|
||||
fmt.Fprintf(b, "\n%s RequestID: %s", hostStr, l.RequestID)
|
||||
}
|
||||
if l.RemoteHost != "" {
|
||||
fmt.Fprintf(b, "\n%s RemoteHost: %s", hostStr, l.RemoteHost)
|
||||
}
|
||||
if l.UserAgent != "" {
|
||||
fmt.Fprintf(b, "\n%s UserAgent: %s", hostStr, l.UserAgent)
|
||||
}
|
||||
if l.Message != "" {
|
||||
fmt.Fprintf(b, "\n%s Message: %s", hostStr, l.Message)
|
||||
}
|
||||
if l.Trace != nil {
|
||||
if l.Trace.Message != "" {
|
||||
fmt.Fprintf(b, "\n%s Error: %s", hostStr, console.Colorize("LogMessage", l.Trace.Message))
|
||||
}
|
||||
if l.Trace.Variables != nil {
|
||||
for key, value := range l.Trace.Variables {
|
||||
if value != "" {
|
||||
fmt.Fprintf(b, "\n%s %s=%s", hostStr, key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
if l.Trace.Source != nil {
|
||||
traceLength := len(l.Trace.Source)
|
||||
for i, element := range l.Trace.Source {
|
||||
fmt.Fprintf(b, "\n%s %8v: %s", hostStr, traceLength-i, element)
|
||||
}
|
||||
}
|
||||
}
|
||||
logMsg := strings.TrimPrefix(b.String(), "\n")
|
||||
return fmt.Sprintf("%s\n", logMsg)
|
||||
}
|
||||
|
||||
// mainAdminLogs - the entry function of admin logs
|
||||
func mainAdminLogs(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkLogsShowSyntax(ctx)
|
||||
console.SetColor("LogMessage", color.New(color.Bold, color.FgRed))
|
||||
console.SetColor("Api", color.New(color.Bold, color.FgWhite))
|
||||
for _, c := range colors {
|
||||
console.SetColor(fmt.Sprintf("Node%d", c), color.New(c))
|
||||
}
|
||||
aliasedURL := ctx.Args().Get(0)
|
||||
var node string
|
||||
if len(ctx.Args()) > 1 {
|
||||
node = ctx.Args().Get(1)
|
||||
}
|
||||
var last int
|
||||
if ctx.IsSet("last") {
|
||||
last = ctx.Int("last")
|
||||
if last <= 0 {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "please set a proper limit, for example: '--last 5' to display last 5 logs, omit this flag to display all available logs")
|
||||
}
|
||||
}
|
||||
logType := strings.ToLower(ctx.String("type"))
|
||||
if logType != "minio" && logType != "application" && logType != "all" {
|
||||
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "Invalid value for --type flag. Valid options are [minio, application, all]")
|
||||
}
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
ctxt, cancel := context.WithCancel(globalContext)
|
||||
defer cancel()
|
||||
|
||||
// Start listening on all console log activity.
|
||||
logCh := client.GetLogs(ctxt, node, last, logType)
|
||||
for logInfo := range logCh {
|
||||
if logInfo.Err != nil {
|
||||
fatalIf(probe.NewError(logInfo.Err), "Unable to listen to console logs")
|
||||
}
|
||||
// drop nodeName from output if specified as cli arg
|
||||
if node != "" {
|
||||
logInfo.NodeName = ""
|
||||
}
|
||||
if logInfo.DeploymentID != "" {
|
||||
printMsg(logMessage{LogInfo: logInfo})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+7
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -37,6 +37,7 @@ var adminCmdSubcommands = []cli.Command{
|
||||
adminGroupCmd,
|
||||
adminPolicyCmd,
|
||||
adminReplicateCmd,
|
||||
adminIDPCmd,
|
||||
adminConfigCmd,
|
||||
adminDecommissionCmd,
|
||||
adminHealCmd,
|
||||
@@ -48,9 +49,14 @@ var adminCmdSubcommands = []cli.Command{
|
||||
adminTierCmd,
|
||||
adminSpeedtestCmd,
|
||||
adminProfileCmd,
|
||||
adminScannerCmd,
|
||||
adminTopCmd,
|
||||
adminTraceCmd,
|
||||
adminConsoleCmd,
|
||||
adminClusterCmd,
|
||||
adminRebalanceCmd,
|
||||
adminLogsCmd,
|
||||
adminAccesskeyCmd,
|
||||
}
|
||||
|
||||
var adminCmd = cli.Command{
|
||||
|
||||
+12
-121
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,131 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminPolicyAddCmd = cli.Command{
|
||||
Name: "add",
|
||||
Usage: "add new policy",
|
||||
Action: mainAdminPolicyAdd,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET POLICYNAME POLICYFILE
|
||||
|
||||
POLICYNAME:
|
||||
Name of the canned policy on MinIO server.
|
||||
|
||||
POLICYFILE:
|
||||
Name of the policy file associated with the policy name.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Add a new canned policy 'writeonly'.
|
||||
{{.Prompt}} {{.HelpName}} myminio writeonly /tmp/writeonly.json
|
||||
`,
|
||||
Name: "add",
|
||||
Usage: "add an IAM policy",
|
||||
Action: mainAdminPolicyAdd,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `Please use 'mc admin policy create'`,
|
||||
}
|
||||
|
||||
// checkAdminPolicyAddSyntax - validate all the passed arguments
|
||||
func checkAdminPolicyAddSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "add", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// userPolicyMessage container for content message structure
|
||||
type userPolicyMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
Policy string `json:"policy,omitempty"`
|
||||
PolicyInfo madmin.PolicyInfo `json:"policyInfo,omitempty"`
|
||||
UserOrGroup string `json:"userOrGroup,omitempty"`
|
||||
IsGroup bool `json:"isGroup"`
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) accountType() string {
|
||||
switch u.op {
|
||||
case "set", "unset", "update":
|
||||
if u.IsGroup {
|
||||
return "group"
|
||||
}
|
||||
return "user"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) String() string {
|
||||
switch u.op {
|
||||
case "info":
|
||||
buf, e := json.MarshalIndent(u.PolicyInfo, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON.")
|
||||
return string(buf)
|
||||
case "list":
|
||||
policyFieldMaxLen := 20
|
||||
// Create a new pretty table with cols configuration
|
||||
return newPrettyTable(" ",
|
||||
Field{"Policy", policyFieldMaxLen},
|
||||
).buildRow(u.Policy)
|
||||
case "remove":
|
||||
return console.Colorize("PolicyMessage", "Removed policy `"+u.Policy+"` successfully.")
|
||||
case "add":
|
||||
return console.Colorize("PolicyMessage", "Added policy `"+u.Policy+"` successfully.")
|
||||
case "set", "unset":
|
||||
return console.Colorize("PolicyMessage",
|
||||
fmt.Sprintf("Policy `%s` is %s on %s `%s`", u.Policy, u.op, u.accountType(), u.UserOrGroup))
|
||||
case "update":
|
||||
return console.Colorize("PolicyMessage",
|
||||
fmt.Sprintf("Policy `%s` is added to %s `%s`", u.Policy, u.accountType(), u.UserOrGroup))
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
// mainAdminPolicyAdd is the handle for "mc admin policy add" command.
|
||||
func mainAdminPolicyAdd(ctx *cli.Context) error {
|
||||
checkAdminPolicyAddSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policy, e := ioutil.ReadFile(args.Get(2))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get policy")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), policy)).Trace(args...), "Unable to add new policy")
|
||||
|
||||
printMsg(userPolicyMessage{
|
||||
op: "add",
|
||||
Policy: args.Get(1),
|
||||
})
|
||||
|
||||
func mainAdminPolicyAdd(_ *cli.Context) error {
|
||||
deprecatedError("mc admin policy create")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
const (
|
||||
errCodeChangeAlreadyApplied = "XMinioAdminPolicyChangeAlreadyApplied"
|
||||
)
|
||||
|
||||
var adminAttachPolicyFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "attach policy to user",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "attach policy to group",
|
||||
},
|
||||
}
|
||||
|
||||
var adminPolicyAttachCmd = cli.Command{
|
||||
Name: "attach",
|
||||
Usage: "attach an IAM policy to a user or group",
|
||||
Action: mainAdminPolicyAttach,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminAttachPolicyFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [--user USER | --group GROUP]
|
||||
|
||||
Exactly one of --user or --group is required.
|
||||
|
||||
POLICY:
|
||||
Name of the policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Attach the "readonly" policy to user "james".
|
||||
{{.Prompt}} {{.HelpName}} myminio readonly --user james
|
||||
2. Attach the "audit-policy" and "acct-policy" policies to group "legal".
|
||||
{{.Prompt}} {{.HelpName}} myminio audit-policy acct-policy --group legal
|
||||
`,
|
||||
}
|
||||
|
||||
// mainAdminPolicyAttach is the handler for "mc admin policy attach" command.
|
||||
func mainAdminPolicyAttach(ctx *cli.Context) error {
|
||||
return userAttachOrDetachPolicy(ctx, true)
|
||||
}
|
||||
|
||||
func userAttachOrDetachPolicy(ctx *cli.Context, attach bool) error {
|
||||
if len(ctx.Args()) < 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
user := ctx.String("user")
|
||||
group := ctx.String("group")
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policies := args[1:]
|
||||
req := madmin.PolicyAssociationReq{
|
||||
User: user,
|
||||
Group: group,
|
||||
Policies: policies,
|
||||
}
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
var e error
|
||||
var res madmin.PolicyAssociationResp
|
||||
if attach {
|
||||
res, e = client.AttachPolicy(globalContext, req)
|
||||
} else {
|
||||
res, e = client.DetachPolicy(globalContext, req)
|
||||
}
|
||||
|
||||
if e != nil && madmin.ToErrorResponse(e).Code != errCodeChangeAlreadyApplied {
|
||||
fatalIf(probe.NewError(e), "Unable to make user/group policy association")
|
||||
}
|
||||
|
||||
var emptyResp madmin.PolicyAssociationResp
|
||||
if res.UpdatedAt.Equal(emptyResp.UpdatedAt) {
|
||||
// Older minio does not send a result, so we populate res manually to
|
||||
// simulate a result. TODO(aditya): remove this after newer minio is
|
||||
// released in a few months (Older API Deprecated in Jun 2023)
|
||||
if attach {
|
||||
res.PoliciesAttached = policies
|
||||
} else {
|
||||
res.PoliciesDetached = policies
|
||||
}
|
||||
}
|
||||
|
||||
m := policyAssociationMessage{
|
||||
attach: attach,
|
||||
Status: "success",
|
||||
PoliciesAttached: res.PoliciesAttached,
|
||||
PoliciesDetached: res.PoliciesDetached,
|
||||
User: user,
|
||||
Group: group,
|
||||
}
|
||||
printMsg(m)
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
json "github.com/minio/colorjson"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminPolicyCreateCmd = cli.Command{
|
||||
Name: "create",
|
||||
Usage: "create a new IAM policy",
|
||||
Action: mainAdminPolicyCreate,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET POLICYNAME POLICYFILE
|
||||
|
||||
POLICYNAME:
|
||||
Name of the canned policy on MinIO server.
|
||||
|
||||
POLICYFILE:
|
||||
Name of the policy file associated with the policy name.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Create a new canned policy 'writeonly'.
|
||||
{{.Prompt}} {{.HelpName}} myminio writeonly /tmp/writeonly.json
|
||||
`,
|
||||
}
|
||||
|
||||
// checkAdminPolicyCreateSyntax - validate all the passed arguments
|
||||
func checkAdminPolicyCreateSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 3 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// userPolicyMessage container for content message structure
|
||||
type userPolicyMessage struct {
|
||||
op string
|
||||
Status string `json:"status"`
|
||||
Policy string `json:"policy,omitempty"`
|
||||
PolicyInfo madmin.PolicyInfo `json:"policyInfo,omitempty"`
|
||||
UserOrGroup string `json:"userOrGroup,omitempty"`
|
||||
IsGroup bool `json:"isGroup"`
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) accountType() string {
|
||||
switch u.op {
|
||||
case "attach", "detach":
|
||||
if u.IsGroup {
|
||||
return "group"
|
||||
}
|
||||
return "user"
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) String() string {
|
||||
switch u.op {
|
||||
case "info":
|
||||
buf, e := json.MarshalIndent(u.PolicyInfo, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal to JSON.")
|
||||
return string(buf)
|
||||
case "list":
|
||||
return console.Colorize("PolicyName", u.Policy)
|
||||
case "remove":
|
||||
return console.Colorize("PolicyMessage", "Removed policy `"+u.Policy+"` successfully.")
|
||||
case "create":
|
||||
return console.Colorize("PolicyMessage", "Created policy `"+u.Policy+"` successfully.")
|
||||
case "detach":
|
||||
return console.Colorize("PolicyMessage",
|
||||
fmt.Sprintf("Policy `%s` successfully detached from %s `%s`", u.Policy, u.accountType(), u.UserOrGroup))
|
||||
case "attach":
|
||||
return console.Colorize("PolicyMessage",
|
||||
fmt.Sprintf("Policy `%s` successfully attached to %s `%s`", u.Policy, u.accountType(), u.UserOrGroup))
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u userPolicyMessage) JSON() string {
|
||||
u.Status = "success"
|
||||
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||
|
||||
return string(jsonMessageBytes)
|
||||
}
|
||||
|
||||
// mainAdminPolicyCreate is the handle for "mc admin policy create" command.
|
||||
func mainAdminPolicyCreate(ctx *cli.Context) error {
|
||||
checkAdminPolicyCreateSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
policy, e := os.ReadFile(args.Get(2))
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get policy")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), policy)).Trace(args...), "Unable to create new policy")
|
||||
|
||||
printMsg(userPolicyMessage{
|
||||
op: ctx.Command.Name,
|
||||
Policy: args.Get(1),
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
)
|
||||
|
||||
var adminDetachPolicyFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "user, u",
|
||||
Usage: "detach policy from user",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "group, g",
|
||||
Usage: "detach policy from group",
|
||||
},
|
||||
}
|
||||
|
||||
var adminPolicyDetachCmd = cli.Command{
|
||||
Name: "detach",
|
||||
Usage: "detach an IAM policy from a user or group",
|
||||
Action: mainAdminPolicyDetach,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminDetachPolicyFlags, globalFlags...),
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET POLICY [POLICY...] [--user USER | --group GROUP]
|
||||
|
||||
Exactly one of --user or --group is required.
|
||||
|
||||
POLICY:
|
||||
Name of the policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Detach the "readonly" policy from user "james".
|
||||
{{.Prompt}} {{.HelpName}} myminio readonly --user james
|
||||
2. Detach the "audit-policy" and "acct-policy" policies from group "legal".
|
||||
{{.Prompt}} {{.HelpName}} myminio audit-policy acct-policy --group legal
|
||||
`,
|
||||
}
|
||||
|
||||
// mainAdmihPolicyDetach is the handler for "mc admin policy detach" command.
|
||||
func mainAdminPolicyDetach(ctx *cli.Context) error {
|
||||
return userAttachOrDetachPolicy(ctx, false)
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
)
|
||||
|
||||
var adminPolicyEntitiesFlags = []cli.Flag{
|
||||
cli.StringSliceFlag{
|
||||
Name: "user, u",
|
||||
Usage: "list policies associated with user(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "group, g",
|
||||
Usage: "list policies associated with group(s)",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
Name: "policy, p",
|
||||
Usage: "list users or groups associated with policy",
|
||||
},
|
||||
}
|
||||
|
||||
var adminPolicyEntitiesCmd = cli.Command{
|
||||
Name: "entities",
|
||||
Usage: "list policy association entities",
|
||||
Action: mainAdminPolicyEntities,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminPolicyEntitiesFlags, globalFlags...),
|
||||
OnUsageError: onUsageError,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. List all entities associated with all policies
|
||||
{{.Prompt}} {{.HelpName}} play/
|
||||
2. List all entities associated with the policies 'finteam-policy' and 'mlteam-policy'
|
||||
{{.Prompt}} {{.HelpName}} play/ --policy finteam-policy --policy mlteam-policy
|
||||
3. List all policies associated with a pair of user entities
|
||||
{{.Prompt}} {{.HelpName}} play/ --user bob --user james
|
||||
4. List all policies associated with a pair of group entities
|
||||
{{.Prompt}} {{.HelpName}} play/ --group auditors --group accounting
|
||||
5. List all entities associated with a policy, group and user
|
||||
{{.Prompt}} {{.HelpName}} play/ \
|
||||
--policy finteam-policy --user bobfisher --group consulting
|
||||
`,
|
||||
}
|
||||
|
||||
// mainAdminPolicyEntities is the handler for "mc admin policy entities" command.
|
||||
func mainAdminPolicyEntities(ctx *cli.Context) error {
|
||||
if len(ctx.Args()) != 1 {
|
||||
showCommandHelpAndExit(ctx, 1)
|
||||
}
|
||||
|
||||
usersToQuery := ctx.StringSlice("user")
|
||||
groupsToQuery := ctx.StringSlice("group")
|
||||
policiesToQuery := ctx.StringSlice("policy")
|
||||
|
||||
args := ctx.Args()
|
||||
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
res, e := client.GetPolicyEntities(globalContext,
|
||||
madmin.PolicyEntitiesQuery{
|
||||
Users: usersToQuery,
|
||||
Groups: groupsToQuery,
|
||||
Policy: policiesToQuery,
|
||||
})
|
||||
fatalIf(probe.NewError(e), "Unable to fetch policy entities")
|
||||
|
||||
printMsg(policyEntitiesFrom(res))
|
||||
return nil
|
||||
}
|
||||
+12
-14
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/madmin-go/v3"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var policyInfoFlags = []cli.Flag{
|
||||
@@ -36,7 +36,7 @@ var policyInfoFlags = []cli.Flag{
|
||||
|
||||
var adminPolicyInfoCmd = cli.Command{
|
||||
Name: "info",
|
||||
Usage: "show info on a policy",
|
||||
Usage: "show info on an IAM policy",
|
||||
Action: mainAdminPolicyInfo,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -65,7 +65,7 @@ EXAMPLES:
|
||||
// checkAdminPolicyInfoSyntax - validate all the passed arguments
|
||||
func checkAdminPolicyInfoSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ func getPolicyInfo(client *madmin.AdminClient, policyName string) (*madmin.Polic
|
||||
|
||||
if pinfo.PolicyName == "" {
|
||||
// Likely server only supports the older version.
|
||||
// nolint:staticcheck
|
||||
pinfo.Policy, e = client.InfoCannedPolicy(globalContext, policyName)
|
||||
if e != nil {
|
||||
return nil, e
|
||||
@@ -107,18 +108,15 @@ func mainAdminPolicyInfo(ctx *cli.Context) error {
|
||||
|
||||
policyFile := ctx.String("policy-file")
|
||||
if policyFile != "" {
|
||||
f, err := os.Create(policyFile)
|
||||
if err != nil {
|
||||
fatalIf(probe.NewError(err).Trace(args...), "Could not open given policy file")
|
||||
}
|
||||
_, err = f.Write(pinfo.Policy)
|
||||
if err != nil {
|
||||
fatalIf(probe.NewError(err).Trace(args...), "Could not write to given policy file")
|
||||
}
|
||||
f, e := os.Create(policyFile)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Could not open given policy file")
|
||||
|
||||
_, e = f.Write(pinfo.Policy)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Could not write to given policy file")
|
||||
}
|
||||
|
||||
printMsg(userPolicyMessage{
|
||||
op: "info",
|
||||
op: ctx.Command.Name,
|
||||
Policy: policyName,
|
||||
PolicyInfo: *pinfo,
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -21,12 +21,13 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminPolicyListCmd = cli.Command{
|
||||
Name: "list",
|
||||
Usage: "list all policies",
|
||||
ShortName: "ls",
|
||||
Usage: "list all IAM policies",
|
||||
Action: mainAdminPolicyList,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -49,7 +50,7 @@ EXAMPLES:
|
||||
// checkAdminPolicyListSyntax - validate all the passed arguments
|
||||
func checkAdminPolicyListSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,8 +58,7 @@ func checkAdminPolicyListSyntax(ctx *cli.Context) {
|
||||
func mainAdminPolicyList(ctx *cli.Context) error {
|
||||
checkAdminPolicyListSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
console.SetColor("Policy", color.New(color.FgBlue))
|
||||
console.SetColor("PolicyName", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
@@ -73,7 +73,7 @@ func mainAdminPolicyList(ctx *cli.Context) error {
|
||||
|
||||
for k := range policies {
|
||||
printMsg(userPolicyMessage{
|
||||
op: "list",
|
||||
op: ctx.Command.Name,
|
||||
Policy: k,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -21,12 +21,13 @@ import (
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
)
|
||||
|
||||
var adminPolicyRemoveCmd = cli.Command{
|
||||
Name: "remove",
|
||||
Usage: "remove policy",
|
||||
ShortName: "rm",
|
||||
Usage: "remove an IAM policy",
|
||||
Action: mainAdminPolicyRemove,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
@@ -52,7 +53,7 @@ EXAMPLES:
|
||||
// checkAdminPolicyRemoveSyntax - validate all the passed arguments
|
||||
func checkAdminPolicyRemoveSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 2 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +74,7 @@ func mainAdminPolicyRemove(ctx *cli.Context) error {
|
||||
fatalIf(probe.NewError(client.RemoveCannedPolicy(globalContext, args.Get(1))).Trace(args...), "Unable to remove policy")
|
||||
|
||||
printMsg(userPolicyMessage{
|
||||
op: "remove",
|
||||
op: ctx.Command.Name,
|
||||
Policy: args.Get(1),
|
||||
})
|
||||
|
||||
|
||||
+12
-89
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,99 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminPolicySetCmd = cli.Command{
|
||||
Name: "set",
|
||||
Usage: "set IAM policy on a user or group",
|
||||
Action: mainAdminPolicySet,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET POLICYNAME [ user=username1 | group=groupname1 ]
|
||||
|
||||
POLICYNAME:
|
||||
Name of the policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Set the "readwrite" policy for user "james".
|
||||
{{.Prompt}} {{.HelpName}} myminio readwrite user=james
|
||||
|
||||
2. Set the "readonly" policy for group "auditors".
|
||||
{{.Prompt}} {{.HelpName}} myminio readonly group=auditors
|
||||
`,
|
||||
Name: "set",
|
||||
Usage: "set IAM policy on a user or group",
|
||||
Action: mainAdminPolicySet,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `Please use 'mc admin policy attach'`,
|
||||
}
|
||||
|
||||
var errBadUserGroupArg = errors.New("Last argument must be of the form user=xx or group=xx")
|
||||
|
||||
func checkAdminPolicySetSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "set", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func parseEntityArg(arg string) (userOrGroup string, isGroup bool, err error) {
|
||||
parts := strings.SplitN(arg, "=", 2)
|
||||
switch {
|
||||
case len(parts) != 2 || parts[1] == "":
|
||||
err = errBadUserGroupArg
|
||||
case strings.ToLower(parts[0]) == "user":
|
||||
userOrGroup = parts[1]
|
||||
isGroup = false
|
||||
case strings.ToLower(parts[0]) == "group":
|
||||
userOrGroup = parts[1]
|
||||
isGroup = true
|
||||
default:
|
||||
err = errBadUserGroupArg
|
||||
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// mainAdminPolicySet is the handler for "mc admin policy set" command.
|
||||
func mainAdminPolicySet(ctx *cli.Context) error {
|
||||
checkAdminPolicySetSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
console.SetColor("Policy", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
policyName := strings.TrimSpace(args.Get(1))
|
||||
entityArg := args.Get(2)
|
||||
|
||||
userOrGroup, isGroup, e1 := parseEntityArg(entityArg)
|
||||
fatalIf(probe.NewError(e1).Trace(args...), "Bad last argument")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
e := client.SetPolicy(globalContext, policyName, userOrGroup, isGroup)
|
||||
if e == nil {
|
||||
printMsg(userPolicyMessage{
|
||||
op: "set",
|
||||
Policy: policyName,
|
||||
UserOrGroup: userOrGroup,
|
||||
IsGroup: isGroup,
|
||||
})
|
||||
} else {
|
||||
fatalIf(probe.NewError(e), "Unable to set the policy")
|
||||
}
|
||||
func mainAdminPolicySet(_ *cli.Context) error {
|
||||
deprecatedError("mc admin policy attach")
|
||||
return nil
|
||||
}
|
||||
|
||||
+12
-110
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,120 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminPolicyUnsetCmd = cli.Command{
|
||||
Name: "unset",
|
||||
Usage: "unset an IAM policy for a user or group",
|
||||
Action: mainAdminPolicyUnset,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET POLICYNAME [ user=username1 | group=groupname1 ]
|
||||
|
||||
POLICYNAME:
|
||||
Name of the policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Unset the "diagnostics" policy for user "james".
|
||||
{{.Prompt}} {{.HelpName}} myminio diagnostics user=james
|
||||
|
||||
2. Set the "diagnostics" policy for group "auditors".
|
||||
{{.Prompt}} {{.HelpName}} myminio diagnostics group=auditors
|
||||
`,
|
||||
Name: "unset",
|
||||
Usage: "unset an IAM policy for a user or group",
|
||||
Action: mainAdminPolicyUnsetErr,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `Please use 'mc admin policy detach'`,
|
||||
}
|
||||
|
||||
func checkAdminPolicyUnsetSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "unset", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func removeCannedPolicies(existingPolicies, policiesToRemove string) (string, error) {
|
||||
policiesToRemove = strings.TrimSpace(policiesToRemove)
|
||||
if policiesToRemove == "" {
|
||||
return "", errors.New("empty policy name is not supported")
|
||||
}
|
||||
filteredPolicies := strings.Split(existingPolicies, ",")
|
||||
for _, p1 := range strings.Split(policiesToRemove, ",") {
|
||||
found := false
|
||||
for i, p2 := range filteredPolicies {
|
||||
if p1 == p2 {
|
||||
found = true
|
||||
filteredPolicies = append(filteredPolicies[:i], filteredPolicies[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return "", fmt.Errorf("policy `%s` not found", p1)
|
||||
}
|
||||
|
||||
}
|
||||
return strings.Join(filteredPolicies, ","), nil
|
||||
}
|
||||
|
||||
// mainAdminPolicyUnset is the handler for "mc admin policy unset" command.
|
||||
func mainAdminPolicyUnset(ctx *cli.Context) error {
|
||||
checkAdminPolicyUnsetSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
console.SetColor("Policy", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
policiesToUnset := args.Get(1)
|
||||
entityArg := args.Get(2)
|
||||
|
||||
userOrGroup, isGroup, e1 := parseEntityArg(entityArg)
|
||||
fatalIf(probe.NewError(e1).Trace(args...), "Bad last argument")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
var existingPolicies string
|
||||
|
||||
if !isGroup {
|
||||
userInfo, e := client.GetUserInfo(globalContext, userOrGroup)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get user policy info")
|
||||
existingPolicies = userInfo.PolicyName
|
||||
} else {
|
||||
groupInfo, e := client.GetGroupDescription(globalContext, userOrGroup)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get group policy info")
|
||||
existingPolicies = groupInfo.Policy
|
||||
}
|
||||
|
||||
newPolicies, e := removeCannedPolicies(existingPolicies, policiesToUnset)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to unset the policy")
|
||||
}
|
||||
|
||||
e = client.SetPolicy(globalContext, newPolicies, userOrGroup, isGroup)
|
||||
if e == nil {
|
||||
printMsg(userPolicyMessage{
|
||||
op: "unset",
|
||||
Policy: policiesToUnset,
|
||||
UserOrGroup: userOrGroup,
|
||||
IsGroup: isGroup,
|
||||
})
|
||||
} else {
|
||||
fatalIf(probe.NewError(e), "Unable to unset the policy")
|
||||
}
|
||||
func mainAdminPolicyUnsetErr(_ *cli.Context) error {
|
||||
deprecatedError("mc admin policy detach")
|
||||
return nil
|
||||
}
|
||||
|
||||
+12
-115
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,125 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminPolicyUpdateCmd = cli.Command{
|
||||
Name: "update",
|
||||
Usage: "Attach new IAM policy to a user or group",
|
||||
Action: mainAdminPolicyUpdate,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET POLICYNAME [ user=username1 | group=groupname1 ]
|
||||
|
||||
POLICYNAME:
|
||||
Name of the policy on the MinIO server.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Add the "diagnostics" policy for user "james".
|
||||
{{.Prompt}} {{.HelpName}} myminio diagnostics user=james
|
||||
|
||||
2. Add the "diagnostics" policy for group "auditors".
|
||||
{{.Prompt}} {{.HelpName}} myminio diagnostics group=auditors
|
||||
`,
|
||||
Name: "update",
|
||||
Usage: "attach a new IAM policy to user or group",
|
||||
Action: mainAdminPolicyUpdateErr,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: `Please use 'mc admin policy attach'`,
|
||||
}
|
||||
|
||||
func checkAdminPolicyUpdateSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 3 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
func updateCannedPolicies(existingPolicies, policiesToAdd string) (string, error) {
|
||||
policiesToAdd = strings.TrimSpace(policiesToAdd)
|
||||
if policiesToAdd == "" {
|
||||
return "", errors.New("empty policy name is unsupported")
|
||||
}
|
||||
var updatedPolicies []string
|
||||
if existingPolicies != "" {
|
||||
updatedPolicies = strings.Split(existingPolicies, ",")
|
||||
}
|
||||
|
||||
for _, p1 := range strings.Split(policiesToAdd, ",") {
|
||||
found := false
|
||||
p1 = strings.TrimSpace(p1)
|
||||
for _, p2 := range updatedPolicies {
|
||||
if p1 == p2 {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
return "", fmt.Errorf("policy `%s` already exists", p1)
|
||||
}
|
||||
updatedPolicies = append(updatedPolicies, p1)
|
||||
}
|
||||
|
||||
return strings.Join(updatedPolicies, ","), nil
|
||||
}
|
||||
|
||||
// mainAdminPolicyUpdate is the handler for "mc admin policy update" command.
|
||||
func mainAdminPolicyUpdate(ctx *cli.Context) error {
|
||||
checkAdminPolicyUpdateSyntax(ctx)
|
||||
|
||||
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||
console.SetColor("Policy", color.New(color.FgBlue))
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
policiesToAdd := args.Get(1)
|
||||
entityArg := args.Get(2)
|
||||
|
||||
userOrGroup, isGroup, e1 := parseEntityArg(entityArg)
|
||||
fatalIf(probe.NewError(e1).Trace(args...), "Bad last argument")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
fatalIf(err, "Unable to initialize admin connection.")
|
||||
|
||||
var existingPolicies string
|
||||
|
||||
if !isGroup {
|
||||
userInfo, e := client.GetUserInfo(globalContext, userOrGroup)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get user policy info")
|
||||
existingPolicies = userInfo.PolicyName
|
||||
} else {
|
||||
groupInfo, e := client.GetGroupDescription(globalContext, userOrGroup)
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to get group policy info")
|
||||
existingPolicies = groupInfo.Policy
|
||||
}
|
||||
|
||||
updatedPolicies, e := updateCannedPolicies(existingPolicies, policiesToAdd)
|
||||
if e != nil {
|
||||
fatalIf(probe.NewError(e).Trace(args...), "Unable to update the policy")
|
||||
}
|
||||
|
||||
e = client.SetPolicy(globalContext, updatedPolicies, userOrGroup, isGroup)
|
||||
if e == nil {
|
||||
printMsg(userPolicyMessage{
|
||||
op: "update",
|
||||
Policy: policiesToAdd,
|
||||
UserOrGroup: userOrGroup,
|
||||
IsGroup: isGroup,
|
||||
})
|
||||
} else {
|
||||
fatalIf(probe.NewError(e), "Unable to unset the policy")
|
||||
}
|
||||
func mainAdminPolicyUpdateErr(_ *cli.Context) error {
|
||||
deprecatedError("mc admin policy attach")
|
||||
return nil
|
||||
}
|
||||
|
||||
+6
-2
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -20,10 +20,14 @@ package cmd
|
||||
import "github.com/minio/cli"
|
||||
|
||||
var adminPolicySubcommands = []cli.Command{
|
||||
adminPolicyAddCmd,
|
||||
adminPolicyCreateCmd,
|
||||
adminPolicyRemoveCmd,
|
||||
adminPolicyListCmd,
|
||||
adminPolicyInfoCmd,
|
||||
adminPolicyAttachCmd,
|
||||
adminPolicyDetachCmd,
|
||||
adminPolicyEntitiesCmd,
|
||||
adminPolicyAddCmd,
|
||||
adminPolicySetCmd,
|
||||
adminPolicyUnsetCmd,
|
||||
adminPolicyUpdateCmd,
|
||||
|
||||
+11
-96
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,107 +18,22 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/set"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminProfileStartFlags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "type",
|
||||
Usage: "start profiler type, possible values are 'cpu', 'mem', 'block', 'mutex', 'trace', 'threads' and 'goroutines'",
|
||||
Value: "cpu,mem,block,goroutines",
|
||||
},
|
||||
}
|
||||
|
||||
var adminProfileStartCmd = cli.Command{
|
||||
Name: "start",
|
||||
Usage: "start recording profile data",
|
||||
Action: mainAdminProfileStart,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: append(adminProfileStartFlags, globalFlags...),
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
1. Start CPU profiling only
|
||||
{{.Prompt}} {{.HelpName}} --type cpu myminio/
|
||||
|
||||
2. Start CPU, Memory and Block profiling concurrently
|
||||
{{.Prompt}} {{.HelpName}} --type cpu,mem,block myminio/
|
||||
`,
|
||||
}
|
||||
|
||||
func checkAdminProfileStartSyntax(ctx *cli.Context) {
|
||||
// Check flags combinations
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "start", 1) // last argument is exit code
|
||||
}
|
||||
|
||||
s := set.NewStringSet()
|
||||
supportedProfilerTypes := []madmin.ProfilerType{
|
||||
madmin.ProfilerCPU,
|
||||
madmin.ProfilerMEM,
|
||||
madmin.ProfilerBlock,
|
||||
madmin.ProfilerMutex,
|
||||
madmin.ProfilerTrace,
|
||||
madmin.ProfilerThreads,
|
||||
madmin.ProfilerGoroutines,
|
||||
}
|
||||
for _, profilerType := range supportedProfilerTypes {
|
||||
s.Add(string(profilerType))
|
||||
}
|
||||
// Check if the provided profiler type is known and supported
|
||||
supportedProfiler := false
|
||||
profilers := strings.Split(strings.ToLower(ctx.String("type")), ",")
|
||||
for _, profiler := range profilers {
|
||||
if profiler != "" {
|
||||
if s.Contains(profiler) {
|
||||
supportedProfiler = true
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if !supportedProfiler {
|
||||
fatalIf(errDummy().Trace(ctx.String("type")),
|
||||
"Profiler type unrecognized. Possible values are: %v.", supportedProfilerTypes)
|
||||
}
|
||||
Name: "start",
|
||||
Usage: "start recording profile data",
|
||||
Action: mainAdminProfileStart,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: "Please use 'mc support profile start'",
|
||||
}
|
||||
|
||||
// mainAdminProfileStart - the entry function of profile command
|
||||
func mainAdminProfileStart(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminProfileStartSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
profilers := ctx.String("type")
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start profile
|
||||
_, cmdErr := client.StartProfiling(globalContext, madmin.ProfilerType(profilers))
|
||||
fatalIf(probe.NewError(cmdErr), "Unable to start profile.")
|
||||
|
||||
console.Infoln("Profile data successfully started.")
|
||||
func mainAdminProfileStart(_ *cli.Context) error {
|
||||
deprecatedError("mc support profile start")
|
||||
return nil
|
||||
}
|
||||
|
||||
+12
-107
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,118 +18,23 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
)
|
||||
|
||||
var adminProfileStopCmd = cli.Command{
|
||||
Name: "stop",
|
||||
Usage: "stop and download profile data",
|
||||
Action: mainAdminProfileStop,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
CustomHelpTemplate: `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} [FLAGS] TARGET
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
2. Download latest profile data in the current directory
|
||||
{{.Prompt}} {{.HelpName}} myminio/
|
||||
`,
|
||||
}
|
||||
|
||||
func checkAdminProfileStopSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "stop", 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
// moveFile - os.Rename cannot handle cross device renames, in our situation
|
||||
// it is possible that /tmp is mounted from a separate partition and current
|
||||
// working directory is a different partition. To allow all situations to
|
||||
// be handled appropriately use this function instead of os.Rename()
|
||||
func moveFile(sourcePath, destPath string) error {
|
||||
inputFile, err := os.Open(sourcePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
outputFile, err := os.Create(destPath)
|
||||
if err != nil {
|
||||
inputFile.Close()
|
||||
return err
|
||||
}
|
||||
defer outputFile.Close()
|
||||
|
||||
_, err = io.Copy(outputFile, inputFile)
|
||||
inputFile.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// The copy was successful, so now delete the original file
|
||||
return os.Remove(sourcePath)
|
||||
Name: "stop",
|
||||
Usage: "stop and download profile data",
|
||||
Action: mainAdminProfileStop,
|
||||
OnUsageError: onUsageError,
|
||||
Before: setGlobalsFromContext,
|
||||
Flags: globalFlags,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
CustomHelpTemplate: "Please use 'mc support profile stop'",
|
||||
}
|
||||
|
||||
// mainAdminProfileStop - the entry function of profile stop command
|
||||
func mainAdminProfileStop(ctx *cli.Context) error {
|
||||
// Check for command syntax
|
||||
checkAdminProfileStopSyntax(ctx)
|
||||
|
||||
// Get the alias parameter from cli
|
||||
args := ctx.Args()
|
||||
aliasedURL := args.Get(0)
|
||||
|
||||
// Create a new MinIO Admin Client
|
||||
client, err := newAdminClient(aliasedURL)
|
||||
if err != nil {
|
||||
fatalIf(err.Trace(aliasedURL), "Unable to initialize admin client.")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Create profile zip file
|
||||
tmpFile, e := ioutil.TempFile("", "mc-profile-")
|
||||
fatalIf(probe.NewError(e), "Unable to download profile data.")
|
||||
|
||||
// Ask for profile data, which will come compressed with zip format
|
||||
zippedData, adminErr := client.DownloadProfilingData(globalContext)
|
||||
fatalIf(probe.NewError(adminErr), "Unable to download profile data.")
|
||||
|
||||
// Copy zip content to target download file
|
||||
_, e = io.Copy(tmpFile, zippedData)
|
||||
fatalIf(probe.NewError(e), "Unable to download profile data.")
|
||||
|
||||
// Close everything
|
||||
zippedData.Close()
|
||||
tmpFile.Close()
|
||||
|
||||
downloadPath := "profile.zip"
|
||||
|
||||
fi, e := os.Stat(downloadPath)
|
||||
if e == nil && !fi.IsDir() {
|
||||
e = moveFile(downloadPath, downloadPath+"."+time.Now().Format(dateTimeFormatFilename))
|
||||
fatalIf(probe.NewError(e), "Unable to create a backup of profile.zip")
|
||||
} else {
|
||||
if !os.IsNotExist(e) {
|
||||
fatal(probe.NewError(e), "Unable to download profile data.")
|
||||
}
|
||||
}
|
||||
|
||||
fatalIf(probe.NewError(moveFile(tmpFile.Name(), downloadPath)), "Unable to download profile data.")
|
||||
|
||||
console.Infof("Profile data successfully downloaded as %s\n", downloadPath)
|
||||
func mainAdminProfileStop(_ *cli.Context) error {
|
||||
deprecatedError("mc support profile stop")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2022 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -35,10 +35,11 @@ var adminProfileCmd = cli.Command{
|
||||
Flags: globalFlags,
|
||||
Subcommands: adminProfileSubcommands,
|
||||
HideHelpCommand: true,
|
||||
Hidden: true,
|
||||
}
|
||||
|
||||
// mainAdminProfile is the handle for "mc admin profile" command.
|
||||
func mainAdminProfile(ctx *cli.Context) error {
|
||||
commandNotFound(ctx, adminProfileSubcommands)
|
||||
func mainAdminProfile(_ *cli.Context) error {
|
||||
deprecatedError("mc support profile")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2015-2021 MinIO, Inc.
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
@@ -18,31 +18,28 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/pkg/console"
|
||||
"github.com/minio/pkg/v3/console"
|
||||
|
||||
jwtgo "github.com/golang-jwt/jwt"
|
||||
json "github.com/minio/colorjson"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultJobName = "minio-job"
|
||||
defaultMetricsPath = "/minio/v2/metrics/cluster"
|
||||
defaultJobName = "minio-job"
|
||||
metricsV2BasePath = "/minio/v2/metrics"
|
||||
)
|
||||
|
||||
var prometheusFlags = []cli.Flag{
|
||||
var prometheusFlags = append(metricsFlags,
|
||||
cli.BoolFlag{
|
||||
Name: "public",
|
||||
Usage: "disable bearer token generation for scrape_configs",
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
var adminPrometheusGenerateCmd = cli.Command{
|
||||
Name: "generate",
|
||||
@@ -56,15 +53,71 @@ var adminPrometheusGenerateCmd = cli.Command{
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
|
||||
USAGE:
|
||||
{{.HelpName}} TARGET
|
||||
{{.HelpName}} TARGET [METRIC-TYPE]
|
||||
|
||||
METRIC-TYPE:
|
||||
valid values are
|
||||
api-version v2 ['cluster', 'node', 'bucket', 'resource']. defaults to 'cluster' if not specified.
|
||||
api-version v3 ["api", "system", "debug", "cluster", "ilm", "audit", "logger", "replication", "notification", "scanner"]. defaults to all if not specified.
|
||||
|
||||
FLAGS:
|
||||
{{range .VisibleFlags}}{{.}}
|
||||
{{end}}
|
||||
EXAMPLES:
|
||||
EXAMPLES (v3):
|
||||
1. Generate a default prometheus config.
|
||||
{{.Prompt}} {{.HelpName}} myminio
|
||||
{{.Prompt}} {{.HelpName}} play --api-version v3
|
||||
|
||||
2. Generate prometheus config for api metrics.
|
||||
{{.Prompt}} {{.HelpName}} play api --api-version v3
|
||||
|
||||
3. Generate prometheus config for api metrics of bucket 'mybucket'.
|
||||
{{.Prompt}} {{.HelpName}} play api --bucket mybucket --api-version v3
|
||||
|
||||
4. Generate prometheus config for system metrics.
|
||||
{{.Prompt}} {{.HelpName}} play system --api-version v3
|
||||
|
||||
5. Generate prometheus config for debug metrics.
|
||||
{{.Prompt}} {{.HelpName}} play debug --api-version v3
|
||||
|
||||
6. Generate prometheus config for cluster metrics.
|
||||
{{.Prompt}} {{.HelpName}} play cluster --api-version v3
|
||||
|
||||
7. Generate prometheus config for ilm metrics.
|
||||
{{.Prompt}} {{.HelpName}} play ilm --api-version v3
|
||||
|
||||
8. Generate prometheus config for audit metrics.
|
||||
{{.Prompt}} {{.HelpName}} play audit --api-version v3
|
||||
|
||||
9. Generate prometheus config for logger metrics.
|
||||
{{.Prompt}} {{.HelpName}} play logger --api-version v3
|
||||
|
||||
10. Generate prometheus config for replication metrics.
|
||||
{{.Prompt}} {{.HelpName}} play replication --api-version v3
|
||||
|
||||
11. Generate prometheus config for replication metrics of bucket 'mybucket'.
|
||||
{{.Prompt}} {{.HelpName}} play replication --bucket mybucket --api-version v3
|
||||
|
||||
12. Generate prometheus config for notification metrics.
|
||||
{{.Prompt}} {{.HelpName}} play notification --api-version v3
|
||||
|
||||
13. Generate prometheus config for scanner metrics.
|
||||
{{.Prompt}} {{.HelpName}} play scanner --api-version v3
|
||||
|
||||
EXAMPLES (v2):
|
||||
1. Generate a default prometheus config.
|
||||
{{.Prompt}} {{.HelpName}} play
|
||||
|
||||
2. Generate prometheus config for node metrics.
|
||||
{{.Prompt}} {{.HelpName}} play node
|
||||
|
||||
3. Generate prometheus config for bucket metrics.
|
||||
{{.Prompt}} {{.HelpName}} play bucket
|
||||
|
||||
4. Generate prometheus config for resource metrics.
|
||||
{{.Prompt}} {{.HelpName}} play resource
|
||||
|
||||
5. Generate prometheus config for cluster metrics.
|
||||
{{.Prompt}} {{.HelpName}} play cluster
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -75,10 +128,9 @@ type PrometheusConfig struct {
|
||||
|
||||
// String colorized prometheus config yaml.
|
||||
func (c PrometheusConfig) String() string {
|
||||
b, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("error creating config string: %s", err)
|
||||
}
|
||||
b, e := yaml.Marshal(c)
|
||||
fatalIf(probe.NewError(e), "Unable to generate Prometheus config")
|
||||
|
||||
return console.Colorize("yaml", string(b))
|
||||
}
|
||||
|
||||
@@ -96,10 +148,9 @@ type StatConfig struct {
|
||||
|
||||
// String colorized stat config yaml.
|
||||
func (t StatConfig) String() string {
|
||||
b, err := yaml.Marshal(t)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("error creating config string: %s", err)
|
||||
}
|
||||
b, e := yaml.Marshal(t)
|
||||
fatalIf(probe.NewError(e), "Unable to generate Prometheus config")
|
||||
|
||||
return console.Colorize("yaml", string(b))
|
||||
}
|
||||
|
||||
@@ -123,24 +174,10 @@ const (
|
||||
defaultPrometheusJWTExpiry = 100 * 365 * 24 * time.Hour
|
||||
)
|
||||
|
||||
var defaultConfig = PrometheusConfig{
|
||||
ScrapeConfigs: []ScrapeConfig{
|
||||
{
|
||||
JobName: defaultJobName,
|
||||
MetricsPath: defaultMetricsPath,
|
||||
StaticConfigs: []StatConfig{
|
||||
{
|
||||
Targets: []string{""},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// checkAdminPrometheusSyntax - validate all the passed arguments
|
||||
func checkAdminPrometheusSyntax(ctx *cli.Context) {
|
||||
if len(ctx.Args()) != 1 {
|
||||
cli.ShowCommandHelpAndExit(ctx, "generate", 1) // last argument is exit code
|
||||
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
|
||||
showCommandHelpAndExit(ctx, 1) // last argument is exit code
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,25 +201,58 @@ func generatePrometheusConfig(ctx *cli.Context) error {
|
||||
return e
|
||||
}
|
||||
|
||||
if !ctx.Bool("public") {
|
||||
jwt := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, jwtgo.StandardClaims{
|
||||
ExpiresAt: UTCNow().Add(defaultPrometheusJWTExpiry).Unix(),
|
||||
Subject: hostConfig.AccessKey,
|
||||
Issuer: "prometheus",
|
||||
})
|
||||
metricsSubSystem := args.Get(1)
|
||||
apiVer := ctx.String("api-version")
|
||||
jobName := defaultJobName
|
||||
metricsPath := ""
|
||||
|
||||
token, e := jwt.SignedString([]byte(hostConfig.SecretKey))
|
||||
switch apiVer {
|
||||
case "v2":
|
||||
if metricsSubSystem == "" {
|
||||
metricsSubSystem = "cluster"
|
||||
}
|
||||
validateV2Args(ctx, metricsSubSystem)
|
||||
if metricsSubSystem != "cluster" {
|
||||
jobName = defaultJobName + "-" + metricsSubSystem
|
||||
}
|
||||
metricsPath = metricsV2BasePath + "/" + metricsSubSystem
|
||||
case "v3":
|
||||
bucket := ctx.String("bucket")
|
||||
validateV3Args(metricsSubSystem, bucket)
|
||||
metricsPath = getMetricsV3Path(metricsSubSystem, bucket)
|
||||
if metricsSubSystem != "" {
|
||||
jobName = defaultJobName + "-" + metricsSubSystem
|
||||
}
|
||||
default:
|
||||
fatalIf(errInvalidArgument().Trace(), "Invalid api version `"+apiVer+"`")
|
||||
}
|
||||
|
||||
config := PrometheusConfig{
|
||||
ScrapeConfigs: []ScrapeConfig{
|
||||
{
|
||||
JobName: jobName,
|
||||
MetricsPath: metricsPath,
|
||||
StaticConfigs: []StatConfig{
|
||||
{
|
||||
Targets: []string{""},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if !ctx.Bool("public") {
|
||||
token, e := getPrometheusToken(hostConfig)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
// Setting the values
|
||||
defaultConfig.ScrapeConfigs[0].BearerToken = token
|
||||
config.ScrapeConfigs[0].BearerToken = token
|
||||
}
|
||||
defaultConfig.ScrapeConfigs[0].Scheme = u.Scheme
|
||||
defaultConfig.ScrapeConfigs[0].StaticConfigs[0].Targets[0] = u.Host
|
||||
config.ScrapeConfigs[0].Scheme = u.Scheme
|
||||
config.ScrapeConfigs[0].StaticConfigs[0].Targets[0] = u.Host
|
||||
|
||||
printMsg(defaultConfig)
|
||||
printMsg(config)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
// Copyright (c) 2015-2024 MinIO, Inc.
|
||||
//
|
||||
// This file is part of MinIO Object Storage stack
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/minio/cli"
|
||||
"github.com/minio/minio-go/v7/pkg/set"
|
||||
)
|
||||
|
||||
var (
|
||||
metricsV3Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "bucket",
|
||||
Usage: "bucket name to list metrics for. only applicable with api version v3 for metric type 'api, replication'",
|
||||
},
|
||||
}
|
||||
|
||||
metricsV3SubSystems = set.CreateStringSet("api", "system", "debug", "cluster",
|
||||
"ilm", "audit", "logger", "replication", "notification", "scanner")
|
||||
|
||||
bucketMetricsSubSystems = set.CreateStringSet("api", "replication")
|
||||
)
|
||||
|
||||
const metricsV3EndPointRoot = "/minio/metrics/v3"
|
||||
|
||||
func getMetricsV3Path(subsys string, bucket string) string {
|
||||
params := url.Values{}
|
||||
|
||||
metricsPath := metricsV3EndPointRoot
|
||||
if len(bucket) > 0 {
|
||||
metricsPath += "/bucket"
|
||||
}
|
||||
|
||||
if len(subsys) > 0 {
|
||||
metricsPath += "/" + subsys
|
||||
}
|
||||
|
||||
if len(bucket) > 0 {
|
||||
// bucket specific metrics endpoints have '/bucket' prefix and bucket name as suffix.
|
||||
// e.g. bucket api metrics: /bucket/api/mybucket
|
||||
metricsPath += "/" + bucket
|
||||
}
|
||||
|
||||
qparams := params.Encode()
|
||||
if len(qparams) > 0 {
|
||||
metricsPath += "?" + qparams
|
||||
}
|
||||
return metricsPath
|
||||
}
|
||||
|
||||
func validateV3Args(subsys string, bucket string) {
|
||||
if subsys != "" && !metricsV3SubSystems.Contains(subsys) {
|
||||
fatalIf(errInvalidArgument().Trace(),
|
||||
"invalid metric type `"+subsys+"`. valid values are `"+
|
||||
strings.Join(metricsV3SubSystems.ToSlice(), ", ")+"`")
|
||||
}
|
||||
|
||||
if len(bucket) > 0 {
|
||||
bms := strings.Join(bucketMetricsSubSystems.ToSlice(), ", ")
|
||||
if len(subsys) == 0 {
|
||||
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("metric type must be passed with --bucket. valid values are `%s`", bms))
|
||||
}
|
||||
|
||||
if !bucketMetricsSubSystems.Contains(subsys) {
|
||||
fatalIf(errInvalidArgument().Trace(), fmt.Sprintf("--bucket is applicable only for metric types `%s`", bms))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func printPrometheusMetricsV3(ctx *cli.Context, req prometheusMetricsReq) error {
|
||||
bucket := ctx.String("bucket")
|
||||
validateV3Args(req.subsystem, bucket)
|
||||
|
||||
metricsURL := req.aliasURL + getMetricsV3Path(req.subsystem, bucket)
|
||||
|
||||
resp, e := fetchMetrics(metricsURL, req.token)
|
||||
if e != nil {
|
||||
return e
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
printMsg(prometheusMetricsReader{Reader: resp.Body})
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New(resp.Status)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user