1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.transport.minio;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23
24 import java.util.Map;
25
26 import org.eclipse.aether.RepositorySystemSession;
27 import org.eclipse.aether.repository.RemoteRepository;
28 import org.eclipse.aether.spi.connector.transport.Transporter;
29 import org.eclipse.aether.spi.connector.transport.TransporterFactory;
30 import org.eclipse.aether.spi.io.PathProcessor;
31 import org.eclipse.aether.transfer.NoTransporterException;
32 import org.eclipse.aether.util.ConfigUtils;
33
34 import static java.util.Objects.requireNonNull;
35
36
37
38
39
40
41 @Named(MinioTransporterFactory.NAME)
42 public final class MinioTransporterFactory implements TransporterFactory {
43 public static final String NAME = "minio";
44
45 private static final float DEFAULT_PRIORITY = 0.0f;
46
47 private float priority = DEFAULT_PRIORITY;
48
49 private final Map<String, ObjectNameMapperFactory> objectNameMapperFactories;
50
51 private final PathProcessor pathProcessor;
52
53 @Inject
54 public MinioTransporterFactory(
55 Map<String, ObjectNameMapperFactory> objectNameMapperFactories, PathProcessor pathProcessor) {
56 this.objectNameMapperFactories = requireNonNull(objectNameMapperFactories, "objectNameMapperFactories");
57 this.pathProcessor = requireNonNull(pathProcessor, "pathProcessor");
58 }
59
60 @Override
61 public float getPriority() {
62 return priority;
63 }
64
65 public MinioTransporterFactory setPriority(float priority) {
66 this.priority = priority;
67 return this;
68 }
69
70 @Override
71 public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
72 throws NoTransporterException {
73 requireNonNull(session, "session cannot be null");
74 requireNonNull(repository, "repository cannot be null");
75
76
77
78 RemoteRepository adjusted = repository;
79 boolean prefixStripped = false;
80 if ("minio+http".equalsIgnoreCase(repository.getProtocol())
81 || "minio+https".equalsIgnoreCase(repository.getProtocol())) {
82 adjusted = new RemoteRepository.Builder(repository)
83 .setUrl(repository.getUrl().substring("minio+".length()))
84 .build();
85 prefixStripped = true;
86 } else if ("s3+http".equalsIgnoreCase(repository.getProtocol())
87 || "s3+https".equalsIgnoreCase(repository.getProtocol())) {
88 adjusted = new RemoteRepository.Builder(repository)
89 .setUrl(repository.getUrl().substring("s3+".length()))
90 .build();
91 prefixStripped = true;
92 } else if (priority == DEFAULT_PRIORITY) {
93 throw new NoTransporterException(
94 repository,
95 "To use Minio transport with plain HTTP/HTTPS repositories, increase the Minio transport priority");
96 }
97
98
99
100
101 if (prefixStripped && "http".equalsIgnoreCase(adjusted.getProtocol())) {
102 boolean allowInsecureProtocol = ConfigUtils.getBoolean(
103 session,
104 MinioTransporterConfigurationKeys.DEFAULT_ALLOW_INSECURE_PROTOCOL,
105 MinioTransporterConfigurationKeys.CONFIG_PROP_ALLOW_INSECURE_PROTOCOL + "." + repository.getId(),
106 MinioTransporterConfigurationKeys.CONFIG_PROP_ALLOW_INSECURE_PROTOCOL);
107 if (!allowInsecureProtocol) {
108 throw new NoTransporterException(
109 repository,
110 "Plaintext HTTP object storage endpoints are insecure (no transport integrity; not subject"
111 + " to 'external:http:*' mirror blocking) and are refused by default: use the"
112 + " 'minio+https'/'s3+https' URL form, or explicitly opt in by setting the"
113 + " configuration property '"
114 + MinioTransporterConfigurationKeys.CONFIG_PROP_ALLOW_INSECURE_PROTOCOL
115 + "' (optionally suffixed with '." + repository.getId() + "') to 'true'");
116 }
117 }
118 String objectNameMapperConf = ConfigUtils.getString(
119 session,
120 MinioTransporterConfigurationKeys.DEFAULT_OBJECT_NAME_MAPPER,
121 MinioTransporterConfigurationKeys.CONFIG_PROP_OBJECT_NAME_MAPPER + "." + repository.getId(),
122 MinioTransporterConfigurationKeys.CONFIG_PROP_OBJECT_NAME_MAPPER);
123 ObjectNameMapperFactory objectNameMapperFactory = objectNameMapperFactories.get(objectNameMapperConf);
124 if (objectNameMapperFactory == null) {
125 throw new IllegalArgumentException("Unknown object name mapper configured '" + objectNameMapperConf
126 + "' for repository " + repository.getId());
127 }
128 return new MinioTransporter(session, adjusted, objectNameMapperFactory, pathProcessor);
129 }
130 }