Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e9625733d | ||
|
|
1513d76ca9 | ||
|
|
87dc0bf80e | ||
|
|
69c0d33543 | ||
|
|
8d891755e0 | ||
|
|
a9cd7869eb | ||
|
|
c40ab338a3 | ||
|
|
0fcd10d793 | ||
|
|
b7b75c5f46 | ||
|
|
b97b7b8987 | ||
|
|
8f3d514e3b | ||
|
|
bb3c0d45f2 | ||
|
|
9ebde383d4 | ||
|
|
cfea4fdc75 | ||
|
|
dd47bdfeaa | ||
|
|
ec9b92cbb7 | ||
|
|
975423abe2 | ||
|
|
3dd971f673 | ||
|
|
133dd1f7da | ||
|
|
bdefdc0169 | ||
|
|
c51e3b3ec9 | ||
|
|
88223f96be | ||
|
|
fa520cbd1a | ||
|
|
166db95464 | ||
|
|
0e27dd4ed4 | ||
|
|
2403e7a744 | ||
|
|
ea03e61fac | ||
|
|
f55e9c1997 | ||
|
|
7664bb2c8d | ||
|
|
09f832f597 | ||
|
|
4cc297ba4e | ||
|
|
bf731558cd | ||
|
|
949dd282f9 | ||
|
|
61b74e90bf | ||
|
|
3b479cf92e | ||
|
|
09c31c4ab2 | ||
|
|
71196b1013 | ||
|
|
72c8e92459 | ||
|
|
a6d82862cd | ||
|
|
672390b86a | ||
|
|
2e586e6b9d | ||
|
|
ad0bc4c33d | ||
|
|
a75dca16bd | ||
|
|
4e3b501528 | ||
|
|
dc2ad27429 | ||
|
|
b99c313366 | ||
|
|
e13751f5d5 | ||
|
|
ca650e227a | ||
|
|
df8bb795ba | ||
|
|
2fe7d04043 | ||
|
|
138d7656ba | ||
|
|
2018319125 | ||
|
|
c8c5c15249 | ||
|
|
32d8ef24ef | ||
|
|
f82a7b13c1 | ||
|
|
49c2beec79 | ||
|
|
24a72e4a33 | ||
|
|
c7166eac3a | ||
|
|
20dd7011b9 | ||
|
|
f23f814764 | ||
|
|
e1617a504b | ||
|
|
89930fed29 | ||
|
|
8c262e1f3f | ||
|
|
e6a6cfcebf | ||
|
|
bb43b2adf1 | ||
|
|
2d6a960f94 | ||
|
|
4036009dc2 | ||
|
|
ab2500e2ef | ||
|
|
5c4add2000 | ||
|
|
59187f2ef7 | ||
|
|
37ee28a051 | ||
|
|
91ca683b03 | ||
|
|
68b638f2f9 | ||
|
|
42023a1298 | ||
|
|
150bc75a2c | ||
|
|
4388f6d69b | ||
|
|
9e4e435c56 | ||
|
|
dfa1e42b25 | ||
|
|
cb9e103714 | ||
|
|
dee04e3d73 | ||
|
|
18f81e5458 | ||
|
|
8cae137525 | ||
|
|
3b31837927 | ||
|
|
f0f56ac906 | ||
|
|
4d36c1f8b8 | ||
|
|
a9e875b503 | ||
|
|
51ef254a41 | ||
|
|
e05f02d9f4 | ||
|
|
0ea8d1d479 | ||
|
|
eeeca2332d | ||
|
|
080414009e | ||
|
|
25de1da81b | ||
|
|
1fb87a492e | ||
|
|
71eb7f6689 | ||
|
|
64a78e7811 | ||
|
|
b010699112 | ||
|
|
3230acae32 | ||
|
|
91da0da183 | ||
|
|
fc04dc6463 | ||
|
|
fd43df09a1 | ||
|
|
b621ae58f5 | ||
|
|
bcbbfa7352 | ||
|
|
5b5d65a142 | ||
|
|
1a27f7f51d | ||
|
|
1092f6932f | ||
|
|
128f81461c | ||
|
|
7a26f993a2 | ||
|
|
c170a2db6c | ||
|
|
d58cf3c8c6 | ||
|
|
a7dd97f140 | ||
|
|
093bf0d54a | ||
|
|
a0d9e26dc7 | ||
|
|
24e7caa146 | ||
|
|
b65d6797cd | ||
|
|
67e90b8fcb | ||
|
|
fd89251270 | ||
|
|
4152714126 | ||
|
|
3862184a8a | ||
|
|
7e1e91d9c9 | ||
|
|
5d9a04bac6 | ||
|
|
2f2aecb09d | ||
|
|
e03d8d99a3 | ||
|
|
f7c366ae3d | ||
|
|
0724774bd8 | ||
|
|
551a124804 | ||
|
|
609274326b | ||
|
|
ac9b942397 | ||
|
|
b70a79e39b | ||
|
|
0baee49a66 | ||
|
|
6a2da1a6ef | ||
|
|
28aae43c8c | ||
|
|
0596acea95 | ||
|
|
8694ddb3ee | ||
|
|
c27941bc2a | ||
|
|
79e183fd0f | ||
|
|
632f0949bd | ||
|
|
374100da7e | ||
|
|
3f87064138 | ||
|
|
63821bbe3f | ||
|
|
2a66f9ba2b | ||
|
|
27a033440e | ||
|
|
50766862c1 | ||
|
|
6d1a41458b | ||
|
|
9663319e9e | ||
|
|
8f0b923312 | ||
|
|
7c9ea88742 | ||
|
|
ee283811a3 | ||
|
|
d92d2f0d4f | ||
|
|
f2f8f858a6 | ||
|
|
64e0c36e3b | ||
|
|
85f814eb44 | ||
|
|
2616a1d051 | ||
|
|
7038207039 | ||
|
|
23aab5b458 | ||
|
|
e109a5370a | ||
|
|
871b8da9a6 | ||
|
|
34757e2ce2 | ||
|
|
dff0f0318c | ||
|
|
45df811a89 | ||
|
|
8a488ba0e4 | ||
|
|
ea0a4b2142 | ||
|
|
4482063fb9 | ||
|
|
2d8bd7aecc | ||
|
|
69bea2eb96 | ||
|
|
c5112d4a0f | ||
|
|
a8064ff644 | ||
|
|
fccdcfe803 | ||
|
|
543ea4bd90 | ||
|
|
da47ed8ac4 | ||
|
|
f3b2d5471f | ||
|
|
3f426ff7e0 | ||
|
|
1e1480f408 | ||
|
|
4e316c3a40 | ||
|
|
cb110f7403 | ||
|
|
21a79b4a44 | ||
|
|
cf6defe025 | ||
|
|
6eaf0dd05e | ||
|
|
c2a771f51c | ||
|
|
6cfbc809cf | ||
|
|
3dc37f1ecd | ||
|
|
5dda155f81 | ||
|
|
c51267871c | ||
|
|
9a9a6d853d | ||
|
|
9aebf1e818 | ||
|
|
3df8101903 | ||
|
|
94943334d4 | ||
|
|
27d1131825 | ||
|
|
e0c6fabda6 | ||
|
|
71f5a7568f | ||
|
|
2a33d28cb9 | ||
|
|
9927c0d5c7 | ||
|
|
42898064f2 | ||
|
|
810978720f | ||
|
|
90a60d3b6a | ||
|
|
f6240587db | ||
|
|
80aecfddff | ||
|
|
72403ecbd1 | ||
|
|
16965bc19a | ||
|
|
d7078ae153 | ||
|
|
bced96ee98 | ||
|
|
990a7b6d51 | ||
|
|
735aa139b1 | ||
|
|
aa4a4774da | ||
|
|
c389ee4aa0 | ||
|
|
f93fe1330a | ||
|
|
3710c443bb | ||
|
|
0f8345b207 | ||
|
|
6f478d0a6f | ||
|
|
d902705d90 | ||
|
|
f79aefa797 | ||
|
|
196723372c | ||
|
|
f687722587 | ||
|
|
26b9044a86 | ||
|
|
a9c606f119 | ||
|
|
26b71711e8 | ||
|
|
6438350130 | ||
|
|
508869e3f1 | ||
|
|
1db7a3bbed | ||
|
|
57a9c6fab2 | ||
|
|
93297260be | ||
|
|
dff077e34b | ||
|
|
a8380a00ef | ||
|
|
5afb0a3aa7 | ||
|
|
54ee3a2800 | ||
|
|
9f75caef55 | ||
|
|
bc1c6bde1d | ||
|
|
1dd2b4494d | ||
|
|
5fc35b6682 | ||
|
|
22ab93da0f | ||
|
|
1582b1cf35 | ||
|
|
bd7564a2d4 | ||
|
|
af7d551010 | ||
|
|
3acbeda9c2 | ||
|
|
89d30e9aa2 | ||
|
|
64d45ac35a | ||
|
|
f8661fd87e | ||
|
|
12add870fc | ||
|
|
00a2f81589 | ||
|
|
617b5e39f5 | ||
|
|
1555979f96 | ||
|
|
418c8e7182 | ||
|
|
3b94d4d3e0 | ||
|
|
e541715e42 | ||
|
|
37bdbd037e | ||
|
|
d399b1e70b | ||
|
|
fef437bdd6 | ||
|
|
809741e161 | ||
|
|
0f360131cb | ||
|
|
cb3ce8fb97 | ||
|
|
b56e297be0 | ||
|
|
81eb54d146 | ||
|
|
9fabc08520 | ||
|
|
b885d13060 | ||
|
|
67dbada736 | ||
|
|
c25461640b | ||
|
|
c727be5a48 | ||
|
|
ae098462c9 | ||
|
|
74a7c3dc9a | ||
|
|
c2fcfe6512 | ||
|
|
bdcb9dcb2f | ||
|
|
6200a34522 | ||
|
|
9a25e66e87 | ||
|
|
7c454d8f94 | ||
|
|
ab3e70ae9f | ||
|
|
1818191dca | ||
|
|
31e5ac02bd | ||
|
|
aa3c9f58df | ||
|
|
df9320134b | ||
|
|
6003da8daa | ||
|
|
41e3ea5664 | ||
|
|
8b33b2809c | ||
|
|
56309a4999 | ||
|
|
2d691508c2 | ||
|
|
98e88c2ff0 | ||
|
|
675618574a | ||
|
|
d97cfaa55d | ||
|
|
ec76f67668 | ||
|
|
a12c507bec | ||
|
|
ca26dac8e2 | ||
|
|
5d0a9c0803 | ||
|
|
b85dabd6b4 | ||
|
|
e978c71b7c | ||
|
|
eb9493458e | ||
|
|
f4bb0b8850 | ||
|
|
dd4e356c64 | ||
|
|
c1ed052638 | ||
|
|
88a3c2b1e1 | ||
|
|
f0f156aca8 | ||
|
|
b1aa2232ef | ||
|
|
4b4555b811 | ||
|
|
ecdeb3934d | ||
|
|
abceea8fa1 | ||
|
|
83a9d8b91d | ||
|
|
68a9eeae18 | ||
|
|
5729a01e69 | ||
|
|
ea469140d5 | ||
|
|
b5b7a56eca | ||
|
|
66677d7c21 | ||
|
|
7805774cf3 | ||
|
|
8ae04b41b0 | ||
|
|
b27cd5ada8 | ||
|
|
a1355e50e2 | ||
|
|
2ad65c0799 | ||
|
|
7f2770e68f | ||
|
|
c34dec5495 | ||
|
|
ba92305de0 | ||
|
|
0a790a1a2e | ||
|
|
3ea090fe18 | ||
|
|
0490231b34 | ||
|
|
030aa5aba5 | ||
|
|
09d04326dc | ||
|
|
cfb25fe81b | ||
|
|
ecfd4526a3 | ||
|
|
affc127af0 | ||
|
|
a498b9b3a2 | ||
|
|
e684b48cfe | ||
|
|
5b585c4759 | ||
|
|
2e612b23d6 | ||
|
|
4a130c60a8 | ||
|
|
b72d2d9cc5 | ||
|
|
b3229507a9 | ||
|
|
1761b338f9 | ||
|
|
c63c5732e9 | ||
|
|
dba70c0b92 | ||
|
|
c75abbb3f9 | ||
|
|
19e14db50a | ||
|
|
bd5372f165 | ||
|
|
a3203d4fe7 | ||
|
|
e538599e2f | ||
|
|
4b62f520e8 | ||
|
|
bc1a108e5c | ||
|
|
38965dd432 | ||
|
|
30491f369d | ||
|
|
1941a2532a | ||
|
|
3a22044471 | ||
|
|
da3e027145 | ||
|
|
7bc792e745 | ||
|
|
939e1006cc | ||
|
|
57faed2725 | ||
|
|
f9a6d70bc0 | ||
|
|
e3854b077a | ||
|
|
75a36b4831 | ||
|
|
30965763d6 | ||
|
|
e940856fee | ||
|
|
07169d421e | ||
|
|
a5ea937df2 | ||
|
|
539cd245d6 | ||
|
|
ede0911de2 | ||
|
|
733d3c5d54 | ||
|
|
0854af6e6d | ||
|
|
d8d3a3dec1 | ||
|
|
59ef9fe468 | ||
|
|
9ddc45162a | ||
|
|
bda754d07f | ||
|
|
124b9fa4d9 | ||
|
|
45578f0ed2 | ||
|
|
4e7eeb0725 | ||
|
|
f0309e33e1 | ||
|
|
8964876217 | ||
|
|
e3b84ac010 | ||
|
|
d541a7f6ef | ||
|
|
69f967b3f3 | ||
|
|
1bb64f0bf0 | ||
|
|
2073642656 | ||
|
|
f3eaa54a32 | ||
|
|
a91204ea6f | ||
|
|
5117f74fce | ||
|
|
57414cbb6e | ||
|
|
24d4c28aa9 | ||
|
|
cb4f46854b | ||
|
|
0992c3a50d | ||
|
|
c5eaa30253 | ||
|
|
6faac81eb0 | ||
|
|
2fc5413002 | ||
|
|
8137e79d0c | ||
|
|
b827fac635 | ||
|
|
4479667d4c | ||
|
|
9226796558 | ||
|
|
fd340638bb | ||
|
|
6ca902d13a | ||
|
|
73a61b4203 | ||
|
|
96378448c5 | ||
|
|
eab117c07c | ||
|
|
7b69f0064d | ||
|
|
0dd32c1b26 | ||
|
|
c707a17f30 | ||
|
|
502e28d2be | ||
|
|
b7e87b623d | ||
|
|
7bbc81ffa4 | ||
|
|
449cad0eb8 | ||
|
|
7260b0f9ea | ||
|
|
a83ffe321c | ||
|
|
a215fbb718 | ||
|
|
87f7e65c4c | ||
|
|
ab31cf97da | ||
|
|
b2d2e09105 | ||
|
|
c9f33698fc | ||
|
|
044a95b6cf | ||
|
|
c352cadd4b | ||
|
|
40971c0b93 | ||
|
|
0d0638b398 | ||
|
|
12627c35e4 | ||
|
|
1d5870b2a2 | ||
|
|
ae88af8b1b | ||
|
|
bc756e3dbd | ||
|
|
bc679788ac | ||
|
|
a1110bc022 | ||
|
|
073ed250fe | ||
|
|
3b78c115f6 | ||
|
|
f8aafcc774 | ||
|
|
22b8ab43bd | ||
|
|
5eab7c2698 | ||
|
|
26f5102eae | ||
|
|
9998e077df | ||
|
|
480bc8aa2a | ||
|
|
a8c97b467d | ||
|
|
7f01db2cda | ||
|
|
d83e73b85b | ||
|
|
7e49e2d519 | ||
|
|
5a962a7cf5 | ||
|
|
70dcf20d74 | ||
|
|
c57a2dc4c2 | ||
|
|
4ab7f30f99 | ||
|
|
29f2dbca6b | ||
|
|
4070902cda | ||
|
|
556bbc2de5 | ||
|
|
7e879edabc | ||
|
|
f48ac0de19 | ||
|
|
1a5aab3ff4 | ||
|
|
8cf797da5f | ||
|
|
023b38fe3f | ||
|
|
afcfe758f3 | ||
|
|
c0b89a7aec | ||
|
|
4f1f864f64 | ||
|
|
2d4346bfe1 | ||
|
|
d566905d7a | ||
|
|
743d72ea1a | ||
|
|
10059459f3 | ||
|
|
376b4ce2f8 | ||
|
|
961c4b5dae | ||
|
|
1711f0bb46 | ||
|
|
b41b98b04d | ||
|
|
1b794a4ae1 | ||
|
|
182ad295d8 | ||
|
|
75e9691616 | ||
|
|
1ccf40d1e5 | ||
|
|
2dc48e9dd3 | ||
|
|
757fff7764 | ||
|
|
0fe4319e17 | ||
|
|
18ddd3925b | ||
|
|
8aaf909a08 | ||
|
|
da5c19848d | ||
|
|
45b32d3985 | ||
|
|
ae3c123a5c | ||
|
|
fe82b0381c | ||
|
|
0ede95b65e | ||
|
|
4758556eec | ||
|
|
ea580b0b65 | ||
|
|
b1dd99c94d | ||
|
|
57bf0c0e79 | ||
|
|
7ebe7908ea | ||
|
|
750644ec4d | ||
|
|
efeaf2ee72 | ||
|
|
97c7984bca | ||
|
|
335a53ad29 | ||
|
|
d4981656d3 | ||
|
|
766e04d79d | ||
|
|
4e30ca1617 | ||
|
|
65e22bee24 | ||
|
|
3987f1405a | ||
|
|
e1056aa50d | ||
|
|
017dddef97 | ||
|
|
55f06077e5 | ||
|
|
99ee2a5042 | ||
|
|
793cda2ca0 | ||
|
|
83bb797389 | ||
|
|
8fbbd0ee83 | ||
|
|
b94b8e67e9 | ||
|
|
f93fb55606 | ||
|
|
3b4626ea15 | ||
|
|
d9663e5d96 | ||
|
|
5d703df69d | ||
|
|
5f2f82b5f7 | ||
|
|
5dee56d5d0 | ||
|
|
722ee94165 | ||
|
|
b64c8a3aa9 | ||
|
|
13259eea21 | ||
|
|
9da492975c | ||
|
|
96dc4f920d | ||
|
|
2d221ba8da | ||
|
|
87309ebaac | ||
|
|
eeb18ff75c | ||
|
|
4cb6e35342 | ||
|
|
5ddf9728f8 | ||
|
|
275db95170 | ||
|
|
399187c4fb | ||
|
|
1fd03fb81f | ||
|
|
0aa704ad5e | ||
|
|
1e7b4c9e4a | ||
|
|
65c582cd5b | ||
|
|
336e7f58bf | ||
|
|
dfffc1e7cc | ||
|
|
a63a1f7eca | ||
|
|
b3fe40e113 | ||
|
|
093ab6b034 | ||
|
|
ceb38130fc | ||
|
|
7498e97182 | ||
|
|
32a8f34f7d | ||
|
|
014d09412a | ||
|
|
ab6b2a83ac | ||
|
|
79a51e9afc | ||
|
|
c9448749d0 | ||
|
|
aa8d5ed0cc | ||
|
|
a86080a0b7 | ||
|
|
59685e2d6b | ||
|
|
582f99b438 | ||
|
|
26c7c3e500 | ||
|
|
785e14a725 | ||
|
|
7ad9a36b9d | ||
|
|
9831612507 | ||
|
|
207d5cfb61 | ||
|
|
c10b429dcb | ||
|
|
8f38471e29 | ||
|
|
25254c7622 | ||
|
|
7d062fb08c | ||
|
|
37e5a78779 | ||
|
|
07e810fd51 | ||
|
|
224e602e59 | ||
|
|
be710ecb52 | ||
|
|
4810ab8727 | ||
|
|
5a2798dddb | ||
|
|
36d7d0b9a7 | ||
|
|
b1812ebe5a | ||
|
|
683fcf0dd2 | ||
|
|
39197ea3ae | ||
|
|
48bd32570f | ||
|
|
49ef42d36a | ||
|
|
fe583468ce | ||
|
|
3f4d3ee1c0 | ||
|
|
dd3b659f9e | ||
|
|
dc47c3819a | ||
|
|
e6ca983442 | ||
|
|
ca96cfc6e6 | ||
|
|
60681d7fb6 | ||
|
|
e53ad24e8c | ||
|
|
b62fa406d8 | ||
|
|
d066ff71f5 | ||
|
|
3e2c3fc94d | ||
|
|
c1b9079b73 | ||
|
|
b9401d574f | ||
|
|
eba548ca88 | ||
|
|
b4d7ec07f4 | ||
|
|
4753e1e61b | ||
|
|
8d7888eb4f | ||
|
|
54a7460fa0 | ||
|
|
5c135d25d6 | ||
|
|
8391a69dc5 | ||
|
|
1b9beadf2b | ||
|
|
05f588fd19 | ||
|
|
d01a50d301 | ||
|
|
3b53bbe478 | ||
|
|
685299ab75 | ||
|
|
1a8561115b | ||
|
|
c32b1ea48b | ||
|
|
ea05fcbcf5 | ||
|
|
2d44e8c85e | ||
|
|
21c677fc2d | ||
|
|
800f0af04e | ||
|
|
398bac82d9 | ||
|
|
cd16de763c | ||
|
|
694ab27649 | ||
|
|
61f2595852 | ||
|
|
be3370396a | ||
|
|
fed9ebe39d | ||
|
|
6c677e0d11 | ||
|
|
320e29e03f | ||
|
|
7f65ad4957 | ||
|
|
372e905dad | ||
|
|
7027211e58 | ||
|
|
f0ccc91890 | ||
|
|
136e286ef4 | ||
|
|
e54962e17f | ||
|
|
39aa635971 | ||
|
|
61e511cc3e | ||
|
|
dd9e715599 | ||
|
|
9bdb7affb1 | ||
|
|
9a881562b9 | ||
|
|
656f4f13d0 | ||
|
|
9eb967cabf | ||
|
|
1bf5ac350f | ||
|
|
313d0a358f | ||
|
|
81f3ffa3af | ||
|
|
9ea42680b0 | ||
|
|
018bcbf629 | ||
|
|
0733d37c67 | ||
|
|
b0968e29e8 | ||
|
|
fac4ef81b2 | ||
|
|
e494e138fe | ||
|
|
5805a37d27 | ||
|
|
ad04a6fcc4 | ||
|
|
7084a4361e | ||
|
|
a009299433 | ||
|
|
1c038760ce | ||
|
|
eafa942a30 | ||
|
|
05468dfc8d | ||
|
|
ff7ed00714 | ||
|
|
3c0094a5fe | ||
|
|
923c0e24b1 | ||
|
|
3b57e86cd3 | ||
|
|
1a6987558a | ||
|
|
a15d54c4a8 | ||
|
|
3c4c1222d8 | ||
|
|
250def49d5 | ||
|
|
b1e3d147f5 | ||
|
|
6c89b81d7b | ||
|
|
7c7969ed55 | ||
|
|
29920f8c9c | ||
|
|
9ebb916902 | ||
|
|
4369359286 | ||
|
|
1dab94c625 | ||
|
|
6c0f804f32 | ||
|
|
7991f67863 | ||
|
|
22ab1c4901 | ||
|
|
53cb92038a | ||
|
|
4425378b37 | ||
|
|
7fda78af40 | ||
|
|
6e8320a6dc | ||
|
|
99682ecbdb | ||
|
|
bf657a33e3 | ||
|
|
bab1b9302e | ||
|
|
8ce6f43e35 | ||
|
|
ecee324c00 | ||
|
|
0934a39d73 | ||
|
|
7673ef084d | ||
|
|
55e010ca52 | ||
|
|
1ef242a5c1 | ||
|
|
071c71efbc | ||
|
|
798775775b | ||
|
|
2ca601ef22 | ||
|
|
1cfb326e2f | ||
|
|
675fbee1f3 | ||
|
|
d055f0edac | ||
|
|
1f48b16acb | ||
|
|
41d4857d73 | ||
|
|
f7dbf9a20b | ||
|
|
d7a3a0bce3 | ||
|
|
7483cdebfb | ||
|
|
e7e44b96ee | ||
|
|
43388a06ca | ||
|
|
ace3f452c3 | ||
|
|
fb9d10772a | ||
|
|
a5014a8c71 | ||
|
|
8ce4b39fed | ||
|
|
f01f94a691 | ||
|
|
04cd5e80ee | ||
|
|
4fd1500312 | ||
|
|
5b74d8c444 | ||
|
|
1d683ea83e | ||
|
|
38652b168a | ||
|
|
cca8c10f33 | ||
|
|
2ffa265d8c | ||
|
|
ad850412d2 | ||
|
|
4f0c2bf376 | ||
|
|
fa75251c76 | ||
|
|
3fefebd05d | ||
|
|
9d7529118e | ||
|
|
507e7672c2 | ||
|
|
9c81d374b1 | ||
|
|
38c3703d08 | ||
|
|
973dc13cc0 | ||
|
|
bca93f6c83 | ||
|
|
caf6bfb76f | ||
|
|
76180184a5 | ||
|
|
0e1e954768 | ||
|
|
b031817fce | ||
|
|
6b2e63e66c | ||
|
|
085a1e512f | ||
|
|
31cb23f586 | ||
|
|
6a7ca4311e | ||
|
|
d87078bee6 | ||
|
|
50228116e1 | ||
|
|
95033f3f76 | ||
|
|
a8acbe5cfb | ||
|
|
f9d4c4dbac | ||
|
|
17abc6c736 | ||
|
|
94bd9564d0 | ||
|
|
c6cb6595be | ||
|
|
a2f25c2f3b | ||
|
|
5d3c4ed96c | ||
|
|
7cec8f2285 | ||
|
|
86777e7863 | ||
|
|
853fea16b4 | ||
|
|
9cf76b1233 | ||
|
|
66a65aab02 | ||
|
|
5581915bc0 | ||
|
|
ee7f4e1d52 | ||
|
|
8c65985cd0 | ||
|
|
23a58eb5da | ||
|
|
9193eef1c9 | ||
|
|
e90e9bc352 | ||
|
|
a1d860f818 | ||
|
|
d733d68b0c | ||
|
|
4a96d65408 | ||
|
|
1e16ed5e55 | ||
|
|
782352ae56 | ||
|
|
d97ba4eb0d | ||
|
|
282246fff2 | ||
|
|
b3059164aa | ||
|
|
64166319ee | ||
|
|
b8e732e526 | ||
|
|
f0d926ebba | ||
|
|
1e48d10617 | ||
|
|
ce9d706716 | ||
|
|
81abbca12f | ||
|
|
2cd67b296e | ||
|
|
7976d6d805 | ||
|
|
df395786bd | ||
|
|
2412aae68f | ||
|
|
0a42e2969a | ||
|
|
b51e6b0485 | ||
|
|
e1ed7c65e7 | ||
|
|
cf89d74561 | ||
|
|
38aec4d875 | ||
|
|
23f0a27acc | ||
|
|
447cb7a726 | ||
|
|
fa5a339434 | ||
|
|
7a295dd5fa | ||
|
|
2895b0acca | ||
|
|
ab9cdd7fce | ||
|
|
cc6fa9acbf | ||
|
|
e14dcccd37 | ||
|
|
27526399f5 | ||
|
|
8009e8108b | ||
|
|
b45d48f4f1 | ||
|
|
b9f1950320 | ||
|
|
6de2b4559e | ||
|
|
0661f537cf | ||
|
|
b737b2e7fc | ||
|
|
d9b3f276b8 | ||
|
|
53ab0168e4 | ||
|
|
01f0c35651 | ||
|
|
75d55783c0 | ||
|
|
f03aaef72f | ||
|
|
f54e426bb1 | ||
|
|
5b94ddc703 | ||
|
|
477461325d | ||
|
|
3094af8a5e | ||
|
|
add7dcc763 | ||
|
|
df7acbcad4 | ||
|
|
15b91126d5 | ||
|
|
2b24a7b520 | ||
|
|
b404c7583b | ||
|
|
6ce337ca38 | ||
|
|
d0caa630af | ||
|
|
8a48d604a8 | ||
|
|
80b0aa3842 | ||
|
|
c6a383590d | ||
|
|
fd34958ffa | ||
|
|
530a34a3f3 | ||
|
|
90093b5d8c | ||
|
|
939dad5900 | ||
|
|
85717527d9 | ||
|
|
768be74f74 | ||
|
|
a885ffd64b | ||
|
|
e25f1ee72f | ||
|
|
6e943832d5 | ||
|
|
3a3bc2ffb1 | ||
|
|
90a421e4af | ||
|
|
bc72ffb6b2 | ||
|
|
a30f0aca85 | ||
|
|
2ea2ec90d2 | ||
|
|
22670acfbe | ||
|
|
358a5af98e | ||
|
|
c70bd05494 | ||
|
|
0b4d52a141 | ||
|
|
a47c86c54c | ||
|
|
082ea3c295 | ||
|
|
a4177ad30b | ||
|
|
3603766f1c | ||
|
|
951429fe67 | ||
|
|
f5ff7e15cf | ||
|
|
c9c95f2e9e | ||
|
|
bc79fba49a | ||
|
|
b51fb32054 | ||
|
|
c9ecd023fa | ||
|
|
c28aa819b6 | ||
|
|
f6ca45c384 | ||
|
|
75de34de90 | ||
|
|
429a0d00af | ||
|
|
acf933646b | ||
|
|
b427202237 | ||
|
|
8eaa9463c1 | ||
|
|
e15f04c01b | ||
|
|
626baab73d | ||
|
|
5e8f861eac | ||
|
|
9217553a3c | ||
|
|
ab20dc98f7 | ||
|
|
9f1315fa64 | ||
|
|
46d158d023 | ||
|
|
acd80370e6 | ||
|
|
9ad19bfe52 | ||
|
|
eed14719db | ||
|
|
589c821f9b | ||
|
|
a09795c8a7 | ||
|
|
52df29917b | ||
|
|
16ae081c4c | ||
|
|
489d1629fb | ||
|
|
9be8aebfff | ||
|
|
e53fa1a5a2 | ||
|
|
92d1e226d3 | ||
|
|
64dbb7ed9c | ||
|
|
21b0f4b0d2 | ||
|
|
fc448e49d5 | ||
|
|
7a21e4bb0d | ||
|
|
47ca8a61ea | ||
|
|
1c3f889f6e | ||
|
|
6f4a0f9cbb | ||
|
|
67c1957eb0 | ||
|
|
3d7796f38c | ||
|
|
2d431dacbc | ||
|
|
17468c8863 | ||
|
|
475670de7d | ||
|
|
f9efb67bc2 | ||
|
|
9766ff1805 | ||
|
|
cc4227e3f2 | ||
|
|
ba2e8149c8 | ||
|
|
b48371e971 | ||
|
|
8b074767db | ||
|
|
e5bc26c75a | ||
|
|
959fa74ca5 | ||
|
|
ac57970229 | ||
|
|
9fb8cfc1b3 | ||
|
|
06ad6c53f7 | ||
|
|
a9b0b14149 | ||
|
|
9a454e714d | ||
|
|
319b3d8434 | ||
|
|
2fec2b4107 | ||
|
|
382aa26859 | ||
|
|
d7854b6dfa | ||
|
|
e3b6c12925 | ||
|
|
d9224348ce | ||
|
|
6b91c6f430 | ||
|
|
7e9b96e354 | ||
|
|
8a8d4619de | ||
|
|
3af0902f28 | ||
|
|
6b4c1a4239 | ||
|
|
783d29794a | ||
|
|
a094c50f5a | ||
|
|
621e8cf0ff | ||
|
|
4bd9336139 | ||
|
|
c517833663 | ||
|
|
8e4cc8df00 | ||
|
|
94f4c4cd2d | ||
|
|
c4c99999bc | ||
|
|
6abd3a4ed6 | ||
|
|
9e94120d68 | ||
|
|
ba088b8fc0 | ||
|
|
98ac1817cb | ||
|
|
65a31e34c9 | ||
|
|
264f1ef992 | ||
|
|
b30bbc0e74 | ||
|
|
7a77686878 | ||
|
|
0c4200306b | ||
|
|
619b1b4e2a | ||
|
|
57d22664f4 | ||
|
|
38339b7cd9 | ||
|
|
d5cb19aeab | ||
|
|
3d04e56228 | ||
|
|
3e8f7684f2 | ||
|
|
c11527780a | ||
|
|
5a204741b9 | ||
|
|
b23e8a77fc | ||
|
|
e926266c62 | ||
|
|
1eca4f8c0d | ||
|
|
edb1824006 | ||
|
|
6666262e51 | ||
|
|
221ee6c26b | ||
|
|
d3d4afd223 | ||
|
|
f55f64b5b9 | ||
|
|
69fbb9a87d | ||
|
|
8e50e8e8c3 | ||
|
|
8cdf71b539 | ||
|
|
e7f4b63212 | ||
|
|
12adf3be32 | ||
|
|
087516a783 | ||
|
|
1b2a2fc7f9 | ||
|
|
3e205dba15 | ||
|
|
ff874575e1 | ||
|
|
1e1516c968 | ||
|
|
aeb6de996c | ||
|
|
82d87111fc | ||
|
|
49953d53ed | ||
|
|
13a4133da5 | ||
|
|
a02ae19de2 | ||
|
|
9617f22fcd | ||
|
|
e156d62e44 | ||
|
|
f4e8352f5a | ||
|
|
deb7f72be2 | ||
|
|
a5a57fa2be | ||
|
|
c3fb1d52f4 | ||
|
|
9820dce775 | ||
|
|
426df2c9ab | ||
|
|
20c7a00af5 | ||
|
|
00d0f1e9d9 | ||
|
|
4cecac4ea4 | ||
|
|
b0e2bde84d | ||
|
|
49851c8795 | ||
|
|
7bdb39c743 | ||
|
|
09495582c4 | ||
|
|
f15be9582a | ||
|
|
c022107515 | ||
|
|
373b593c3e | ||
|
|
ca06c0e09f | ||
|
|
bd1086c244 | ||
|
|
69c8bf7959 | ||
|
|
db6b4f1344 | ||
|
|
05db6e3981 | ||
|
|
2623eeb82e | ||
|
|
cbebadc16a | ||
|
|
614d6d81e5 | ||
|
|
cac451c83e | ||
|
|
54a86c69e1 | ||
|
|
ea8f5c0f33 | ||
|
|
340d576931 | ||
|
|
7db8820042 | ||
|
|
54761b22fd | ||
|
|
253f13640c | ||
|
|
97110c9676 | ||
|
|
9805c4d907 | ||
|
|
56d548ad10 | ||
|
|
c196f6ee08 | ||
|
|
db55841e7d | ||
|
|
fb70ef7b1c | ||
|
|
fa82223c50 | ||
|
|
6f3cd87993 | ||
|
|
3ca7ac613d | ||
|
|
fe5b2f97e3 | ||
|
|
220bf92a3c | ||
|
|
5219fd59e8 | ||
|
|
4832da5cda | ||
|
|
4ef3dcffc4 | ||
|
|
fbe4768658 | ||
|
|
f63de3cc30 | ||
|
|
7c7d9e07a2 | ||
|
|
708f1e17f4 | ||
|
|
8fc48cf24a |
@@ -0,0 +1,12 @@
|
|||||||
|
## Expected behavior
|
||||||
|
|
||||||
|
## Actual behavior
|
||||||
|
|
||||||
|
## Steps to reproduce the behavior
|
||||||
|
|
||||||
|
## mc --version
|
||||||
|
- (paste output of `mc --version`)
|
||||||
|
|
||||||
|
## System information
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Bug report template
|
||||||
|
title: ''
|
||||||
|
labels: community, triage
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Expected behavior
|
||||||
|
|
||||||
|
## Actual behavior
|
||||||
|
|
||||||
|
## Steps to reproduce the behavior
|
||||||
|
|
||||||
|
## mc --version
|
||||||
|
- (paste output of `mc --version`)
|
||||||
|
|
||||||
|
## System information
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: MinIO Community Support
|
||||||
|
url: https://slack.min.io
|
||||||
|
about: Please ask and answer questions here.
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app
|
||||||
|
|
||||||
|
# Number of days of inactivity before a closed issue or pull request is locked
|
||||||
|
daysUntilLock: 365
|
||||||
|
|
||||||
|
# Skip issues and pull requests created before a given timestamp. Timestamp must
|
||||||
|
# follow ISO 8601 (`YYYY-MM-DD`). Set to `false` to disable
|
||||||
|
skipCreatedBefore: false
|
||||||
|
|
||||||
|
# Issues and pull requests with these labels will be ignored. Set to `[]` to disable
|
||||||
|
exemptLabels: []
|
||||||
|
|
||||||
|
# Label to add before locking, such as `outdated`. Set to `false` to disable
|
||||||
|
lockLabel: false
|
||||||
|
|
||||||
|
# Comment to post before locking. Set to `false` to disable
|
||||||
|
lockComment: >-
|
||||||
|
|
||||||
|
This thread has been automatically locked since there has not been
|
||||||
|
any recent activity after it was closed. Please open a new issue for
|
||||||
|
related bugs.
|
||||||
|
|
||||||
|
# Assign `resolved` as the reason for locking. Set to `false` to disable
|
||||||
|
setLockReason: true
|
||||||
|
|
||||||
|
# Limit to only `issues` or `pulls`
|
||||||
|
only: issues
|
||||||
|
|
||||||
|
# Optionally, specify configuration settings just for `issues` or `pulls`
|
||||||
|
# issues:
|
||||||
|
# exemptLabels:
|
||||||
|
# - help-wanted
|
||||||
|
# lockLabel: outdated
|
||||||
|
|
||||||
|
# pulls:
|
||||||
|
# daysUntilLock: 30
|
||||||
|
|
||||||
|
# Repository to extend settings from
|
||||||
|
# _extends: repo
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# Configuration for probot-stale - https://github.com/probot/stale
|
||||||
|
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request becomes stale
|
||||||
|
daysUntilStale: 90
|
||||||
|
|
||||||
|
# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
|
||||||
|
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
|
||||||
|
daysUntilClose: 30
|
||||||
|
|
||||||
|
# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
|
||||||
|
onlyLabels: []
|
||||||
|
|
||||||
|
# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
|
||||||
|
exemptLabels:
|
||||||
|
- "security"
|
||||||
|
- "pending discussion"
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a project (defaults to false)
|
||||||
|
exemptProjects: false
|
||||||
|
|
||||||
|
# Set to true to ignore issues in a milestone (defaults to false)
|
||||||
|
exemptMilestones: false
|
||||||
|
|
||||||
|
# Set to true to ignore issues with an assignee (defaults to false)
|
||||||
|
exemptAssignees: false
|
||||||
|
|
||||||
|
# Label to use when marking as stale
|
||||||
|
staleLabel: stale
|
||||||
|
|
||||||
|
# Comment to post when marking as stale. Set to `false` to disable
|
||||||
|
markComment: >-
|
||||||
|
This issue has been automatically marked as stale because it has not had
|
||||||
|
recent activity. It will be closed after 21 days if no further activity
|
||||||
|
occurs. Thank you for your contributions.
|
||||||
|
# Comment to post when removing the stale label.
|
||||||
|
# unmarkComment: >
|
||||||
|
# Your comment here.
|
||||||
|
|
||||||
|
# Comment to post when closing a stale Issue or Pull Request.
|
||||||
|
# closeComment: >
|
||||||
|
# Your comment here.
|
||||||
|
|
||||||
|
# Limit the number of actions per hour, from 1-30. Default is 30
|
||||||
|
limitPerRun: 1
|
||||||
|
|
||||||
|
# Limit to only `issues` or `pulls`
|
||||||
|
# only: issues
|
||||||
|
|
||||||
|
# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
|
||||||
|
# pulls:
|
||||||
|
# daysUntilStale: 30
|
||||||
|
# markComment: >
|
||||||
|
# This pull request has been automatically marked as stale because it has not had
|
||||||
|
# recent activity. It will be closed if no further activity occurs. Thank you
|
||||||
|
# for your contributions.
|
||||||
|
|
||||||
|
# issues:
|
||||||
|
# exemptLabels:
|
||||||
|
# - confirmed
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
name: "Code scanning - action"
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 19 * * 0'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
CodeQL-Build:
|
||||||
|
|
||||||
|
# CodeQL runs on ubuntu-latest and windows-latest
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
# We must fetch at least the immediate parents so that if this is
|
||||||
|
# a pull request then we can checkout the head.
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
# If this run was triggered by a pull request event, then checkout
|
||||||
|
# the head of the pull request instead of the merge commit.
|
||||||
|
- run: git checkout HEAD^2
|
||||||
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
|
# Initializes the CodeQL tools for scanning.
|
||||||
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
# Override language selection by uncommenting this and choosing your languages
|
||||||
|
# with:
|
||||||
|
# languages: go, javascript, csharp, python, cpp, java
|
||||||
|
|
||||||
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
|
- name: Autobuild
|
||||||
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
|
# 📚 https://git.io/JvXDl
|
||||||
|
|
||||||
|
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||||
|
# and modify them (or add more) to build your code if your project
|
||||||
|
# uses a compiled language
|
||||||
|
|
||||||
|
#- run: |
|
||||||
|
# make bootstrap
|
||||||
|
# make release
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
name: Go
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Test on Go ${{ matrix.go-version }} and ${{ matrix.os }}
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go-version: [1.13.x]
|
||||||
|
os: [ubuntu-latest, windows-latest]
|
||||||
|
steps:
|
||||||
|
- name: Set up Go ${{ matrix.go-version }} on ${{ matrix.os }}
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go-version }}
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Build on ${{ matrix.os }}
|
||||||
|
if: matrix.os == 'windows-latest'
|
||||||
|
env:
|
||||||
|
GO111MODULE: on
|
||||||
|
run: |
|
||||||
|
go build --ldflags="-s -w" -o %GOPATH%\bin\mc.exe
|
||||||
|
go test -v -race --timeout 30m ./...
|
||||||
|
- name: Build on ${{ matrix.os }}
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
|
env:
|
||||||
|
GO111MODULE: on
|
||||||
|
run: |
|
||||||
|
make
|
||||||
|
diff -au <(gofmt -d *.go) <(printf "")
|
||||||
|
diff -au <(gofmt -s -d cmd) <(printf "")
|
||||||
|
diff -au <(gofmt -s -d pkg) <(printf "")
|
||||||
|
make test-race
|
||||||
|
make verify
|
||||||
|
make crosscompile
|
||||||
+10
-1
@@ -1,4 +1,13 @@
|
|||||||
cover.out
|
cover.out
|
||||||
mc
|
|
||||||
*~
|
*~
|
||||||
*.test
|
*.test
|
||||||
|
release
|
||||||
|
experimental
|
||||||
|
coverage.txt
|
||||||
|
*.tar.bz2
|
||||||
|
parts/
|
||||||
|
prime/
|
||||||
|
stage/
|
||||||
|
mc
|
||||||
|
.run*
|
||||||
|
.idea/
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
linters-settings:
|
||||||
|
golint:
|
||||||
|
min-confidence: 0
|
||||||
|
|
||||||
|
misspell:
|
||||||
|
locale: US
|
||||||
|
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- typecheck
|
||||||
|
- goimports
|
||||||
|
- misspell
|
||||||
|
- govet
|
||||||
|
- golint
|
||||||
|
- ineffassign
|
||||||
|
- gosimple
|
||||||
|
- deadcode
|
||||||
|
- structcheck
|
||||||
|
|
||||||
|
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.20.0 # use the fixed version to not introduce new linters unexpectedly
|
||||||
+167
@@ -0,0 +1,167 @@
|
|||||||
|
project_name: mc
|
||||||
|
|
||||||
|
release:
|
||||||
|
name_template: "Version {{.Version}}"
|
||||||
|
disable: true
|
||||||
|
github:
|
||||||
|
owner: minio
|
||||||
|
name: mc
|
||||||
|
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
- GO111MODULE=on
|
||||||
|
|
||||||
|
before:
|
||||||
|
hooks:
|
||||||
|
- make clean
|
||||||
|
- go generate ./...
|
||||||
|
- go mod tidy
|
||||||
|
- go mod download
|
||||||
|
|
||||||
|
builds:
|
||||||
|
-
|
||||||
|
goos:
|
||||||
|
- linux
|
||||||
|
- darwin
|
||||||
|
- windows
|
||||||
|
- freebsd
|
||||||
|
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
|
- arm64
|
||||||
|
- arm
|
||||||
|
- ppc64le
|
||||||
|
- s390x
|
||||||
|
|
||||||
|
goarm:
|
||||||
|
- 7
|
||||||
|
|
||||||
|
ignore:
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm64
|
||||||
|
- goos: darwin
|
||||||
|
goarch: arm
|
||||||
|
- goos: darwin
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: darwin
|
||||||
|
goarch: s390x
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm64
|
||||||
|
- goos: windows
|
||||||
|
goarch: arm
|
||||||
|
- goos: windows
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: windows
|
||||||
|
goarch: s390x
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: arm64
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: ppc64le
|
||||||
|
- goos: freebsd
|
||||||
|
goarch: s390x
|
||||||
|
|
||||||
|
flags:
|
||||||
|
- -tags=kqueue
|
||||||
|
- -trimpath
|
||||||
|
|
||||||
|
ldflags:
|
||||||
|
- "-s -w -X github.com/minio/mc/cmd.Version={{.Version}} -X github.com/minio/mc/cmd.ReleaseTag={{.Tag}} -X github.com/minio/mc/cmd.CommitID={{.FullCommit}} -X github.com/minio/mc/cmd.ShortCommitID={{.ShortCommit}}"
|
||||||
|
|
||||||
|
archives:
|
||||||
|
-
|
||||||
|
format: binary
|
||||||
|
name_template: "{{ .Binary }}-release/{{ .Os }}-{{ .Arch }}/{{ .Binary }}.{{ .Version }}"
|
||||||
|
|
||||||
|
nfpms:
|
||||||
|
-
|
||||||
|
id: minio
|
||||||
|
package_name: mc
|
||||||
|
vendor: MinIO, Inc.
|
||||||
|
homepage: https://min.io/
|
||||||
|
maintainer: dev@min.io
|
||||||
|
description: 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).
|
||||||
|
license: Apache 2.0
|
||||||
|
bindir: /usr/bin
|
||||||
|
formats:
|
||||||
|
- deb
|
||||||
|
- rpm
|
||||||
|
overrides:
|
||||||
|
deb:
|
||||||
|
file_name_template: "{{ .Binary }}-release/debs/{{ .ProjectName }}-{{ .Version }}_{{ .Arch }}"
|
||||||
|
replacements:
|
||||||
|
arm: armv7
|
||||||
|
files:
|
||||||
|
"NOTICE": "/usr/share/mc/NOTICE"
|
||||||
|
"CREDITS": "/usr/share/mc/CREDITS"
|
||||||
|
"LICENSE": "/usr/share/mc/LICENSE"
|
||||||
|
"README.md": "/usr/share/mc/README.md"
|
||||||
|
rpm:
|
||||||
|
file_name_template: "{{ .Binary }}-release/rpms/{{ .ProjectName }}-{{ .Version }}.{{ .Arch }}"
|
||||||
|
replacements:
|
||||||
|
amd64: x86_64
|
||||||
|
arm64: aarch64
|
||||||
|
arm: armv7
|
||||||
|
files:
|
||||||
|
"NOTICE": "/usr/share/mc/NOTICE"
|
||||||
|
"CREDITS": "/usr/share/mc/CREDITS"
|
||||||
|
"LICENSE": "/usr/share/mc/LICENSE"
|
||||||
|
"README.md": "/usr/share/mc/README.md"
|
||||||
|
|
||||||
|
checksum:
|
||||||
|
algorithm: sha256
|
||||||
|
|
||||||
|
signs:
|
||||||
|
-
|
||||||
|
signature: "${artifact}.asc"
|
||||||
|
cmd: "sh"
|
||||||
|
args:
|
||||||
|
- '-c'
|
||||||
|
- 'gpg --quiet --detach-sign -a ${artifact}'
|
||||||
|
artifacts: all
|
||||||
|
|
||||||
|
changelog:
|
||||||
|
sort: asc
|
||||||
|
filters:
|
||||||
|
exclude:
|
||||||
|
- '^Update yaml files'
|
||||||
|
|
||||||
|
dockers:
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: amd64
|
||||||
|
dockerfile: Dockerfile.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}
|
||||||
|
- minio/mc:latest
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: ppc64le
|
||||||
|
dockerfile: Dockerfile.ppc64le.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-ppc64le
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: s390x
|
||||||
|
dockerfile: Dockerfile.s390x.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-s390x
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: arm64
|
||||||
|
goarm: ''
|
||||||
|
dockerfile: Dockerfile.arm64.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-arm64
|
||||||
|
|
||||||
|
-
|
||||||
|
goos: linux
|
||||||
|
goarch: arm
|
||||||
|
goarm: '7'
|
||||||
|
dockerfile: Dockerfile.arm.release
|
||||||
|
image_templates:
|
||||||
|
- minio/mc:{{ .Tag }}-arm
|
||||||
@@ -6,10 +6,10 @@
|
|||||||
#
|
#
|
||||||
# For explanation on this file format: man git-shortlog
|
# For explanation on this file format: man git-shortlog
|
||||||
|
|
||||||
Anand Babu (AB) Periasamy <ab@minio.io> Anand Babu (AB) Periasamy <abperiasamy@users.noreply.github.com>
|
Anand Babu (AB) Periasamy <ab@min.io> Anand Babu (AB) Periasamy <abperiasamy@users.noreply.github.com>
|
||||||
Anand Babu (AB) Periasamy <ab@minio.io> <ab@unlocksmith.org>
|
Anand Babu (AB) Periasamy <ab@min.io> <ab@unlocksmith.org>
|
||||||
Anis Elleuch <vadmeste@gmail.com>
|
Anis Elleuch <vadmeste@gmail.com>
|
||||||
Frederick F. Kautz IV <fkautz@minio.io> <fkautz@alumni.cmu.edu>
|
Frederick F. Kautz IV <fkautz@min.io> <fkautz@alumni.cmu.edu>
|
||||||
Harshavardhana <harsha@minio.io> <harsha@harshavardhana.net>
|
Harshavardhana <harsha@min.io> <harsha@harshavardhana.net>
|
||||||
Krishna Srinivas <krishna@minio.io> <krishna.srinivas@gmail.com>
|
Krishna Srinivas <krishna@min.io> <krishna.srinivas@gmail.com>
|
||||||
Bosky <bosky@helpshift.com>
|
Bosky <bosky@helpshift.com>
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
sudo: false
|
|
||||||
language: go
|
|
||||||
|
|
||||||
script:
|
|
||||||
- make test GOFLAGS="-race"
|
|
||||||
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
|
|
||||||
env:
|
|
||||||
- ARCH=x86_64
|
|
||||||
- ARCH=i686
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.5.2
|
|
||||||
- 1.5.3
|
|
||||||
|
|
||||||
script:
|
|
||||||
- diff -au <(gofmt -d *.go) <(printf "")
|
|
||||||
- diff -au <(gofmt -d pkg) <(printf "")
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
slack:
|
|
||||||
secure: McinxQ4R/Yu2r/U8lVsdAIQ195Rf+3/Ku6DViWyqLHsTt5fTnVrSfbIKs8vy0t2A0bRLO6zv2xOSMWjfiimZLPMgMbMqLtTFEzUzB8RZyx2n2xgmL8q3gjXcLA3vkBreaRYCzJzX6DjvrxRfhyOg+BQHpLpACWik3FS/7VIdDCI=
|
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
## mc (MinIO Client) v/s Midnight Commander (mc)
|
||||||
|
|
||||||
|
There has been some amount of [requests](https://github.com/minio/mc/issues?q=is%3Aissue+midnight+commander+is%3Aclosed) on renaming this project to avoid the conflict with Midnight Commander for Unix distributions. We struggled with this, it is harder to find a name sweeter and shorter than `mc` for MinIO Client.
|
||||||
|
|
||||||
|
Besides `mc` is a single static binary and can reside inside your application and is fully self contained. Midnight Commander (mc) is a free software clone of Norton Commander (nc). MinIO and Midnight shares no code or ideas. Only their abbreviation matches.
|
||||||
|
|
||||||
|
Package managers are free to choose a different name if they like. One such solution [pointed out](https://github.com/minio/mc/issues/873#issuecomment-267583013) by one of our community members.
|
||||||
|
|
||||||
|
```
|
||||||
|
mv ./mc ./mcli
|
||||||
|
```
|
||||||
+4
-8
@@ -1,6 +1,6 @@
|
|||||||
### Setup your mc Github Repository
|
### Setup your mc Github Repository
|
||||||
Fork [mc upstream](https://github.com/minio/mc/fork) source repository to your own personal repository.
|
Fork [mc upstream](https://github.com/minio/mc/fork) source repository to your own personal repository.
|
||||||
```sh
|
```
|
||||||
$ mkdir -p $GOPATH/src/github.com/minio
|
$ mkdir -p $GOPATH/src/github.com/minio
|
||||||
$ cd $GOPATH/src/github.com/minio
|
$ cd $GOPATH/src/github.com/minio
|
||||||
$ git clone https://github.com/$USER_ID/mc
|
$ git clone https://github.com/$USER_ID/mc
|
||||||
@@ -20,20 +20,16 @@ $ mc --help
|
|||||||
- Push to the branch (git push origin my-new-feature)
|
- Push to the branch (git push origin my-new-feature)
|
||||||
- Create new Pull Request
|
- Create new Pull Request
|
||||||
|
|
||||||
* If you have additional dependencies for ``mc``, ``mc`` manages its dependencies using [govendor](https://github.com/kardianos/govendor)
|
* If you have additional dependencies for ``mc``, ``mc`` manages its dependencies using `go mod`
|
||||||
- Run `go get foo/bar`
|
- Run `go get foo/bar`
|
||||||
- Edit your code to import foo/bar
|
- Edit your code to import foo/bar
|
||||||
- Run `make pkg-add PKG=foo/bar` from top-level folder
|
- Run `GO111MODULE=on go mod tidy` from top-level folder
|
||||||
|
|
||||||
* If you have dependencies which needs to be removed from ``mc``
|
|
||||||
- Edit your code to not import foo/bar
|
|
||||||
- Run `make pkg-remove PKG=foo/bar` from top-level folder
|
|
||||||
|
|
||||||
* When you're ready to create a pull request, be sure to:
|
* When you're ready to create a pull request, be sure to:
|
||||||
- Have test cases for the new code. If you have questions about how to do it, please ask in your pull request.
|
- Have test cases for the new code. If you have questions about how to do it, please ask in your pull request.
|
||||||
- Run `go fmt`
|
- Run `go fmt`
|
||||||
- Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request.
|
- Squash your commits into a single commit. `git rebase -i`. It's okay to force update your pull request.
|
||||||
- Make sure `make build` completes.
|
- Make sure `make install` completes.
|
||||||
|
|
||||||
* Read [Effective Go](https://github.com/golang/go/wiki/CodeReviewComments) article from Golang project
|
* Read [Effective Go](https://github.com/golang/go/wiki/CodeReviewComments) article from Golang project
|
||||||
- `mc` project is conformant with Golang style
|
- `mc` project is conformant with Golang style
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
## Contributors
|
|
||||||
<!-- DO NOT EDIT - CONTRIBUTORS.md is autogenerated from git commit log by contributors.sh script. -->
|
|
||||||
|
|
||||||
- Anand Babu (AB) Periasamy <ab@minio.io>
|
|
||||||
- Anis Elleuch <vadmeste@gmail.com>
|
|
||||||
- Bosky <bosky@helpshift.com>
|
|
||||||
- Frederick F. Kautz IV <fkautz@minio.io>
|
|
||||||
- Harshavardhana <harsha@minio.io>
|
|
||||||
- Krishna Srinivas <krishna@minio.io>
|
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
FROM golang:1.13-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 alpine:3.12
|
||||||
|
|
||||||
|
COPY --from=build /go/bin/mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN \
|
||||||
|
apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/master/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM arm32v7/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM arm64v8/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
FROM alpine:3.12
|
||||||
|
|
||||||
|
COPY mc /usr/bin/
|
||||||
|
COPY CREDITS /
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM ppc64le/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
FROM alpine:3.12
|
||||||
|
|
||||||
|
MAINTAINER MinIO Inc <dev@min.io>
|
||||||
|
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
FROM multiarch/qemu-user-static:x86_64-arm as qemu
|
||||||
|
FROM s390x/alpine:3.12
|
||||||
|
|
||||||
|
LABEL maintainer="MinIO Inc <dev@min.io>"
|
||||||
|
|
||||||
|
COPY --from=qemu /usr/bin/qemu-arm-static /usr/bin
|
||||||
|
COPY mc /usr/bin/mc
|
||||||
|
|
||||||
|
RUN apk add --no-cache ca-certificates 'curl>7.61.0' && \
|
||||||
|
curl -s -q -O https://raw.githubusercontent.com/minio/minio/release/CREDITS
|
||||||
|
|
||||||
|
ENTRYPOINT ["mc"]
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
## Ubuntu (Kylin) 14.04
|
|
||||||
### Build Dependencies
|
|
||||||
This installation guide is based on Ubuntu 14.04+ on x86-64 platform.
|
|
||||||
|
|
||||||
##### Install Git, GCC
|
|
||||||
```sh
|
|
||||||
$ sudo apt-get install git build-essential
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Install Go 1.5+
|
|
||||||
|
|
||||||
Download Go 1.5+ from [https://golang.org/dl/](https://golang.org/dl/).
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz
|
|
||||||
$ mkdir -p ${HOME}/bin/
|
|
||||||
$ mkdir -p ${HOME}/go/
|
|
||||||
$ tar -C ${HOME}/bin/ -xzf go1.5.1.linux-amd64.tar.gz
|
|
||||||
```
|
|
||||||
##### Setup GOROOT and GOPATH
|
|
||||||
|
|
||||||
Add the following exports to your ``~/.bashrc``. Environment variable GOROOT specifies the location of your golang binaries
|
|
||||||
and GOPATH specifies the location of your project workspace.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
export GOROOT=${HOME}/bin/go
|
|
||||||
export GOPATH=${HOME}/go
|
|
||||||
export PATH=$PATH:${HOME}/bin/go/bin:${GOPATH}/bin
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Source the new environment
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ source ~/.bashrc
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Testing it all
|
|
||||||
```sh
|
|
||||||
$ go env
|
|
||||||
```
|
|
||||||
|
|
||||||
## OS X (Yosemite) 10.10
|
|
||||||
### Build Dependencies
|
|
||||||
This installation document assumes OS X Yosemite 10.10+ on x86-64 platform.
|
|
||||||
|
|
||||||
##### Install brew
|
|
||||||
```sh
|
|
||||||
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Install Git, Python
|
|
||||||
```sh
|
|
||||||
$ brew install git python
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Install Go 1.5+
|
|
||||||
|
|
||||||
Install golang binaries using `brew`
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ brew install go
|
|
||||||
$ mkdir -p $HOME/go
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Setup GOROOT and GOPATH
|
|
||||||
|
|
||||||
Add the following exports to your ``~/.bash_profile``. Environment variable GOROOT specifies the location of your golang binaries
|
|
||||||
and GOPATH specifies the location of your project workspace.
|
|
||||||
|
|
||||||
```sh
|
|
||||||
export GOPATH=${HOME}/go
|
|
||||||
export GOVERSION=$(brew list go | head -n 1 | cut -d '/' -f 6)
|
|
||||||
export GOROOT=$(brew --prefix)/Cellar/go/${GOVERSION}/libexec
|
|
||||||
export PATH=$PATH:${GOPATH}/bin
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Source the new environment
|
|
||||||
|
|
||||||
```sh
|
|
||||||
$ source ~/.bash_profile
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Testing it all
|
|
||||||
```sh
|
|
||||||
$ go env
|
|
||||||
```
|
|
||||||
@@ -1,85 +1,81 @@
|
|||||||
|
PWD := $(shell pwd)
|
||||||
|
GOPATH := $(shell go env GOPATH)
|
||||||
LDFLAGS := $(shell go run buildscripts/gen-ldflags.go)
|
LDFLAGS := $(shell go run buildscripts/gen-ldflags.go)
|
||||||
|
|
||||||
|
GOARCH := $(shell go env GOARCH)
|
||||||
|
GOOS := $(shell go env GOOS)
|
||||||
|
|
||||||
BUILD_LDFLAGS := '$(LDFLAGS)'
|
BUILD_LDFLAGS := '$(LDFLAGS)'
|
||||||
|
|
||||||
all: install
|
VERSION ?= $(shell git describe --tags)
|
||||||
|
TAG ?= "minio/mc:$(VERSION)"
|
||||||
|
|
||||||
checkdeps:
|
all: build
|
||||||
@echo "Checking deps:"
|
|
||||||
|
checks:
|
||||||
|
@echo "Checking dependencies"
|
||||||
@(env bash $(PWD)/buildscripts/checkdeps.sh)
|
@(env bash $(PWD)/buildscripts/checkdeps.sh)
|
||||||
|
|
||||||
checkgopath:
|
getdeps:
|
||||||
@echo "Checking if project is at ${GOPATH}"
|
@mkdir -p ${GOPATH}/bin
|
||||||
@for mcpath in $(echo ${GOPATH} | sed 's/:/\n/g'); do if [ ! -d ${mcpath}/src/github.com/minio/mc ]; then echo "Project not found in ${mcpath}, please follow instructions provided at https://github.com/minio/minio/blob/master/CONTRIBUTING.md#setup-your-minio-github-repository" && exit 1; fi done
|
@which golangci-lint 1>/dev/null || (echo "Installing golangci-lint" && curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.27.0)
|
||||||
@echo "BUILD_LDFLAGS: ${BUILD_LDFLAGS}"
|
|
||||||
|
|
||||||
getdeps: checkdeps checkgopath
|
crosscompile:
|
||||||
@go get github.com/golang/lint/golint && echo "Installed golint:"
|
@(env bash $(PWD)/buildscripts/cross-compile.sh)
|
||||||
@go get golang.org/x/tools/cmd/vet && echo "Installed vet:"
|
|
||||||
@go get github.com/fzipp/gocyclo && echo "Installed gocyclo:"
|
|
||||||
@go get github.com/remyoudompheng/go-misc/deadcode && echo "Installed deadcode:"
|
|
||||||
|
|
||||||
# verifiers: getdeps vet fmt lint cyclo deadcode
|
verifiers: getdeps vet fmt lint
|
||||||
verifiers: getdeps vet fmt lint cyclo deadcode
|
|
||||||
|
docker: build
|
||||||
|
@docker build -t $(TAG) . -f Dockerfile.dev
|
||||||
|
|
||||||
vet:
|
vet:
|
||||||
@echo "Running $@:"
|
@echo "Running $@"
|
||||||
@GO15VENDOREXPERIMENT=1 go tool vet -all *.go
|
@GO111MODULE=on go vet github.com/minio/mc/...
|
||||||
@GO15VENDOREXPERIMENT=1 go tool vet -all ./pkg
|
|
||||||
@GO15VENDOREXPERIMENT=1 go tool vet -shadow=true *.go
|
|
||||||
@GO15VENDOREXPERIMENT=1 go tool vet -shadow=true ./pkg
|
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
@echo "Running $@:"
|
@echo "Running $@"
|
||||||
@GO15VENDOREXPERIMENT=1 gofmt -s -l *.go
|
@GO111MODULE=on gofmt -d cmd/
|
||||||
@GO15VENDOREXPERIMENT=1 gofmt -s -l pkg
|
@GO111MODULE=on gofmt -d pkg/
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
@echo "Running $@:"
|
@echo "Running $@ check"
|
||||||
@GO15VENDOREXPERIMENT=1 golint .
|
@GO111MODULE=on ${GOPATH}/bin/golangci-lint cache clean
|
||||||
@GO15VENDOREXPERIMENT=1 golint github.com/minio/mc/pkg...
|
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=5m --config ./.golangci.yml
|
||||||
|
|
||||||
cyclo:
|
# Builds mc, runs the verifiers then runs the tests.
|
||||||
@echo "Running $@:"
|
check: test
|
||||||
@GO15VENDOREXPERIMENT=1 gocyclo -over 40 *.go
|
test: verifiers build
|
||||||
@GO15VENDOREXPERIMENT=1 gocyclo -over 40 pkg
|
@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)
|
||||||
|
|
||||||
deadcode:
|
test-race: verifiers build
|
||||||
@echo "Running $@:"
|
@echo "Running unit tests under -race"
|
||||||
@GO15VENDOREXPERIMENT=1 deadcode
|
@GO111MODULE=on go test -race -v --timeout 20m ./... 1>/dev/null
|
||||||
|
|
||||||
build: verifiers
|
# Verify mc binary
|
||||||
@echo "Installing mc:"
|
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)
|
||||||
|
|
||||||
test: verifiers
|
# Builds mc locally.
|
||||||
@echo "Running all testing:"
|
build: checks
|
||||||
@GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) ./
|
@echo "Building mc binary to './mc'"
|
||||||
@GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/mc/pkg...
|
@GO111MODULE=on CGO_ENABLED=0 go build -trimpath -tags kqueue --ldflags $(BUILD_LDFLAGS) -o $(PWD)/mc
|
||||||
|
|
||||||
gomake-all: build
|
# Builds MinIO and installs it to $GOPATH/bin.
|
||||||
@GO15VENDOREXPERIMENT=1 go build --ldflags $(BUILD_LDFLAGS) -o $(GOPATH)/bin/mc
|
install: build
|
||||||
@mkdir -p $(HOME)/.mc
|
@echo "Installing mc binary to '$(GOPATH)/bin/mc'"
|
||||||
|
@mkdir -p $(GOPATH)/bin && cp -f $(PWD)/mc $(GOPATH)/bin/mc
|
||||||
coverage:
|
@echo "Installation successful. To learn more, try \"mc --help\"."
|
||||||
@GO15VENDOREXPERIMENT=1 go test -race -coverprofile=cover.out ./
|
|
||||||
@go tool cover -html=cover.out && echo "Visit your browser"
|
|
||||||
|
|
||||||
pkg-add:
|
|
||||||
@GO15VENDOREXPERIMENT=1 govendor add $(PKG)
|
|
||||||
|
|
||||||
pkg-update:
|
|
||||||
@GO15VENDOREXPERIMENT=1 govendor update $(PKG)
|
|
||||||
|
|
||||||
pkg-remove:
|
|
||||||
@GO15VENDOREXPERIMENT=1 govendor remove $(PKG)
|
|
||||||
|
|
||||||
install: gomake-all
|
|
||||||
|
|
||||||
all-tests: test
|
|
||||||
# TODO disable them for now.
|
|
||||||
#@./tests/test-minio.sh
|
|
||||||
|
|
||||||
release:
|
|
||||||
@./release.sh
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -fv cover.out
|
@echo "Cleaning up all the generated files"
|
||||||
@rm -fv mc
|
@find . -name '*.test' | xargs rm -fv
|
||||||
|
@find . -name '*~' | xargs rm -fv
|
||||||
|
@rm -rvf mc
|
||||||
|
@rm -rvf build
|
||||||
|
@rm -rvf release
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
Minio Client (C) 2014, 2015 Minio, Inc.
|
MinIO Client (C) 2014-2020 MinIO, Inc.
|
||||||
|
|
||||||
This product includes software developed at Minio, Inc.
|
This product includes software developed at MinIO, Inc.
|
||||||
(https://minio.io/).
|
(https://min.io/).
|
||||||
|
|
||||||
The Minio project contains unmodified/modified subcomponents too with
|
The MinIO project contains unmodified/modified subcomponents too with
|
||||||
separate copyright notices and license terms. Your use of the source
|
separate copyright notices and license terms. Your use of the source
|
||||||
code for the these subcomponents is subject to the terms and conditions
|
code for the these subcomponents is subject to the terms and conditions
|
||||||
of the following licenses.
|
of the following licenses.
|
||||||
|
|||||||
@@ -1,106 +1,224 @@
|
|||||||
# Minio Client (mc) [](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
# MinIO Client Quickstart Guide
|
||||||
|
[](https://slack.min.io) [](https://goreportcard.com/report/minio/mc) [](https://hub.docker.com/r/minio/mc/)
|
||||||
|
|
||||||
``mc`` provides minimal tools to work with Amazon S3 compatible cloud storage and filesystems. It has features like resumable uploads/downloads, progress bar, parallel copy. ``mc`` is written in golang and released under [Apache license v2](./LICENSE).
|
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).
|
||||||
|
|
||||||
## Commands
|
|
||||||
|
|
||||||
``mc`` implements the following commands
|
|
||||||
```
|
```
|
||||||
ls List files and folders.
|
ls list buckets and objects
|
||||||
mb Make a bucket or folder.
|
mb make a bucket
|
||||||
cat Display contents of a file.
|
rb remove a bucket
|
||||||
pipe Write contents of stdin to one or more targets. When no target is specified, it writes to stdout.
|
cat display object contents
|
||||||
share Generate URL for sharing.
|
head display first 'n' lines of an object
|
||||||
cp Copy one or more objects to a target.
|
pipe stream STDIN to an object
|
||||||
mirror Mirror folders recursively from a single source to many destinations.
|
share generate URL for temporary access to an object
|
||||||
diff Compute differences between two folders.
|
cp copy objects
|
||||||
rm Remove file or bucket [WARNING: Use with care].
|
mirror synchronize objects to a remote site
|
||||||
access Manage bucket access permissions.
|
find search for objects
|
||||||
session Manage saved sessions of cp and mirror operations.
|
sql run sql queries on objects
|
||||||
config Manage configuration file.
|
stat stat contents of objects
|
||||||
update Check for a new software update.
|
lock set and get object lock configuration
|
||||||
version Print version.
|
retention set object retention for objects with a given prefix
|
||||||
|
legalhold set object legal hold for objects
|
||||||
|
diff list differences in object name, size, and date between buckets
|
||||||
|
rm remove objects
|
||||||
|
event manage object notifications
|
||||||
|
watch watch for object events
|
||||||
|
policy manage anonymous access to objects
|
||||||
|
admin manage MinIO servers
|
||||||
|
session manage saved sessions for cp command
|
||||||
|
config manage mc configuration file
|
||||||
|
update check for a new software update
|
||||||
|
version print version info
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install [](https://travis-ci.org/minio/mc) [](https://ci.appveyor.com/project/harshavardhana/mc)
|
## Docker Container
|
||||||
|
### Stable
|
||||||
|
```
|
||||||
|
docker pull minio/mc
|
||||||
|
docker run minio/mc ls play
|
||||||
|
```
|
||||||
|
|
||||||
#### GNU/Linux
|
### Edge
|
||||||
|
```
|
||||||
|
docker pull minio/mc:edge
|
||||||
|
docker run minio/mc:edge ls play
|
||||||
|
```
|
||||||
|
|
||||||
Download ``mc`` for:
|
**Note:** Above examples run `mc` against MinIO [_play_ environment](#test-your-setup) by default. To run `mc` against other S3 compatible servers, start the container this way:
|
||||||
|
|
||||||
- ``64-bit Intel`` from https://dl.minio.io/client/mc/release/linux-amd64/mc
|
```
|
||||||
- ``32-bit Intel`` from https://dl.minio.io/client/mc/release/linux-386/mc
|
docker run -it --entrypoint=/bin/sh minio/mc
|
||||||
- ``32-bit ARM`` from https://dl.minio.io/client/mc/release/linux-arm/mc
|
```
|
||||||
|
|
||||||
~~~
|
then use the [`mc config` command](#add-a-cloud-storage-service).
|
||||||
$ chmod +x mc
|
|
||||||
$ ./mc --help
|
|
||||||
~~~
|
|
||||||
|
|
||||||
#### OS X
|
## macOS
|
||||||
|
### Homebrew
|
||||||
|
Install mc packages using [Homebrew](http://brew.sh/)
|
||||||
|
|
||||||
Download ``mc`` from https://dl.minio.io/client/mc/release/darwin-amd64/mc
|
```
|
||||||
|
brew install minio/stable/mc
|
||||||
|
mc --help
|
||||||
|
```
|
||||||
|
|
||||||
~~~
|
## GNU/Linux
|
||||||
$ chmod 755 mc
|
### Binary Download
|
||||||
$ ./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 |
|
||||||
|
|
||||||
#### Microsoft Windows
|
```
|
||||||
|
wget https://dl.min.io/client/mc/release/linux-amd64/mc
|
||||||
|
chmod +x mc
|
||||||
|
./mc --help
|
||||||
|
```
|
||||||
|
|
||||||
Download ``mc`` for:
|
## Microsoft Windows
|
||||||
|
### Binary Download
|
||||||
|
| Platform | Architecture | URL |
|
||||||
|
| ---------- | -------- |------|
|
||||||
|
|Microsoft Windows|64-bit Intel|https://dl.min.io/client/mc/release/windows-amd64/mc.exe |
|
||||||
|
|
||||||
- ``64-bit`` from https://dl.minio.io/client/mc/release/windows-amd64/mc.exe
|
```
|
||||||
- ``32-bit`` from https://dl.minio.io/client/mc/release/windows-386/mc.exe
|
mc.exe --help
|
||||||
|
```
|
||||||
|
|
||||||
~~~
|
## Install from Source
|
||||||
C:\Users\Username\Downloads> mc.exe --help
|
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.13](https://golang.org/dl/#stable)
|
||||||
~~~
|
|
||||||
|
|
||||||
#### Source
|
|
||||||
<blockquote>
|
|
||||||
NOTE: Source installation is intended for only developers and advanced users. ‘mc update’ continuous delivery mechanism is not supported for ‘go get’ based binary builds. Please download official releases from https://minio.io/#mc.
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
If you do not have a working Golang environment, please follow [Install Golang](./INSTALLGO.md).
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ GO15VENDOREXPERIMENT=1 go get -u github.com/minio/mc
|
GO111MODULE=on go get github.com/minio/mc
|
||||||
```
|
```
|
||||||
|
|
||||||
## Public Minio Server
|
## Add a Cloud Storage Service
|
||||||
|
If you are planning to use `mc` only on POSIX compatible filesystems, you may skip this step and proceed to [everyday use](#everyday-use).
|
||||||
|
|
||||||
Minio cloud storage server is hosted at ``https://play.minio.io:9000`` for public use. This service is primarily intended for developers and users to familiarize themselves with Amazon S3 compatible cloud storage. Minio runs with filesystem backend with auto-expiry for objects in about 24 hours. No account signup is required, which means S3 compatible tools and applications can access this service without access and secret keys.
|
To add one or more Amazon S3 compatible hosts, please follow the instructions below. `mc` stores all its configuration information in ``~/.mc/config.json`` file.
|
||||||
|
|
||||||
## Configuring mc for Amazon S3
|
|
||||||
|
|
||||||
Get your AccessKeyID and SecretAccessKey by following [AWS Credentials Guide](http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSGettingStartedGuide/AWSCredentials.html).
|
|
||||||
|
|
||||||
Once you have them update your ``~/.mc/config.json`` configuration file.
|
|
||||||
```
|
```
|
||||||
$ mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> S3v4
|
mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> --api <API-SIGNATURE> --lookup <BUCKET-LOOKUP-TYPE>
|
||||||
```
|
```
|
||||||
|
|
||||||
Example
|
Alias is simply a short name to your cloud storage service. S3 end-point, access and secret keys are supplied by your cloud storage provider. API signature is an optional argument. By default, it is set to "S3v4".
|
||||||
|
|
||||||
|
Lookup is an optional argument. It is used to indicate whether dns or path style url requests are supported by the server. It accepts "dns", "path" or "auto" as valid values. By default, it is set to "auto" and SDK automatically determines the type of url lookup to use.
|
||||||
|
|
||||||
|
### Example - MinIO Cloud Storage
|
||||||
|
MinIO server displays URL, access and secret keys.
|
||||||
|
|
||||||
```
|
```
|
||||||
$ mc config host add mys3 https://s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
mc config host add minio http://192.168.1.51 BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: ``S3v4`` is default if not specified.
|
### Example - Amazon S3 Cloud Storage
|
||||||
|
Get your AccessKeyID and SecretAccessKey by following [AWS Credentials Guide](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html).
|
||||||
|
|
||||||
## Configure mc for Google Cloud Storage
|
|
||||||
|
|
||||||
Get your AccessKeyID and SecretAccessKey by following [Google Credentials Guide](https://cloud.google.com/storage/docs/migrating?hl=en#keys).
|
|
||||||
|
|
||||||
Once you have them update your ``~/.mc/config.json`` configuration file.
|
|
||||||
```
|
```
|
||||||
$ mc config host add <ALIAS> https://storage.googleapis.com <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> S3v2
|
mc config host add s3 https://s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||||
```
|
```
|
||||||
|
|
||||||
NOTE: Google Cloud Storage only supports Legacy Signature Version ``2``, so you have to pick - ``S3v2``
|
**Note**: As an IAM user on Amazon S3 you need to make sure the user has full access to the buckets or set the following restricted policy for your IAM user
|
||||||
|
|
||||||
## Contribute to Minio Client
|
```json
|
||||||
Please follow Minio [Contributor's Guide](./CONTRIBUTING.md)
|
{
|
||||||
|
"Version": "2012-10-17",
|
||||||
|
"Statement": [
|
||||||
|
{
|
||||||
|
"Sid": "AllowBucketStat",
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": [
|
||||||
|
"s3:HeadBucket"
|
||||||
|
],
|
||||||
|
"Resource": "*"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Sid": "AllowThisBucketOnly",
|
||||||
|
"Effect": "Allow",
|
||||||
|
"Action": "s3:*",
|
||||||
|
"Resource": [
|
||||||
|
"arn:aws:s3:::<your-restricted-bucket>/*",
|
||||||
|
"arn:aws:s3:::<your-restricted-bucket>"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Jobs
|
### Example - Google Cloud Storage
|
||||||
If you think in Lisp or Haskell and hack in go, you would blend right in. Send your github link to callhome@minio.io.
|
Get your AccessKeyID and SecretAccessKey by following [Google Credentials Guide](https://cloud.google.com/storage/docs/migrating?hl=en#keys)
|
||||||
|
|
||||||
|
```
|
||||||
|
mc config host add gcs https://storage.googleapis.com BKIKJAA5BMMU2RHO6IBB V8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
|
||||||
|
List all buckets from https://play.min.io
|
||||||
|
|
||||||
|
```
|
||||||
|
mc ls play
|
||||||
|
[2016-03-22 19:47:48 PDT] 0B my-bucketname/
|
||||||
|
[2016-03-22 22:01:07 PDT] 0B mytestbucket/
|
||||||
|
[2016-03-22 20:04:39 PDT] 0B mybucketname/
|
||||||
|
[2016-01-28 17:23:11 PST] 0B newbucket/
|
||||||
|
[2016-03-20 09:08:36 PDT] 0B s3git-test/
|
||||||
|
```
|
||||||
|
|
||||||
|
Make a bucket
|
||||||
|
`mb` command creates a new bucket.
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
```
|
||||||
|
mc mb play/mybucket
|
||||||
|
Bucket created successfully `play/mybucket`.
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy Objects
|
||||||
|
`cp` command copies data from one or more sources to a target.
|
||||||
|
|
||||||
|
*Example:*
|
||||||
|
```
|
||||||
|
mc cp myobject.txt play/mybucket
|
||||||
|
myobject.txt: 14 B / 14 B ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100.00 % 41 B/s 0
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<a name="everyday-use"></a>
|
||||||
|
## Everyday Use
|
||||||
|
|
||||||
|
### Shell aliases
|
||||||
|
You may add shell aliases to override your common Unix tools.
|
||||||
|
|
||||||
|
```
|
||||||
|
alias ls='mc ls'
|
||||||
|
alias cp='mc cp'
|
||||||
|
alias cat='mc cat'
|
||||||
|
alias mkdir='mc mb'
|
||||||
|
alias pipe='mc pipe'
|
||||||
|
alias find='mc find'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Shell autocompletion
|
||||||
|
In case you are using bash, zsh or fish. Shell completion is embedded by default in `mc`, to install auto-completion use `mc --autocompletion`. Restart the shell, mc will auto-complete commands as shown below.
|
||||||
|
|
||||||
|
```
|
||||||
|
mc <TAB>
|
||||||
|
admin config diff find ls mirror policy session sql update watch
|
||||||
|
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)
|
||||||
|
|
||||||
|
## License
|
||||||
|
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fminio%2Fmc?ref=badge_large)
|
||||||
|
|||||||
+173
@@ -0,0 +1,173 @@
|
|||||||
|
# MinIO客户端快速入门指南
|
||||||
|
[](https://slack.min.io) [](https://goreportcard.com/report/minio/mc) [](https://hub.docker.com/r/minio/mc/)
|
||||||
|
|
||||||
|
MinIO Client (mc)为ls,cat,cp,mirror,diff,find等UNIX命令提供了一种替代方案。它支持文件系统和兼容Amazon S3的云存储服务(AWS Signature v2和v4)。
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
ls 列出文件和文件夹。
|
||||||
|
mb 创建一个存储桶或一个文件夹。
|
||||||
|
cat 显示文件和对象内容。
|
||||||
|
pipe 将一个STDIN重定向到一个对象或者文件或者STDOUT。
|
||||||
|
share 生成用于共享的URL。
|
||||||
|
cp 拷贝文件和对象。
|
||||||
|
mirror 给存储桶和文件夹做镜像。
|
||||||
|
find 基于参数查找文件。
|
||||||
|
diff 对两个文件夹或者存储桶比较差异。
|
||||||
|
rm 删除文件和对象。
|
||||||
|
events 管理对象通知。
|
||||||
|
watch 监听文件和对象的事件。
|
||||||
|
policy 管理访问策略。
|
||||||
|
session 为cp命令管理保存的会话。
|
||||||
|
config 管理mc配置文件。
|
||||||
|
update 检查软件更新。
|
||||||
|
version 输出版本信息。
|
||||||
|
```
|
||||||
|
|
||||||
|
## Docker容器
|
||||||
|
### 稳定版
|
||||||
|
```
|
||||||
|
docker pull minio/mc
|
||||||
|
docker run minio/mc ls play
|
||||||
|
```
|
||||||
|
|
||||||
|
### 尝鲜版
|
||||||
|
```
|
||||||
|
docker pull minio/mc:edge
|
||||||
|
docker run minio/mc:edge ls play
|
||||||
|
```
|
||||||
|
|
||||||
|
**注意:** 上述示例默认使用MinIO[演示环境](#test-your-setup)做演示,如果想用`mc`操作其它S3兼容的服务,采用下面的方式来启动容器:
|
||||||
|
|
||||||
|
```
|
||||||
|
docker run -it --entrypoint=/bin/sh minio/mc
|
||||||
|
```
|
||||||
|
|
||||||
|
然后使用[`mc config`命令](#add-a-cloud-storage-service)。
|
||||||
|
|
||||||
|
## macOS
|
||||||
|
### Homebrew
|
||||||
|
使用[Homebrew](http://brew.sh/)安装mc。
|
||||||
|
|
||||||
|
```
|
||||||
|
brew install minio/stable/mc
|
||||||
|
mc --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## GNU/Linux
|
||||||
|
### 下载二进制文件
|
||||||
|
| 平台 | CPU架构 | URL |
|
||||||
|
| ---------- | -------- |------|
|
||||||
|
|GNU/Linux|64-bit Intel|https://dl.min.io/client/mc/release/linux-amd64/mc |
|
||||||
|
|
||||||
|
```
|
||||||
|
chmod +x mc
|
||||||
|
./mc --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## Microsoft Windows
|
||||||
|
### 下载二进制文件
|
||||||
|
| 平台 | CPU架构 | URL |
|
||||||
|
| ---------- | -------- |------|
|
||||||
|
|Microsoft Windows|64-bit Intel|https://dl.min.io/client/mc/release/windows-amd64/mc.exe |
|
||||||
|
|
||||||
|
```
|
||||||
|
mc.exe --help
|
||||||
|
```
|
||||||
|
|
||||||
|
## 通过源码安装
|
||||||
|
通过源码安装仅适用于开发人员和高级用户。`mc update`命令不支持基于源码安装的更新通知。请从https://min.io/download/#minio-client下载官方版本。
|
||||||
|
|
||||||
|
如果您没有Golang环境,请参照[如何安装Golang](https://golang.org/doc/install)。
|
||||||
|
|
||||||
|
```
|
||||||
|
go get -d github.com/minio/mc
|
||||||
|
cd ${GOPATH}/src/github.com/minio/mc
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
## 添加一个云存储服务
|
||||||
|
如果你打算仅在POSIX兼容文件系统中使用`mc`,那你可以直接略过本节,跳到[日常使用](#everyday-use)。
|
||||||
|
|
||||||
|
添加一个或多个S3兼容的服务,请参考下面说明。`mc`将所有的配置信息都存储在``~/.mc/config.json``文件中。
|
||||||
|
|
||||||
|
```
|
||||||
|
mc config host add <ALIAS> <YOUR-S3-ENDPOINT> <YOUR-ACCESS-KEY> <YOUR-SECRET-KEY> [--api API-SIGNATURE]
|
||||||
|
```
|
||||||
|
|
||||||
|
别名就是给你的云存储服务起了一个短点的外号。S3 endpoint,access key和secret key是你的云存储服务提供的。API签名是可选参数,默认情况下,它被设置为"S3v4"。
|
||||||
|
|
||||||
|
### 示例-MinIO云存储
|
||||||
|
从MinIO服务获得URL、access key和secret key。
|
||||||
|
|
||||||
|
```
|
||||||
|
mc config host add minio http://192.168.1.51 BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 --api s3v4
|
||||||
|
```
|
||||||
|
|
||||||
|
### 示例-Amazon S3云存储
|
||||||
|
参考[AWS Credentials指南](http://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html)获取你的AccessKeyID和SecretAccessKey。
|
||||||
|
|
||||||
|
```
|
||||||
|
mc config host add s3 https://s3.amazonaws.com BKIKJAA5BMMU2RHO6IBB V7f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 --api s3v4
|
||||||
|
```
|
||||||
|
|
||||||
|
### 示例-Google云存储
|
||||||
|
参考[Google Credentials Guide](https://cloud.google.com/storage/docs/migrating?hl=en#keys)获取你的AccessKeyID和SecretAccessKey。
|
||||||
|
|
||||||
|
```
|
||||||
|
mc config host add gcs https://storage.googleapis.com BKIKJAA5BMMU2RHO6IBB V8f1CwQqAcwo80UEIJEjc5gVQUSSx5ohQ9GSrr12 --api s3v2
|
||||||
|
```
|
||||||
|
|
||||||
|
注意:Google云存储只支持旧版签名版本V2,所以你需要选择S3v2。
|
||||||
|
|
||||||
|
## 验证
|
||||||
|
`mc`预先配置了云存储服务URL:https://play.min.io,别名“play”。它是一个用于研发和测试的MinIO服务。如果想测试Amazon S3,你可以将“play”替换为“s3”。
|
||||||
|
|
||||||
|
*示例:*
|
||||||
|
|
||||||
|
列出https://play.min.io上的所有存储桶。
|
||||||
|
|
||||||
|
```
|
||||||
|
mc ls play
|
||||||
|
[2016-03-22 19:47:48 PDT] 0B my-bucketname/
|
||||||
|
[2016-03-22 22:01:07 PDT] 0B mytestbucket/
|
||||||
|
[2016-03-22 20:04:39 PDT] 0B mybucketname/
|
||||||
|
[2016-01-28 17:23:11 PST] 0B newbucket/
|
||||||
|
[2016-03-20 09:08:36 PDT] 0B s3git-test/
|
||||||
|
```
|
||||||
|
<a name="everyday-use"></a>
|
||||||
|
## 日常使用
|
||||||
|
|
||||||
|
### Shell别名
|
||||||
|
你可以添加shell别名来覆盖默认的Unix工具命令。
|
||||||
|
|
||||||
|
```
|
||||||
|
alias ls='mc ls'
|
||||||
|
alias cp='mc cp'
|
||||||
|
alias cat='mc cat'
|
||||||
|
alias mkdir='mc mb'
|
||||||
|
alias pipe='mc pipe'
|
||||||
|
alias find='mc find'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Shell自动补全
|
||||||
|
你也可以下载[`autocomplete/bash_autocomplete`](https://raw.githubusercontent.com/minio/mc/master/autocomplete/bash_autocomplete)到`/etc/bash_completion.d/`,然后将其重命名为`mc`。别忘了在这个文件运行source命令让其在你的当前shell上可用。
|
||||||
|
|
||||||
|
```
|
||||||
|
sudo wget https://raw.githubusercontent.com/minio/mc/master/autocomplete/bash_autocomplete -O /etc/bash_completion.d/mc
|
||||||
|
source /etc/bash_completion.d/mc
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
mc <TAB>
|
||||||
|
admin config diff ls mirror policy session update watch
|
||||||
|
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[贡献者指南](https://github.com/minio/mc/blob/master/docs/zh_CN/CONTRIBUTING.md)
|
||||||
-205
@@ -1,205 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minio Client, (C) 2015 Minio, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/fatih/color"
|
|
||||||
"github.com/minio/cli"
|
|
||||||
"github.com/minio/mc/pkg/console"
|
|
||||||
"github.com/minio/minio-xl/pkg/probe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
accessFlags = []cli.Flag{
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "help, h",
|
|
||||||
Usage: "Help of access.",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Set access permissions.
|
|
||||||
var accessCmd = cli.Command{
|
|
||||||
Name: "access",
|
|
||||||
Usage: "Manage bucket access permissions.",
|
|
||||||
Action: mainAccess,
|
|
||||||
Flags: append(accessFlags, globalFlags...),
|
|
||||||
CustomHelpTemplate: `Name:
|
|
||||||
mc {{.Name}} - {{.Usage}}
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
mc {{.Name}} [FLAGS] set PERMISSION TARGET [TARGET...]
|
|
||||||
mc {{.Name}} [FLAGS] get TARGET [TARGET...]
|
|
||||||
|
|
||||||
PERMISSION:
|
|
||||||
Allowed permissions are: [private, readonly, public, authorized].
|
|
||||||
|
|
||||||
FLAGS:
|
|
||||||
{{range .Flags}}{{.}}
|
|
||||||
{{end}}
|
|
||||||
EXAMPLES:
|
|
||||||
1. Set bucket to "private" on Amazon S3 cloud storage.
|
|
||||||
$ mc {{.Name}} set private s3/burningman2011
|
|
||||||
|
|
||||||
2. Set bucket to "public" on Amazon S3 cloud storage.
|
|
||||||
$ mc {{.Name}} set public s3/shared
|
|
||||||
|
|
||||||
3. Set bucket to "authenticated" on Amazon S3 cloud storage to provide read access to IAM Authenticated Users group.
|
|
||||||
$ mc {{.Name}} set authorized s3/shared-authenticated
|
|
||||||
|
|
||||||
4. Get bucket permissions.
|
|
||||||
$ mc {{.Name}} get s3/shared
|
|
||||||
|
|
||||||
5. Get bucket permissions.
|
|
||||||
$ mc {{.Name}} get gcs/miniocloud
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
|
|
||||||
// accessMessage is container for access command on bucket success and failure messages.
|
|
||||||
type accessMessage struct {
|
|
||||||
Operation string `json:"operation"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Bucket string `json:"bucket"`
|
|
||||||
Perms accessPerms `json:"permission"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// String colorized access message.
|
|
||||||
func (s accessMessage) String() string {
|
|
||||||
if s.Operation == "set" {
|
|
||||||
return console.Colorize("Access",
|
|
||||||
"Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
|
|
||||||
}
|
|
||||||
if s.Operation == "get" {
|
|
||||||
return console.Colorize("Access",
|
|
||||||
"Access permission for ‘"+s.Bucket+"’"+" is ‘"+string(s.Perms)+"’")
|
|
||||||
}
|
|
||||||
// nothing to print
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
// JSON jsonified access message.
|
|
||||||
func (s accessMessage) JSON() string {
|
|
||||||
accessJSONBytes, e := json.Marshal(s)
|
|
||||||
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
|
||||||
|
|
||||||
return string(accessJSONBytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkAccessSyntax check for incoming syntax.
|
|
||||||
func checkAccessSyntax(ctx *cli.Context) {
|
|
||||||
if !ctx.Args().Present() {
|
|
||||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code.
|
|
||||||
}
|
|
||||||
if len(ctx.Args()) < 2 {
|
|
||||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code.
|
|
||||||
}
|
|
||||||
switch ctx.Args().First() {
|
|
||||||
case "set":
|
|
||||||
if len(ctx.Args().Tail()) < 2 {
|
|
||||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code.
|
|
||||||
}
|
|
||||||
perms := accessPerms(ctx.Args().Tail().Get(0))
|
|
||||||
if !perms.isValidAccessPERM() {
|
|
||||||
fatalIf(errDummy().Trace(),
|
|
||||||
"Unrecognized permission ‘"+perms.String()+"’. Allowed values are [private, public, readonly, authorized].")
|
|
||||||
}
|
|
||||||
for _, arg := range ctx.Args().Tail().Tail() {
|
|
||||||
if strings.TrimSpace(arg) == "" {
|
|
||||||
fatalIf(errInvalidArgument().Trace(), "Unable to validate empty argument.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case "get":
|
|
||||||
if len(ctx.Args().Tail()) < 1 {
|
|
||||||
cli.ShowCommandHelpAndExit(ctx, "access", 1) // last argument is exit code.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// doSetAccess do set access.
|
|
||||||
func doSetAccess(targetURL string, targetPERMS accessPerms) *probe.Error {
|
|
||||||
clnt, err := newClient(targetURL)
|
|
||||||
if err != nil {
|
|
||||||
return err.Trace(targetURL)
|
|
||||||
}
|
|
||||||
if err = clnt.SetBucketAccess(targetPERMS.String()); err != nil {
|
|
||||||
return err.Trace(targetURL, targetPERMS.String())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// doGetAccess do get access.
|
|
||||||
func doGetAccess(targetURL string) (perms accessPerms, err *probe.Error) {
|
|
||||||
clnt, err := newClient(targetURL)
|
|
||||||
if err != nil {
|
|
||||||
return "", err.Trace(targetURL)
|
|
||||||
}
|
|
||||||
acl, err := clnt.GetBucketAccess()
|
|
||||||
if err != nil {
|
|
||||||
return "", err.Trace(targetURL)
|
|
||||||
}
|
|
||||||
return aclToPerms(acl), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mainAccess(ctx *cli.Context) {
|
|
||||||
// Set global flags from context.
|
|
||||||
setGlobalsFromContext(ctx)
|
|
||||||
|
|
||||||
// check 'access' cli arguments.
|
|
||||||
checkAccessSyntax(ctx)
|
|
||||||
|
|
||||||
// Additional command speific theme customization.
|
|
||||||
console.SetColor("Access", color.New(color.FgGreen, color.Bold))
|
|
||||||
|
|
||||||
switch ctx.Args().First() {
|
|
||||||
case "set":
|
|
||||||
perms := accessPerms(ctx.Args().Tail().First())
|
|
||||||
URLs := ctx.Args().Tail().Tail()
|
|
||||||
for _, targetURL := range URLs {
|
|
||||||
err := doSetAccess(targetURL, perms)
|
|
||||||
// Upon error, print and continue.
|
|
||||||
if err != nil {
|
|
||||||
errorIf(err.Trace(targetURL, string(perms)),
|
|
||||||
"Unable to set access permission ‘"+string(perms)+"’ for ‘"+targetURL+"’.")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
printMsg(accessMessage{
|
|
||||||
Status: "success",
|
|
||||||
Operation: "set",
|
|
||||||
Bucket: targetURL,
|
|
||||||
Perms: perms,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
case "get":
|
|
||||||
URLs := ctx.Args().Tail()
|
|
||||||
for _, targetURL := range URLs {
|
|
||||||
perms, err := doGetAccess(targetURL)
|
|
||||||
if err != nil {
|
|
||||||
errorIf(err.Trace(targetURL), "Unable to get access permission for ‘"+targetURL+"’.")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
printMsg(accessMessage{
|
|
||||||
Status: "success",
|
|
||||||
Operation: "get",
|
|
||||||
Bucket: targetURL,
|
|
||||||
Perms: perms,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minio Client (C) 2015 Minio, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
// isValidAccessPERM - is provided access perm string supported.
|
|
||||||
func (b accessPerms) isValidAccessPERM() bool {
|
|
||||||
switch true {
|
|
||||||
case b.isPrivate():
|
|
||||||
fallthrough
|
|
||||||
case b.isReadOnly():
|
|
||||||
fallthrough
|
|
||||||
case b.isPublic():
|
|
||||||
fallthrough
|
|
||||||
case b.isAuthorized():
|
|
||||||
return true
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// accessPerms - access level.
|
|
||||||
type accessPerms string
|
|
||||||
|
|
||||||
// different types of Access perm's currently supported by accesss command.
|
|
||||||
const (
|
|
||||||
accessPrivate = accessPerms("private")
|
|
||||||
accessReadOnly = accessPerms("readonly")
|
|
||||||
accessPublic = accessPerms("public")
|
|
||||||
accessAuthorized = accessPerms("authorized")
|
|
||||||
)
|
|
||||||
|
|
||||||
func (b accessPerms) String() string {
|
|
||||||
if !b.isValidAccessPERM() {
|
|
||||||
return string(b)
|
|
||||||
}
|
|
||||||
if b.isReadOnly() {
|
|
||||||
return "public-read"
|
|
||||||
}
|
|
||||||
if b.isPublic() {
|
|
||||||
return "public-read-write"
|
|
||||||
}
|
|
||||||
if b.isAuthorized() {
|
|
||||||
return "authenticated-read"
|
|
||||||
}
|
|
||||||
return "private"
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert acl's to access perms
|
|
||||||
func aclToPerms(acl string) accessPerms {
|
|
||||||
switch acl {
|
|
||||||
case "private":
|
|
||||||
return accessPerms("private")
|
|
||||||
case "public-read":
|
|
||||||
return accessPerms("readonly")
|
|
||||||
case "public-read-write":
|
|
||||||
return accessPerms("public")
|
|
||||||
case "authenticated-read":
|
|
||||||
return accessPerms("authorized")
|
|
||||||
default:
|
|
||||||
return accessPerms(acl)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// isPrivate - is acl Private.
|
|
||||||
func (b accessPerms) isPrivate() bool {
|
|
||||||
return b == accessPrivate
|
|
||||||
}
|
|
||||||
|
|
||||||
// isPublicRead - is acl PublicRead.
|
|
||||||
func (b accessPerms) isReadOnly() bool {
|
|
||||||
return b == accessReadOnly
|
|
||||||
}
|
|
||||||
|
|
||||||
// isPublicReadWrite - is acl PublicReadWrite.
|
|
||||||
func (b accessPerms) isPublic() bool {
|
|
||||||
return b == accessPublic
|
|
||||||
}
|
|
||||||
|
|
||||||
// isAuthorized - is acl AuthorizedRead.
|
|
||||||
func (b accessPerms) isAuthorized() bool {
|
|
||||||
return b == accessAuthorized
|
|
||||||
}
|
|
||||||
@@ -1,167 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minio Client (C) 2015 Minio, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"io"
|
|
||||||
"net/http"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type objectAPIHandler struct {
|
|
||||||
lock *sync.Mutex
|
|
||||||
bucket string
|
|
||||||
object map[string][]byte
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h objectAPIHandler) getHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
h.lock.Lock()
|
|
||||||
defer h.lock.Unlock()
|
|
||||||
switch {
|
|
||||||
case r.URL.Path == "/":
|
|
||||||
response := []byte("<ListAllMyBucketsResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Buckets><Bucket><Name>bucket</Name><CreationDate>2015-05-20T23:05:09.230Z</CreationDate></Bucket></Buckets><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner></ListAllMyBucketsResult>")
|
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
|
||||||
w.Write(response)
|
|
||||||
return
|
|
||||||
case r.URL.Path == "/bucket":
|
|
||||||
_, ok := r.URL.Query()["acl"]
|
|
||||||
if ok {
|
|
||||||
response := []byte("<?xml version=\"1.0\" encoding=\"UTF-8\"?><AccessControlPolicy><Owner><ID>75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a</ID><DisplayName>CustomersName@amazon.com</DisplayName></Owner><AccessControlList><Grant><Grantee xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"CanonicalUser\"><ID>75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a</ID><DisplayName>CustomersName@amazon.com</DisplayName></Grantee><Permission>FULL_CONTROL</Permission></Grant></AccessControlList></AccessControlPolicy>")
|
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
|
||||||
w.Write(response)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fallthrough
|
|
||||||
case r.URL.Path == "/bucket":
|
|
||||||
response := []byte("<ListBucketResult xmlns=\"http://doc.s3.amazonaws.com/2006-03-01\"><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object0</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object1</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object2</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object3</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object4</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object5</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object6</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Contents><ETag>b1946ac92492d2347c6235b4d2611184</ETag><Key>object7</Key><LastModified>2015-05-21T18:24:21.097Z</LastModified><Size>22061</Size><Owner><ID>minio</ID><DisplayName>minio</DisplayName></Owner><StorageClass>STANDARD</StorageClass></Contents><Delimiter></Delimiter><EncodingType></EncodingType><IsTruncated>false</IsTruncated><Marker></Marker><MaxKeys>1000</MaxKeys><Name>testbucket</Name><NextMarker></NextMarker><Prefix></Prefix></ListBucketResult>")
|
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(response)))
|
|
||||||
w.Write(response)
|
|
||||||
return
|
|
||||||
case r.URL.Path != "":
|
|
||||||
if _, ok := h.object[filepath.Base(r.URL.Path)]; !ok {
|
|
||||||
w.WriteHeader(http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(h.object[filepath.Base(r.URL.Path)])))
|
|
||||||
w.Header().Set("Last-Modified", time.Now().UTC().Format(http.TimeFormat))
|
|
||||||
w.Header().Set("ETag", "b1946ac92492d2347c6235b4d2611184")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
io.Copy(w, bytes.NewReader(h.object[filepath.Base(r.URL.Path)]))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h objectAPIHandler) headHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
h.lock.Lock()
|
|
||||||
defer h.lock.Unlock()
|
|
||||||
switch {
|
|
||||||
case r.URL.Path == "/":
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
case r.URL.Path == "/bucket":
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
case r.URL.Path != "":
|
|
||||||
w.Header().Set("Content-Length", strconv.Itoa(len(h.object[filepath.Base(r.URL.Path)])))
|
|
||||||
w.Header().Set("Last-Modified", time.Now().UTC().Format(http.TimeFormat))
|
|
||||||
w.Header().Set("ETag", "b1946ac92492d2347c6235b4d2611184")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func isValidBucket(bucket string) bool {
|
|
||||||
if len(bucket) < 3 || len(bucket) > 63 {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if bucket[0] == '.' || bucket[len(bucket)-1] == '.' {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if match, _ := regexp.MatchString("\\.\\.", bucket); match == true {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
// We don't support buckets with '.' in them
|
|
||||||
match, _ := regexp.MatchString("^[a-zA-Z][a-zA-Z0-9\\-]+[a-zA-Z0-9]$", bucket)
|
|
||||||
return match
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h objectAPIHandler) putHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
h.lock.Lock()
|
|
||||||
defer h.lock.Unlock()
|
|
||||||
switch {
|
|
||||||
case r.URL.Path == "/":
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
case r.URL.Path == "/bucket":
|
|
||||||
_, ok := r.URL.Query()["acl"]
|
|
||||||
if ok {
|
|
||||||
switch r.Header.Get("x-amz-acl") {
|
|
||||||
case "public-read-write":
|
|
||||||
fallthrough
|
|
||||||
case "public-read":
|
|
||||||
fallthrough
|
|
||||||
case "private":
|
|
||||||
fallthrough
|
|
||||||
case "authenticated-read":
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
w.WriteHeader(http.StatusNotImplemented)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
case r.URL.Path != "":
|
|
||||||
if !isValidBucket(strings.Split(r.URL.Path, "/")[1]) {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
length, e := strconv.Atoi(r.Header.Get("Content-Length"))
|
|
||||||
if e != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var buffer bytes.Buffer
|
|
||||||
if _, e = io.CopyN(&buffer, r.Body, int64(length)); e != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
h.object[filepath.Base(r.URL.Path)] = buffer.Bytes()
|
|
||||||
w.Header().Set("ETag", "b1946ac92492d2347c6235b4d2611184")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h objectAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch {
|
|
||||||
case r.Method == "GET":
|
|
||||||
h.getHandler(w, r)
|
|
||||||
case r.Method == "HEAD":
|
|
||||||
h.headHandler(w, r)
|
|
||||||
case r.Method == "PUT":
|
|
||||||
h.putHandler(w, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
# version format
|
|
||||||
version: "{build}"
|
|
||||||
|
|
||||||
# Operating system (build VM template)
|
|
||||||
os: Windows Server 2012 R2
|
|
||||||
|
|
||||||
clone_folder: c:\gopath\src\github.com\minio\mc
|
|
||||||
|
|
||||||
# environment variables
|
|
||||||
environment:
|
|
||||||
GOPATH: c:\gopath
|
|
||||||
GO15VENDOREXPERIMENT: 1
|
|
||||||
|
|
||||||
# scripts that run after cloning repository
|
|
||||||
install:
|
|
||||||
- set PATH=%GOPATH%\bin;c:\go\bin;%PATH%
|
|
||||||
- go version
|
|
||||||
- go env
|
|
||||||
- go get -u github.com/golang/lint/golint
|
|
||||||
- go get -u golang.org/x/tools/cmd/vet
|
|
||||||
- go get -u github.com/fzipp/gocyclo
|
|
||||||
- go get -u github.com/remyoudompheng/go-misc/deadcode
|
|
||||||
- go get -u github.com/alecthomas/gometalinter
|
|
||||||
- go get -u github.com/client9/misspell
|
|
||||||
|
|
||||||
# to run your custom scripts instead of automatic MSBuild
|
|
||||||
build_script:
|
|
||||||
- go tool vet -all ./pkg
|
|
||||||
- go tool vet -shadow=true ./pkg
|
|
||||||
- gofmt -s -l pkg
|
|
||||||
- golint .
|
|
||||||
- golint github.com/minio/mc/pkg...
|
|
||||||
- gometalinter --disable-all --linter='misspell:misspell ./*.go:PATH:LINE:COL:MESSAGE' --enable=misspell ./...
|
|
||||||
- gocyclo -over 40 pkg
|
|
||||||
- deadcode
|
|
||||||
- go test -race .
|
|
||||||
- go test -race github.com/minio/mc/pkg...
|
|
||||||
- go run buildscripts/gen-ldflags.go > temp.txt
|
|
||||||
- set /p LDFLAGS=<temp.txt
|
|
||||||
- go build -ldflags="%LDFLAGS%" -o %GOPATH%\bin\mc.exe
|
|
||||||
- mc version
|
|
||||||
|
|
||||||
# to disable automatic tests
|
|
||||||
test: off
|
|
||||||
|
|
||||||
# to disable deployment
|
|
||||||
deploy: off
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
## FIXME:
|
||||||
|
## In OSX, 'sort -V' option does not exist, hence
|
||||||
|
## we have our own version compare function.
|
||||||
|
## Once OSX has the option, below function is good enough.
|
||||||
|
##
|
||||||
|
## check_minimum_version() {
|
||||||
|
## versions=($(echo -e "$1\n$2" | sort -V))
|
||||||
|
## return [ "$1" == "${versions[0]}" ]
|
||||||
|
## }
|
||||||
|
##
|
||||||
|
check_minimum_version() {
|
||||||
|
IFS='.' read -r -a varray1 <<< "$1"
|
||||||
|
IFS='.' read -r -a varray2 <<< "$2"
|
||||||
|
|
||||||
|
for i in "${!varray1[@]}"; do
|
||||||
|
if [[ ${varray1[i]} -lt ${varray2[i]} ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ ${varray1[i]} -gt ${varray2[i]} ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
Executable
+110
@@ -0,0 +1,110 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
_init() {
|
||||||
|
# Save release LDFLAGS
|
||||||
|
LDFLAGS=$(go run buildscripts/gen-ldflags.go)
|
||||||
|
|
||||||
|
# Extract release tag
|
||||||
|
release_tag=$(echo $LDFLAGS | awk {'print $6'} | cut -f2 -d=)
|
||||||
|
|
||||||
|
# Verify release tag.
|
||||||
|
if [ -z "$release_tag" ]; then
|
||||||
|
echo "Release tag cannot be empty. Please check return value of \`go run buildscripts/gen-ldflags.go\`"
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Extract release string.
|
||||||
|
release_str=$(echo $MC_RELEASE | tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
# Verify release string.
|
||||||
|
if [ -z "$release_str" ]; then
|
||||||
|
echo "Release string cannot be empty. Please set \`MC_RELEASE\` env variable."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
# List of supported architectures
|
||||||
|
SUPPORTED_OSARCH='linux/amd64 linux/ppc64le windows/amd64 darwin/amd64'
|
||||||
|
|
||||||
|
## System binaries
|
||||||
|
CP=`which cp`
|
||||||
|
SHASUM=`which shasum`
|
||||||
|
SHA256SUM="${SHASUM} -a 256"
|
||||||
|
SED=`which sed`
|
||||||
|
}
|
||||||
|
|
||||||
|
go_build() {
|
||||||
|
local osarch=$1
|
||||||
|
os=$(echo $osarch | cut -f1 -d'/')
|
||||||
|
arch=$(echo $osarch | cut -f2 -d'/')
|
||||||
|
package=$(go list -f '{{.ImportPath}}')
|
||||||
|
echo -n "-->"
|
||||||
|
printf "%15s:%s\n" "${osarch}" "${package}"
|
||||||
|
|
||||||
|
# Release binary name
|
||||||
|
release_bin="$release_str/$os-$arch/$(basename $package).$release_tag"
|
||||||
|
# Release binary downloadable name
|
||||||
|
release_real_bin="$release_str/$os-$arch/$(basename $package)"
|
||||||
|
|
||||||
|
# Release sha1sum name
|
||||||
|
release_shasum="$release_str/$os-$arch/$(basename $package).${release_tag}.shasum"
|
||||||
|
# Release sha1sum default
|
||||||
|
release_shasum_default="$release_str/$os-$arch/$(basename $package).shasum"
|
||||||
|
|
||||||
|
# Release sha256sum name
|
||||||
|
release_sha256sum="$release_str/$os-$arch/$(basename $package).${release_tag}.sha256sum"
|
||||||
|
# Release sha256sum default
|
||||||
|
release_sha256sum_default="$release_str/$os-$arch/$(basename $package).sha256sum"
|
||||||
|
|
||||||
|
# Go build to build the binary.
|
||||||
|
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -tags kqueue --ldflags "${LDFLAGS}" -o $release_bin
|
||||||
|
|
||||||
|
# Create copy
|
||||||
|
if [ $os == "windows" ]; then
|
||||||
|
$CP -p $release_bin ${release_real_bin}.exe
|
||||||
|
else
|
||||||
|
$CP -p $release_bin $release_real_bin
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Calculate sha1sum
|
||||||
|
shasum_str=$(${SHASUM} ${release_bin})
|
||||||
|
echo ${shasum_str} | $SED "s/$release_str\/$os-$arch\///g" > $release_shasum
|
||||||
|
$CP -p $release_shasum $release_shasum_default
|
||||||
|
|
||||||
|
# Calculate sha256sum
|
||||||
|
sha256sum_str=$(${SHA256SUM} ${release_bin})
|
||||||
|
echo ${sha256sum_str} | $SED "s/$release_str\/$os-$arch\///g" > $release_sha256sum
|
||||||
|
$CP -p $release_sha256sum $release_sha256sum_default
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
# Build releases.
|
||||||
|
echo "Executing $release_str builds for OS: ${SUPPORTED_OSARCH}"
|
||||||
|
echo "Choose an OS Arch from the below"
|
||||||
|
for osarch in ${SUPPORTED_OSARCH}; do
|
||||||
|
echo ${osarch}
|
||||||
|
done
|
||||||
|
|
||||||
|
read -p "If you want to build for all, Just press Enter: " chosen_osarch
|
||||||
|
if [ "$chosen_osarch" = "" ] || [ "$chosen_osarch" = "all" ]; then
|
||||||
|
for each_osarch in ${SUPPORTED_OSARCH}; do
|
||||||
|
go_build ${each_osarch}
|
||||||
|
done
|
||||||
|
else
|
||||||
|
local found=0
|
||||||
|
for each_osarch in ${SUPPORTED_OSARCH}; do
|
||||||
|
if [ "$chosen_osarch" = "$each_osarch" ]; then
|
||||||
|
found=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ ${found} -eq 1 ]; then
|
||||||
|
go_build ${chosen_osarch}
|
||||||
|
else
|
||||||
|
echo "Unknown architecture \"${chosen_osarch}\""
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
# Run main.
|
||||||
|
_init && main
|
||||||
+72
-156
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Minio Client, (C) 2015 Minio, Inc.
|
# MinIO Client, (C) 2015, 2016, 2017, 2018, 2019 MinIO, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -15,20 +15,35 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# shellcheck source=buildscripts/build.env
|
||||||
|
. "$(pwd)/buildscripts/build.env"
|
||||||
|
|
||||||
_init() {
|
_init() {
|
||||||
|
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
|
|
||||||
## Minimum required versions for build dependencies
|
## Minimum required versions for build dependencies
|
||||||
GIT_VERSION="1.0"
|
GIT_VERSION="1.0"
|
||||||
GO_VERSION="1.5.1"
|
GO_VERSION="1.13"
|
||||||
OSX_VERSION="10.8"
|
OSX_VERSION="10.8"
|
||||||
UNAME=$(uname -sm)
|
KNAME=$(uname -s)
|
||||||
|
ARCH=$(uname -m)
|
||||||
## Check all dependencies are present
|
case "${KNAME}" in
|
||||||
MISSING=""
|
SunOS )
|
||||||
|
ARCH=$(isainfo -k)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## FIXME:
|
||||||
|
## In OSX, 'readlink -f' option does not exist, hence
|
||||||
|
## we have our own readlink -f behavior here.
|
||||||
|
## Once OSX has the option, below function is good enough.
|
||||||
|
##
|
||||||
|
## readlink() {
|
||||||
|
## return /bin/readlink -f "$1"
|
||||||
|
## }
|
||||||
|
##
|
||||||
readlink() {
|
readlink() {
|
||||||
TARGET_FILE=$1
|
TARGET_FILE=$1
|
||||||
|
|
||||||
@@ -50,169 +65,70 @@ readlink() {
|
|||||||
echo $RESULT
|
echo $RESULT
|
||||||
}
|
}
|
||||||
|
|
||||||
###
|
assert_is_supported_arch() {
|
||||||
#
|
case "${ARCH}" in
|
||||||
# Takes two arguments
|
x86_64 | amd64 | ppc64le | aarch64 | arm* | s390x )
|
||||||
# arg1: version number in `x.x.x` format
|
return
|
||||||
# arg2: version number in `x.x.x` format
|
|
||||||
#
|
|
||||||
# example: check_version "$version1" "$version2"
|
|
||||||
#
|
|
||||||
# returns:
|
|
||||||
# 0 - Installed version is equal to required
|
|
||||||
# 1 - Installed version is greater than required
|
|
||||||
# 2 - Installed version is lesser than required
|
|
||||||
# 3 - If args have length zero
|
|
||||||
#
|
|
||||||
####
|
|
||||||
check_version() {
|
|
||||||
## validate args
|
|
||||||
[[ -z "$1" ]] && return 3
|
|
||||||
[[ -z "$2" ]] && return 3
|
|
||||||
|
|
||||||
if [[ $1 == $2 ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
local IFS=.
|
|
||||||
local i ver1=($1) ver2=($2)
|
|
||||||
# fill empty fields in ver1 with zeros
|
|
||||||
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
|
|
||||||
ver1[i]=0
|
|
||||||
done
|
|
||||||
for ((i=0; i<${#ver1[@]}; i++)); do
|
|
||||||
if [[ -z ${ver2[i]} ]]; then
|
|
||||||
# fill empty fields in ver2 with zeros
|
|
||||||
ver2[i]=0
|
|
||||||
fi
|
|
||||||
if ((10#${ver1[i]} > 10#${ver2[i]})); then
|
|
||||||
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ((10#${ver1[i]} < 10#${ver2[i]})); then
|
|
||||||
## Installed version is lesser than required - Bad condition
|
|
||||||
return 2
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
check_golang_env() {
|
|
||||||
echo ${GOROOT:?} 2>&1 >/dev/null
|
|
||||||
if [ $? -eq 1 ]; then
|
|
||||||
echo "ERROR"
|
|
||||||
echo "GOROOT environment variable missing, please refer to Go installation document"
|
|
||||||
echo "https://github.com/minio/mc/blob/master/INSTALLGO.md#install-go-13"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo ${GOPATH:?} 2>&1 >/dev/null
|
|
||||||
if [ $? -eq 1 ]; then
|
|
||||||
echo "ERROR"
|
|
||||||
echo "GOPATH environment variable missing, please refer to Go installation document"
|
|
||||||
echo "https://github.com/minio/mc/blob/master/INSTALLGO.md#install-go-13"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local go_binary_path=$(which go)
|
|
||||||
|
|
||||||
if [ -z "${go_binary_path}" ] ; then
|
|
||||||
echo "Cannot find go binary in your PATH configuration, please refer to Go installation document"
|
|
||||||
echo "https://github.com/minio/mc/blob/master/INSTALLGO.md#install-go-13"
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local new_go_binary_path=${go_binary_path}
|
|
||||||
if [ -h "${go_binary_path}" ]; then
|
|
||||||
new_go_binary_path=$(readlink ${go_binary_path})
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ !"$(dirname ${new_go_binary_path})" =~ *"${GOROOT%%*(/)}"* ]] ; then
|
|
||||||
echo "The go binary found in your PATH configuration does not belong to the Go installation pointed by your GOROOT environment," \
|
|
||||||
"please refer to Go installation document"
|
|
||||||
echo "https://github.com/minio/mc/blob/master/INSTALLGO.md#install-go-13"
|
|
||||||
exit -1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
is_supported_os() {
|
|
||||||
case ${UNAME%% *} in
|
|
||||||
"Linux")
|
|
||||||
os="linux"
|
|
||||||
;;
|
|
||||||
"Darwin")
|
|
||||||
osx_host_version=$(env sw_vers -productVersion)
|
|
||||||
check_version "${osx_host_version}" "${OSX_VERSION}"
|
|
||||||
[[ $? -ge 2 ]] && die "Minimum OSX version supported is ${OSX_VERSION}"
|
|
||||||
;;
|
|
||||||
"*")
|
|
||||||
echo "Exiting.. unsupported operating system found"
|
|
||||||
exit 1;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
is_supported_arch() {
|
|
||||||
local supported
|
|
||||||
case ${UNAME##* } in
|
|
||||||
"x86_64")
|
|
||||||
supported=1
|
|
||||||
;;
|
|
||||||
"arm"*)
|
|
||||||
supported=1
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
supported=0
|
echo "Arch '${ARCH}' is not supported. Supported Arch: [x86_64, amd64, ppc64le, aarch64, arm*, s390x]"
|
||||||
;;
|
exit 1
|
||||||
esac
|
esac
|
||||||
if [ $supported -eq 0 ]; then
|
}
|
||||||
echo "Invalid arch: ${UNAME} not supported, please use x86_64/amd64"
|
|
||||||
exit 1;
|
assert_is_supported_os() {
|
||||||
|
case "${KNAME}" in
|
||||||
|
Linux | FreeBSD | OpenBSD | NetBSD | DragonFly | SunOS )
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
Darwin )
|
||||||
|
osx_host_version=$(env sw_vers -productVersion)
|
||||||
|
if ! check_minimum_version "${OSX_VERSION}" "${osx_host_version}"; then
|
||||||
|
echo "OSX version '${osx_host_version}' is not supported. Minimum supported version: ${OSX_VERSION}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "OS '${KNAME}' is not supported. Supported OS: [Linux, FreeBSD, OpenBSD, NetBSD, Darwin, DragonFly]"
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_check_golang_env() {
|
||||||
|
if ! which go >/dev/null 2>&1; then
|
||||||
|
echo "Cannot find go binary in your PATH configuration, please refer to Go installation document at https://golang.org/doc/install"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
installed_go_version=$(go version | sed 's/^.* go\([0-9.]*\).*$/\1/')
|
||||||
|
if ! check_minimum_version "${GO_VERSION}" "${installed_go_version}"; then
|
||||||
|
echo "Go runtime version '${installed_go_version}' is unsupported. Minimum supported version: ${GO_VERSION} to compile."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_deps() {
|
assert_check_deps() {
|
||||||
check_version "$(env go version 2>/dev/null | sed 's/^.* go\([0-9.]*\).*$/\1/')" "${GO_VERSION}"
|
# support unusual Git versions such as: 2.7.4 (Apple Git-66)
|
||||||
if [ $? -ge 2 ]; then
|
installed_git_version=$(git version | perl -ne '$_ =~ m/git version (.*?)( |$)/; print "$1\n";')
|
||||||
MISSING="${MISSING} golang(>=${GO_VERSION})"
|
if ! check_minimum_version "${GIT_VERSION}" "${installed_git_version}"; then
|
||||||
fi
|
echo "Git version '${installed_git_version}' is not supported. Minimum supported version: ${GIT_VERSION}"
|
||||||
|
exit 1
|
||||||
check_version "$(env git --version 2>/dev/null | sed -e 's/^.* \([0-9.\].*\).*$/\1/' -e 's/^\([0-9.\]*\).*/\1/g')" "${GIT_VERSION}"
|
|
||||||
if [ $? -ge 2 ]; then
|
|
||||||
MISSING="${MISSING} git(>=${GIT_VERSION})"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
echo -n "Check for supported arch.. "
|
## Check for supported arch
|
||||||
is_supported_arch
|
assert_is_supported_arch
|
||||||
|
|
||||||
echo -n "Check for supported os.. "
|
## Check for supported os
|
||||||
is_supported_os
|
assert_is_supported_os
|
||||||
|
|
||||||
echo -n "Checking if proper environment variables are set.. "
|
## Check for Go environment
|
||||||
check_golang_env
|
assert_check_golang_env
|
||||||
|
|
||||||
echo "Done"
|
## Check for dependencies
|
||||||
echo "Using GOPATH=${GOPATH} and GOROOT=${GOROOT}"
|
assert_check_deps
|
||||||
|
|
||||||
echo -n "Checking dependencies for Minio Client.. "
|
|
||||||
check_deps
|
|
||||||
|
|
||||||
## If dependencies are missing, warn the user and abort
|
|
||||||
if [ "x${MISSING}" != "x" ]; then
|
|
||||||
echo "ERROR"
|
|
||||||
echo
|
|
||||||
echo "The following build tools are missing:"
|
|
||||||
echo
|
|
||||||
echo "** ${MISSING} **"
|
|
||||||
echo
|
|
||||||
echo "Please install them "
|
|
||||||
echo "${MISSING}"
|
|
||||||
echo
|
|
||||||
echo "Follow https://github.com/minio/mc/blob/master/INSTALLGO.md for further instructions"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
echo "Done"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_init && main "$@"
|
_init && main "$@"
|
||||||
|
|||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Enable tracing if set.
|
||||||
|
[ -n "$BASH_XTRACEFD" ] && set -ex
|
||||||
|
|
||||||
|
function _init() {
|
||||||
|
## All binaries are static make sure to disable CGO.
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
|
## List of architectures and OS to test coss compilation.
|
||||||
|
SUPPORTED_OSARCH="linux/ppc64le linux/arm64 linux/s390x darwin/amd64 freebsd/amd64 linux/arm linux/386 windows/amd64"
|
||||||
|
}
|
||||||
|
|
||||||
|
function _build() {
|
||||||
|
local osarch=$1
|
||||||
|
IFS=/ read -r -a arr <<<"$osarch"
|
||||||
|
os="${arr[0]}"
|
||||||
|
arch="${arr[1]}"
|
||||||
|
package=$(go list -f '{{.ImportPath}}')
|
||||||
|
printf -- "--> %15s:%s\n" "${osarch}" "${package}"
|
||||||
|
|
||||||
|
# Go build to build the binary.
|
||||||
|
export GOOS=$os
|
||||||
|
export GOARCH=$arch
|
||||||
|
export GO111MODULE=on
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
go build -tags kqueue -o /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
echo "Testing builds for OS/Arch: ${SUPPORTED_OSARCH}"
|
||||||
|
for each_osarch in ${SUPPORTED_OSARCH}; do
|
||||||
|
_build "${each_osarch}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
_init && main "$@"
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
// +build ignore
|
// +build ignore
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Mc Client (C) 2014, 2015 Mc, Inc.
|
* MinIO Client (C) 2014, 2015, 2016, 2017, 2018 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -28,16 +28,16 @@ import (
|
|||||||
|
|
||||||
func genLDFlags(version string) string {
|
func genLDFlags(version string) string {
|
||||||
var ldflagsStr string
|
var ldflagsStr string
|
||||||
ldflagsStr = "-X main.mcVersion=" + version + " "
|
ldflagsStr = "-s -w -X github.com/minio/mc/cmd.Version=" + version + " "
|
||||||
ldflagsStr = ldflagsStr + "-X main.mcReleaseTag=" + releaseTag(version) + " "
|
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.ReleaseTag=" + releaseTag(version) + " "
|
||||||
ldflagsStr = ldflagsStr + "-X main.mcCommitID=" + commitID() + " "
|
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.CommitID=" + commitID() + " "
|
||||||
ldflagsStr = ldflagsStr + "-X main.mcShortCommitID=" + commitID()[:12]
|
ldflagsStr = ldflagsStr + "-X github.com/minio/mc/cmd.ShortCommitID=" + commitID()[:12]
|
||||||
return ldflagsStr
|
return ldflagsStr
|
||||||
}
|
}
|
||||||
|
|
||||||
// genReleaseTag prints release tag to the console for easy git tagging.
|
// genReleaseTag prints release tag to the console for easy git tagging.
|
||||||
func releaseTag(version string) string {
|
func releaseTag(version string) string {
|
||||||
relPrefix := "UNOFFICIAL"
|
relPrefix := "DEVELOPMENT"
|
||||||
if prefix := os.Getenv("MC_RELEASE"); prefix != "" {
|
if prefix := os.Getenv("MC_RELEASE"); prefix != "" {
|
||||||
relPrefix = prefix
|
relPrefix = prefix
|
||||||
}
|
}
|
||||||
|
|||||||
-152
@@ -1,152 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minio Client, (C) 2015 Minio, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/minio/cli"
|
|
||||||
"github.com/minio/minio-xl/pkg/probe"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
catFlags = []cli.Flag{
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "help, h",
|
|
||||||
Usage: "Help of cat",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Display contents of a file.
|
|
||||||
var catCmd = cli.Command{
|
|
||||||
Name: "cat",
|
|
||||||
Usage: "Display contents of a file.",
|
|
||||||
Action: mainCat,
|
|
||||||
Flags: append(catFlags, globalFlags...),
|
|
||||||
CustomHelpTemplate: `NAME:
|
|
||||||
mc {{.Name}} - {{.Usage}}
|
|
||||||
|
|
||||||
USAGE:
|
|
||||||
mc {{.Name}} [FLAGS] SOURCE [SOURCE...]
|
|
||||||
|
|
||||||
FLAGS:
|
|
||||||
{{range .Flags}}{{.}}
|
|
||||||
{{end}}
|
|
||||||
EXAMPLES:
|
|
||||||
1. Stream an object from Amazon S3 cloud storage to mplayer standard input.
|
|
||||||
$ mc {{.Name}} s3/ferenginar/klingon_opera_aktuh_maylotah.ogg | mplayer -
|
|
||||||
|
|
||||||
2. Concantenate contents of file1.txt and stdin to standard output.
|
|
||||||
$ mc {{.Name}} file1.txt - > file.txt
|
|
||||||
|
|
||||||
3. Concantenate multiple files to one.
|
|
||||||
$ mc {{.Name}} part.* > complete.img
|
|
||||||
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
|
|
||||||
// checkCatSyntax performs command-line input validation for cat command.
|
|
||||||
func checkCatSyntax(ctx *cli.Context) {
|
|
||||||
args := ctx.Args()
|
|
||||||
if !args.Present() {
|
|
||||||
args = []string{"-"}
|
|
||||||
}
|
|
||||||
for _, arg := range args {
|
|
||||||
if strings.HasPrefix(arg, "-") && len(arg) > 1 {
|
|
||||||
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Unknown flag ‘%s’ passed.", arg))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// catURL displays contents of a URL to stdout.
|
|
||||||
func catURL(sourceURL string) *probe.Error {
|
|
||||||
var reader io.Reader
|
|
||||||
switch sourceURL {
|
|
||||||
case "-":
|
|
||||||
reader = os.Stdin
|
|
||||||
default:
|
|
||||||
// Ignore size, since os.Stat() would not return proper size all the
|
|
||||||
// time for local filesystem for example /proc files.
|
|
||||||
var err *probe.Error
|
|
||||||
if reader, err = getSourceStream(sourceURL); err != nil {
|
|
||||||
return err.Trace(sourceURL)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return catOut(reader).Trace(sourceURL)
|
|
||||||
}
|
|
||||||
|
|
||||||
// catOut reads from reader stream and writes to stdout.
|
|
||||||
func catOut(r io.Reader) *probe.Error {
|
|
||||||
// Read till EOF.
|
|
||||||
if _, e := io.Copy(os.Stdout, r); e != nil {
|
|
||||||
switch e := e.(type) {
|
|
||||||
case *os.PathError:
|
|
||||||
if e.Err == syscall.EPIPE {
|
|
||||||
// stdout closed by the user. Gracefully exit.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return probe.NewError(e)
|
|
||||||
default:
|
|
||||||
return probe.NewError(e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// mainCat is the main entry point for cat command.
|
|
||||||
func mainCat(ctx *cli.Context) {
|
|
||||||
// Set global flags from context.
|
|
||||||
setGlobalsFromContext(ctx)
|
|
||||||
|
|
||||||
// check 'cat' cli arguments.
|
|
||||||
checkCatSyntax(ctx)
|
|
||||||
|
|
||||||
// Set command flags from context.
|
|
||||||
stdinMode := false
|
|
||||||
if !ctx.Args().Present() {
|
|
||||||
stdinMode = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle std input data.
|
|
||||||
if stdinMode {
|
|
||||||
fatalIf(catOut(os.Stdin).Trace(), "Unable to read from standard input.")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// if Args contain ‘-’, we need to preserve its order specially.
|
|
||||||
args := []string(ctx.Args())
|
|
||||||
if ctx.Args().First() == "-" {
|
|
||||||
for i, arg := range os.Args {
|
|
||||||
if arg == "cat" {
|
|
||||||
// Overwrite ctx.Args with os.Args.
|
|
||||||
args = os.Args[i+1:]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert arguments to URLs: expand alias, fix format.
|
|
||||||
for _, url := range args {
|
|
||||||
fatalIf(catURL(url).Trace(url), "Unable to read from ‘"+url+"’.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2015 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "path/filepath"
|
||||||
|
|
||||||
|
// isValidAccessPERM - is provided access perm string supported.
|
||||||
|
func (b accessPerms) isValidAccessPERM() bool {
|
||||||
|
switch b {
|
||||||
|
case accessNone, accessDownload, accessUpload, accessPublic:
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b accessPerms) isValidAccessFile() bool {
|
||||||
|
return filepath.Ext(string(b)) == ".json"
|
||||||
|
}
|
||||||
|
|
||||||
|
// accessPerms - access level.
|
||||||
|
type accessPerms string
|
||||||
|
|
||||||
|
// different types of Access perm's currently supported by policy command.
|
||||||
|
const (
|
||||||
|
accessNone = accessPerms("none")
|
||||||
|
accessDownload = accessPerms("download")
|
||||||
|
accessUpload = accessPerms("upload")
|
||||||
|
accessPublic = accessPerms("public")
|
||||||
|
accessCustom = accessPerms("custom")
|
||||||
|
)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Client (C) 2014, 2015 Minio, Inc.
|
* MinIO Client (C) 2014, 2015 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,12 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/cheggaaa/pb"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// accounter keeps tabs of ongoing data transfer information.
|
// accounter keeps tabs of ongoing data transfer information.
|
||||||
@@ -51,7 +56,7 @@ func newAccounter(total int64) *accounter {
|
|||||||
|
|
||||||
// write calculate the final speed.
|
// write calculate the final speed.
|
||||||
func (a *accounter) write(current int64) float64 {
|
func (a *accounter) write(current int64) float64 {
|
||||||
fromStart := time.Now().Sub(a.startTime)
|
fromStart := time.Since(a.startTime)
|
||||||
currentFromStart := current - a.startValue
|
currentFromStart := current - a.startValue
|
||||||
if currentFromStart > 0 {
|
if currentFromStart > 0 {
|
||||||
speed := float64(currentFromStart) / (float64(fromStart) / float64(time.Second))
|
speed := float64(currentFromStart) / (float64(fromStart) / float64(time.Second))
|
||||||
@@ -75,9 +80,30 @@ func (a *accounter) writer() {
|
|||||||
|
|
||||||
// accountStat cantainer for current stats captured.
|
// accountStat cantainer for current stats captured.
|
||||||
type accountStat struct {
|
type accountStat struct {
|
||||||
Total int64
|
Status string `json:"status"`
|
||||||
Transferred int64
|
Total int64 `json:"total"`
|
||||||
Speed float64
|
Transferred int64 `json:"transferred"`
|
||||||
|
Speed float64 `json:"speed"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c accountStat) JSON() string {
|
||||||
|
c.Status = "success"
|
||||||
|
accountMessageBytes, e := json.MarshalIndent(c, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(accountMessageBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c accountStat) String() string {
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stat provides current stats captured.
|
// Stat provides current stats captured.
|
||||||
@@ -86,7 +112,7 @@ func (a *accounter) Stat() accountStat {
|
|||||||
a.finishOnce.Do(func() {
|
a.finishOnce.Do(func() {
|
||||||
close(a.isFinished)
|
close(a.isFinished)
|
||||||
acntStat.Total = a.Total
|
acntStat.Total = a.Total
|
||||||
acntStat.Transferred = a.current
|
acntStat.Transferred = atomic.LoadInt64(&a.current)
|
||||||
acntStat.Speed = a.write(atomic.LoadInt64(&a.current))
|
acntStat.Speed = a.write(atomic.LoadInt64(&a.current))
|
||||||
})
|
})
|
||||||
return acntStat
|
return acntStat
|
||||||
@@ -107,6 +133,14 @@ func (a *accounter) Set(n int64) *accounter {
|
|||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get gets current value atomically
|
||||||
|
func (a *accounter) Get() int64 {
|
||||||
|
return atomic.LoadInt64(&a.current)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *accounter) SetTotal(int64) {
|
||||||
|
}
|
||||||
|
|
||||||
// Add add to current value atomically.
|
// Add add to current value atomically.
|
||||||
func (a *accounter) Add(n int64) int64 {
|
func (a *accounter) Add(n int64) int64 {
|
||||||
return atomic.AddInt64(&a.current, n)
|
return atomic.AddInt64(&a.current, n)
|
||||||
@@ -0,0 +1,189 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminQuotaFlags = []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "fifo",
|
||||||
|
Usage: "set fifo quota, allowing automatic deletion of older content",
|
||||||
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "hard",
|
||||||
|
Usage: "set a hard quota, disallowing writes after quota is reached",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "clear",
|
||||||
|
Usage: "clears bucket quota configured for bucket",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: append(adminQuotaFlags, globalFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET [--fifo QUOTA | --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
|
||||||
|
|
||||||
|
2. Set FIFO quota for a bucket "mybucket" on MinIO.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/mybucket --fifo 64kB
|
||||||
|
|
||||||
|
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, "quota", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.IsSet("hard") && ctx.IsSet("fifo") {
|
||||||
|
fatalIf(errInvalidArgument(), "Only one of --hard or --fifo flags can be set")
|
||||||
|
}
|
||||||
|
if (ctx.IsSet("hard") || ctx.IsSet("fifo")) && len(ctx.Args()) == 0 {
|
||||||
|
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "please specify bucket and quota")
|
||||||
|
}
|
||||||
|
if ctx.IsSet("clear") && len(ctx.Args()) == 0 {
|
||||||
|
fatalIf(errInvalidArgument().Trace(ctx.Args()...), "clear flag must be passed with target alone")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
quotaStr := ctx.String("fifo")
|
||||||
|
if ctx.IsSet("hard") {
|
||||||
|
quotaStr = ctx.String("hard")
|
||||||
|
}
|
||||||
|
_, targetURL := url2Alias(args[0])
|
||||||
|
if ctx.IsSet("fifo") || ctx.IsSet("hard") && len(args) == 1 {
|
||||||
|
qType := madmin.FIFOQuota
|
||||||
|
if ctx.IsSet("hard") {
|
||||||
|
qType = madmin.HardQuota
|
||||||
|
}
|
||||||
|
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") && len(args) == 1 {
|
||||||
|
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",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminBucketCmd = cli.Command{
|
||||||
|
Name: "bucket",
|
||||||
|
Usage: "manage buckets defined in the MinIO server",
|
||||||
|
Action: mainAdminBucket,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminBucketQuotaCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminBucket is the handle for "mc admin bucket" command.
|
||||||
|
func mainAdminBucket(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "quota", "usage" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigExportCmd = cli.Command{
|
||||||
|
Name: "export",
|
||||||
|
Usage: "export all config keys to STDOUT",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigExport,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Export the current config from MinIO server
|
||||||
|
{{.Prompt}} {{.HelpName}} play/ > config.txt
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configExportMessage container to hold locks information.
|
||||||
|
type configExportMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Value []byte `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configExportMessage) String() string {
|
||||||
|
return string(u.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configExportMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminConfigExport(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminConfigExportSyntax(ctx)
|
||||||
|
|
||||||
|
// Export 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.")
|
||||||
|
|
||||||
|
// Call get config API
|
||||||
|
buf, e := client.GetConfig(globalContext)
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get server config")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configExportMessage{
|
||||||
|
Value: buf,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigGetCmd = cli.Command{
|
||||||
|
Name: "get",
|
||||||
|
Usage: "interactively retrieve a config key parameters",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigGet,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get the current region setting on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/ region
|
||||||
|
region name=us-east-1
|
||||||
|
|
||||||
|
2. Get the current notification settings for Webhook target on MinIO server
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/ notify_webhook
|
||||||
|
notify_webhook endpoint="http://localhost:8080" auth_token= queue_limit=10000 queue_dir="/home/events"
|
||||||
|
|
||||||
|
3. Get the current compression settings on MinIO server
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/ compression
|
||||||
|
compression extensions=".txt,.csv" mime_types="text/*"
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configGetMessage container to hold locks information.
|
||||||
|
type configGetMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Value []byte `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configGetMessage) String() string {
|
||||||
|
return string(u.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configGetMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminConfigGet(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminConfigGetSyntax(ctx)
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
if len(ctx.Args()) == 1 {
|
||||||
|
// Call get config API
|
||||||
|
hr, e := client.HelpConfigKV(globalContext, "", "", false)
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configHelpMessage{
|
||||||
|
Value: hr,
|
||||||
|
envOnly: false,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call get config API
|
||||||
|
buf, e := client.GetConfigKV(globalContext, strings.Join(args.Tail(), " "))
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get server '%s' config", args.Tail())
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configGetMessage{
|
||||||
|
Value: buf,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HelpTmpl template used by all sub-systems
|
||||||
|
const HelpTmpl = `{{if ne .SubSys ""}}{{colorBlueBold "KEY:"}}
|
||||||
|
{{if .MultipleTargets}}{{colorYellowBold .SubSys}}[:name]{{"\t"}}{{else}}{{colorYellowBold .SubSys}}{{"\t"}}{{end}}{{.Description}}
|
||||||
|
|
||||||
|
{{colorBlueBold "ARGS:"}}{{range .KeysHelp}}
|
||||||
|
{{if .Optional}}{{colorYellowBold .Key}}{{else}}{{colorRedBold .Key}}*{{end}}{{"\t"}}({{.Type}}){{"\t"}}{{.Description}}{{end}}{{else}}{{colorBlueBold "KEYS:"}}{{range .KeysHelp}}
|
||||||
|
{{colorGreenBold .Key}}{{"\t"}}{{.Description}}{{end}}{{end}}`
|
||||||
|
|
||||||
|
var funcMap = template.FuncMap{
|
||||||
|
"colorBlueBold": color.New(color.FgBlue, color.Bold).SprintfFunc(),
|
||||||
|
"colorYellowBold": color.New(color.FgYellow, color.Bold).SprintfFunc(),
|
||||||
|
"colorCyanBold": color.New(color.FgCyan, color.Bold).SprintFunc(),
|
||||||
|
"colorRedBold": color.New(color.FgRed, color.Bold).SprintfFunc(),
|
||||||
|
"colorGreenBold": color.New(color.FgGreen, color.Bold).SprintfFunc(),
|
||||||
|
}
|
||||||
|
|
||||||
|
// HelpTemplate - captures config help template
|
||||||
|
var HelpTemplate = template.Must(template.New("config-help").Funcs(funcMap).Parse(HelpTmpl))
|
||||||
|
|
||||||
|
// HelpEnvTemplate - captures config help template
|
||||||
|
var HelpEnvTemplate = template.Must(template.New("config-help-env").Funcs(funcMap).Parse(HelpTmpl))
|
||||||
|
|
||||||
|
// configHelpMessage container to hold locks information.
|
||||||
|
type configHelpMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Value madmin.Help `json:"help"`
|
||||||
|
envOnly bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configHelpMessage) String() string {
|
||||||
|
var s strings.Builder
|
||||||
|
w := tabwriter.NewWriter(&s, 1, 8, 2, ' ', 0)
|
||||||
|
var e error
|
||||||
|
if !u.envOnly {
|
||||||
|
e = HelpTemplate.Execute(w, u.Value)
|
||||||
|
} else {
|
||||||
|
e = HelpEnvTemplate.Execute(w, u.Value)
|
||||||
|
}
|
||||||
|
fatalIf(probe.NewError(e), "Cannot initialize template writer")
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
|
||||||
|
return s.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configHelpMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"text/tabwriter"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var historyListFlags = []cli.Flag{
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "count, n",
|
||||||
|
Usage: "list only last 'n' entries",
|
||||||
|
Value: 10,
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "clear, c",
|
||||||
|
Usage: "clear all history",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminConfigHistoryCmd = cli.Command{
|
||||||
|
Name: "history",
|
||||||
|
Usage: "show all historic configuration changes",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigHistory,
|
||||||
|
Flags: append(append([]cli.Flag{}, globalFlags...), historyListFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. List all history entries sorted by time.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// History template used by all sub-systems
|
||||||
|
const History = `{{range .}}{{colorYellowBold "RestoreId:"}} {{colorYellowBold .RestoreID}}
|
||||||
|
Date: {{.CreateTime}}
|
||||||
|
|
||||||
|
{{.Targets}}
|
||||||
|
|
||||||
|
{{end}}`
|
||||||
|
|
||||||
|
// HistoryTemplate - captures history list template
|
||||||
|
var HistoryTemplate = template.Must(template.New("history-list").Funcs(funcMap).Parse(History))
|
||||||
|
|
||||||
|
type historyEntry struct {
|
||||||
|
RestoreID string `json:"restoreId"`
|
||||||
|
CreateTime string `json:"createTime"`
|
||||||
|
Targets string `json:"targets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// configHistoryMessage container to hold locks information.
|
||||||
|
type configHistoryMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Entries []historyEntry `json:"entries"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configHistoryMessage) String() string {
|
||||||
|
var s strings.Builder
|
||||||
|
w := tabwriter.NewWriter(&s, 1, 8, 2, ' ', 0)
|
||||||
|
e := HistoryTemplate.Execute(w, u.Entries)
|
||||||
|
fatalIf(probe.NewError(e), "Cannot initialize template writer")
|
||||||
|
|
||||||
|
w.Flush()
|
||||||
|
return s.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configHistoryMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminConfigHistory(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminConfigHistorySyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("ConfigHistoryMessageRestoreID", color.New(color.Bold))
|
||||||
|
console.SetColor("ConfigHistoryMessageTime", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
if ctx.IsSet("clear") {
|
||||||
|
fatalIf(probe.NewError(client.ClearConfigHistoryKV(globalContext, "all")), "Cannot clear server configuration.")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configHistoryMessage{})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
chEntries, e := client.ListConfigHistoryKV(globalContext, ctx.Int("count"))
|
||||||
|
fatalIf(probe.NewError(e), "Cannot list server history configuration.")
|
||||||
|
|
||||||
|
hentries := make([]historyEntry, len(chEntries))
|
||||||
|
for i, chEntry := range chEntries {
|
||||||
|
hentries[i] = historyEntry{
|
||||||
|
RestoreID: chEntry.RestoreID,
|
||||||
|
CreateTime: chEntry.CreateTimeFormatted(),
|
||||||
|
}
|
||||||
|
hentries[i].Targets = chEntry.Data
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configHistoryMessage{
|
||||||
|
Entries: hentries,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigImportCmd = cli.Command{
|
||||||
|
Name: "import",
|
||||||
|
Usage: "import multiple config keys from STDIN",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigImport,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Import the new local config and apply to the MinIO server
|
||||||
|
{{.Prompt}} {{.HelpName}} play/ < config.txt
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configImportMessage container to hold locks information.
|
||||||
|
type configImportMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
targetAlias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configImportMessage) String() (msg string) {
|
||||||
|
msg += console.Colorize("SetConfigSuccess",
|
||||||
|
"Setting new key has been successful.\n")
|
||||||
|
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||||
|
msg += console.Colorize("SetConfigSuccess",
|
||||||
|
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configImportMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminConfigImport(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminConfigImportSyntax(ctx)
|
||||||
|
|
||||||
|
// Set color preference of command outputs
|
||||||
|
console.SetColor("SetConfigSuccess", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// Import 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.")
|
||||||
|
|
||||||
|
// Call set config API
|
||||||
|
fatalIf(probe.NewError(client.SetConfig(globalContext, os.Stdin)), "Cannot set server config")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configImportMessage{
|
||||||
|
targetAlias: aliasedURL,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigEnvFlags = []cli.Flag{
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "env",
|
||||||
|
Usage: "list all the env only help",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminConfigResetCmd = cli.Command{
|
||||||
|
Name: "reset",
|
||||||
|
Usage: "interactively reset a config key parameters",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigReset,
|
||||||
|
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Reset MQTT notifcation target 'name1' settings to default values.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/ notify_mqtt:name1
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configResetMessage container to hold locks information.
|
||||||
|
type configResetMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
targetAlias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
msg += console.Colorize("ResetConfigSuccess",
|
||||||
|
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status message.
|
||||||
|
func (u configResetMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// main config set function
|
||||||
|
func mainAdminConfigReset(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
// Check command arguments
|
||||||
|
checkAdminConfigResetSyntax(ctx)
|
||||||
|
|
||||||
|
// Reset color preference of command outputs
|
||||||
|
console.SetColor("ResetConfigSuccess", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("ResetConfigFailure", color.New(color.FgRed, color.Bold))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
if len(ctx.Args()) == 1 {
|
||||||
|
// Call get config API
|
||||||
|
hr, e := client.HelpConfigKV(globalContext, "", "", ctx.IsSet("env"))
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configHelpMessage{
|
||||||
|
Value: hr,
|
||||||
|
envOnly: ctx.IsSet("env"),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call reset config API
|
||||||
|
input := strings.Join(args.Tail(), " ")
|
||||||
|
fatalIf(probe.NewError(client.DelConfigKV(globalContext, input)),
|
||||||
|
"Cannot reset '%s' on the server", input)
|
||||||
|
|
||||||
|
// Print set config result
|
||||||
|
printMsg(configResetMessage{
|
||||||
|
targetAlias: aliasedURL,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigRestoreCmd = cli.Command{
|
||||||
|
Name: "restore",
|
||||||
|
Usage: "rollback back changes to a specific config history",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigRestore,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET RESTOREID
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Restore 'restore-id' history key value on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/ <restore-id>
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configRestoreMessage container to hold locks information.
|
||||||
|
type configRestoreMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
RestoreID string `json:"restoreID"`
|
||||||
|
targetAlias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configRestoreMessage) String() (msg string) {
|
||||||
|
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||||
|
msg += console.Colorize("ConfigRestoreMessage",
|
||||||
|
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||||
|
msg += console.Colorize("ConfigRestoreMessage", "Restored "+u.RestoreID+" kv successfully.")
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status Message message.
|
||||||
|
func (u configRestoreMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminConfigRestore(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminConfigRestoreSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("ConfigRestoreMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
// Call get config API
|
||||||
|
fatalIf(probe.NewError(client.RestoreConfigHistoryKV(globalContext, args.Get(1))), "Cannot restore server configuration.")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configRestoreMessage{
|
||||||
|
RestoreID: args.Get(1),
|
||||||
|
targetAlias: aliasedURL,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminConfigSetCmd = cli.Command{
|
||||||
|
Name: "set",
|
||||||
|
Usage: "interactively set a config key parameters",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminConfigSet,
|
||||||
|
Flags: append(adminConfigEnvFlags, globalFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Enable webhook notification target for MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/ notify_webhook endpoint="http://localhost:8080/minio/events"
|
||||||
|
|
||||||
|
2. Change region name for the MinIO server to 'us-west-1'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/ region name=us-west-1
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// configSetMessage container to hold locks information.
|
||||||
|
type configSetMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
targetAlias string
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service status message.
|
||||||
|
func (u configSetMessage) String() (msg string) {
|
||||||
|
msg += console.Colorize("SetConfigSuccess",
|
||||||
|
"Setting new key has been successful.\n")
|
||||||
|
suggestion := fmt.Sprintf("mc admin service restart %s", u.targetAlias)
|
||||||
|
msg += console.Colorize("SetConfigSuccess",
|
||||||
|
fmt.Sprintf("Please restart your server with `%s`.\n", suggestion))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service status message.
|
||||||
|
func (u configSetMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// main config set function
|
||||||
|
func mainAdminConfigSet(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
// Check command arguments
|
||||||
|
checkAdminConfigSetSyntax(ctx)
|
||||||
|
|
||||||
|
// Set color preference of command outputs
|
||||||
|
console.SetColor("SetConfigSuccess", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
input := strings.Join(args.Tail(), " ")
|
||||||
|
|
||||||
|
if !strings.Contains(input, madmin.KvSeparator) {
|
||||||
|
// Call get config API
|
||||||
|
hr, e := client.HelpConfigKV(globalContext, args.Get(1), args.Get(2), ctx.IsSet("env"))
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get help for the sub-system")
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printMsg(configHelpMessage{
|
||||||
|
Value: hr,
|
||||||
|
envOnly: ctx.IsSet("env"),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Call set config API
|
||||||
|
fatalIf(probe.NewError(client.SetConfigKV(globalContext, input)),
|
||||||
|
"Cannot set '%s' to server", input)
|
||||||
|
|
||||||
|
// Print set config result
|
||||||
|
printMsg(configSetMessage{
|
||||||
|
targetAlias: aliasedURL,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminConfigCmd = cli.Command{
|
||||||
|
Name: "config",
|
||||||
|
Usage: "manage MinIO server configuration",
|
||||||
|
Action: mainAdminConfig,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminConfigGetCmd,
|
||||||
|
adminConfigSetCmd,
|
||||||
|
adminConfigResetCmd,
|
||||||
|
adminConfigHistoryCmd,
|
||||||
|
adminConfigRestoreCmd,
|
||||||
|
adminConfigExportCmd,
|
||||||
|
adminConfigImportCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminConfig is the handle for "mc admin config" command.
|
||||||
|
func mainAdminConfig(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "get", "set" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const logTimeFormat string = "15:04:05 MST 01/02/2006"
|
||||||
|
|
||||||
|
var adminConsoleFlags = []cli.Flag{
|
||||||
|
cli.IntFlag{
|
||||||
|
Name: "limit, 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 adminConsoleCmd = cli.Command{
|
||||||
|
Name: "console",
|
||||||
|
Usage: "show console logs for MinIO server",
|
||||||
|
Action: mainAdminConsole,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
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 {
|
||||||
|
madmin.LogInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON - jsonify loginfo
|
||||||
|
func (l logMessage) JSON() string {
|
||||||
|
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
|
||||||
|
var 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
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), "Cannot initialize admin client.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
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), "Cannot listen to console logs")
|
||||||
|
}
|
||||||
|
// drop nodeName from output if specified as cli arg
|
||||||
|
if node != "" {
|
||||||
|
logInfo.NodeName = ""
|
||||||
|
}
|
||||||
|
printMsg(logMessage{logInfo})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminGroupAddCmd = cli.Command{
|
||||||
|
Name: "add",
|
||||||
|
Usage: "add users to a new or existing group",
|
||||||
|
Action: mainAdminGroupAdd,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET GROUPNAME MEMBERS...
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Add users 'fivecent' and 'tencent' to the group 'allcents':
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents fivecent tencent
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// groupMessage container for content message structure
|
||||||
|
type groupMessage struct {
|
||||||
|
op string
|
||||||
|
Status string `json:"status"`
|
||||||
|
GroupName string `json:"groupName,omitempty"`
|
||||||
|
Groups []string `json:"groups,omitempty"`
|
||||||
|
Members []string `json:"members,omitempty"`
|
||||||
|
GroupStatus string `json:"groupStatus,omitempty"`
|
||||||
|
GroupPolicy string `json:"groupPolicy,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u groupMessage) String() string {
|
||||||
|
switch u.op {
|
||||||
|
case "list":
|
||||||
|
var s []string
|
||||||
|
for _, g := range u.Groups {
|
||||||
|
s = append(s, console.Colorize("GroupMessage", g))
|
||||||
|
}
|
||||||
|
return strings.Join(s, "\n")
|
||||||
|
case "disable":
|
||||||
|
return console.Colorize("GroupMessage", "Disabled group `"+u.GroupName+"` successfully.")
|
||||||
|
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.")
|
||||||
|
case "remove":
|
||||||
|
if len(u.Members) > 0 {
|
||||||
|
membersStr := fmt.Sprintf("{%s}", strings.Join(u.Members, ","))
|
||||||
|
return console.Colorize("GroupMessage", "Removed members "+membersStr+" from group "+u.GroupName+" successfully.")
|
||||||
|
}
|
||||||
|
return console.Colorize("GroupMessage", "Removed group "+u.GroupName+" successfully.")
|
||||||
|
case "info":
|
||||||
|
return strings.Join([]string{
|
||||||
|
console.Colorize("GroupMessage", "Group: "+u.GroupName),
|
||||||
|
console.Colorize("GroupMessage", "Status: "+u.GroupStatus),
|
||||||
|
console.Colorize("GroupMessage", "Policy: "+u.GroupPolicy),
|
||||||
|
console.Colorize("GroupMessage", "Members: "+strings.Join(u.Members, ",")),
|
||||||
|
}, "\n")
|
||||||
|
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u groupMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(jsonMessageBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroupAdd is the handle for "mc admin group add" command.
|
||||||
|
func mainAdminGroupAdd(ctx *cli.Context) error {
|
||||||
|
checkAdminGroupAddSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("GroupMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
members := []string{}
|
||||||
|
for i := 2; i < ctx.NArg(); i++ {
|
||||||
|
members = append(members, args.Get(i))
|
||||||
|
}
|
||||||
|
gAddRemove := madmin.GroupAddRemove{
|
||||||
|
Group: args.Get(1),
|
||||||
|
Members: members,
|
||||||
|
IsRemove: false,
|
||||||
|
}
|
||||||
|
fatalIf(probe.NewError(client.UpdateGroupMembers(globalContext, gAddRemove)).Trace(args...), "Cannot add new group")
|
||||||
|
|
||||||
|
printMsg(groupMessage{
|
||||||
|
op: "add",
|
||||||
|
GroupName: args.Get(1),
|
||||||
|
Members: members,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Client (C) 2015 Minio, Inc.
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,21 +14,29 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package cmd
|
||||||
|
|
||||||
// commonPrefix returns the longest common prefix between two strings.
|
import (
|
||||||
func commonPrefix(first, second string) string {
|
"github.com/minio/cli"
|
||||||
if first == "" || second == "" {
|
)
|
||||||
return ""
|
|
||||||
}
|
var adminGroupDisableCmd = cli.Command{
|
||||||
if first > second {
|
Name: "disable",
|
||||||
// Pick the shorter one for looping.
|
Usage: "Disable a group",
|
||||||
first, second = second, first
|
Action: mainAdminGroupEnableDisable,
|
||||||
}
|
Before: initBeforeRunningCmd,
|
||||||
for i := range first {
|
Flags: globalFlags,
|
||||||
if first[i] != second[i] {
|
CustomHelpTemplate: `NAME:
|
||||||
return first[:i]
|
{{.HelpName}} - {{.Usage}}
|
||||||
}
|
|
||||||
}
|
USAGE:
|
||||||
return first
|
{{.HelpName}} TARGET GROUPNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Disable group 'allcents'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents
|
||||||
|
`,
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminGroupEnableCmd = cli.Command{
|
||||||
|
Name: "enable",
|
||||||
|
Usage: "Enable a group",
|
||||||
|
Action: mainAdminGroupEnableDisable,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET GROUPNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Enable group 'allcents'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroupEnableDisable is the handle for "mc admin group enable|disable" command.
|
||||||
|
func mainAdminGroupEnableDisable(ctx *cli.Context) error {
|
||||||
|
checkAdminGroupEnableSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("GroupMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
group := args.Get(1)
|
||||||
|
var err1 error
|
||||||
|
var status madmin.GroupStatus
|
||||||
|
if ctx.Command.Name == "enable" {
|
||||||
|
status = madmin.GroupEnabled
|
||||||
|
} else if ctx.Command.Name == "disable" {
|
||||||
|
status = madmin.GroupDisabled
|
||||||
|
} else {
|
||||||
|
err1 = errors.New("cannot happen")
|
||||||
|
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")
|
||||||
|
}
|
||||||
|
err1 = client.SetGroupStatus(globalContext, group, status)
|
||||||
|
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group enable")
|
||||||
|
|
||||||
|
printMsg(groupMessage{
|
||||||
|
op: ctx.Command.Name,
|
||||||
|
GroupName: group,
|
||||||
|
GroupStatus: string(status),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminGroupInfoCmd = cli.Command{
|
||||||
|
Name: "info",
|
||||||
|
Usage: "display group info",
|
||||||
|
Action: mainAdminGroupInfo,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET GROUPNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get info on group 'allcents'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroupInfo is the handle for "mc admin group info" command.
|
||||||
|
func mainAdminGroupInfo(ctx *cli.Context) error {
|
||||||
|
checkAdminGroupInfoSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("GroupMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
group := args.Get(1)
|
||||||
|
gd, err1 := client.GetGroupDescription(globalContext, group)
|
||||||
|
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group info")
|
||||||
|
|
||||||
|
printMsg(groupMessage{
|
||||||
|
op: "info",
|
||||||
|
GroupName: group,
|
||||||
|
GroupStatus: gd.Status,
|
||||||
|
GroupPolicy: gd.Policy,
|
||||||
|
Members: gd.Members,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminGroupListCmd = cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "display list of groups",
|
||||||
|
Action: mainAdminGroupList,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. List all groups.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroupList is the handle for "mc admin group list" command.
|
||||||
|
func mainAdminGroupList(ctx *cli.Context) error {
|
||||||
|
checkAdminGroupListSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("GroupMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
gs, err1 := client.ListGroups(globalContext)
|
||||||
|
fatalIf(probe.NewError(err1).Trace(args...), "Could not get group list")
|
||||||
|
|
||||||
|
printMsg(groupMessage{
|
||||||
|
op: "list",
|
||||||
|
Groups: gs,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminGroupRemoveCmd = cli.Command{
|
||||||
|
Name: "remove",
|
||||||
|
Usage: "remove group or members from a group",
|
||||||
|
Action: mainAdminGroupRemove,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET GROUPNAME [USERNAMES...]
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Remove members 'tencent' and 'fivecent' from group 'allcents'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents tencent fivecent
|
||||||
|
|
||||||
|
2. Remove group 'allcents'.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio allcents
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroupRemove is the handle for "mc admin group remove" command.
|
||||||
|
func mainAdminGroupRemove(ctx *cli.Context) error {
|
||||||
|
checkAdminGroupRemoveSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("GroupMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
members := []string{}
|
||||||
|
for i := 2; i < ctx.NArg(); i++ {
|
||||||
|
members = append(members, args.Get(i))
|
||||||
|
}
|
||||||
|
gAddRemove := madmin.GroupAddRemove{
|
||||||
|
Group: args.Get(1),
|
||||||
|
Members: members,
|
||||||
|
IsRemove: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
e := client.UpdateGroupMembers(globalContext, gAddRemove)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Could not perform remove operation")
|
||||||
|
|
||||||
|
printMsg(groupMessage{
|
||||||
|
op: "remove",
|
||||||
|
GroupName: args.Get(1),
|
||||||
|
Members: members,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminGroupCmd = cli.Command{
|
||||||
|
Name: "group",
|
||||||
|
Usage: "manage groups",
|
||||||
|
Action: mainAdminGroup,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminGroupAddCmd,
|
||||||
|
adminGroupRemoveCmd,
|
||||||
|
adminGroupInfoCmd,
|
||||||
|
adminGroupListCmd,
|
||||||
|
adminGroupEnableCmd,
|
||||||
|
adminGroupDisableCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminGroup is the handle for "mc admin config" command.
|
||||||
|
func mainAdminGroup(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "get", "set" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type hri struct {
|
||||||
|
*madmin.HealResultItem
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHRI(i *madmin.HealResultItem) *hri {
|
||||||
|
return &hri{i}
|
||||||
|
}
|
||||||
|
|
||||||
|
// getObjectHCCChange - returns before and after color change for
|
||||||
|
// objects
|
||||||
|
func (h hri) getObjectHCCChange() (b, a col, err error) {
|
||||||
|
parityShards := h.ParityBlocks
|
||||||
|
dataShards := h.DataBlocks
|
||||||
|
|
||||||
|
onlineBefore, onlineAfter := h.GetOnlineCounts()
|
||||||
|
surplusShardsBeforeHeal := onlineBefore - dataShards
|
||||||
|
surplusShardsAfterHeal := onlineAfter - dataShards
|
||||||
|
|
||||||
|
b, err = getHColCode(surplusShardsBeforeHeal, parityShards)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a, err = getHColCode(surplusShardsAfterHeal, parityShards)
|
||||||
|
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
|
||||||
|
c, err = getHColCode(surplus, parity)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
onlineBefore, onlineAfter := h.GetOnlineCounts()
|
||||||
|
b, err = getColCode(onlineBefore)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a, err = getColCode(onlineAfter)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h hri) makeHealEntityString() string {
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemObject:
|
||||||
|
return h.Bucket + "/" + h.Object
|
||||||
|
case madmin.HealItemBucket:
|
||||||
|
return h.Bucket
|
||||||
|
case madmin.HealItemMetadata:
|
||||||
|
return "[disk-format]"
|
||||||
|
case madmin.HealItemBucketMetadata:
|
||||||
|
return fmt.Sprintf("[bucket-metadata]%s/%s", h.Bucket, h.Object)
|
||||||
|
}
|
||||||
|
return "** unexpected **"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h hri) getHRTypeAndName() (typ, name string) {
|
||||||
|
name = fmt.Sprintf("%s/%s", h.Bucket, h.Object)
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata:
|
||||||
|
typ = "system"
|
||||||
|
name = h.Detail
|
||||||
|
case madmin.HealItemBucketMetadata:
|
||||||
|
typ = "system"
|
||||||
|
name = "bucket-metadata:" + name
|
||||||
|
case madmin.HealItemBucket:
|
||||||
|
typ = "bucket"
|
||||||
|
case madmin.HealItemObject:
|
||||||
|
typ = "object"
|
||||||
|
default:
|
||||||
|
typ = fmt.Sprintf("!! Unknown heal result record %#v !!", h)
|
||||||
|
name = typ
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h hri) getHealResultStr() string {
|
||||||
|
typ, name := h.getHRTypeAndName()
|
||||||
|
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||||
|
return typ + ":" + name
|
||||||
|
default:
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,446 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
lineWidth = 80
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
hColOrder = []col{colRed, colYellow, colGreen}
|
||||||
|
hColTable = map[int][]int{
|
||||||
|
1: {0, -1, 1},
|
||||||
|
2: {0, 1, 2},
|
||||||
|
3: {1, 2, 3},
|
||||||
|
4: {1, 2, 4},
|
||||||
|
5: {1, 3, 5},
|
||||||
|
6: {2, 4, 6},
|
||||||
|
7: {2, 4, 7},
|
||||||
|
8: {2, 5, 8},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
if surplusShards < 0 {
|
||||||
|
return colGrey, err
|
||||||
|
}
|
||||||
|
colRow := hColTable[parityShards]
|
||||||
|
for index, val := range colRow {
|
||||||
|
if val != -1 && surplusShards <= val {
|
||||||
|
return hColOrder[index], err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c, fmt.Errorf("cannot get a heal color code")
|
||||||
|
}
|
||||||
|
|
||||||
|
type uiData struct {
|
||||||
|
Bucket, Prefix string
|
||||||
|
Client *madmin.AdminClient
|
||||||
|
ClientToken string
|
||||||
|
ForceStart bool
|
||||||
|
HealOpts *madmin.HealOpts
|
||||||
|
LastItem *hri
|
||||||
|
|
||||||
|
// Total time since heal start
|
||||||
|
HealDuration time.Duration
|
||||||
|
|
||||||
|
// Accumulated statistics of heal result records
|
||||||
|
BytesScanned int64
|
||||||
|
|
||||||
|
// Counter for objects, and another counter for all kinds of
|
||||||
|
// items
|
||||||
|
ObjectsScanned, ItemsScanned int64
|
||||||
|
|
||||||
|
// Counters for healed objects and all kinds of healed items
|
||||||
|
ObjectsHealed, ItemsHealed int64
|
||||||
|
|
||||||
|
// Map from online drives to number of objects with that many
|
||||||
|
// online drives.
|
||||||
|
ObjectsByOnlineDrives map[int]int64
|
||||||
|
// Map of health color code to number of objects with that
|
||||||
|
// health color code.
|
||||||
|
HealthCols map[col]int64
|
||||||
|
|
||||||
|
// channel to receive a prompt string to indicate activity on
|
||||||
|
// the terminal
|
||||||
|
CurChan (<-chan string)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) updateStats(i madmin.HealResultItem) error {
|
||||||
|
if i.Type == madmin.HealItemObject {
|
||||||
|
// Objects whose size could not be found have -1 size
|
||||||
|
// returned.
|
||||||
|
if i.ObjectSize >= 0 {
|
||||||
|
ui.BytesScanned += i.ObjectSize
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.ObjectsScanned++
|
||||||
|
}
|
||||||
|
ui.ItemsScanned++
|
||||||
|
|
||||||
|
beforeUp, afterUp := i.GetOnlineCounts()
|
||||||
|
if afterUp > beforeUp {
|
||||||
|
if i.Type == madmin.HealItemObject {
|
||||||
|
ui.ObjectsHealed++
|
||||||
|
}
|
||||||
|
ui.ItemsHealed++
|
||||||
|
}
|
||||||
|
ui.ObjectsByOnlineDrives[afterUp]++
|
||||||
|
|
||||||
|
// Update health color stats:
|
||||||
|
|
||||||
|
// Fetch health color after heal:
|
||||||
|
var err error
|
||||||
|
var afterCol col
|
||||||
|
h := newHRI(&i)
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||||
|
_, afterCol, err = h.getReplicatedFileHCCChange()
|
||||||
|
default:
|
||||||
|
_, afterCol, err = h.getObjectHCCChange()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.HealthCols[afterCol]++
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) updateDuration(s *madmin.HealTaskStatus) {
|
||||||
|
ui.HealDuration = UTCNow().Sub(s.StartTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) getProgress() (oCount, objSize, duration string) {
|
||||||
|
oCount = humanize.Comma(ui.ObjectsScanned)
|
||||||
|
|
||||||
|
duration = ui.HealDuration.Round(time.Second).String()
|
||||||
|
|
||||||
|
bytesScanned := float64(ui.BytesScanned)
|
||||||
|
|
||||||
|
// Compute unit for object size
|
||||||
|
magnitudes := []float64{1 << 10, 1 << 20, 1 << 30, 1 << 40, 1 << 50, 1 << 60}
|
||||||
|
units := []string{"B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB"}
|
||||||
|
var i int
|
||||||
|
for i = 0; i < len(magnitudes); i++ {
|
||||||
|
if bytesScanned <= magnitudes[i] {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
numUnits := int(bytesScanned * (1 << 10) / magnitudes[i])
|
||||||
|
objSize = fmt.Sprintf("%d %s", numUnits, units[i])
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) getPercentsNBars() (p map[col]float64, b map[col]string) {
|
||||||
|
// barChar, emptyBarChar := "█", "░"
|
||||||
|
barChar, emptyBarChar := "█", " "
|
||||||
|
barLen := 12
|
||||||
|
sum := float64(ui.ItemsScanned)
|
||||||
|
cols := []col{colGrey, colRed, colYellow, colGreen}
|
||||||
|
|
||||||
|
p = make(map[col]float64, len(cols))
|
||||||
|
b = make(map[col]string, len(cols))
|
||||||
|
var filledLen int
|
||||||
|
for _, col := range cols {
|
||||||
|
v := float64(ui.HealthCols[col])
|
||||||
|
if sum == 0 {
|
||||||
|
p[col] = 0
|
||||||
|
filledLen = 0
|
||||||
|
} else {
|
||||||
|
p[col] = v * 100 / sum
|
||||||
|
// round up the filled part
|
||||||
|
filledLen = int(math.Ceil(float64(barLen) * v / sum))
|
||||||
|
}
|
||||||
|
b[col] = strings.Repeat(barChar, filledLen) +
|
||||||
|
strings.Repeat(emptyBarChar, barLen-filledLen)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) printItemsQuietly(s *madmin.HealTaskStatus) (err error) {
|
||||||
|
lpad := func(s col) string {
|
||||||
|
return fmt.Sprintf("%-6s", string(s))
|
||||||
|
}
|
||||||
|
rpad := func(s col) string {
|
||||||
|
return fmt.Sprintf("%6s", string(s))
|
||||||
|
}
|
||||||
|
printColStr := func(before, after col) {
|
||||||
|
console.PrintC("[" + lpad(before) + " -> " + rpad(after) + "] ")
|
||||||
|
}
|
||||||
|
|
||||||
|
var b, a col
|
||||||
|
for _, item := range s.Items {
|
||||||
|
h := newHRI(&item)
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||||
|
b, a, err = h.getReplicatedFileHCCChange()
|
||||||
|
default:
|
||||||
|
b, a, err = h.getObjectHCCChange()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
printColStr(b, a)
|
||||||
|
hrStr := h.getHealResultStr()
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata, madmin.HealItemBucketMetadata:
|
||||||
|
console.PrintC(fmt.Sprintln("**", hrStr, "**"))
|
||||||
|
default:
|
||||||
|
console.PrintC(hrStr, "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) printStatsQuietly(s *madmin.HealTaskStatus) {
|
||||||
|
totalObjects, totalSize, totalTime := ui.getProgress()
|
||||||
|
|
||||||
|
healedStr := fmt.Sprintf("Healed:\t%s/%s objects; %s in %s\n",
|
||||||
|
humanize.Comma(ui.ObjectsHealed), totalObjects,
|
||||||
|
totalSize, totalTime)
|
||||||
|
|
||||||
|
console.PrintC(healedStr)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) printItemsJSON(s *madmin.HealTaskStatus) (err error) {
|
||||||
|
type healRec struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Before struct {
|
||||||
|
Color string `json:"color"`
|
||||||
|
Offline int `json:"offline"`
|
||||||
|
Online int `json:"online"`
|
||||||
|
Missing int `json:"missing"`
|
||||||
|
Corrupted int `json:"corrupted"`
|
||||||
|
Drives []madmin.HealDriveInfo `json:"drives"`
|
||||||
|
} `json:"before"`
|
||||||
|
After struct {
|
||||||
|
Color string `json:"color"`
|
||||||
|
Offline int `json:"offline"`
|
||||||
|
Online int `json:"online"`
|
||||||
|
Missing int `json:"missing"`
|
||||||
|
Corrupted int `json:"corrupted"`
|
||||||
|
Drives []madmin.HealDriveInfo `json:"drives"`
|
||||||
|
} `json:"after"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
}
|
||||||
|
makeHR := func(h *hri) (r healRec, err error) {
|
||||||
|
r.Status = "success"
|
||||||
|
r.Type, r.Name = h.getHRTypeAndName()
|
||||||
|
|
||||||
|
var b, a col
|
||||||
|
switch h.Type {
|
||||||
|
case madmin.HealItemMetadata, madmin.HealItemBucket:
|
||||||
|
b, a, err = h.getReplicatedFileHCCChange()
|
||||||
|
default:
|
||||||
|
if h.Type == madmin.HealItemObject {
|
||||||
|
r.Size = h.ObjectSize
|
||||||
|
}
|
||||||
|
b, a, err = h.getObjectHCCChange()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return r, err
|
||||||
|
}
|
||||||
|
r.Before.Color = strings.ToLower(string(b))
|
||||||
|
r.After.Color = strings.ToLower(string(a))
|
||||||
|
r.Before.Online, r.After.Online = h.GetOnlineCounts()
|
||||||
|
r.Before.Missing, r.After.Missing = h.GetMissingCounts()
|
||||||
|
r.Before.Corrupted, r.After.Corrupted = h.GetCorruptedCounts()
|
||||||
|
r.Before.Offline, r.After.Offline = h.GetOfflineCounts()
|
||||||
|
r.Before.Drives = h.Before.Drives
|
||||||
|
r.After.Drives = h.After.Drives
|
||||||
|
return r, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range s.Items {
|
||||||
|
h := newHRI(&item)
|
||||||
|
r, err := makeHR(h)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
jsonBytes, err := json.MarshalIndent(r, "", " ")
|
||||||
|
fatalIf(probe.NewError(err), "Unable to marshal to JSON.")
|
||||||
|
console.Println(string(jsonBytes))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) printStatsJSON(s *madmin.HealTaskStatus) {
|
||||||
|
var summary struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ObjectsScanned int64 `json:"objects_scanned"`
|
||||||
|
ObjectsHealed int64 `json:"objects_healed"`
|
||||||
|
ItemsScanned int64 `json:"items_scanned"`
|
||||||
|
ItemsHealed int64 `json:"items_healed"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
ElapsedTime int64 `json:"duration"`
|
||||||
|
}
|
||||||
|
|
||||||
|
summary.Status = "success"
|
||||||
|
summary.Type = "summary"
|
||||||
|
|
||||||
|
summary.ObjectsScanned = ui.ObjectsScanned
|
||||||
|
summary.ObjectsHealed = ui.ObjectsHealed
|
||||||
|
summary.ItemsScanned = ui.ItemsScanned
|
||||||
|
summary.ItemsHealed = ui.ItemsHealed
|
||||||
|
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.")
|
||||||
|
console.Println(string(jBytes))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) updateUI(s *madmin.HealTaskStatus) (err error) {
|
||||||
|
itemCount := len(s.Items)
|
||||||
|
h := ui.LastItem
|
||||||
|
if itemCount > 0 {
|
||||||
|
item := s.Items[itemCount-1]
|
||||||
|
h = newHRI(&item)
|
||||||
|
ui.LastItem = h
|
||||||
|
}
|
||||||
|
scannedStr := "** waiting for status from server **"
|
||||||
|
if h != nil {
|
||||||
|
scannedStr = lineTrunc(h.makeHealEntityString(), lineWidth-len("Scanned: "))
|
||||||
|
}
|
||||||
|
|
||||||
|
totalObjects, totalSize, totalTime := ui.getProgress()
|
||||||
|
healedStr := fmt.Sprintf("%s/%s objects; %s in %s",
|
||||||
|
humanize.Comma(ui.ObjectsHealed), totalObjects,
|
||||||
|
totalSize, totalTime)
|
||||||
|
|
||||||
|
console.Print(console.Colorize("HealUpdateUI", fmt.Sprintf(" %s", <-ui.CurChan)))
|
||||||
|
console.PrintC(fmt.Sprintf(" %s\n", scannedStr))
|
||||||
|
console.PrintC(fmt.Sprintf(" %s\n", healedStr))
|
||||||
|
|
||||||
|
dspOrder := []col{colGreen, colYellow, colRed, colGrey}
|
||||||
|
printColors := []*color.Color{}
|
||||||
|
for _, c := range dspOrder {
|
||||||
|
printColors = append(printColors, getPrintCol(c))
|
||||||
|
}
|
||||||
|
t := console.NewTable(printColors, []bool{false, true, true}, 4)
|
||||||
|
|
||||||
|
percentMap, barMap := ui.getPercentsNBars()
|
||||||
|
cellText := make([][]string, len(dspOrder))
|
||||||
|
for i := range cellText {
|
||||||
|
cellText[i] = []string{
|
||||||
|
string(dspOrder[i]),
|
||||||
|
fmt.Sprint(humanize.Comma(ui.HealthCols[dspOrder[i]])),
|
||||||
|
fmt.Sprintf("%5.1f%% %s", percentMap[dspOrder[i]], barMap[dspOrder[i]]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
t.DisplayTable(cellText)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) UpdateDisplay(s *madmin.HealTaskStatus) (err error) {
|
||||||
|
// Update state
|
||||||
|
ui.updateDuration(s)
|
||||||
|
for _, i := range s.Items {
|
||||||
|
ui.updateStats(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update display
|
||||||
|
switch {
|
||||||
|
case globalJSON:
|
||||||
|
err = ui.printItemsJSON(s)
|
||||||
|
case globalQuiet:
|
||||||
|
err = ui.printItemsQuietly(s)
|
||||||
|
default:
|
||||||
|
err = ui.updateUI(s)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) healResumeMsg(aliasedURL string) string {
|
||||||
|
var flags string
|
||||||
|
if ui.HealOpts.Recursive {
|
||||||
|
flags += "--recursive "
|
||||||
|
}
|
||||||
|
if ui.HealOpts.DryRun {
|
||||||
|
flags += "--dry-run "
|
||||||
|
}
|
||||||
|
return fmt.Sprintf("Healing is backgrounded, to resume watching use `mc admin heal %s %s`", flags, aliasedURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ui *uiData) DisplayAndFollowHealStatus(aliasedURL string) (res madmin.HealTaskStatus, err error) {
|
||||||
|
quitMsg := ui.healResumeMsg(aliasedURL)
|
||||||
|
|
||||||
|
firstIter := true
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-globalContext.Done():
|
||||||
|
return res, errors.New(quitMsg)
|
||||||
|
default:
|
||||||
|
_, res, err = ui.Client.Heal(globalContext, ui.Bucket, ui.Prefix, *ui.HealOpts,
|
||||||
|
ui.ClientToken, ui.ForceStart, false)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
if firstIter {
|
||||||
|
firstIter = false
|
||||||
|
} else {
|
||||||
|
if !globalQuiet && !globalJSON {
|
||||||
|
console.RewindLines(8)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err = ui.UpdateDisplay(&res)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Summary == "finished" {
|
||||||
|
if globalJSON {
|
||||||
|
ui.printStatsJSON(&res)
|
||||||
|
} else if globalQuiet {
|
||||||
|
ui.printStatsQuietly(&res)
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.Summary == "stopped" {
|
||||||
|
return res, fmt.Errorf("Heal had an error - %s", res.FailureDetail)
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,282 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017, 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
scanNormalMode = "normal"
|
||||||
|
scanDeepMode = "deep"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminHealFlags = []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "scan",
|
||||||
|
Usage: "select the healing scan mode (normal/deep)",
|
||||||
|
Value: scanNormalMode,
|
||||||
|
},
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminHealCmd = cli.Command{
|
||||||
|
Name: "heal",
|
||||||
|
Usage: "heal disks, buckets and objects on MinIO server",
|
||||||
|
Action: mainAdminHeal,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: append(adminHealFlags, globalFlags...),
|
||||||
|
HideHelpCommand: true,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} [FLAGS] TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
SCAN MODES:
|
||||||
|
normal (default): Heal objects which are missing on one or more disks.
|
||||||
|
deep : Heal objects which are missing or with silent data corruption on one or more disks.
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
1. To format newly replaced disks in a MinIO server with alias 'myminio'
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
|
||||||
|
2. Heal 'testbucket' in a MinIO server with alias 'myminio'
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/testbucket/
|
||||||
|
|
||||||
|
3. Heal all objects under 'dir' prefix
|
||||||
|
{{.Prompt}} {{.HelpName}} --recursive myminio/testbucket/dir/
|
||||||
|
|
||||||
|
4. Issue a dry-run heal operation to inspect objects health but not heal them
|
||||||
|
{{.Prompt}} {{.HelpName}} --dry-run myminio
|
||||||
|
|
||||||
|
5. Issue a dry-run heal operation to inspect objects health under 'dir' prefix
|
||||||
|
{{.Prompt}} {{.HelpName}} --recursive --dry-run myminio/testbucket/dir/
|
||||||
|
|
||||||
|
6. Force start a running heal sequence (meaning it will force kill the running heal sequence and start a new one)
|
||||||
|
{{.Prompt}} {{.HelpName}} --force-start myminio/testbucket/dir/
|
||||||
|
|
||||||
|
7. Force stop a running heal sequence (meaning it will force kill the running heal sequence)
|
||||||
|
{{.Prompt}} {{.HelpName}} --force-stop myminio/testbucket/dir/
|
||||||
|
|
||||||
|
8. Issue a dry-run heal operation to inspect objects health under 'dir' prefix
|
||||||
|
{{.Prompt}} {{.HelpName}} --dry-run myminio/testbucket/dir/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkAdminHealSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "heal", 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// stopHealMessage is container for stop heal success and failure messages.
|
||||||
|
type stopHealMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized stop heal message.
|
||||||
|
func (s stopHealMessage) String() string {
|
||||||
|
return console.Colorize("HealStopped", "Heal stopped successfully at `"+s.Alias+"`.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified stop heal message.
|
||||||
|
func (s stopHealMessage) JSON() string {
|
||||||
|
stopHealJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(stopHealJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// backgroundHealStatusMessage is container for stop heal success and failure messages.
|
||||||
|
type backgroundHealStatusMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
HealInfo madmin.BgHealState
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized to show background heal status message.
|
||||||
|
func (s backgroundHealStatusMessage) String() string {
|
||||||
|
dot := console.Colorize("Dot", " ● ")
|
||||||
|
|
||||||
|
healPrettyMsg := console.Colorize("HealBackgroundTitle", "Background healing status:\n")
|
||||||
|
healPrettyMsg += dot + fmt.Sprintf("%s item(s) scanned in total\n",
|
||||||
|
console.Colorize("HealBackground", s.HealInfo.ScannedItemsCount))
|
||||||
|
|
||||||
|
lastHealingTime := dot + "Never executed"
|
||||||
|
if !s.HealInfo.LastHealActivity.IsZero() {
|
||||||
|
lastHealingTime = dot + "Completed " + timeDurationToHumanizedDuration(time.Since(s.HealInfo.LastHealActivity)).StringShort() + " ago"
|
||||||
|
}
|
||||||
|
healPrettyMsg += console.Colorize("HealBackground", lastHealingTime) + "\n"
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
|
if !s.HealInfo.NextHealRound.IsZero() && s.HealInfo.NextHealRound.After(now) {
|
||||||
|
nextHealingRound := timeDurationToHumanizedDuration(s.HealInfo.NextHealRound.Sub(now)).StringShort()
|
||||||
|
healPrettyMsg += dot + fmt.Sprintf("Next scheduled in %s\n", console.Colorize("HealBackground", nextHealingRound))
|
||||||
|
}
|
||||||
|
|
||||||
|
return healPrettyMsg
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified stop heal message.
|
||||||
|
func (s backgroundHealStatusMessage) JSON() string {
|
||||||
|
healJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(healJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func transformScanArg(scanArg string) madmin.HealScanMode {
|
||||||
|
switch scanArg {
|
||||||
|
case "deep":
|
||||||
|
return madmin.HealDeepScan
|
||||||
|
}
|
||||||
|
return madmin.HealNormalScan
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminHeal - the entry function of heal command
|
||||||
|
func mainAdminHeal(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
// Check for command syntax
|
||||||
|
checkAdminHealSyntax(ctx)
|
||||||
|
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
aliasedURL := args.Get(0)
|
||||||
|
|
||||||
|
console.SetColor("Heal", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("Dot", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("HealBackgroundTitle", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("HealBackground", color.New(color.Bold))
|
||||||
|
console.SetColor("HealUpdateUI", color.New(color.FgYellow, color.Bold))
|
||||||
|
console.SetColor("HealStopped", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// Create a new MinIO Admin Client
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
if err != nil {
|
||||||
|
fatalIf(err.Trace(aliasedURL), "Cannot 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]
|
||||||
|
|
||||||
|
clnt, err := newClient(aliasedURL)
|
||||||
|
if err != nil {
|
||||||
|
fatalIf(err.Trace(clnt.GetURL().String()), "Unable to create client for URL ", aliasedURL)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for content := range clnt.List(globalContext, false, false, false, DirNone) {
|
||||||
|
if content.Err != nil {
|
||||||
|
fatalIf(content.Err.Trace(clnt.GetURL().String()), "Unable to heal bucket `"+bucket+"`.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the background heal status when the user
|
||||||
|
// doesn't pass a bucket or --recursive flag.
|
||||||
|
if bucket == "" && !ctx.Bool("recursive") {
|
||||||
|
bgHealStatus, berr := client.BackgroundHealStatus(globalContext)
|
||||||
|
fatalIf(probe.NewError(berr), "Failed to get the status of the background heal.")
|
||||||
|
printMsg(backgroundHealStatusMessage{Status: "success", HealInfo: bgHealStatus})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := madmin.HealOpts{
|
||||||
|
ScanMode: transformScanArg(ctx.String("scan")),
|
||||||
|
Remove: ctx.Bool("remove"),
|
||||||
|
Recursive: ctx.Bool("recursive"),
|
||||||
|
DryRun: ctx.Bool("dry-run"),
|
||||||
|
}
|
||||||
|
|
||||||
|
forceStart := ctx.Bool("force-start")
|
||||||
|
forceStop := ctx.Bool("force-stop")
|
||||||
|
if forceStop {
|
||||||
|
_, _, herr := client.Heal(globalContext, bucket, prefix, opts, "", forceStart, forceStop)
|
||||||
|
fatalIf(probe.NewError(herr), "Failed to stop heal sequence.")
|
||||||
|
printMsg(stopHealMessage{Status: "success", Alias: aliasedURL})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
healStart, _, herr := client.Heal(globalContext, bucket, prefix, opts, "", forceStart, false)
|
||||||
|
fatalIf(probe.NewError(herr), "Failed to start heal sequence.")
|
||||||
|
|
||||||
|
ui := uiData{
|
||||||
|
Bucket: bucket,
|
||||||
|
Prefix: prefix,
|
||||||
|
Client: client,
|
||||||
|
ClientToken: healStart.ClientToken,
|
||||||
|
ForceStart: forceStart,
|
||||||
|
HealOpts: &opts,
|
||||||
|
ObjectsByOnlineDrives: make(map[int]int64),
|
||||||
|
HealthCols: make(map[col]int64),
|
||||||
|
CurChan: cursorAnimate(),
|
||||||
|
}
|
||||||
|
|
||||||
|
res, e := ui.DisplayAndFollowHealStatus(aliasedURL)
|
||||||
|
if e != nil {
|
||||||
|
if res.FailureDetail != "" {
|
||||||
|
data, _ := json.MarshalIndent(res, "", " ")
|
||||||
|
traceStr := string(data)
|
||||||
|
fatalIf(probe.NewError(e).Trace(aliasedURL, traceStr), "Unable to display heal status.")
|
||||||
|
} else {
|
||||||
|
fatalIf(probe.NewError(e).Trace(aliasedURL), "Unable to display heal status.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
|
"github.com/dustin/go-humanize/english"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminInfoCmd = cli.Command{
|
||||||
|
Name: "info",
|
||||||
|
Usage: "display MinIO server information",
|
||||||
|
Action: mainAdminInfo,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get server information of the 'play' MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
func (u clusterStruct) String() (msg string) {
|
||||||
|
// Check cluster level "Status" field for error
|
||||||
|
if u.Status == "error" {
|
||||||
|
fatal(probe.NewError(errors.New(u.Error)), "Cannot get service status")
|
||||||
|
}
|
||||||
|
|
||||||
|
// If nothing has been collected, error out
|
||||||
|
if u.Info.Servers == nil {
|
||||||
|
fatal(probe.NewError(errors.New("Cannot get service status")), "")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialization
|
||||||
|
var totalOnlineDisksCluster int
|
||||||
|
var totalOfflineDisksCluster int
|
||||||
|
|
||||||
|
// Color palette initialization
|
||||||
|
console.SetColor("Info", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("InfoFail", color.New(color.FgRed, color.Bold))
|
||||||
|
|
||||||
|
// MinIO server type default
|
||||||
|
backendType := "Unknown"
|
||||||
|
// Set the type of MinIO server ("FS", "Erasure", "Unknown")
|
||||||
|
v := reflect.ValueOf(u.Info.Backend)
|
||||||
|
if v.Kind() == reflect.Map {
|
||||||
|
for _, key := range v.MapKeys() {
|
||||||
|
val := v.MapIndex(key)
|
||||||
|
switch t := val.Interface().(type) {
|
||||||
|
case string:
|
||||||
|
backendType = t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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" {
|
||||||
|
// "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\n", console.Colorize("InfoFail", "offline"))
|
||||||
|
// Continue to the next server
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print server title
|
||||||
|
msg += fmt.Sprintf("%s %s\n", console.Colorize("Info", dot), console.Colorize("PrintB", srv.Endpoint))
|
||||||
|
|
||||||
|
// Uptime
|
||||||
|
msg += fmt.Sprintf(" Uptime: %s\n", console.Colorize("Info",
|
||||||
|
humanize.RelTime(time.Now(), time.Now().Add(time.Duration(srv.Uptime)*time.Second), "", "")))
|
||||||
|
|
||||||
|
// Version
|
||||||
|
version := srv.Version
|
||||||
|
if srv.Version == "DEVELOPMENT.GOGET" {
|
||||||
|
version = "<development>"
|
||||||
|
}
|
||||||
|
msg += fmt.Sprintf(" Version: %s\n", version)
|
||||||
|
|
||||||
|
// Network info, only available for non-FS types
|
||||||
|
var connectionAlive int
|
||||||
|
totalNodes := strconv.Itoa(len(srv.Network))
|
||||||
|
if srv.Network != nil {
|
||||||
|
for _, v := range srv.Network {
|
||||||
|
if v == "online" {
|
||||||
|
connectionAlive++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
displayNwInfo := strconv.Itoa(connectionAlive) + "/" + totalNodes
|
||||||
|
msg += fmt.Sprintf(" Network: %s %s\n", displayNwInfo, console.Colorize("Info", "OK "))
|
||||||
|
}
|
||||||
|
|
||||||
|
if backendType != "FS" {
|
||||||
|
// Info about drives on a server, only available for non-FS types
|
||||||
|
var OffDisks int
|
||||||
|
var OnDisks int
|
||||||
|
var dispNoOfDisks string
|
||||||
|
for _, disk := range srv.Disks {
|
||||||
|
if disk.State == "ok" {
|
||||||
|
OnDisks++
|
||||||
|
} else {
|
||||||
|
OffDisks++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
totalDisksPerServer := OnDisks + OffDisks
|
||||||
|
totalOnlineDisksCluster += OnDisks
|
||||||
|
totalOfflineDisksCluster += OffDisks
|
||||||
|
|
||||||
|
dispNoOfDisks = strconv.Itoa(OnDisks) + "/" + strconv.Itoa(totalDisksPerServer)
|
||||||
|
msg += fmt.Sprintf(" Drives: %s %s\n", dispNoOfDisks, console.Colorize("Info", "OK "))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
msg += "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Summary on used space, total no of buckets and
|
||||||
|
// total no of objects at the Cluster level
|
||||||
|
usedTotal := humanize.IBytes(uint64(u.Info.Usage.Size))
|
||||||
|
if u.Info.Buckets.Count > 0 {
|
||||||
|
msg += fmt.Sprintf("%s Used, %s, %s\n", usedTotal,
|
||||||
|
english.Plural(int(u.Info.Buckets.Count), "Bucket", ""),
|
||||||
|
english.Plural(int(u.Info.Objects.Count), "Object", ""))
|
||||||
|
}
|
||||||
|
if backendType != "FS" {
|
||||||
|
// Summary on total no of online and total
|
||||||
|
// number of offline disks at the Cluster level
|
||||||
|
msg += fmt.Sprintf("%s online, %s offline\n",
|
||||||
|
english.Plural(totalOnlineDisksCluster, "drive", ""),
|
||||||
|
english.Plural(totalOfflineDisksCluster, "drive", ""))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the last new line if any
|
||||||
|
// since this is a String() function
|
||||||
|
msg = strings.TrimSuffix(msg, "\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonifies service status message.
|
||||||
|
func (u clusterStruct) JSON() string {
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminInfo(ctx *cli.Context) error {
|
||||||
|
checkAdminInfoSyntax(ctx)
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
var clusterInfo clusterStruct
|
||||||
|
// Fetch info of all servers (cluster or single server)
|
||||||
|
admInfo, e := client.ServerInfo(globalContext)
|
||||||
|
if e != nil {
|
||||||
|
clusterInfo.Status = "error"
|
||||||
|
clusterInfo.Error = e.Error()
|
||||||
|
} else {
|
||||||
|
clusterInfo.Status = "success"
|
||||||
|
clusterInfo.Error = ""
|
||||||
|
}
|
||||||
|
clusterInfo.Info = admInfo
|
||||||
|
printMsg(clusterStruct(clusterInfo))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminKMSKeyStatusCmd = cli.Command{
|
||||||
|
Name: "status",
|
||||||
|
Usage: "request status information for a KMS master key",
|
||||||
|
Action: mainAdminKMSKeyStatus,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET [KEY_NAME]
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get default master key and its status from a MinIO server/cluster.
|
||||||
|
$ {{.HelpName}} play
|
||||||
|
2. Get the status of one particular master key from a MinIO server/cluster.
|
||||||
|
$ {{.HelpName}} play my-master-key
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := newAdminClient(ctx.Args().Get(0))
|
||||||
|
fatalIf(err, "Cannot get a configured admin connection.")
|
||||||
|
|
||||||
|
var keyID string
|
||||||
|
if len(ctx.Args()) == 2 {
|
||||||
|
keyID = ctx.Args().Get(1)
|
||||||
|
}
|
||||||
|
status, e := client.GetKeyStatus(globalContext, keyID)
|
||||||
|
fatalIf(probe.NewError(e), "Failed to get status information")
|
||||||
|
|
||||||
|
printMsg(kmsKeyStatusMsg(*status))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type kmsKeyStatusMsg madmin.KMSKeyStatus
|
||||||
|
|
||||||
|
func (s kmsKeyStatusMsg) String() string {
|
||||||
|
msg := fmt.Sprintf("Key: %s\n", s.KeyID)
|
||||||
|
if s.EncryptionErr == "" {
|
||||||
|
msg = fmt.Sprintf("%s %s", msg, "\t • Encryption ✔\n")
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%s \t • Encryption failed: %s\n", msg, s.EncryptionErr)
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.DecryptionErr == "" {
|
||||||
|
msg = fmt.Sprintf("%s %s", msg, "\t • Decryption ✔\n")
|
||||||
|
} else {
|
||||||
|
return fmt.Sprintf("%s \t • Decryption failed: %s\n", msg, s.DecryptionErr)
|
||||||
|
}
|
||||||
|
return msg
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s kmsKeyStatusMsg) JSON() string {
|
||||||
|
const fmtStr = `{"key-id":"%s","encryption-error":"%s","decryption-error":"%s"}`
|
||||||
|
return fmt.Sprintf(fmtStr, s.KeyID, s.EncryptionErr, s.DecryptionErr)
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminKMSKeyCmd = cli.Command{
|
||||||
|
Name: "key",
|
||||||
|
Usage: "Manage KMS master keys: Request key status information",
|
||||||
|
Action: mainAdminKMSKey,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminKMSKeyStatusCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminKMSKey is the handle for the "mc admin kms key" command.
|
||||||
|
func mainAdminKMSKey(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Cloud Storage, (C) 2015 Minio, Inc.
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,28 +14,23 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package user_test
|
package cmd
|
||||||
|
|
||||||
import (
|
import "github.com/minio/cli"
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/minio/minio/pkg/user"
|
var adminKMSCmd = cli.Command{
|
||||||
|
Name: "kms",
|
||||||
. "gopkg.in/check.v1"
|
Usage: "perform KMS management operations",
|
||||||
)
|
Action: mainAdminKMS,
|
||||||
|
Flags: globalFlags,
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
Subcommands: []cli.Command{
|
||||||
|
adminKMSKeyCmd,
|
||||||
type MySuite struct{}
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
var _ = Suite(&MySuite{})
|
|
||||||
|
|
||||||
func (s *MySuite) TestUser(c *C) {
|
|
||||||
_, err := user.Current()
|
|
||||||
c.Assert(err, IsNil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *MySuite) TestHomeDir(c *C) {
|
// mainAdminKMS is the handle for the "mc admin kms" command.
|
||||||
_, err := user.HomeDir()
|
func mainAdminKMS(ctx *cli.Context) error {
|
||||||
c.Assert(err, IsNil)
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2016, 2017 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var (
|
||||||
|
adminFlags = []cli.Flag{}
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// dot represents a list item, for eg. server status - online (green) or offline (red)
|
||||||
|
dot = "●"
|
||||||
|
// check represents successful operation
|
||||||
|
check = "✔"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminCmd = cli.Command{
|
||||||
|
Name: "admin",
|
||||||
|
Usage: "manage MinIO servers",
|
||||||
|
Action: mainAdmin,
|
||||||
|
HideHelpCommand: true,
|
||||||
|
Flags: append(adminFlags, globalFlags...),
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminServiceCmd,
|
||||||
|
adminServerUpdateCmd,
|
||||||
|
adminInfoCmd,
|
||||||
|
adminUserCmd,
|
||||||
|
adminGroupCmd,
|
||||||
|
adminPolicyCmd,
|
||||||
|
adminConfigCmd,
|
||||||
|
adminHealCmd,
|
||||||
|
adminProfileCmd,
|
||||||
|
adminTopCmd,
|
||||||
|
adminTraceCmd,
|
||||||
|
adminConsoleCmd,
|
||||||
|
adminPrometheusCmd,
|
||||||
|
adminKMSCmd,
|
||||||
|
adminOBDCmd,
|
||||||
|
adminBucketCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateTimeFormatFilename = "2006-01-02T15-04-05.999999-07-00"
|
||||||
|
|
||||||
|
// mainAdmin is the handle for "mc admin" command.
|
||||||
|
func mainAdmin(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "service", "heal", "top" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,418 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/klauspost/compress/gzip"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
cjson "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminOBDFlags = []cli.Flag{
|
||||||
|
OBDDataTypeFlag{
|
||||||
|
Name: "tests",
|
||||||
|
Usage: "choose OBD tests to run [" + options.String() + "]",
|
||||||
|
Value: nil,
|
||||||
|
EnvVar: "MC_OBD_DATA",
|
||||||
|
Hidden: true,
|
||||||
|
},
|
||||||
|
cli.DurationFlag{
|
||||||
|
Name: "deadline",
|
||||||
|
Usage: "maximum duration that OBD tests should be allowed to run",
|
||||||
|
Value: 3600 * time.Second,
|
||||||
|
EnvVar: "MC_OBD_DEADLINE",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminOBDCmd = cli.Command{
|
||||||
|
Name: "obd",
|
||||||
|
Usage: "run on-board diagnostics",
|
||||||
|
Action: mainAdminOBD,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: append(adminOBDFlags, globalFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get server information of the 'play' MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
type clusterOBDStruct struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Info madmin.OBDInfo `json:"obdInfo,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u clusterOBDStruct) String() string {
|
||||||
|
u.Status = ""
|
||||||
|
data, err := json.Marshal(u)
|
||||||
|
if err != nil {
|
||||||
|
fatalIf(probe.NewError(err), "unable to marshal into JSON.")
|
||||||
|
}
|
||||||
|
return string(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonifies service status message.
|
||||||
|
func (u clusterOBDStruct) JSON() string {
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, " ", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminInfoSyntax - validate arguments passed by a user
|
||||||
|
func checkAdminOBDSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "obd", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//compress and tar obd output
|
||||||
|
func tarGZ(c clusterOBDStruct, alias string) error {
|
||||||
|
filename := fmt.Sprintf("%s-obd_%s.json.gz", filepath.Clean(alias), time.Now().Format("20060102150405"))
|
||||||
|
f, err := os.OpenFile(filename, os.O_CREATE|os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
fmt.Println("OBD data saved to", filename)
|
||||||
|
}()
|
||||||
|
|
||||||
|
gzWriter := gzip.NewWriter(f)
|
||||||
|
defer gzWriter.Close()
|
||||||
|
|
||||||
|
enc := json.NewEncoder(gzWriter)
|
||||||
|
if err := enc.Encode(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
warningMsgBoundary := "*********************************************************************************"
|
||||||
|
warning := warnText(" WARNING!!")
|
||||||
|
warningContents := infoText(` ** THIS FILE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR ENVIRONMENT **
|
||||||
|
** PLEASE INSPECT CONTENTS BEFORE SHARING IT ON ANY PUBLIC FORUM **`)
|
||||||
|
|
||||||
|
warningMsgHeader := infoText(warningMsgBoundary)
|
||||||
|
warningMsgTrailer := infoText(warningMsgBoundary)
|
||||||
|
fmt.Printf("%s\n%s\n%s\n%s\n", warningMsgHeader, warning, warningContents, warningMsgTrailer)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func infoText(s string) string {
|
||||||
|
console.SetColor("INFO", color.New(color.FgGreen, color.Bold))
|
||||||
|
return console.Colorize("INFO", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func greenText(s string) string {
|
||||||
|
console.SetColor("GREEN", color.New(color.FgGreen))
|
||||||
|
return console.Colorize("GREEN", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func warnText(s string) string {
|
||||||
|
console.SetColor("WARN", color.New(color.FgRed, color.Bold))
|
||||||
|
return console.Colorize("WARN", s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminOBD(ctx *cli.Context) error {
|
||||||
|
checkAdminOBDSyntax(ctx)
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
spinners := []string{"/", "|", "\\", "--", "|"}
|
||||||
|
|
||||||
|
cont, cancel := context.WithCancel(globalContext)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
startSpinner := func(s string) func() {
|
||||||
|
ctx, cancel := context.WithCancel(cont)
|
||||||
|
printText := func(t string, sp string, rewind int) {
|
||||||
|
console.RewindLines(rewind)
|
||||||
|
|
||||||
|
dot := infoText(dot)
|
||||||
|
t = fmt.Sprintf("%s ...", t)
|
||||||
|
t = greenText(t)
|
||||||
|
sp = infoText(sp)
|
||||||
|
toPrint := fmt.Sprintf("%s %s %s ", dot, t, sp)
|
||||||
|
fmt.Printf("%s\n", toPrint)
|
||||||
|
}
|
||||||
|
i := 0
|
||||||
|
sp := func() string {
|
||||||
|
i = i + 1
|
||||||
|
i = i % len(spinners)
|
||||||
|
return spinners[i]
|
||||||
|
}
|
||||||
|
|
||||||
|
done := make(chan bool)
|
||||||
|
doneToggle := false
|
||||||
|
go func() {
|
||||||
|
printText(s, sp(), 0)
|
||||||
|
for {
|
||||||
|
<-time.After(500 * time.Millisecond) //2 fps
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
printText(s, check, 1)
|
||||||
|
done <- true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
printText(s, sp(), 1)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return func() {
|
||||||
|
cancel()
|
||||||
|
if !doneToggle {
|
||||||
|
<-done
|
||||||
|
os.Stdout.Sync()
|
||||||
|
doneToggle = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spinner := func(resource string) func(bool) bool {
|
||||||
|
var spinStopper func()
|
||||||
|
done := false
|
||||||
|
|
||||||
|
if globalJSON {
|
||||||
|
return func(bool) bool {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return func(cond bool) bool {
|
||||||
|
if done {
|
||||||
|
return done
|
||||||
|
}
|
||||||
|
if spinStopper == nil {
|
||||||
|
spinStopper = startSpinner(resource)
|
||||||
|
}
|
||||||
|
if cond {
|
||||||
|
spinStopper()
|
||||||
|
done = true
|
||||||
|
}
|
||||||
|
return done
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterOBDInfo := clusterOBDStruct{}
|
||||||
|
|
||||||
|
admin := spinner("Admin Info")
|
||||||
|
cpu := spinner("CPU")
|
||||||
|
diskHw := spinner("Disk Hardware")
|
||||||
|
osInfo := spinner("Os Info")
|
||||||
|
mem := spinner("Mem Info")
|
||||||
|
process := spinner("Process Info")
|
||||||
|
config := spinner("Config")
|
||||||
|
drive := spinner("Drive")
|
||||||
|
net := spinner("Net")
|
||||||
|
|
||||||
|
progress := func(info madmin.OBDInfo) bool {
|
||||||
|
return admin(len(info.Minio.Info.Servers) > 0) &&
|
||||||
|
cpu(len(info.Sys.CPUInfo) > 0) &&
|
||||||
|
diskHw(len(info.Sys.DiskHwInfo) > 0) &&
|
||||||
|
osInfo(len(info.Sys.OsInfo) > 0) &&
|
||||||
|
mem(len(info.Sys.MemInfo) > 0) &&
|
||||||
|
process(len(info.Sys.ProcInfo) > 0) &&
|
||||||
|
config(info.Minio.Config != nil) &&
|
||||||
|
drive(len(info.Perf.DriveInfo) > 0) &&
|
||||||
|
net(len(info.Perf.Net) > 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch info of all servers (cluster or single server)
|
||||||
|
obdChan := client.ServerOBDInfo(cont, options, ctx.Duration("deadline"))
|
||||||
|
for adminOBDInfo := range obdChan {
|
||||||
|
if adminOBDInfo.Error != "" {
|
||||||
|
clusterOBDInfo.Status = "Error"
|
||||||
|
clusterOBDInfo.Error = adminOBDInfo.Error
|
||||||
|
clusterOBDInfo.Info.Error = ""
|
||||||
|
clusterOBDInfo.Info.Minio.Info = madmin.InfoMessage{}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
clusterOBDInfo.Status = "Success"
|
||||||
|
clusterOBDInfo.Info = adminOBDInfo
|
||||||
|
progress(adminOBDInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If MinIO is not a global distXL cluster, net will never stop spinning.
|
||||||
|
// add this extra check to ensure that doesn't happen
|
||||||
|
if clusterOBDInfo.Error == "" && !progress(clusterOBDInfo.Info) {
|
||||||
|
net(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if globalJSON {
|
||||||
|
jsonBytes, err := cjson.MarshalIndent(clusterOBDInfo, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
fmt.Println(string(jsonBytes))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if clusterOBDInfo.Error != "" {
|
||||||
|
fmt.Println(warnText("Error obtaining obd information:"), clusterOBDInfo.Error)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return tarGZ(clusterOBDInfo, aliasedURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OBDDataTypeSlice is a typed list of OBD tests
|
||||||
|
type OBDDataTypeSlice []madmin.OBDDataType
|
||||||
|
|
||||||
|
// Set - sets the flag to the given value
|
||||||
|
func (d *OBDDataTypeSlice) Set(value string) error {
|
||||||
|
for _, v := range strings.Split(value, ",") {
|
||||||
|
if obdData, ok := madmin.OBDDataTypesMap[strings.Trim(v, " ")]; ok {
|
||||||
|
*d = append(*d, obdData)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("valid options include %s", options.String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// String - returns the string representation of the OBD datatypes
|
||||||
|
func (d *OBDDataTypeSlice) String() string {
|
||||||
|
val := ""
|
||||||
|
for _, obdData := range *d {
|
||||||
|
formatStr := "%s"
|
||||||
|
if val != "" {
|
||||||
|
formatStr = fmt.Sprintf("%s,%%s", formatStr)
|
||||||
|
} else {
|
||||||
|
formatStr = fmt.Sprintf("%s%%s", formatStr)
|
||||||
|
}
|
||||||
|
val = fmt.Sprintf(formatStr, val, string(obdData))
|
||||||
|
}
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
|
||||||
|
// Value - returns the value
|
||||||
|
func (d *OBDDataTypeSlice) Value() []madmin.OBDDataType {
|
||||||
|
return *d
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get - returns the value
|
||||||
|
func (d *OBDDataTypeSlice) Get() interface{} {
|
||||||
|
return *d
|
||||||
|
}
|
||||||
|
|
||||||
|
// OBDDataTypeFlag is a typed flag to represent OBD datatypes
|
||||||
|
type OBDDataTypeFlag struct {
|
||||||
|
Name string
|
||||||
|
Usage string
|
||||||
|
EnvVar string
|
||||||
|
Hidden bool
|
||||||
|
Value *OBDDataTypeSlice
|
||||||
|
}
|
||||||
|
|
||||||
|
// String - returns the string to be shown in the help message
|
||||||
|
func (f OBDDataTypeFlag) String() string {
|
||||||
|
return fmt.Sprintf("--%s %s", f.Name, f.Usage)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetName - returns the name of the flag
|
||||||
|
func (f OBDDataTypeFlag) GetName() string {
|
||||||
|
return f.Name
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetOBDDataTypeSlice - returns the list of set OBD tests
|
||||||
|
func GetOBDDataTypeSlice(c *cli.Context, name string) *OBDDataTypeSlice {
|
||||||
|
generic := c.Generic(name)
|
||||||
|
if generic == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if obdData, ok := generic.(*OBDDataTypeSlice); ok {
|
||||||
|
return obdData
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetGlobalOBDDataTypeSlice - returns the list of set OBD tests set globally
|
||||||
|
func GetGlobalOBDDataTypeSlice(c *cli.Context, name string) *OBDDataTypeSlice {
|
||||||
|
generic := c.GlobalGeneric(name)
|
||||||
|
if generic == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if obdData, ok := generic.(*OBDDataTypeSlice); ok {
|
||||||
|
return obdData
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply - applies the flag
|
||||||
|
func (f OBDDataTypeFlag) Apply(set *flag.FlagSet) {
|
||||||
|
f.ApplyWithError(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApplyWithError - applies with error
|
||||||
|
func (f OBDDataTypeFlag) ApplyWithError(set *flag.FlagSet) error {
|
||||||
|
if f.EnvVar != "" {
|
||||||
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal, ok := syscall.Getenv(envVar); ok {
|
||||||
|
newVal := &OBDDataTypeSlice{}
|
||||||
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
if err := newVal.Set(s); err != nil {
|
||||||
|
return fmt.Errorf("could not parse %s as OBD datatype value for flag %s: %s", envVal, f.Name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.Value = newVal
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, name := range strings.Split(f.Name, ",") {
|
||||||
|
name = strings.Trim(name, " ")
|
||||||
|
if f.Value == nil {
|
||||||
|
f.Value = &OBDDataTypeSlice{}
|
||||||
|
}
|
||||||
|
set.Var(f.Value, name, f.Usage)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = OBDDataTypeSlice(madmin.OBDDataTypesList)
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPolicyAddCmd = cli.Command{
|
||||||
|
Name: "add",
|
||||||
|
Usage: "add new policy",
|
||||||
|
Action: mainAdminPolicyAdd,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
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
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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"`
|
||||||
|
PolicyJSON *iampolicy.Policy `json:"policyJSON,omitempty"`
|
||||||
|
UserOrGroup string `json:"userOrGroup,omitempty"`
|
||||||
|
IsGroup bool `json:"isGroup"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u userPolicyMessage) String() string {
|
||||||
|
switch u.op {
|
||||||
|
case "info":
|
||||||
|
buf, e := json.MarshalIndent(u.PolicyJSON, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to parse policy")
|
||||||
|
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":
|
||||||
|
fragment := "user"
|
||||||
|
if u.IsGroup {
|
||||||
|
fragment = "group"
|
||||||
|
}
|
||||||
|
return console.Colorize("PolicyMessage",
|
||||||
|
fmt.Sprintf("Policy %s is set on %s `%s`", u.Policy, fragment, 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.")
|
||||||
|
|
||||||
|
iamp, e := iampolicy.ParseConfig(bytes.NewReader(policy))
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Unable to parse the input policy")
|
||||||
|
|
||||||
|
fatalIf(probe.NewError(client.AddCannedPolicy(globalContext, args.Get(1), iamp)).Trace(args...), "Unable to add new policy")
|
||||||
|
|
||||||
|
printMsg(userPolicyMessage{
|
||||||
|
op: "add",
|
||||||
|
Policy: args.Get(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPolicyInfoCmd = cli.Command{
|
||||||
|
Name: "info",
|
||||||
|
Usage: "show info on a policy",
|
||||||
|
Action: mainAdminPolicyInfo,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET POLICYNAME
|
||||||
|
|
||||||
|
POLICYNAME:
|
||||||
|
Name of the policy on the MinIO server.
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Show information on a given policy.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio writeonly
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPolicyInfo is the handler for "mc admin policy info" command.
|
||||||
|
func mainAdminPolicyInfo(ctx *cli.Context) error {
|
||||||
|
checkAdminPolicyInfoSyntax(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 := args.Get(1)
|
||||||
|
|
||||||
|
// Create a new MinIO Admin Client
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection")
|
||||||
|
|
||||||
|
policies, e := client.ListCannedPolicies(globalContext)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot list policy")
|
||||||
|
|
||||||
|
iamp, ok := policies[policyName]
|
||||||
|
if ok {
|
||||||
|
printMsg(userPolicyMessage{
|
||||||
|
op: "info",
|
||||||
|
Policy: policyName,
|
||||||
|
PolicyJSON: iamp,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
fatalIf(probe.NewError(fmt.Errorf("%s is not found", policyName)), "Unable to display policy")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPolicyListCmd = cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list all policies",
|
||||||
|
Action: mainAdminPolicyList,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. List all policies on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPolicyList is the handle for "mc admin policy add" command.
|
||||||
|
func mainAdminPolicyList(ctx *cli.Context) error {
|
||||||
|
checkAdminPolicyListSyntax(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)
|
||||||
|
|
||||||
|
// Create a new MinIO Admin Client
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection.")
|
||||||
|
|
||||||
|
policies, e := client.ListCannedPolicies(globalContext)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot list policy")
|
||||||
|
|
||||||
|
for k := range policies {
|
||||||
|
printMsg(userPolicyMessage{
|
||||||
|
op: "list",
|
||||||
|
Policy: k,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPolicyRemoveCmd = cli.Command{
|
||||||
|
Name: "remove",
|
||||||
|
Usage: "remove policy",
|
||||||
|
Action: mainAdminPolicyRemove,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET POLICYNAME
|
||||||
|
|
||||||
|
POLICYNAME:
|
||||||
|
Name of the canned policy on MinIO server.
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Remove 'writeonly' policy on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio writeonly
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPolicyRemove is the handle for "mc admin policy remove" command.
|
||||||
|
func mainAdminPolicyRemove(ctx *cli.Context) error {
|
||||||
|
checkAdminPolicyRemoveSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("PolicyMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
fatalIf(probe.NewError(client.RemoveCannedPolicy(globalContext, args.Get(1))).Trace(args...), "Cannot remove policy")
|
||||||
|
|
||||||
|
printMsg(userPolicyMessage{
|
||||||
|
op: "remove",
|
||||||
|
Policy: args.Get(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPolicySetCmd = cli.Command{
|
||||||
|
Name: "set",
|
||||||
|
Usage: "set IAM policy on a user or group",
|
||||||
|
Action: mainAdminPolicySet,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
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
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
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.Split(arg, "=")
|
||||||
|
switch {
|
||||||
|
case len(parts) != 2:
|
||||||
|
fallthrough
|
||||||
|
case 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 := 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), "Cannot set the policy")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminPolicyCmd = cli.Command{
|
||||||
|
Name: "policy",
|
||||||
|
Usage: "manage policies defined in the MinIO server",
|
||||||
|
Action: mainAdminPolicy,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminPolicyAddCmd,
|
||||||
|
adminPolicyRemoveCmd,
|
||||||
|
adminPolicyListCmd,
|
||||||
|
adminPolicyInfoCmd,
|
||||||
|
adminPolicySetCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPolicy is the handle for "mc admin policy" command.
|
||||||
|
func mainAdminPolicy(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "get", "set" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio-go/v6/pkg/set"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
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",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminProfileStartCmd = cli.Command{
|
||||||
|
Name: "start",
|
||||||
|
Usage: "start recording profile data",
|
||||||
|
Action: mainAdminProfileStart,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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), "Cannot 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.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,133 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminProfileStopCmd = cli.Command{
|
||||||
|
Name: "stop",
|
||||||
|
Usage: "stop and download profile data",
|
||||||
|
Action: mainAdminProfileStop,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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), "Cannot 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)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018-2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/minio/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminProfileCmd = cli.Command{
|
||||||
|
Name: "profile",
|
||||||
|
Usage: "generate profile data for debugging purposes",
|
||||||
|
Action: mainAdminProfile,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminProfileStartCmd,
|
||||||
|
adminProfileStopCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminProfile is the handle for "mc admin profile" command.
|
||||||
|
func mainAdminProfile(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
|
||||||
|
jwtgo "github.com/dgrijalva/jwt-go"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultJobName = "minio-job"
|
||||||
|
defaultMetricsPath = "/minio/prometheus/metrics"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminPrometheusGenerateCmd = cli.Command{
|
||||||
|
Name: "generate",
|
||||||
|
Usage: "generates prometheus config",
|
||||||
|
Action: mainAdminPrometheusGenerate,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
HideHelpCommand: true,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Generate a default prometheus config.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// PrometheusConfig - container to hold the top level scrape config.
|
||||||
|
type PrometheusConfig struct {
|
||||||
|
ScrapeConfigs []ScrapeConfig `yaml:"scrape_configs,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
return console.Colorize("yaml", string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified prometheus config.
|
||||||
|
func (c PrometheusConfig) JSON() string {
|
||||||
|
jsonMessageBytes, e := json.MarshalIndent(c.ScrapeConfigs[0], "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
return string(jsonMessageBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// StatConfig - container to hold the targets config.
|
||||||
|
type StatConfig struct {
|
||||||
|
Targets []string `yaml:",flow" json:"targets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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)
|
||||||
|
}
|
||||||
|
return console.Colorize("yaml", string(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified stat config.
|
||||||
|
func (t StatConfig) JSON() string {
|
||||||
|
jsonMessageBytes, e := json.MarshalIndent(t.Targets, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
return string(jsonMessageBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ScrapeConfig configures a scraping unit for Prometheus.
|
||||||
|
type ScrapeConfig struct {
|
||||||
|
JobName string `yaml:"job_name" json:"jobName"`
|
||||||
|
BearerToken string `yaml:"bearer_token" json:"bearerToken"`
|
||||||
|
MetricsPath string `yaml:"metrics_path,omitempty" json:"metricsPath"`
|
||||||
|
Scheme string `yaml:"scheme,omitempty" json:"scheme"`
|
||||||
|
StaticConfigs []StatConfig `yaml:"static_configs,omitempty" json:"staticConfigs"`
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generatePrometheusConfig(ctx *cli.Context) error {
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
alias := cleanAlias(args.Get(0))
|
||||||
|
|
||||||
|
if !isValidAlias(alias) {
|
||||||
|
fatalIf(errInvalidAlias(alias), "Invalid alias.")
|
||||||
|
}
|
||||||
|
|
||||||
|
hostConfig := mustGetHostConfig(alias)
|
||||||
|
if hostConfig == nil {
|
||||||
|
fatalIf(errInvalidAliasedURL(alias), "No such alias `"+alias+"` found.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := url.Parse(hostConfig.URL)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
jwt := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, jwtgo.StandardClaims{
|
||||||
|
ExpiresAt: UTCNow().Add(defaultPrometheusJWTExpiry).Unix(),
|
||||||
|
Subject: hostConfig.AccessKey,
|
||||||
|
Issuer: "prometheus",
|
||||||
|
})
|
||||||
|
|
||||||
|
token, err := jwt.SignedString([]byte(hostConfig.SecretKey))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setting the values
|
||||||
|
defaultConfig.ScrapeConfigs[0].BearerToken = token
|
||||||
|
defaultConfig.ScrapeConfigs[0].Scheme = u.Scheme
|
||||||
|
defaultConfig.ScrapeConfigs[0].StaticConfigs[0].Targets[0] = u.Host
|
||||||
|
|
||||||
|
printMsg(defaultConfig)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPrometheus is the handle for "mc admin prometheus generate" sub-command.
|
||||||
|
func mainAdminPrometheusGenerate(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
console.SetColor("yaml", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
checkAdminPrometheusSyntax(ctx)
|
||||||
|
|
||||||
|
if err := generatePrometheusConfig(ctx); err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminPrometheusCmd = cli.Command{
|
||||||
|
Name: "prometheus",
|
||||||
|
Usage: "manages prometheus config",
|
||||||
|
Action: mainAdminPrometheus,
|
||||||
|
Flags: globalFlags,
|
||||||
|
HideHelpCommand: true,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminPrometheusGenerateCmd,
|
||||||
|
},
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminPrometheus is the handle for "mc admin prometheus" command.
|
||||||
|
func mainAdminPrometheus(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2016 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminServiceRestartCmd = cli.Command{
|
||||||
|
Name: "restart",
|
||||||
|
Usage: "restart all MinIO servers",
|
||||||
|
Action: mainAdminServiceRestart,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Restart MinIO server represented by its alias 'play'.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// serviceRestartCommand is container for service restart command success and failure messages.
|
||||||
|
type serviceRestartCommand struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ServerURL string `json:"serverURL"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service restart command message.
|
||||||
|
func (s serviceRestartCommand) String() string {
|
||||||
|
return console.Colorize("ServiceRestart", "Restart command successfully sent to `"+s.ServerURL+"`.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service restart command message.
|
||||||
|
func (s serviceRestartCommand) JSON() string {
|
||||||
|
serviceRestartJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(serviceRestartJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// serviceRestartMessage is container for service restart success and failure messages.
|
||||||
|
type serviceRestartMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ServerURL string `json:"serverURL"`
|
||||||
|
Err error `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized service restart message.
|
||||||
|
func (s serviceRestartMessage) String() string {
|
||||||
|
if s.Err == nil {
|
||||||
|
return console.Colorize("ServiceRestart", "Restarted `"+s.ServerURL+"` successfully.")
|
||||||
|
}
|
||||||
|
return console.Colorize("FailedServiceRestart", "Failed to restart `"+s.ServerURL+"`. error: "+s.Err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified service restart message.
|
||||||
|
func (s serviceRestartMessage) JSON() string {
|
||||||
|
serviceRestartJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(serviceRestartJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminServiceRestartSyntax - validate all the passed arguments
|
||||||
|
func checkAdminServiceRestartSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "restart", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminServiceRestart(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
// Validate serivce restart syntax.
|
||||||
|
checkAdminServiceRestartSyntax(ctx)
|
||||||
|
|
||||||
|
// Set color.
|
||||||
|
console.SetColor("ServiceRestart", color.New(color.FgGreen, color.Bold))
|
||||||
|
console.SetColor("FailedServiceRestart", color.New(color.FgRed, color.Bold))
|
||||||
|
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
aliasedURL := args.Get(0)
|
||||||
|
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection.")
|
||||||
|
|
||||||
|
// Restart the specified MinIO server
|
||||||
|
fatalIf(probe.NewError(client.ServiceRestart(globalContext)), "Cannot restart the server.")
|
||||||
|
|
||||||
|
// Success..
|
||||||
|
printMsg(serviceRestartCommand{Status: "success", ServerURL: aliasedURL})
|
||||||
|
|
||||||
|
// Max. time taken by the server to shutdown is 5 seconds.
|
||||||
|
// This can happen when there are lot of s3 requests pending when the server
|
||||||
|
// receives a restart command.
|
||||||
|
// Sleep for 6 seconds and then check if the server is online.
|
||||||
|
time.Sleep(6 * time.Second)
|
||||||
|
|
||||||
|
// Fetch the service status of the specified MinIO server
|
||||||
|
_, e := client.ServerInfo(globalContext)
|
||||||
|
|
||||||
|
if e != nil {
|
||||||
|
printMsg(serviceRestartMessage{Status: "failure", Err: e, ServerURL: aliasedURL})
|
||||||
|
} else {
|
||||||
|
printMsg(serviceRestartMessage{Status: "success", ServerURL: aliasedURL})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminServiceStopCmd = cli.Command{
|
||||||
|
Name: "stop",
|
||||||
|
Usage: "stop MinIO server",
|
||||||
|
Action: mainAdminServiceStop,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Stop MinIO server represented by its alias 'play'.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// serviceStopMessage is container for make bucket success and failure messages.
|
||||||
|
type serviceStopMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ServerURL string `json:"serverURL"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized make bucket message.
|
||||||
|
func (s serviceStopMessage) String() string {
|
||||||
|
return console.Colorize("ServiceStop", "Stopped `"+s.ServerURL+"` successfully.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified make bucket message.
|
||||||
|
func (s serviceStopMessage) JSON() string {
|
||||||
|
serviceStopJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(serviceStopJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminServiceStopSyntax - validate all the passed arguments
|
||||||
|
func checkAdminServiceStopSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "stop", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminServiceStop(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
// Validate serivce stop syntax.
|
||||||
|
checkAdminServiceStopSyntax(ctx)
|
||||||
|
|
||||||
|
// Set color.
|
||||||
|
console.SetColor("ServiceStop", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
aliasedURL := args.Get(0)
|
||||||
|
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection.")
|
||||||
|
|
||||||
|
// Stop the specified MinIO server
|
||||||
|
fatalIf(probe.NewError(client.ServiceStop(globalContext)), "Unable to stop the server.")
|
||||||
|
|
||||||
|
// Success..
|
||||||
|
printMsg(serviceStopMessage{Status: "success", ServerURL: aliasedURL})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2016, 2017, 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminServiceCmd = cli.Command{
|
||||||
|
Name: "service",
|
||||||
|
Usage: "restart and stop all MinIO servers",
|
||||||
|
Action: mainAdminService,
|
||||||
|
Flags: globalFlags,
|
||||||
|
HideHelpCommand: true,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminServiceRestartCmd,
|
||||||
|
adminServiceStopCmd,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdmin is the handle for "mc admin service" command.
|
||||||
|
func mainAdminService(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "status", "restart" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,150 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminTopLocksCmd = cli.Command{
|
||||||
|
Name: "locks",
|
||||||
|
Usage: "Get a list of the 10 oldest locks on a MinIO cluster.",
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Action: mainAdminTopLocks,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Get a list of the 10 oldest locks on a MinIO cluster.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// lockMessage struct to list lock information.
|
||||||
|
type lockMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
Lock madmin.LockEntry `json:"locks"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getTimeDiff(timeStamp time.Time) (string, string) {
|
||||||
|
now := time.Now().UTC()
|
||||||
|
diff := now.Sub(timeStamp)
|
||||||
|
hours := int(diff.Hours())
|
||||||
|
minutes := int(diff.Minutes()) % 60
|
||||||
|
seconds := int(diff.Seconds()) % 60
|
||||||
|
if hours == 0 {
|
||||||
|
if minutes == 0 {
|
||||||
|
return "Lock", fmt.Sprint(seconds, " seconds")
|
||||||
|
}
|
||||||
|
return "Lock", fmt.Sprint(minutes, " minutes")
|
||||||
|
}
|
||||||
|
return "StaleLock", fmt.Sprint(hours, " hours")
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized oldest locks message.
|
||||||
|
func (u lockMessage) String() string {
|
||||||
|
timeFieldMaxLen := 20
|
||||||
|
resourceFieldMaxLen := -1
|
||||||
|
typeFieldMaxLen := 6
|
||||||
|
ownerFieldMaxLen := 20
|
||||||
|
|
||||||
|
lockState, timeDiff := getTimeDiff(u.Lock.Timestamp)
|
||||||
|
return console.Colorize(lockState, newPrettyTable(" ",
|
||||||
|
Field{"Time", timeFieldMaxLen},
|
||||||
|
Field{"Type", typeFieldMaxLen},
|
||||||
|
Field{"Owner", ownerFieldMaxLen},
|
||||||
|
Field{"Resource", resourceFieldMaxLen},
|
||||||
|
).buildRow(timeDiff, u.Lock.Type, u.Lock.Owner, u.Lock.Resource))
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified top oldest locks message.
|
||||||
|
func (u lockMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
statusJSONBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
return string(statusJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminTopLocksSyntax - validate all the passed arguments
|
||||||
|
func checkAdminTopLocksSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "locks", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminTopLocks(ctx *cli.Context) error {
|
||||||
|
|
||||||
|
checkAdminTopLocksSyntax(ctx)
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
// Call top locks API
|
||||||
|
entries, e := client.TopLocks(globalContext)
|
||||||
|
fatalIf(probe.NewError(e), "Cannot get server locks list.")
|
||||||
|
|
||||||
|
console.SetColor("StaleLock", color.New(color.FgRed, color.Bold))
|
||||||
|
console.SetColor("Lock", color.New(color.FgBlue, color.Bold))
|
||||||
|
console.SetColor("Headers", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// Print
|
||||||
|
printLocks(entries)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func printHeaders() {
|
||||||
|
timeFieldMaxLen := 20
|
||||||
|
resourceFieldMaxLen := -1
|
||||||
|
typeFieldMaxLen := 6
|
||||||
|
ownerFieldMaxLen := 20
|
||||||
|
console.Println(console.Colorize("Headers", newPrettyTable(" ",
|
||||||
|
Field{"Time", timeFieldMaxLen},
|
||||||
|
Field{"Type", typeFieldMaxLen},
|
||||||
|
Field{"Owner", ownerFieldMaxLen},
|
||||||
|
Field{"Resource", resourceFieldMaxLen},
|
||||||
|
).buildRow("Time", "Type", "Owner", "Resource")))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prints oldest locks.
|
||||||
|
func printLocks(locks madmin.LockEntries) {
|
||||||
|
if !globalJSON {
|
||||||
|
printHeaders()
|
||||||
|
}
|
||||||
|
for _, entry := range locks {
|
||||||
|
printMsg(lockMessage{Lock: entry})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminTopCmd = cli.Command{
|
||||||
|
Name: "top",
|
||||||
|
Usage: "provide top like statistics for MinIO",
|
||||||
|
Action: mainAdminTop,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminTopLocksCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminTop is the handle for "mc admin top" command.
|
||||||
|
func mainAdminTop(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "locks" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,353 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"hash/fnv"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
humanize "github.com/dustin/go-humanize"
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminTraceFlags = []cli.Flag{
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "verbose, v",
|
||||||
|
Usage: "print verbose trace",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "all, a",
|
||||||
|
Usage: "trace all traffic (including internode traffic between MinIO servers)",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "errors, e",
|
||||||
|
Usage: "trace failed requests only",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminTraceCmd = cli.Command{
|
||||||
|
Name: "trace",
|
||||||
|
Usage: "show http trace for MinIO server",
|
||||||
|
Action: mainAdminTrace,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: append(adminTraceFlags, globalFlags...),
|
||||||
|
HideHelpCommand: true,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} [FLAGS] TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Show console trace for a MinIO server with alias 'play'
|
||||||
|
{{.Prompt}} {{.HelpName}} -v -a play
|
||||||
|
|
||||||
|
2. Show trace only for failed requests for a MinIO server with alias 'myminio'
|
||||||
|
{{.Prompt}} {{.HelpName}} -v -e myminio
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeFormat = "15:04:05.000"
|
||||||
|
|
||||||
|
var (
|
||||||
|
colors = []color.Attribute{color.FgCyan, color.FgWhite, color.FgYellow, color.FgGreen}
|
||||||
|
)
|
||||||
|
|
||||||
|
func checkAdminTraceSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "trace", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminTrace - the entry function of trace command
|
||||||
|
func mainAdminTrace(ctx *cli.Context) error {
|
||||||
|
// Check for command syntax
|
||||||
|
checkAdminTraceSyntax(ctx)
|
||||||
|
verbose := ctx.Bool("verbose")
|
||||||
|
all := ctx.Bool("all")
|
||||||
|
errfltr := ctx.Bool("errors")
|
||||||
|
aliasedURL := ctx.Args().Get(0)
|
||||||
|
console.SetColor("Stat", color.New(color.FgYellow))
|
||||||
|
|
||||||
|
console.SetColor("Request", color.New(color.FgCyan))
|
||||||
|
console.SetColor("Method", color.New(color.Bold, color.FgWhite))
|
||||||
|
console.SetColor("Host", color.New(color.Bold, color.FgGreen))
|
||||||
|
console.SetColor("FuncName", color.New(color.Bold, color.FgGreen))
|
||||||
|
|
||||||
|
console.SetColor("ReqHeaderKey", color.New(color.Bold, color.FgWhite))
|
||||||
|
console.SetColor("RespHeaderKey", color.New(color.Bold, color.FgCyan))
|
||||||
|
console.SetColor("HeaderValue", color.New(color.FgWhite))
|
||||||
|
console.SetColor("RespStatus", color.New(color.Bold, color.FgYellow))
|
||||||
|
console.SetColor("ErrStatus", color.New(color.Bold, color.FgRed))
|
||||||
|
|
||||||
|
console.SetColor("Response", color.New(color.FgGreen))
|
||||||
|
console.SetColor("Body", color.New(color.FgYellow))
|
||||||
|
for _, c := range colors {
|
||||||
|
console.SetColor(fmt.Sprintf("Node%d", c), color.New(c))
|
||||||
|
}
|
||||||
|
// Create a new MinIO Admin Client
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
if err != nil {
|
||||||
|
fatalIf(err.Trace(aliasedURL), "Cannot initialize admin client.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ctxt, cancel := context.WithCancel(globalContext)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
// Start listening on all trace activity.
|
||||||
|
traceCh := client.ServiceTrace(ctxt, all, errfltr)
|
||||||
|
for traceInfo := range traceCh {
|
||||||
|
if traceInfo.Err != nil {
|
||||||
|
fatalIf(probe.NewError(traceInfo.Err), "Cannot listen to http trace")
|
||||||
|
}
|
||||||
|
if verbose {
|
||||||
|
printMsg(traceMessage{traceInfo})
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
printMsg(shortTrace(traceInfo))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Short trace record
|
||||||
|
type shortTraceMsg struct {
|
||||||
|
Host string `json:"host"`
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
Client string `json:"client"`
|
||||||
|
CallStats callStats `json:"callStats"`
|
||||||
|
FuncName string `json:"api"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Query string `json:"query"`
|
||||||
|
StatusCode int `json:"statusCode"`
|
||||||
|
StatusMsg string `json:"statusMsg"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type traceMessage struct {
|
||||||
|
madmin.ServiceTraceInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type requestInfo struct {
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
Method string `json:"method"`
|
||||||
|
Path string `json:"path,omitempty"`
|
||||||
|
RawQuery string `json:"rawQuery,omitempty"`
|
||||||
|
Headers map[string]string `json:"headers,omitempty"`
|
||||||
|
Body string `json:"body,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type responseInfo struct {
|
||||||
|
Time time.Time `json:"time"`
|
||||||
|
Headers map[string]string `json:"headers,omitempty"`
|
||||||
|
Body string `json:"body,omitempty"`
|
||||||
|
StatusCode int `json:"statusCode,omitempty"`
|
||||||
|
}
|
||||||
|
type callStats struct {
|
||||||
|
Rx int `json:"rx"`
|
||||||
|
Tx int `json:"tx"`
|
||||||
|
Duration time.Duration `json:"duration"`
|
||||||
|
Ttfb time.Duration `json:"timeToFirstByte"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type trace struct {
|
||||||
|
NodeName string `json:"host"`
|
||||||
|
FuncName string `json:"api"`
|
||||||
|
RequestInfo requestInfo `json:"request"`
|
||||||
|
ResponseInfo responseInfo `json:"response"`
|
||||||
|
CallStats callStats `json:"callStats"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a struct with minimal trace info.
|
||||||
|
func shortTrace(ti madmin.ServiceTraceInfo) shortTraceMsg {
|
||||||
|
s := shortTraceMsg{}
|
||||||
|
t := ti.Trace
|
||||||
|
s.Time = t.ReqInfo.Time
|
||||||
|
if host, ok := t.ReqInfo.Headers["Host"]; ok {
|
||||||
|
s.Host = strings.Join(host, "")
|
||||||
|
}
|
||||||
|
s.Path = t.ReqInfo.Path
|
||||||
|
s.Query = t.ReqInfo.RawQuery
|
||||||
|
s.FuncName = t.FuncName
|
||||||
|
s.StatusCode = t.RespInfo.StatusCode
|
||||||
|
s.StatusMsg = http.StatusText(t.RespInfo.StatusCode)
|
||||||
|
cSlice := strings.Split(t.ReqInfo.Client, ":")
|
||||||
|
s.Client = cSlice[0]
|
||||||
|
s.CallStats.Duration = t.CallStats.Latency
|
||||||
|
s.CallStats.Rx = t.CallStats.InputBytes
|
||||||
|
s.CallStats.Tx = t.CallStats.OutputBytes
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s shortTraceMsg) 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(s)), "Unable to marshal into JSON.")
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s shortTraceMsg) String() string {
|
||||||
|
var hostStr string
|
||||||
|
var b = &strings.Builder{}
|
||||||
|
|
||||||
|
if s.Host != "" {
|
||||||
|
hostStr = colorizedNodeName(s.Host)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(b, "%s ", s.Time.Format(timeFormat))
|
||||||
|
statusStr := console.Colorize("RespStatus", fmt.Sprintf("%d %s", s.StatusCode, s.StatusMsg))
|
||||||
|
if s.StatusCode >= http.StatusBadRequest {
|
||||||
|
statusStr = console.Colorize("ErrStatus", fmt.Sprintf("%d %s", s.StatusCode, s.StatusMsg))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(b, "[%s] %s ", statusStr, console.Colorize("FuncName", s.FuncName))
|
||||||
|
fmt.Fprintf(b, "%s%s", hostStr, s.Path)
|
||||||
|
|
||||||
|
if s.Query != "" {
|
||||||
|
fmt.Fprintf(b, "?%s ", s.Query)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(b, " %s ", s.Client)
|
||||||
|
spaces := 15 - len(s.Client)
|
||||||
|
fmt.Fprintf(b, "%*s", spaces, " ")
|
||||||
|
fmt.Fprint(b, console.Colorize("HeaderValue", fmt.Sprintf(" %2s", s.CallStats.Duration.Round(time.Microsecond))))
|
||||||
|
spaces = 12 - len(fmt.Sprintf("%2s", s.CallStats.Duration.Round(time.Microsecond)))
|
||||||
|
fmt.Fprintf(b, "%*s", spaces, " ")
|
||||||
|
fmt.Fprint(b, console.Colorize("Stat", " ↑ "))
|
||||||
|
fmt.Fprint(b, console.Colorize("HeaderValue", humanize.IBytes(uint64(s.CallStats.Rx))))
|
||||||
|
fmt.Fprint(b, console.Colorize("Stat", " ↓ "))
|
||||||
|
fmt.Fprint(b, console.Colorize("HeaderValue", humanize.IBytes(uint64(s.CallStats.Tx))))
|
||||||
|
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// colorize node name
|
||||||
|
func colorizedNodeName(nodeName string) string {
|
||||||
|
nodeHash := fnv.New32a()
|
||||||
|
nodeHash.Write([]byte(nodeName))
|
||||||
|
nHashSum := nodeHash.Sum32()
|
||||||
|
idx := uint32(nHashSum) % uint32(len(colors))
|
||||||
|
return console.Colorize(fmt.Sprintf("Node%d", colors[idx]), nodeName)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t traceMessage) JSON() string {
|
||||||
|
rqHdrs := make(map[string]string)
|
||||||
|
rspHdrs := make(map[string]string)
|
||||||
|
rq := t.Trace.ReqInfo
|
||||||
|
rs := t.Trace.RespInfo
|
||||||
|
for k, v := range rq.Headers {
|
||||||
|
rqHdrs[k] = strings.Join(v, " ")
|
||||||
|
}
|
||||||
|
for k, v := range rs.Headers {
|
||||||
|
rspHdrs[k] = strings.Join(v, " ")
|
||||||
|
}
|
||||||
|
trc := trace{
|
||||||
|
NodeName: t.Trace.NodeName,
|
||||||
|
FuncName: t.Trace.FuncName,
|
||||||
|
RequestInfo: requestInfo{
|
||||||
|
Time: rq.Time,
|
||||||
|
Method: rq.Method,
|
||||||
|
Path: rq.Path,
|
||||||
|
RawQuery: rq.RawQuery,
|
||||||
|
Body: string(rq.Body),
|
||||||
|
Headers: rqHdrs,
|
||||||
|
},
|
||||||
|
ResponseInfo: responseInfo{
|
||||||
|
Time: rs.Time,
|
||||||
|
Body: string(rs.Body),
|
||||||
|
Headers: rspHdrs,
|
||||||
|
StatusCode: rs.StatusCode,
|
||||||
|
},
|
||||||
|
CallStats: callStats{
|
||||||
|
Duration: t.Trace.CallStats.Latency,
|
||||||
|
Rx: t.Trace.CallStats.InputBytes,
|
||||||
|
Tx: t.Trace.CallStats.OutputBytes,
|
||||||
|
Ttfb: t.Trace.CallStats.TimeToFirstByte,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
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(trc)), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
// strip off extra newline added by json encoder
|
||||||
|
return strings.TrimSuffix(buf.String(), "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t traceMessage) String() string {
|
||||||
|
var nodeNameStr string
|
||||||
|
var b = &strings.Builder{}
|
||||||
|
|
||||||
|
trc := t.Trace
|
||||||
|
if trc.NodeName != "" {
|
||||||
|
nodeNameStr = fmt.Sprintf("%s ", colorizedNodeName(trc.NodeName))
|
||||||
|
}
|
||||||
|
|
||||||
|
ri := trc.ReqInfo
|
||||||
|
rs := trc.RespInfo
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Request", fmt.Sprintf("[REQUEST %s] ", trc.FuncName)))
|
||||||
|
fmt.Fprintf(b, "%s\n", ri.Time.Format(timeFormat))
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Method", fmt.Sprintf("%s %s", ri.Method, ri.Path)))
|
||||||
|
if ri.RawQuery != "" {
|
||||||
|
fmt.Fprintf(b, "?%s", ri.RawQuery)
|
||||||
|
}
|
||||||
|
fmt.Fprint(b, "\n")
|
||||||
|
host, ok := ri.Headers["Host"]
|
||||||
|
if ok {
|
||||||
|
delete(ri.Headers, "Host")
|
||||||
|
}
|
||||||
|
hostStr := strings.Join(host, "")
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Host", fmt.Sprintf("Host: %s\n", hostStr)))
|
||||||
|
for k, v := range ri.Headers {
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("ReqHeaderKey",
|
||||||
|
fmt.Sprintf("%s: ", k))+console.Colorize("HeaderValue", fmt.Sprintf("%s\n", strings.Join(v, ""))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Body", fmt.Sprintf("%s\n", string(ri.Body))))
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("Response", "[RESPONSE] "))
|
||||||
|
fmt.Fprintf(b, "[%s] ", rs.Time.Format(timeFormat))
|
||||||
|
fmt.Fprint(b, console.Colorize("Stat", fmt.Sprintf("[ Duration %2s ↑ %s ↓ %s ]\n", trc.CallStats.Latency.Round(time.Microsecond), humanize.IBytes(uint64(trc.CallStats.InputBytes)), humanize.IBytes(uint64(trc.CallStats.OutputBytes)))))
|
||||||
|
|
||||||
|
statusStr := console.Colorize("RespStatus", fmt.Sprintf("%d %s", rs.StatusCode, http.StatusText(rs.StatusCode)))
|
||||||
|
if rs.StatusCode != http.StatusOK {
|
||||||
|
statusStr = console.Colorize("ErrStatus", fmt.Sprintf("%d %s", rs.StatusCode, http.StatusText(rs.StatusCode)))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(b, "%s%s\n", nodeNameStr, statusStr)
|
||||||
|
|
||||||
|
for k, v := range rs.Headers {
|
||||||
|
fmt.Fprintf(b, "%s%s", nodeNameStr, console.Colorize("RespHeaderKey",
|
||||||
|
fmt.Sprintf("%s: ", k))+console.Colorize("HeaderValue", fmt.Sprintf("%s\n", strings.Join(v, ""))))
|
||||||
|
}
|
||||||
|
fmt.Fprintf(b, "%s%s\n", nodeNameStr, console.Colorize("Body", string(rs.Body)))
|
||||||
|
fmt.Fprint(b, nodeNameStr)
|
||||||
|
return b.String()
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018-2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminServerUpdateCmd = cli.Command{
|
||||||
|
Name: "update",
|
||||||
|
Usage: "update all MinIO servers",
|
||||||
|
Action: mainAdminServerUpdate,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Update MinIO server represented by its alias 'play'.
|
||||||
|
{{.Prompt}} {{.HelpName}} play/
|
||||||
|
|
||||||
|
2. Update all MinIO servers in a distributed setup, represented by its alias 'mydist'.
|
||||||
|
{{.Prompt}} {{.HelpName}} mydist/
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// serverUpdateMessage is container for ServerUpdate success and failure messages.
|
||||||
|
type serverUpdateMessage struct {
|
||||||
|
Status string `json:"status"`
|
||||||
|
ServerURL string `json:"serverURL"`
|
||||||
|
CurrentVersion string `json:"currentVersion"`
|
||||||
|
UpdatedVersion string `json:"updatedVersion"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// String colorized serverUpdate message.
|
||||||
|
func (s serverUpdateMessage) String() string {
|
||||||
|
if s.CurrentVersion != s.UpdatedVersion {
|
||||||
|
return console.Colorize("ServerUpdate",
|
||||||
|
fmt.Sprintf("Server `%s` updated successfully from %s to %s",
|
||||||
|
s.ServerURL, s.CurrentVersion, s.UpdatedVersion))
|
||||||
|
}
|
||||||
|
return console.Colorize("ServerUpdate",
|
||||||
|
fmt.Sprintf("Server `%s` already running the most recent version %s of MinIO",
|
||||||
|
s.ServerURL, s.CurrentVersion))
|
||||||
|
}
|
||||||
|
|
||||||
|
// JSON jsonified server update message.
|
||||||
|
func (s serverUpdateMessage) JSON() string {
|
||||||
|
serverUpdateJSONBytes, e := json.MarshalIndent(s, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(serverUpdateJSONBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminServerUpdateSyntax - validate all the passed arguments
|
||||||
|
func checkAdminServerUpdateSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) == 0 || len(ctx.Args()) > 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "update", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func mainAdminServerUpdate(ctx *cli.Context) error {
|
||||||
|
// Validate serivce update syntax.
|
||||||
|
checkAdminServerUpdateSyntax(ctx)
|
||||||
|
|
||||||
|
// Set color.
|
||||||
|
console.SetColor("ServerUpdate", color.New(color.FgGreen, color.Bold))
|
||||||
|
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
aliasedURL := args.Get(0)
|
||||||
|
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection.")
|
||||||
|
|
||||||
|
updateURL := args.Get(1)
|
||||||
|
|
||||||
|
// Update the specified MinIO server, optionally also
|
||||||
|
// with the provided update URL.
|
||||||
|
us, e := client.ServerUpdate(globalContext, updateURL)
|
||||||
|
fatalIf(probe.NewError(e), "Unable to update the server.")
|
||||||
|
|
||||||
|
// Success..
|
||||||
|
printMsg(serverUpdateMessage{
|
||||||
|
Status: "success",
|
||||||
|
ServerURL: aliasedURL,
|
||||||
|
CurrentVersion: us.CurrentVersion,
|
||||||
|
UpdatedVersion: us.UpdatedVersion,
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
json "github.com/minio/mc/pkg/colorjson"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"golang.org/x/crypto/ssh/terminal"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserAddCmd = cli.Command{
|
||||||
|
Name: "add",
|
||||||
|
Usage: "add a new user",
|
||||||
|
Action: mainAdminUserAdd,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET ACCESSKEY SECRETKEY
|
||||||
|
|
||||||
|
ACCESSKEY:
|
||||||
|
Also called as username.
|
||||||
|
|
||||||
|
SECRETKEY:
|
||||||
|
Also called as password.
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Add a new user 'foobar' to MinIO server.
|
||||||
|
{{.DisableHistory}}
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio foobar foo12345
|
||||||
|
{{.EnableHistory}}
|
||||||
|
2. Add a new user 'foobar' to MinIO server, prompting for keys.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
Enter Access Key: foobar
|
||||||
|
Enter Secret Key: foobar12345
|
||||||
|
3. Add a new user 'foobar' to MinIO server using piped keys.
|
||||||
|
{{.DisableHistory}}
|
||||||
|
{{.Prompt}} echo -e "foobar\nfoobar12345" | {{.HelpName}} myminio
|
||||||
|
{{.EnableHistory}}
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserAddSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserAddSyntax(ctx *cli.Context) {
|
||||||
|
argsNr := len(ctx.Args())
|
||||||
|
if argsNr > 3 || argsNr < 1 {
|
||||||
|
fatalIf(errInvalidArgument().Trace(ctx.Args().Tail()...),
|
||||||
|
"Incorrect number of arguments for user add command.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// userMessage container for content message structure
|
||||||
|
type userMessage struct {
|
||||||
|
op string
|
||||||
|
Status string `json:"status"` // TODO: remove this?
|
||||||
|
AccessKey string `json:"accessKey,omitempty"`
|
||||||
|
SecretKey string `json:"secretKey,omitempty"`
|
||||||
|
PolicyName string `json:"policyName,omitempty"`
|
||||||
|
UserStatus string `json:"userStatus,omitempty"`
|
||||||
|
MemberOf []string `json:"memberOf,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u userMessage) String() string {
|
||||||
|
switch u.op {
|
||||||
|
case "list":
|
||||||
|
userFieldMaxLen := 9
|
||||||
|
accessFieldMaxLen := 20
|
||||||
|
policyFieldMaxLen := 20
|
||||||
|
|
||||||
|
// Create a new pretty table with cols configuration
|
||||||
|
return newPrettyTable(" ",
|
||||||
|
Field{"UserStatus", userFieldMaxLen},
|
||||||
|
Field{"AccessKey", accessFieldMaxLen},
|
||||||
|
Field{"PolicyName", policyFieldMaxLen},
|
||||||
|
).buildRow(u.UserStatus, u.AccessKey, u.PolicyName)
|
||||||
|
case "info":
|
||||||
|
return console.Colorize("UserMessage", strings.Join(
|
||||||
|
[]string{
|
||||||
|
fmt.Sprintf("AccessKey: %s", u.AccessKey),
|
||||||
|
fmt.Sprintf("Status: %s", u.UserStatus),
|
||||||
|
fmt.Sprintf("PolicyName: %s", u.PolicyName),
|
||||||
|
fmt.Sprintf("MemberOf: %s", strings.Join(u.MemberOf, ",")),
|
||||||
|
}, "\n"))
|
||||||
|
case "remove":
|
||||||
|
return console.Colorize("UserMessage", "Removed user `"+u.AccessKey+"` successfully.")
|
||||||
|
case "disable":
|
||||||
|
return console.Colorize("UserMessage", "Disabled user `"+u.AccessKey+"` successfully.")
|
||||||
|
case "enable":
|
||||||
|
return console.Colorize("UserMessage", "Enabled user `"+u.AccessKey+"` successfully.")
|
||||||
|
case "add":
|
||||||
|
return console.Colorize("UserMessage", "Added user `"+u.AccessKey+"` successfully.")
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u userMessage) JSON() string {
|
||||||
|
u.Status = "success"
|
||||||
|
jsonMessageBytes, e := json.MarshalIndent(u, "", " ")
|
||||||
|
fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
|
||||||
|
|
||||||
|
return string(jsonMessageBytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fetchUserKeys - returns the access and secret key
|
||||||
|
func fetchUserKeys(args cli.Args) (string, string) {
|
||||||
|
accessKey := ""
|
||||||
|
secretKey := ""
|
||||||
|
console.SetColor(cred, color.New(color.FgYellow, color.Italic))
|
||||||
|
isTerminal := terminal.IsTerminal(int(os.Stdin.Fd()))
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
argCount := len(args)
|
||||||
|
|
||||||
|
if argCount == 1 {
|
||||||
|
if isTerminal {
|
||||||
|
fmt.Printf("%s", console.Colorize(cred, "Enter Access Key: "))
|
||||||
|
}
|
||||||
|
value, _, _ := reader.ReadLine()
|
||||||
|
accessKey = string(value)
|
||||||
|
} else {
|
||||||
|
accessKey = args.Get(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
if argCount == 1 || argCount == 2 {
|
||||||
|
if isTerminal {
|
||||||
|
fmt.Printf("%s", console.Colorize(cred, "Enter Secret Key: "))
|
||||||
|
bytePassword, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||||
|
fmt.Printf("\n")
|
||||||
|
secretKey = string(bytePassword)
|
||||||
|
} else {
|
||||||
|
value, _, _ := reader.ReadLine()
|
||||||
|
secretKey = string(value)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
secretKey = args.Get(2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessKey, secretKey
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserAdd is the handle for "mc admin user add" command.
|
||||||
|
func mainAdminUserAdd(ctx *cli.Context) error {
|
||||||
|
checkAdminUserAddSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// Get the alias parameter from cli
|
||||||
|
args := ctx.Args()
|
||||||
|
aliasedURL := args.Get(0)
|
||||||
|
accessKey, secretKey := fetchUserKeys(args)
|
||||||
|
|
||||||
|
// Create a new MinIO Admin Client
|
||||||
|
client, err := newAdminClient(aliasedURL)
|
||||||
|
fatalIf(err, "Unable to initialize admin connection.")
|
||||||
|
|
||||||
|
fatalIf(probe.NewError(client.AddUser(globalContext, accessKey, secretKey)).Trace(args...), "Cannot add new user")
|
||||||
|
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "add",
|
||||||
|
AccessKey: accessKey,
|
||||||
|
SecretKey: secretKey,
|
||||||
|
UserStatus: "enabled",
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserDisableCmd = cli.Command{
|
||||||
|
Name: "disable",
|
||||||
|
Usage: "disable user",
|
||||||
|
Action: mainAdminUserDisable,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET USERNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Disable a user 'foobar' on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio foobar
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserDisableSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserDisableSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "disable", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserDisable is the handle for "mc admin user disable" command.
|
||||||
|
func mainAdminUserDisable(ctx *cli.Context) error {
|
||||||
|
checkAdminUserDisableSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
e := client.SetUserStatus(globalContext, args.Get(1), madmin.AccountDisabled)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot disable user")
|
||||||
|
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "disable",
|
||||||
|
AccessKey: args.Get(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserEnableCmd = cli.Command{
|
||||||
|
Name: "enable",
|
||||||
|
Usage: "enable user",
|
||||||
|
Action: mainAdminUserEnable,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET USERNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Enable a disabled user 'foobar' on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio foobar
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserEnableSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserEnableSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "enable", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserEnable is the handle for "mc admin user enable" command.
|
||||||
|
func mainAdminUserEnable(ctx *cli.Context) error {
|
||||||
|
checkAdminUserEnableSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
e := client.SetUserStatus(globalContext, args.Get(1), madmin.AccountEnabled)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot enable user")
|
||||||
|
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "enable",
|
||||||
|
AccessKey: args.Get(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserInfoCmd = cli.Command{
|
||||||
|
Name: "info",
|
||||||
|
Usage: "display info of a user",
|
||||||
|
Action: mainAdminUserInfo,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET USERNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Display the info of a user "foobar".
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio foobar
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserAddSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserInfoSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserInfo is the handler for "mc admin user info" command.
|
||||||
|
func mainAdminUserInfo(ctx *cli.Context) error {
|
||||||
|
checkAdminUserInfoSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
user, e := client.GetUserInfo(globalContext, args.Get(1))
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot get user info")
|
||||||
|
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "info",
|
||||||
|
AccessKey: args.Get(1),
|
||||||
|
PolicyName: user.PolicyName,
|
||||||
|
UserStatus: string(user.Status),
|
||||||
|
MemberOf: user.MemberOf,
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserListCmd = cli.Command{
|
||||||
|
Name: "list",
|
||||||
|
Usage: "list all users",
|
||||||
|
Action: mainAdminUserList,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. List all users on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserListSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserListSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 1 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "list", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserList is the handle for "mc admin user list" command.
|
||||||
|
func mainAdminUserList(ctx *cli.Context) error {
|
||||||
|
checkAdminUserListSyntax(ctx)
|
||||||
|
|
||||||
|
// Additional command speific theme customization.
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
console.SetColor("AccessKey", color.New(color.FgBlue))
|
||||||
|
console.SetColor("PolicyName", color.New(color.FgYellow))
|
||||||
|
console.SetColor("UserStatus", color.New(color.FgCyan))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
users, e := client.ListUsers(globalContext)
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot list user")
|
||||||
|
|
||||||
|
for k, v := range users {
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "list",
|
||||||
|
AccessKey: k,
|
||||||
|
PolicyName: v.PolicyName,
|
||||||
|
UserStatus: string(v.Status),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/fatih/color"
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio/pkg/console"
|
||||||
|
)
|
||||||
|
|
||||||
|
var adminUserRemoveCmd = cli.Command{
|
||||||
|
Name: "remove",
|
||||||
|
Usage: "remove user",
|
||||||
|
Action: mainAdminUserRemove,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: globalFlags,
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} TARGET USERNAME
|
||||||
|
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}
|
||||||
|
EXAMPLES:
|
||||||
|
1. Remove a user 'foobar' on MinIO server.
|
||||||
|
{{.Prompt}} {{.HelpName}} myminio foobar
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkAdminUserRemoveSyntax - validate all the passed arguments
|
||||||
|
func checkAdminUserRemoveSyntax(ctx *cli.Context) {
|
||||||
|
if len(ctx.Args()) != 2 {
|
||||||
|
cli.ShowCommandHelpAndExit(ctx, "remove", 1) // last argument is exit code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUserRemove is the handle for "mc admin user remove" command.
|
||||||
|
func mainAdminUserRemove(ctx *cli.Context) error {
|
||||||
|
checkAdminUserRemoveSyntax(ctx)
|
||||||
|
|
||||||
|
console.SetColor("UserMessage", color.New(color.FgGreen))
|
||||||
|
|
||||||
|
// 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.")
|
||||||
|
|
||||||
|
e := client.RemoveUser(globalContext, args.Get(1))
|
||||||
|
fatalIf(probe.NewError(e).Trace(args...), "Cannot remove %s", args.Get(1))
|
||||||
|
|
||||||
|
printMsg(userMessage{
|
||||||
|
op: "remove",
|
||||||
|
AccessKey: args.Get(1),
|
||||||
|
})
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2018 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/minio/cli"
|
||||||
|
|
||||||
|
var adminUserCmd = cli.Command{
|
||||||
|
Name: "user",
|
||||||
|
Usage: "manage users",
|
||||||
|
Action: mainAdminUser,
|
||||||
|
Flags: globalFlags,
|
||||||
|
Subcommands: []cli.Command{
|
||||||
|
adminUserAddCmd,
|
||||||
|
adminUserDisableCmd,
|
||||||
|
adminUserEnableCmd,
|
||||||
|
adminUserRemoveCmd,
|
||||||
|
adminUserListCmd,
|
||||||
|
adminUserInfoCmd,
|
||||||
|
},
|
||||||
|
HideHelpCommand: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainAdminUser is the handle for "mc admin config" command.
|
||||||
|
func mainAdminUser(ctx *cli.Context) error {
|
||||||
|
cli.ShowCommandHelp(ctx, ctx.Args().First())
|
||||||
|
return nil
|
||||||
|
// Sub-commands like "get", "set" have their own main.
|
||||||
|
}
|
||||||
@@ -0,0 +1,367 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2019 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/posener/complete"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fsComplete knows how to complete file/dir names by the given path
|
||||||
|
type fsComplete struct{}
|
||||||
|
|
||||||
|
// predictPathWithTilde completes an FS path which starts with a `~/`
|
||||||
|
func (fs fsComplete) predictPathWithTilde(a complete.Args) []string {
|
||||||
|
homeDir, err := os.UserHomeDir()
|
||||||
|
if err != nil || homeDir == "" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Clean the home directory path
|
||||||
|
homeDir = strings.TrimRight(homeDir, "/")
|
||||||
|
|
||||||
|
// Replace the first occurrence of ~ with the real path and complete
|
||||||
|
a.Last = strings.Replace(a.Last, "~", homeDir, 1)
|
||||||
|
predictions := complete.PredictFiles("*").Predict(a)
|
||||||
|
|
||||||
|
// Restore ~ to avoid disturbing the completion user experience
|
||||||
|
for i := range predictions {
|
||||||
|
predictions[i] = strings.Replace(predictions[i], homeDir, "~", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
return predictions
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs fsComplete) Predict(a complete.Args) []string {
|
||||||
|
if strings.HasPrefix(a.Last, "~/") {
|
||||||
|
return fs.predictPathWithTilde(a)
|
||||||
|
}
|
||||||
|
return complete.PredictFiles("*").Predict(a)
|
||||||
|
}
|
||||||
|
|
||||||
|
func completeAdminConfigKeys(aliasPath string, keyPrefix string) (prediction []string) {
|
||||||
|
// Convert alias/bucket/incompl to alias/bucket/ to list its contents
|
||||||
|
parentDirPath := filepath.Dir(aliasPath) + "/"
|
||||||
|
clnt, err := newAdminClient(parentDirPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h, e := clnt.HelpConfigKV(globalContext, "", "", false)
|
||||||
|
if e != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, hkv := range h.KeysHelp {
|
||||||
|
if strings.HasPrefix(hkv.Key, keyPrefix) {
|
||||||
|
prediction = append(prediction, hkv.Key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return prediction
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete S3 path. If the prediction result is only one directory,
|
||||||
|
// then recursively scans it. This is needed to satisfy posener/complete
|
||||||
|
// (look at posener/complete.PredictFiles)
|
||||||
|
func completeS3Path(s3Path string) (prediction []string) {
|
||||||
|
|
||||||
|
// Convert alias/bucket/incompl to alias/bucket/ to list its contents
|
||||||
|
parentDirPath := filepath.Dir(s3Path) + "/"
|
||||||
|
clnt, err := newClient(parentDirPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate alias from the path
|
||||||
|
alias := splitStr(s3Path, "/", 3)[0]
|
||||||
|
|
||||||
|
// List dirPath content and only pick elements that corresponds
|
||||||
|
// to the path that we want to complete
|
||||||
|
for content := range clnt.List(globalContext, false, false, false, DirFirst) {
|
||||||
|
cmplS3Path := alias + getKey(content)
|
||||||
|
if content.Type.IsDir() {
|
||||||
|
if !strings.HasSuffix(cmplS3Path, "/") {
|
||||||
|
cmplS3Path += "/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(cmplS3Path, s3Path) {
|
||||||
|
prediction = append(prediction, cmplS3Path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If completion found only one directory, recursively scan it.
|
||||||
|
if len(prediction) == 1 && strings.HasSuffix(prediction[0], "/") {
|
||||||
|
prediction = append(prediction, completeS3Path(prediction[0])...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
type adminConfigComplete struct{}
|
||||||
|
|
||||||
|
func (adm adminConfigComplete) Predict(a complete.Args) (prediction []string) {
|
||||||
|
defer func() {
|
||||||
|
sort.Strings(prediction)
|
||||||
|
}()
|
||||||
|
|
||||||
|
loadMcConfig = loadMcConfigFactory()
|
||||||
|
conf, err := loadMcConfig()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// We have already predicted the keys, we are done.
|
||||||
|
if len(a.Completed) == 3 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
arg := a.Last
|
||||||
|
lastArg := a.LastCompleted
|
||||||
|
if _, ok := conf.Hosts[filepath.Clean(a.LastCompleted)]; !ok {
|
||||||
|
if strings.IndexByte(arg, '/') == -1 {
|
||||||
|
// Only predict alias since '/' is not found
|
||||||
|
for alias := range conf.Hosts {
|
||||||
|
if strings.HasPrefix(alias, arg) {
|
||||||
|
prediction = append(prediction, alias+"/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prediction = completeAdminConfigKeys(arg, "")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
prediction = completeAdminConfigKeys(lastArg, arg)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// s3Complete knows how to complete an mc s3 path
|
||||||
|
type s3Complete struct {
|
||||||
|
deepLevel int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s3 s3Complete) Predict(a complete.Args) (prediction []string) {
|
||||||
|
defer func() {
|
||||||
|
sort.Strings(prediction)
|
||||||
|
}()
|
||||||
|
|
||||||
|
loadMcConfig = loadMcConfigFactory()
|
||||||
|
conf, err := loadMcConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
arg := a.Last
|
||||||
|
|
||||||
|
if strings.IndexByte(arg, '/') == -1 {
|
||||||
|
// Only predict alias since '/' is not found
|
||||||
|
for alias := range conf.Hosts {
|
||||||
|
if strings.HasPrefix(alias, arg) {
|
||||||
|
prediction = append(prediction, alias+"/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(prediction) == 1 && strings.HasSuffix(prediction[0], "/") {
|
||||||
|
prediction = append(prediction, completeS3Path(prediction[0])...)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Complete S3 path until the specified path deep level
|
||||||
|
if s3.deepLevel > 0 {
|
||||||
|
if strings.Count(arg, "/") >= s3.deepLevel {
|
||||||
|
return []string{arg}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Predict S3 path
|
||||||
|
prediction = completeS3Path(arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// aliasComplete only completes aliases
|
||||||
|
type aliasComplete struct{}
|
||||||
|
|
||||||
|
func (al aliasComplete) Predict(a complete.Args) (prediction []string) {
|
||||||
|
defer func() {
|
||||||
|
sort.Strings(prediction)
|
||||||
|
}()
|
||||||
|
|
||||||
|
loadMcConfig = loadMcConfigFactory()
|
||||||
|
conf, err := loadMcConfig()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
arg := a.Last
|
||||||
|
for alias := range conf.Hosts {
|
||||||
|
if strings.HasPrefix(alias, arg) {
|
||||||
|
prediction = append(prediction, alias+"/")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var adminConfigCompleter = adminConfigComplete{}
|
||||||
|
var s3Completer = s3Complete{}
|
||||||
|
var aliasCompleter = aliasComplete{}
|
||||||
|
var fsCompleter = fsComplete{}
|
||||||
|
|
||||||
|
// The list of all commands supported by mc with their mapping
|
||||||
|
// with their bash completer function
|
||||||
|
var completeCmds = map[string]complete.Predictor{
|
||||||
|
// S3 API level commands
|
||||||
|
"/ls": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/cp": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/rm": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/rb": complete.PredictOr(s3Complete{deepLevel: 2}, fsCompleter),
|
||||||
|
"/cat": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/head": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/diff": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/find": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/mirror": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/pipe": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/stat": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/watch": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/policy": complete.PredictOr(s3Completer, fsCompleter),
|
||||||
|
"/tree": complete.PredictOr(s3Complete{deepLevel: 2}, fsCompleter),
|
||||||
|
"/du": complete.PredictOr(s3Complete{deepLevel: 2}, fsCompleter),
|
||||||
|
"/retention": s3Completer,
|
||||||
|
"/sql": s3Completer,
|
||||||
|
"/lock": complete.PredictOr(s3Complete{deepLevel: 2}),
|
||||||
|
"/mb": aliasCompleter,
|
||||||
|
|
||||||
|
"/event/add": aliasCompleter,
|
||||||
|
"/event/list": aliasCompleter,
|
||||||
|
"/event/remove": aliasCompleter,
|
||||||
|
|
||||||
|
"/tag/list": s3Completer,
|
||||||
|
"/tag/remove": s3Completer,
|
||||||
|
"/tag/set": s3Completer,
|
||||||
|
|
||||||
|
"/share/download": s3Completer,
|
||||||
|
"/share/list": nil,
|
||||||
|
"/share/upload": s3Completer,
|
||||||
|
|
||||||
|
// Admin API commands MinIO only.
|
||||||
|
"/admin/heal": s3Completer,
|
||||||
|
|
||||||
|
"/admin/info": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/config/get": adminConfigCompleter,
|
||||||
|
"/admin/config/set": adminConfigCompleter,
|
||||||
|
"/admin/config/reset": adminConfigCompleter,
|
||||||
|
"/admin/config/import": aliasCompleter,
|
||||||
|
"/admin/config/export": aliasCompleter,
|
||||||
|
"/admin/config/history": aliasCompleter,
|
||||||
|
"/admin/config/restore": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/trace": aliasCompleter,
|
||||||
|
"/admin/console": aliasCompleter,
|
||||||
|
"/admin/update": aliasCompleter,
|
||||||
|
"/admin/top/locks": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/service/stop": aliasCompleter,
|
||||||
|
"/admin/service/restart": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/prometheus/generate": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/profile/start": aliasCompleter,
|
||||||
|
"/admin/profile/stop": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/policy/info": aliasCompleter,
|
||||||
|
"/admin/policy/set": aliasCompleter,
|
||||||
|
"/admin/policy/add": aliasCompleter,
|
||||||
|
"/admin/policy/list": aliasCompleter,
|
||||||
|
"/admin/policy/remove": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/user/add": aliasCompleter,
|
||||||
|
"/admin/user/disable": aliasCompleter,
|
||||||
|
"/admin/user/enable": aliasCompleter,
|
||||||
|
"/admin/user/list": aliasCompleter,
|
||||||
|
"/admin/user/remove": aliasCompleter,
|
||||||
|
"/admin/user/info": aliasCompleter,
|
||||||
|
|
||||||
|
"/admin/group/add": aliasCompleter,
|
||||||
|
"/admin/group/disable": aliasCompleter,
|
||||||
|
"/admin/group/enable": aliasCompleter,
|
||||||
|
"/admin/group/list": aliasCompleter,
|
||||||
|
"/admin/group/remove": aliasCompleter,
|
||||||
|
"/admin/group/info": aliasCompleter,
|
||||||
|
|
||||||
|
"/config/host/add": nil,
|
||||||
|
"/config/host/list": aliasCompleter,
|
||||||
|
"/config/host/remove": aliasCompleter,
|
||||||
|
|
||||||
|
"/update": nil,
|
||||||
|
"/version": nil,
|
||||||
|
}
|
||||||
|
|
||||||
|
// flagsToCompleteFlags transforms a cli.Flag to complete.Flags
|
||||||
|
// understood by posener/complete library.
|
||||||
|
func flagsToCompleteFlags(flags []cli.Flag) complete.Flags {
|
||||||
|
var complFlags = make(complete.Flags)
|
||||||
|
for _, f := range flags {
|
||||||
|
for _, s := range strings.Split(f.GetName(), ",") {
|
||||||
|
var flagName string
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
if len(s) == 1 {
|
||||||
|
flagName = "-" + s
|
||||||
|
} else {
|
||||||
|
flagName = "--" + s
|
||||||
|
}
|
||||||
|
complFlags[flagName] = complete.PredictNothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return complFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function recursively transforms cli.Command to complete.Command
|
||||||
|
// understood by posener/complete library.
|
||||||
|
func cmdToCompleteCmd(cmd cli.Command, parentPath string) complete.Command {
|
||||||
|
var complCmd complete.Command
|
||||||
|
complCmd.Sub = make(complete.Commands)
|
||||||
|
|
||||||
|
for _, subCmd := range cmd.Subcommands {
|
||||||
|
complCmd.Sub[subCmd.Name] = cmdToCompleteCmd(subCmd, parentPath+"/"+cmd.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
complCmd.Flags = flagsToCompleteFlags(cmd.Flags)
|
||||||
|
complCmd.Args = completeCmds[parentPath+"/"+cmd.Name]
|
||||||
|
return complCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main function to answer to bash completion calls
|
||||||
|
func mainComplete() error {
|
||||||
|
// Recursively register all commands and subcommands
|
||||||
|
// along with global and local flags
|
||||||
|
var complCmds = make(complete.Commands)
|
||||||
|
for _, cmd := range appCmds {
|
||||||
|
complCmds[cmd.Name] = cmdToCompleteCmd(cmd, "")
|
||||||
|
}
|
||||||
|
complFlags := flagsToCompleteFlags(globalFlags)
|
||||||
|
mcComplete := complete.Command{
|
||||||
|
Sub: complCmds,
|
||||||
|
GlobalFlags: complFlags,
|
||||||
|
}
|
||||||
|
// Answer to bash completion call
|
||||||
|
complete.New(filepath.Base(os.Args[0]), mcComplete).Run()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Client (C) 2014, 2015 Minio, Inc.
|
* MinIO Client (C) 2014, 2015 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,15 +14,15 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package main
|
package cmd
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// mcVersion - version time.RFC3339.
|
// Version - version time.RFC3339.
|
||||||
mcVersion = "UNOFFICIAL.GOGET"
|
Version = "DEVELOPMENT.GOGET"
|
||||||
// mcReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ.
|
// ReleaseTag - release tag in TAG.%Y-%m-%dT%H-%M-%SZ.
|
||||||
mcReleaseTag = "UNOFFICIAL.GOGET"
|
ReleaseTag = "DEVELOPMENT.GOGET"
|
||||||
// mcCommitID - latest commit id.
|
// CommitID - latest commit id.
|
||||||
mcCommitID = "UNOFFICIAL.GOGET"
|
CommitID = "DEVELOPMENT.GOGET"
|
||||||
// mcShortCommitID - first 12 characters from mcCommitID.
|
// ShortCommitID - first 12 characters from CommitID.
|
||||||
mcShortCommitID = mcCommitID[:12]
|
ShortCommitID = CommitID[:12]
|
||||||
)
|
)
|
||||||
+255
@@ -0,0 +1,255 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client, (C) 2015, 2016, 2017 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
|
"github.com/minio/cli"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// This is kept dummy for future purposes
|
||||||
|
// and also to add ioFlags and globalFlags
|
||||||
|
// in CLI registration.
|
||||||
|
catFlags = []cli.Flag{}
|
||||||
|
)
|
||||||
|
|
||||||
|
// Display contents of a file.
|
||||||
|
var catCmd = cli.Command{
|
||||||
|
Name: "cat",
|
||||||
|
Usage: "display object contents",
|
||||||
|
Action: mainCat,
|
||||||
|
Before: initBeforeRunningCmd,
|
||||||
|
Flags: append(append(catFlags, ioFlags...), globalFlags...),
|
||||||
|
CustomHelpTemplate: `NAME:
|
||||||
|
{{.HelpName}} - {{.Usage}}
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
{{.HelpName}} [FLAGS] SOURCE [SOURCE...]
|
||||||
|
{{if .VisibleFlags}}
|
||||||
|
FLAGS:
|
||||||
|
{{range .VisibleFlags}}{{.}}
|
||||||
|
{{end}}{{end}}
|
||||||
|
ENVIRONMENT VARIABLES:
|
||||||
|
MC_ENCRYPT_KEY: list of comma delimited prefix=secret values
|
||||||
|
|
||||||
|
EXAMPLES:
|
||||||
|
1. Stream an object from Amazon S3 cloud storage to mplayer standard input.
|
||||||
|
{{.Prompt}} {{.HelpName}} s3/mysql-backups/kubecon-mysql-operator.mpv | mplayer -
|
||||||
|
|
||||||
|
2. Concatenate contents of file1.txt and stdin to standard output.
|
||||||
|
{{.Prompt}} {{.HelpName}} file1.txt - > file.txt
|
||||||
|
|
||||||
|
3. Concatenate multiple files to one.
|
||||||
|
{{.Prompt}} {{.HelpName}} part.* > complete.img
|
||||||
|
|
||||||
|
4. Save an encrypted object from Amazon S3 cloud storage to a local file.
|
||||||
|
{{.Prompt}} {{.HelpName}} --encrypt-key 's3/mysql-backups=32byteslongsecretkeymustbegiven1' s3/mysql-backups/backups-201810.gz > /mnt/data/recent.gz
|
||||||
|
|
||||||
|
5. Display the content of encrypted object. In case the encryption key contains non-printable character like tab, pass the
|
||||||
|
base64 encoded string as key.
|
||||||
|
{{.Prompt}} {{.HelpName}} --encrypt-key "play/my-bucket/=MzJieXRlc2xvbmdzZWNyZXRrZQltdXN0YmVnaXZlbjE=" play/my-bucket/my-object
|
||||||
|
`,
|
||||||
|
}
|
||||||
|
|
||||||
|
// prettyStdout replaces some non printable characters
|
||||||
|
// with <hex> format to be better viewable by the user
|
||||||
|
type prettyStdout struct {
|
||||||
|
// Internal data to pretty-print
|
||||||
|
writer io.Writer
|
||||||
|
// Internal buffer which contains pretty printed
|
||||||
|
// form of binary (no printable) characters
|
||||||
|
buffer *bytes.Buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
// newPrettyStdout returns an initialized prettyStdout struct
|
||||||
|
func newPrettyStdout(w io.Writer) *prettyStdout {
|
||||||
|
return &prettyStdout{
|
||||||
|
writer: w,
|
||||||
|
buffer: bytes.NewBuffer([]byte{}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read() returns pretty printed binary characters
|
||||||
|
func (s prettyStdout) Write(input []byte) (int, error) {
|
||||||
|
inputLen := len(input)
|
||||||
|
|
||||||
|
// Convert no printable characters to '^?'
|
||||||
|
// and fill into s.buffer
|
||||||
|
for len(input) > 0 {
|
||||||
|
r, size := utf8.DecodeRune(input)
|
||||||
|
if unicode.IsPrint(r) || unicode.IsSpace(r) {
|
||||||
|
s.buffer.WriteRune(r)
|
||||||
|
} else {
|
||||||
|
s.buffer.WriteString("^?")
|
||||||
|
}
|
||||||
|
input = input[size:]
|
||||||
|
}
|
||||||
|
|
||||||
|
bufLen := s.buffer.Len()
|
||||||
|
|
||||||
|
// Copy all buffer content to the writer (stdout)
|
||||||
|
n, err := s.buffer.WriteTo(s.writer)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if int(n) != bufLen {
|
||||||
|
return 0, errors.New("error when writing to stdout")
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputLen, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// checkCatSyntax performs command-line input validation for cat command.
|
||||||
|
func checkCatSyntax(ctx *cli.Context) {
|
||||||
|
args := ctx.Args()
|
||||||
|
if !args.Present() {
|
||||||
|
args = []string{"-"}
|
||||||
|
}
|
||||||
|
for _, arg := range args {
|
||||||
|
if strings.HasPrefix(arg, "-") && len(arg) > 1 {
|
||||||
|
fatalIf(probe.NewError(errors.New("")), fmt.Sprintf("Unknown flag `%s` passed.", arg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// catURL displays contents of a URL to stdout.
|
||||||
|
func catURL(ctx context.Context, sourceURL string, encKeyDB map[string][]prefixSSEPair) *probe.Error {
|
||||||
|
var reader io.ReadCloser
|
||||||
|
size := int64(-1)
|
||||||
|
switch sourceURL {
|
||||||
|
case "-":
|
||||||
|
reader = os.Stdin
|
||||||
|
default:
|
||||||
|
var err *probe.Error
|
||||||
|
// Try to stat the object, the purpose is to extract the
|
||||||
|
// size of S3 object so we can check if the size of the
|
||||||
|
// downloaded object is equal to the original one. FS files
|
||||||
|
// are ignored since some of them have zero size though they
|
||||||
|
// have contents like files under /proc.
|
||||||
|
client, content, err := url2Stat(ctx, sourceURL, false, encKeyDB)
|
||||||
|
if err == nil && client.GetURL().Type == objectStorage {
|
||||||
|
size = content.Size
|
||||||
|
}
|
||||||
|
if reader, err = getSourceStreamFromURL(ctx, sourceURL, encKeyDB); err != nil {
|
||||||
|
return err.Trace(sourceURL)
|
||||||
|
}
|
||||||
|
defer reader.Close()
|
||||||
|
}
|
||||||
|
return catOut(reader, size).Trace(sourceURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
// catOut reads from reader stream and writes to stdout. Also check the length of the
|
||||||
|
// read bytes against size parameter (if not -1) and return the appropriate error
|
||||||
|
func catOut(r io.Reader, size int64) *probe.Error {
|
||||||
|
var n int64
|
||||||
|
var e error
|
||||||
|
|
||||||
|
var stdout io.Writer
|
||||||
|
|
||||||
|
// In case of a user showing the object content in a terminal,
|
||||||
|
// avoid printing control and other bad characters to avoid
|
||||||
|
// terminal session corruption
|
||||||
|
if isTerminal() {
|
||||||
|
stdout = newPrettyStdout(os.Stdout)
|
||||||
|
} else {
|
||||||
|
stdout = os.Stdout
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read till EOF.
|
||||||
|
if n, e = io.Copy(stdout, r); e != nil {
|
||||||
|
switch e := e.(type) {
|
||||||
|
case *os.PathError:
|
||||||
|
if e.Err == syscall.EPIPE {
|
||||||
|
// stdout closed by the user. Gracefully exit.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return probe.NewError(e)
|
||||||
|
default:
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if size != -1 && n < size {
|
||||||
|
return probe.NewError(UnexpectedEOF{
|
||||||
|
TotalSize: size,
|
||||||
|
TotalWritten: n,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if size != -1 && n > size {
|
||||||
|
return probe.NewError(UnexpectedEOF{
|
||||||
|
TotalSize: size,
|
||||||
|
TotalWritten: n,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// mainCat is the main entry point for cat command.
|
||||||
|
func mainCat(cliCtx *cli.Context) error {
|
||||||
|
ctx, cancelCat := context.WithCancel(globalContext)
|
||||||
|
defer cancelCat()
|
||||||
|
|
||||||
|
// Parse encryption keys per command.
|
||||||
|
encKeyDB, err := getEncKeys(cliCtx)
|
||||||
|
fatalIf(err, "Unable to parse encryption keys.")
|
||||||
|
|
||||||
|
// check 'cat' cli arguments.
|
||||||
|
checkCatSyntax(cliCtx)
|
||||||
|
|
||||||
|
// Set command flags from context.
|
||||||
|
stdinMode := false
|
||||||
|
if !cliCtx.Args().Present() {
|
||||||
|
stdinMode = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle std input data.
|
||||||
|
if stdinMode {
|
||||||
|
fatalIf(catOut(os.Stdin, -1).Trace(), "Unable to read from standard input.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// if Args contain `-`, we need to preserve its order specially.
|
||||||
|
args := []string(cliCtx.Args())
|
||||||
|
if cliCtx.Args().First() == "-" {
|
||||||
|
for i, arg := range os.Args {
|
||||||
|
if arg == "cat" {
|
||||||
|
// Overwrite cliCtx.Args with os.Args.
|
||||||
|
args = os.Args[i+1:]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert arguments to URLs: expand alias, fix format.
|
||||||
|
for _, url := range args {
|
||||||
|
fatalIf(catURL(ctx, url, encKeyDB).Trace(url), "Unable to read from `"+url+"`.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrettyStdout(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
originText string
|
||||||
|
prettyText string
|
||||||
|
}{
|
||||||
|
{"", ""},
|
||||||
|
{"text", "text"},
|
||||||
|
// Check with new lines
|
||||||
|
{"text\r\n", "text\r\n"},
|
||||||
|
{"\ttext\n", "\ttext\n"},
|
||||||
|
// Print some unicode characters and check if it is not altered
|
||||||
|
{"добро пожаловать.", "добро пожаловать."},
|
||||||
|
// Print colored text
|
||||||
|
{"\x1b\x5b\x33\x31\x6d\x66\x61\x69\x6c", "^?[31mfail"},
|
||||||
|
// Print clear screen
|
||||||
|
{"\x1b\x63", "^?c"},
|
||||||
|
// Random data
|
||||||
|
{"\x3d\xef\xd2\xb5", "=�ҵ"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, testCase := range testCases {
|
||||||
|
reader := bytes.NewReader([]byte(testCase.originText))
|
||||||
|
fakeStdout := bytes.NewBuffer([]byte(""))
|
||||||
|
n, err := io.Copy(newPrettyStdout(fakeStdout), reader)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Test %d: %v\n", i+1, err)
|
||||||
|
}
|
||||||
|
if int(n) != len(testCase.originText) {
|
||||||
|
t.Fatalf("Test %d: copy error\n", i+1)
|
||||||
|
}
|
||||||
|
prettyText, err := ioutil.ReadAll(fakeStdout)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Test %d: %v", i+1, err)
|
||||||
|
}
|
||||||
|
if string(prettyText) != testCase.prettyText {
|
||||||
|
t.Fatalf("Test %d: expected output `%s`, found output `%s`", i+1, testCase.prettyText, string(prettyText))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+135
@@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2016 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/x509"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
)
|
||||||
|
|
||||||
|
// getCertsDir - return the full path of certs dir
|
||||||
|
func getCertsDir() (string, *probe.Error) {
|
||||||
|
p, err := getMcConfigDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err.Trace()
|
||||||
|
}
|
||||||
|
return filepath.Join(p, globalMCCertsDir), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// isCertsDirExists - verify if certs directory exists.
|
||||||
|
func isCertsDirExists() bool {
|
||||||
|
certsDir, err := getCertsDir()
|
||||||
|
fatalIf(err.Trace(), "Unable to determine certs folder.")
|
||||||
|
if _, e := os.Stat(certsDir); e != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// createCertsDir - create MinIO Client certs folder
|
||||||
|
func createCertsDir() *probe.Error {
|
||||||
|
p, err := getCertsDir()
|
||||||
|
if err != nil {
|
||||||
|
return err.Trace()
|
||||||
|
}
|
||||||
|
if e := os.MkdirAll(p, 0700); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getCAsDir - return the full path of CAs dir
|
||||||
|
func getCAsDir() (string, *probe.Error) {
|
||||||
|
p, err := getCertsDir()
|
||||||
|
if err != nil {
|
||||||
|
return "", err.Trace()
|
||||||
|
}
|
||||||
|
return filepath.Join(p, globalMCCAsDir), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// mustGetCAsDir - return the full path of CAs dir or empty string when an error occurs
|
||||||
|
func mustGetCAsDir() string {
|
||||||
|
p, err := getCAsDir()
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
// isCAsDirExists - verify if CAs directory exists.
|
||||||
|
func isCAsDirExists() bool {
|
||||||
|
CAsDir, err := getCAsDir()
|
||||||
|
fatalIf(err.Trace(), "Unable to determine CAs folder.")
|
||||||
|
if _, e := os.Stat(CAsDir); e != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// createCAsDir - create MinIO Client CAs folder
|
||||||
|
func createCAsDir() *probe.Error {
|
||||||
|
p, err := getCAsDir()
|
||||||
|
if err != nil {
|
||||||
|
return err.Trace()
|
||||||
|
}
|
||||||
|
if e := os.MkdirAll(p, 0700); e != nil {
|
||||||
|
return probe.NewError(e)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// mustGetCAFiles - get the list of the CA certificates stored in MinIO config dir
|
||||||
|
func mustGetCAFiles() (caCerts []string) {
|
||||||
|
CAsDir := mustGetCAsDir()
|
||||||
|
caFiles, _ := ioutil.ReadDir(CAsDir)
|
||||||
|
for _, cert := range caFiles {
|
||||||
|
caCerts = append(caCerts, filepath.Join(CAsDir, cert.Name()))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// mustGetSystemCertPool - return system CAs or empty pool in case of error (or windows)
|
||||||
|
func mustGetSystemCertPool() *x509.CertPool {
|
||||||
|
pool, err := x509.SystemCertPool()
|
||||||
|
if err != nil {
|
||||||
|
return x509.NewCertPool()
|
||||||
|
}
|
||||||
|
return pool
|
||||||
|
}
|
||||||
|
|
||||||
|
// loadRootCAs fetches CA files provided in MinIO config and adds them to globalRootCAs
|
||||||
|
// Currently under Windows, there is no way to load system + user CAs at the same time
|
||||||
|
func loadRootCAs() {
|
||||||
|
caFiles := mustGetCAFiles()
|
||||||
|
if len(caFiles) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Get system cert pool, and empty cert pool under Windows because it is not supported
|
||||||
|
globalRootCAs = mustGetSystemCertPool()
|
||||||
|
// Load custom root CAs for client requests
|
||||||
|
for _, caFile := range caFiles {
|
||||||
|
caCert, err := ioutil.ReadFile(caFile)
|
||||||
|
if err != nil {
|
||||||
|
fatalIf(probe.NewError(err), "Unable to load a CA file.")
|
||||||
|
}
|
||||||
|
globalRootCAs.AppendCertsFromPEM(caCert)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,159 @@
|
|||||||
|
/*
|
||||||
|
* MinIO Client (C) 2017-2020 MinIO, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
|
"hash/fnv"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/mattn/go-ieproxy"
|
||||||
|
"github.com/minio/mc/pkg/httptracer"
|
||||||
|
"github.com/minio/mc/pkg/probe"
|
||||||
|
"github.com/minio/minio-go/v6/pkg/credentials"
|
||||||
|
"github.com/minio/minio/pkg/madmin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewAdminFactory encloses New function with client cache.
|
||||||
|
func NewAdminFactory() func(config *Config) (*madmin.AdminClient, *probe.Error) {
|
||||||
|
clientCache := make(map[uint32]*madmin.AdminClient)
|
||||||
|
mutex := &sync.Mutex{}
|
||||||
|
|
||||||
|
// Return New function.
|
||||||
|
return func(config *Config) (*madmin.AdminClient, *probe.Error) {
|
||||||
|
// Creates a parsed URL.
|
||||||
|
targetURL, e := url.Parse(config.HostURL)
|
||||||
|
if e != nil {
|
||||||
|
return nil, probe.NewError(e)
|
||||||
|
}
|
||||||
|
// By default enable HTTPs.
|
||||||
|
useTLS := true
|
||||||
|
if targetURL.Scheme == "http" {
|
||||||
|
useTLS = false
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save if target supports virtual host style.
|
||||||
|
hostName := targetURL.Host
|
||||||
|
|
||||||
|
// Generate a hash out of s3Conf.
|
||||||
|
confHash := fnv.New32a()
|
||||||
|
confHash.Write([]byte(hostName + config.AccessKey + config.SecretKey))
|
||||||
|
confSum := confHash.Sum32()
|
||||||
|
|
||||||
|
// Lookup previous cache by hash.
|
||||||
|
mutex.Lock()
|
||||||
|
defer mutex.Unlock()
|
||||||
|
var api *madmin.AdminClient
|
||||||
|
var found bool
|
||||||
|
if api, found = clientCache[confSum]; !found {
|
||||||
|
// Admin API only supports signature v4.
|
||||||
|
creds := credentials.NewStaticV4(config.AccessKey, config.SecretKey, config.SessionToken)
|
||||||
|
|
||||||
|
// Not found. Instantiate a new MinIO
|
||||||
|
var e error
|
||||||
|
api, e = madmin.NewWithOptions(hostName, &madmin.Options{
|
||||||
|
Creds: creds,
|
||||||
|
Secure: useTLS,
|
||||||
|
})
|
||||||
|
if e != nil {
|
||||||
|
return nil, probe.NewError(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Keep TLS config.
|
||||||
|
tlsConfig := &tls.Config{
|
||||||
|
RootCAs: globalRootCAs,
|
||||||
|
// Can't use SSLv3 because of POODLE and BEAST
|
||||||
|
// Can't use TLSv1.0 because of POODLE and BEAST using CBC cipher
|
||||||
|
// Can't use TLSv1.1 because of RC4 cipher usage
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
}
|
||||||
|
if config.Insecure {
|
||||||
|
tlsConfig.InsecureSkipVerify = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var transport http.RoundTripper = &http.Transport{
|
||||||
|
Proxy: ieproxy.GetProxyFunc(),
|
||||||
|
DialContext: (&net.Dialer{
|
||||||
|
Timeout: 10 * time.Second,
|
||||||
|
KeepAlive: 15 * time.Second,
|
||||||
|
}).DialContext,
|
||||||
|
MaxIdleConnsPerHost: 256,
|
||||||
|
IdleConnTimeout: 90 * time.Second,
|
||||||
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
|
ExpectContinueTimeout: 10 * time.Second,
|
||||||
|
TLSClientConfig: tlsConfig,
|
||||||
|
// Set this value so that the underlying transport round-tripper
|
||||||
|
// doesn't try to auto decode the body of objects with
|
||||||
|
// content-encoding set to `gzip`.
|
||||||
|
//
|
||||||
|
// Refer:
|
||||||
|
// https://golang.org/src/net/http/transport.go?h=roundTrip#L1843
|
||||||
|
DisableCompression: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Debug {
|
||||||
|
transport = httptracer.GetNewTraceTransport(newTraceV4(), transport)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set custom transport.
|
||||||
|
api.SetCustomTransport(transport)
|
||||||
|
|
||||||
|
// Set app info.
|
||||||
|
api.SetAppInfo(config.AppName, config.AppVersion)
|
||||||
|
|
||||||
|
// Cache the new MinIO Client with hash of config as key.
|
||||||
|
clientCache[confSum] = api
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the new api object.
|
||||||
|
return api, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// newAdminClient gives a new client interface
|
||||||
|
func newAdminClient(aliasedURL string) (*madmin.AdminClient, *probe.Error) {
|
||||||
|
alias, urlStrFull, hostCfg, err := expandAlias(aliasedURL)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err.Trace(aliasedURL)
|
||||||
|
}
|
||||||
|
// Verify if the aliasedURL is a real URL, fail in those cases
|
||||||
|
// indicating the user to add alias.
|
||||||
|
if hostCfg == nil && urlRgx.MatchString(aliasedURL) {
|
||||||
|
return nil, errInvalidAliasedURL(aliasedURL).Trace(aliasedURL)
|
||||||
|
}
|
||||||
|
|
||||||
|
if hostCfg == nil {
|
||||||
|
return nil, probe.NewError(fmt.Errorf("No valid configuration found for '%s' host alias", urlStrFull))
|
||||||
|
}
|
||||||
|
|
||||||
|
s3Config := NewS3Config(urlStrFull, hostCfg)
|
||||||
|
|
||||||
|
s3Client, err := s3AdminNew(s3Config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err.Trace(alias, urlStrFull)
|
||||||
|
}
|
||||||
|
return s3Client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// s3AdminNew returns an initialized minioAdmin structure. If debug is enabled,
|
||||||
|
// it also enables an internal trace transport.
|
||||||
|
var s3AdminNew = NewAdminFactory()
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Minio Client (C) 2015 Minio, Inc.
|
* MinIO Client (C) 2015 MinIO, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -14,12 +14,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package client
|
package cmd
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
/// Collection of standard errors
|
/// Collection of standard errors
|
||||||
|
|
||||||
@@ -30,16 +27,7 @@ type APINotImplemented struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e APINotImplemented) Error() string {
|
func (e APINotImplemented) Error() string {
|
||||||
return "‘" + e.API + "’ feature " + "is not implemented for ‘" + e.APIType + "’."
|
return "`" + e.API + "` is not supported for `" + e.APIType + "`."
|
||||||
}
|
|
||||||
|
|
||||||
// InvalidRange - invalid range requested
|
|
||||||
type InvalidRange struct {
|
|
||||||
Offset int64
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e InvalidRange) Error() string {
|
|
||||||
return "Invalid range offset: ‘" + strconv.FormatInt(e.Offset, 10) + "’."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericBucketError - generic bucket operations error
|
// GenericBucketError - generic bucket operations error
|
||||||
@@ -51,21 +39,14 @@ type GenericBucketError struct {
|
|||||||
type BucketDoesNotExist GenericBucketError
|
type BucketDoesNotExist GenericBucketError
|
||||||
|
|
||||||
func (e BucketDoesNotExist) Error() string {
|
func (e BucketDoesNotExist) Error() string {
|
||||||
return "Bucket ‘" + e.Bucket + "’ does not exist."
|
return "Bucket `" + e.Bucket + "` does not exist."
|
||||||
}
|
}
|
||||||
|
|
||||||
// BucketExists - bucket exists.
|
// BucketExists - bucket exists.
|
||||||
type BucketExists GenericBucketError
|
type BucketExists GenericBucketError
|
||||||
|
|
||||||
func (e BucketExists) Error() string {
|
func (e BucketExists) Error() string {
|
||||||
return "Bucket ‘" + e.Bucket + "’ exists."
|
return "Bucket `" + e.Bucket + "` exists."
|
||||||
}
|
|
||||||
|
|
||||||
// InvalidBucketName - bucket name invalid (http://goo.gl/wJlzDz)
|
|
||||||
type InvalidBucketName GenericBucketError
|
|
||||||
|
|
||||||
func (e InvalidBucketName) Error() string {
|
|
||||||
return "Invalid bucketname [‘" + e.Bucket + "’], please read http://goo.gl/wJlzDz."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// BucketNameEmpty - bucket name empty (http://goo.gl/wJlzDz)
|
// BucketNameEmpty - bucket name empty (http://goo.gl/wJlzDz)
|
||||||
@@ -75,10 +56,20 @@ func (e BucketNameEmpty) Error() string {
|
|||||||
return "Bucket name cannot be empty."
|
return "Bucket name cannot be empty."
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericObjectError - generic object operations error
|
// ObjectNameEmpty - object name empty.
|
||||||
type GenericObjectError struct {
|
type ObjectNameEmpty struct{}
|
||||||
|
|
||||||
|
func (e ObjectNameEmpty) Error() string {
|
||||||
|
return "Object name cannot be empty."
|
||||||
|
}
|
||||||
|
|
||||||
|
// BucketInvalid - bucket name invalid.
|
||||||
|
type BucketInvalid struct {
|
||||||
Bucket string
|
Bucket string
|
||||||
Object string
|
}
|
||||||
|
|
||||||
|
func (e BucketInvalid) Error() string {
|
||||||
|
return "Bucket name " + e.Bucket + " not valid."
|
||||||
}
|
}
|
||||||
|
|
||||||
// ObjectAlreadyExists - typed return for MethodNotAllowed
|
// ObjectAlreadyExists - typed return for MethodNotAllowed
|
||||||
@@ -87,21 +78,32 @@ type ObjectAlreadyExists struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e ObjectAlreadyExists) Error() string {
|
func (e ObjectAlreadyExists) Error() string {
|
||||||
return "Object ‘" + e.Object + "’ already exists."
|
return "Object `" + e.Object + "` already exists."
|
||||||
}
|
}
|
||||||
|
|
||||||
// InvalidObjectName - object requested is invalid
|
// ObjectAlreadyExistsAsDirectory - typed return for XMinioObjectExistsAsDirectory
|
||||||
type InvalidObjectName GenericObjectError
|
type ObjectAlreadyExistsAsDirectory struct {
|
||||||
|
Object string
|
||||||
|
}
|
||||||
|
|
||||||
func (e InvalidObjectName) Error() string {
|
func (e ObjectAlreadyExistsAsDirectory) Error() string {
|
||||||
return "Object ‘" + e.Object + "’ at ‘" + e.Bucket + "’ is invalid."
|
return "Object `" + e.Object + "` already exists as directory."
|
||||||
|
}
|
||||||
|
|
||||||
|
// ObjectOnGlacier - object is of storage class glacier.
|
||||||
|
type ObjectOnGlacier struct {
|
||||||
|
Object string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ObjectOnGlacier) Error() string {
|
||||||
|
return "Object `" + e.Object + "` is on Glacier storage."
|
||||||
}
|
}
|
||||||
|
|
||||||
// BucketNameTopLevel - generic error
|
// BucketNameTopLevel - generic error
|
||||||
type BucketNameTopLevel struct{}
|
type BucketNameTopLevel struct{}
|
||||||
|
|
||||||
func (e BucketNameTopLevel) Error() string {
|
func (e BucketNameTopLevel) Error() string {
|
||||||
return "Buckets can only be created at the top level."
|
return "Buckets or prefixes can only be created with `/` suffix."
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericFileError - generic file error.
|
// GenericFileError - generic file error.
|
||||||
@@ -113,35 +115,35 @@ type GenericFileError struct {
|
|||||||
type PathNotFound GenericFileError
|
type PathNotFound GenericFileError
|
||||||
|
|
||||||
func (e PathNotFound) Error() string {
|
func (e PathNotFound) Error() string {
|
||||||
return "Requested file ‘" + e.Path + "’ not found"
|
return "Requested file `" + e.Path + "` not found"
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathIsNotRegular (ENOTREG) - file is not a regular file.
|
// PathIsNotRegular (ENOTREG) - file is not a regular file.
|
||||||
type PathIsNotRegular GenericFileError
|
type PathIsNotRegular GenericFileError
|
||||||
|
|
||||||
func (e PathIsNotRegular) Error() string {
|
func (e PathIsNotRegular) Error() string {
|
||||||
return "Requested file ‘" + e.Path + "’ is not a regular file."
|
return "Requested file `" + e.Path + "` is not a regular file."
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathInsufficientPermission (EPERM) - permission denied.
|
// PathInsufficientPermission (EPERM) - permission denied.
|
||||||
type PathInsufficientPermission GenericFileError
|
type PathInsufficientPermission GenericFileError
|
||||||
|
|
||||||
func (e PathInsufficientPermission) Error() string {
|
func (e PathInsufficientPermission) Error() string {
|
||||||
return "Insufficient permissions to access this file ‘" + e.Path + "’"
|
return "Insufficient permissions to access this file `" + e.Path + "`"
|
||||||
}
|
}
|
||||||
|
|
||||||
// BrokenSymlink (ENOTENT) - file has broken symlink.
|
// BrokenSymlink (ENOTENT) - file has broken symlink.
|
||||||
type BrokenSymlink GenericFileError
|
type BrokenSymlink GenericFileError
|
||||||
|
|
||||||
func (e BrokenSymlink) Error() string {
|
func (e BrokenSymlink) Error() string {
|
||||||
return "Requested file ‘" + e.Path + "’ has broken symlink"
|
return "Requested file `" + e.Path + "` has broken symlink"
|
||||||
}
|
}
|
||||||
|
|
||||||
// TooManyLevelsSymlink (ELOOP) - file has too many levels of symlinks.
|
// TooManyLevelsSymlink (ELOOP) - file has too many levels of symlinks.
|
||||||
type TooManyLevelsSymlink GenericFileError
|
type TooManyLevelsSymlink GenericFileError
|
||||||
|
|
||||||
func (e TooManyLevelsSymlink) Error() string {
|
func (e TooManyLevelsSymlink) Error() string {
|
||||||
return "Requested file ‘" + e.Path + "’ has too many levels of symlinks"
|
return "Requested file `" + e.Path + "` has too many levels of symlinks"
|
||||||
}
|
}
|
||||||
|
|
||||||
// EmptyPath (EINVAL) - invalid argument.
|
// EmptyPath (EINVAL) - invalid argument.
|
||||||
@@ -155,7 +157,7 @@ func (e EmptyPath) Error() string {
|
|||||||
type ObjectMissing struct{}
|
type ObjectMissing struct{}
|
||||||
|
|
||||||
func (e ObjectMissing) Error() string {
|
func (e ObjectMissing) Error() string {
|
||||||
return "Object key is missing, object key cannot be empty"
|
return "Object does not exist"
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnexpectedShortWrite - write wrote less bytes than expected.
|
// UnexpectedShortWrite - write wrote less bytes than expected.
|
||||||
@@ -165,7 +167,7 @@ type UnexpectedShortWrite struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e UnexpectedShortWrite) Error() string {
|
func (e UnexpectedShortWrite) Error() string {
|
||||||
msg := fmt.Sprintf("Wrote less data than requested. Expected ‘%d’ bytes, but only wrote ‘%d’ bytes.", e.InputSize, e.WriteSize)
|
msg := fmt.Sprintf("Wrote less data than requested. Expected `%d` bytes, but only wrote `%d` bytes.", e.InputSize, e.WriteSize)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +178,7 @@ type UnexpectedEOF struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e UnexpectedEOF) Error() string {
|
func (e UnexpectedEOF) Error() string {
|
||||||
msg := fmt.Sprintf("Input reader closed pre-maturely. Expected ‘%d’ bytes, but only received ‘%d’ bytes.", e.TotalSize, e.TotalWritten)
|
msg := fmt.Sprintf("Input reader closed pre-maturely. Expected `%d` bytes, but only received `%d` bytes.", e.TotalSize, e.TotalWritten)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +186,15 @@ func (e UnexpectedEOF) Error() string {
|
|||||||
type UnexpectedExcessRead UnexpectedEOF
|
type UnexpectedExcessRead UnexpectedEOF
|
||||||
|
|
||||||
func (e UnexpectedExcessRead) Error() string {
|
func (e UnexpectedExcessRead) Error() string {
|
||||||
msg := fmt.Sprintf("Received excess data on input reader. Expected only ‘%d’ bytes, but received ‘%d’ bytes.", e.TotalSize, e.TotalWritten)
|
msg := fmt.Sprintf("Received excess data on input reader. Expected only `%d` bytes, but received `%d` bytes.", e.TotalSize, e.TotalWritten)
|
||||||
return msg
|
return msg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SameFile - source and destination are same files.
|
||||||
|
type SameFile struct {
|
||||||
|
Source, Destination string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e SameFile) Error() string {
|
||||||
|
return fmt.Sprintf("'%s' and '%s' are the same file", e.Source, e.Destination)
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user