README.md 2.32 KB
Newer Older
Martin Abbrent's avatar
Martin Abbrent committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# MinIO CLI Wrapper

A small package to wrap the
[MinIO Client](https://docs.min.io/docs/minio-client-complete-guide.html)
(`mc`) commands that are not provided by the [MinIO Python
SDK](https://docs.min.io/docs/python-client-api-reference.html) like
most of the `admin` functions. As it uses an individual and temporary
configuration folder with each instance it is concurrency save and does
not interfere with your personal settings.

# Setup

Install
[MinIO Client](https://docs.min.io/docs/minio-client-complete-guide.html)
from
https://docs.min.io/docs/minio-client-quickstart-guide.html#GNU/Linux
like described in the
[guide](https://docs.min.io/docs/minio-client-quickstart-guide.html#GNU/Linux).

Install the MinIO CLI Wrapper package or add the to `requirements.txt`:

```bash
23
24
25
26
27
28
pip install -i https://git.ufz.de/api/v4/projects/2959/packages/pypi/simple minio-cli-wrapper
```
`requirements.txt`:
```
-i https://git.ufz.de/api/v4/projects/2959/packages/pypi/simple
minio-cli-wrapper>=0.0.12
Martin Abbrent's avatar
Martin Abbrent committed
29
30
31
32
33
34
35
```

# Usage

Create a client instance:

```python
Martin Abbrent's avatar
Martin Abbrent committed
36
from minio_cli_wrapper.mc import Mc
Martin Abbrent's avatar
Martin Abbrent committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
mc = Mc(
    "localhost:9000",
    secure=False,
    access_key="minio",
    secret_key="minio123"
)
```

Create a MinIO user:

```python
mc.user_add('my-user', 'my_secret')
```

Create a IAM policy:

```python
mc.policy_add('my-policy-name', {
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::{bucket_name}".format(bucket_name='my-bucket-name')
            ]
        }
    ]
})
```

Assign a IAM policy to a user:

```python
mc.policy_set_user('my-user', 'my-policy-name')
```

Create a new service account for a user (this doesn't work until the
user has an IAM policy assigned):

```python
svc_creds = mc.create_service_account('my-user')
```
Martin Abbrent's avatar
Martin Abbrent committed
85
86
87
88
89
90
91
92
93

# Tests

There is a integration test tailored for an empty minio container:

```bash
docker run --rm -p 9000:9000 -p 9001:9001 -e MINIO_NOTIFY_KAFKA_ENABLE="on" -e MINIO_NOTIFY_KAFKA_BROKERS="kafka:9092" -e MINIO_NOTIFY_KAFKA_TOPIC="minio-bucket-notifications" minio/minio server /vol0 /vol1 /vol2 /vol3 --console-address :9001
python ./tests/integration_test.py
```