├── .gitignore
├── README.md
├── minio-swarm.yml
├── miniosample
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── me
│ │ └── aboullaite
│ │ └── minio
│ │ └── MinioSampleApplication.java
│ └── resources
│ └── application.yml
├── miniospringbootautoconfigure
├── pom.xml
└── src
│ └── main
│ ├── java
│ └── me
│ │ └── aboullaite
│ │ └── minio
│ │ ├── MinioAutoConfiguration.java
│ │ ├── MinioProperties.java
│ │ ├── exception
│ │ ├── MinioEntityExceptionHandler.java
│ │ └── MinioError.java
│ │ ├── http
│ │ └── MinioEndpoint.java
│ │ ├── service
│ │ └── MinioTemplate.java
│ │ └── vo
│ │ ├── MinioItem.java
│ │ └── MinioObject.java
│ └── resources
│ ├── META-INF
│ ├── spring-configuration-metadata.json
│ └── spring.factories
│ └── application.properties
├── miniospringbootstarter
└── pom.xml
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | /src/main/resources/**
4 | !.src/main/resources/application.properties
5 | CSV_Files
6 | CSV_Files/**
7 |
8 | ### STS ###
9 | .apt_generated
10 | .classpath
11 | .factorypath
12 | .project
13 | .settings
14 | .springBeans
15 |
16 |
17 | ### IntelliJ IDEA ###
18 | .idea
19 | *.iws
20 | *.iml
21 | *.ipr
22 |
23 | ### NetBeans ###
24 | nbproject/private/
25 | build/
26 | nbbuild/
27 | dist/
28 | nbdist/
29 | .nb-gradle/
30 |
31 |
32 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Minio spring boot starter
2 | Spring boot starter project that autoconfigure a Minio client.
3 | [Minio](https://www.minio.io/) is a high performance distributed object storage server, designed for large-scale private cloud infrastructure.
4 |
5 | #### Usage
6 | ##### Start minio stack:
7 | 1. Add Docker swarm secrets
8 | ```
9 | echo "AKIAIOSFODNN7EXAMPLE" | docker secret create access_key -
10 | echo "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" | docker secret create secret_key -
11 | ```
12 | See []Minio Docker Quickstart Guide](https://docs.minio.io/docs/minio-docker-quickstart-guide)
13 |
14 | 2. Deploy stack
15 | ```
16 | docker stack deploy --compose-file=minio-swarm.yml minio_stack
17 | ```
18 | 3. Test proxy
19 | We configured Træfɪk with Host:minioproxy. So we need to have a dns record for `minioproxy` pointing to a ip address of any Docker swarm node or just add it to `/etc/hosts` for a quick test.
20 |
21 | #### Configuration
22 | You need to add `minio-springboot-starter` dependency to your pom. Till now, you need to build the starter and it to your repo.
23 | You can either use the rest API to interact with minio, by setting `minio.endpoint.enable = true` (default value is false), or using the `MinioTemplate` class service directly on your code. you need also to setup minion credentials.
24 |
25 | Below a configuration example
26 |
27 | ```
28 | minio:
29 | url: http://minioproxy
30 | access-key: changeme
31 | secret-key: changeme
32 | endpoint:
33 | enable: true
34 | name: miniotest
35 | ```
--------------------------------------------------------------------------------
/minio-swarm.yml:
--------------------------------------------------------------------------------
1 | version: '3.1'
2 |
3 | services:
4 | minio1:
5 | image: minio/minio
6 | volumes:
7 | - minio1-data:/export
8 | networks:
9 | - minio_distributed
10 | deploy:
11 | restart_policy:
12 | delay: 10s
13 | max_attempts: 10
14 | window: 60s
15 | labels:
16 | traefik.frontend.rule: "Host:minioproxy"
17 | traefik.port: "9000"
18 | command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
19 | secrets:
20 | - secret_key
21 | - access_key
22 |
23 | minio2:
24 | image: minio/minio
25 | volumes:
26 | - minio2-data:/export
27 | networks:
28 | - minio_distributed
29 | deploy:
30 | restart_policy:
31 | delay: 10s
32 | max_attempts: 10
33 | window: 60s
34 | labels:
35 | traefik.frontend.rule: "Host:minioproxy"
36 | traefik.port: "9000"
37 | command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
38 | secrets:
39 | - secret_key
40 | - access_key
41 |
42 | minio3:
43 | image: minio/minio
44 | volumes:
45 | - minio3-data:/export
46 | networks:
47 | - minio_distributed
48 | deploy:
49 | restart_policy:
50 | delay: 10s
51 | max_attempts: 10
52 | window: 60s
53 | labels:
54 | traefik.frontend.rule: "Host:minioproxy"
55 | traefik.port: "9000"
56 | command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
57 | secrets:
58 | - secret_key
59 | - access_key
60 |
61 | minio4:
62 | image: minio/minio
63 | volumes:
64 | - minio4-data:/export
65 | networks:
66 | - minio_distributed
67 | deploy:
68 | restart_policy:
69 | delay: 10s
70 | max_attempts: 10
71 | window: 60s
72 | labels:
73 | traefik.frontend.rule: "Host:minioproxy"
74 | traefik.port: "9000"
75 | command: server http://minio1/export http://minio2/export http://minio3/export http://minio4/export
76 | secrets:
77 | - secret_key
78 | - access_key
79 |
80 | minioproxy:
81 | image: traefik
82 | volumes:
83 | - /var/run/docker.sock:/var/run/docker.sock
84 | networks:
85 | - minio_distributed
86 | ports:
87 | - 80:80
88 | - 8081:8080
89 | deploy:
90 | placement:
91 | constraints: [node.role == manager]
92 | command: --docker --docker.swarmmode --docker.domain=minio --docker.watch --web
93 |
94 | volumes:
95 | minio1-data:
96 |
97 | minio2-data:
98 |
99 | minio3-data:
100 |
101 | minio4-data:
102 |
103 | networks:
104 | minio_distributed:
105 | driver: overlay
106 |
107 | secrets:
108 | secret_key:
109 | external: true
110 | access_key:
111 | external: true
--------------------------------------------------------------------------------
/miniosample/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | me.aboullaite
8 | 0.0.1-SNAPSHOT
9 | minio-sample
10 |
11 | Spring Boot AutoConfiguration :: Minio Sample
12 | Spring Boot sample Minio app
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.6.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.8
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-web
30 |
31 |
32 | me.aboullaite
33 | minio-springboot-starter
34 | 0.0.1-SNAPSHOT
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-test
39 | test
40 |
41 |
42 |
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-maven-plugin
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/miniosample/src/main/java/me/aboullaite/minio/MinioSampleApplication.java:
--------------------------------------------------------------------------------
1 | package me.aboullaite.minio;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MinioSampleApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MinioSampleApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/miniosample/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | minio:
2 | url: http://minioproxy
3 | access-key: changeme
4 | secret-key: changeme
5 | endpoint:
6 | enable: true
7 | name: miniotest
8 |
--------------------------------------------------------------------------------
/miniospringbootautoconfigure/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | me.aboullaite
8 | 0.0.1-SNAPSHOT
9 | minio-springboot-autoconfigure
10 | jar
11 |
12 | Spring Boot AutoConfiguration :: MINIO
13 | Spring Boot auto-configuration Minio
14 |
15 |
16 | UTF-8
17 | 1.8
18 | 1.8
19 | 1.8
20 | 3.0.12
21 |
22 |
23 |
24 |
25 | org.springframework.boot
26 | spring-boot-autoconfigure
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-configuration-processor
31 | true
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 | io.minio
39 | minio
40 | ${minio.version}
41 |
42 |
43 | junit
44 | junit
45 | test
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-dependencies
58 | 1.5.9.RELEASE
59 | pom
60 | import
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/miniospringbootautoconfigure/src/main/java/me/aboullaite/minio/MinioAutoConfiguration.java:
--------------------------------------------------------------------------------
1 | package me.aboullaite.minio;
2 |
3 | import me.aboullaite.minio.service.MinioTemplate;
4 | import org.springframework.beans.factory.annotation.Autowired;
5 | import org.springframework.boot.autoconfigure.condition.*;
6 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.Configuration;
9 |
10 | @Configuration
11 | @EnableConfigurationProperties({ MinioProperties.class })
12 | public class MinioAutoConfiguration {
13 |
14 | @Autowired
15 | private MinioProperties properties;
16 |
17 | @Bean
18 | @ConditionalOnMissingBean(MinioTemplate.class)
19 | @ConditionalOnProperty(name = "minio.url")
20 | MinioTemplate template(){
21 | return new MinioTemplate(
22 | properties.getUrl(),
23 | properties.getAccessKey(),
24 | properties.getSecretKey()
25 | );
26 | }
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/miniospringbootautoconfigure/src/main/java/me/aboullaite/minio/MinioProperties.java:
--------------------------------------------------------------------------------
1 | package me.aboullaite.minio;
2 |
3 | import org.springframework.boot.context.properties.ConfigurationProperties;
4 | import org.springframework.boot.context.properties.NestedConfigurationProperty;
5 | import org.springframework.context.annotation.Configuration;
6 |
7 | @ConfigurationProperties(prefix = "minio")
8 | public class MinioProperties {
9 |
10 | private String url, accessKey, secretKey;
11 |
12 | public String getUrl() {
13 | return url;
14 | }
15 |
16 | public void setUrl(String url) {
17 | this.url = url;
18 | }
19 |
20 | public String getAccessKey() {
21 | return accessKey;
22 | }
23 |
24 | public void setAccessKey(String accessKey) {
25 | this.accessKey = accessKey;
26 | }
27 |
28 | public String getSecretKey() {
29 | return secretKey;
30 | }
31 |
32 | public void setSecretKey(String secretKey) {
33 | this.secretKey = secretKey;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "MinioProperties{" +
39 | "url='" + url + '\'' +
40 | ", accessKey='" + accessKey + '\'' +
41 | ", secretKey='" + secretKey + '\'' +
42 | '}';
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/miniospringbootautoconfigure/src/main/java/me/aboullaite/minio/exception/MinioEntityExceptionHandler.java:
--------------------------------------------------------------------------------
1 | package me.aboullaite.minio.exception;
2 |
3 | import io.minio.errors.*;
4 | import org.springframework.http.HttpHeaders;
5 | import org.springframework.http.HttpStatus;
6 | import org.springframework.http.ResponseEntity;
7 | import org.springframework.web.bind.annotation.ControllerAdvice;
8 | import org.springframework.web.bind.annotation.ExceptionHandler;
9 | import org.springframework.web.context.request.WebRequest;
10 | import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
11 |
12 | @ControllerAdvice
13 | public class MinioEntityExceptionHandler extends ResponseEntityExceptionHandler{
14 |
15 | @ExceptionHandler(value = {InvalidPortException.class})
16 | protected ResponseEntity