View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.transport.minio.internal;
20  
21  import javax.inject.Named;
22  import javax.inject.Singleton;
23  
24  import java.util.Map;
25  
26  import io.minio.MinioClient;
27  import org.eclipse.aether.RepositorySystemSession;
28  import org.eclipse.aether.repository.RemoteRepository;
29  import org.eclipse.aether.transport.minio.MinioTransporterConfigurationKeys;
30  import org.eclipse.aether.transport.minio.ObjectName;
31  import org.eclipse.aether.transport.minio.ObjectNameMapper;
32  import org.eclipse.aether.transport.minio.ObjectNameMapperFactory;
33  import org.eclipse.aether.util.ConfigUtils;
34  
35  /**
36   * A fixed bucket mapper, uses given bucket ID and then constructs object name using repository ID and layout path as
37   * object name.
38   */
39  @Singleton
40  @Named(FixedBucketObjectNameMapperFactory.NAME)
41  public class FixedBucketObjectNameMapperFactory implements ObjectNameMapperFactory {
42      public static final String NAME = "fixedBucket";
43  
44      @Override
45      public ObjectNameMapper create(
46              RepositorySystemSession session,
47              RemoteRepository repository,
48              MinioClient unused,
49              Map<String, String> headers) {
50          String bucket = ConfigUtils.getString(
51                  session,
52                  MinioTransporterConfigurationKeys.CONFIG_PROP_FIXED_BUCKET_NAME,
53                  MinioTransporterConfigurationKeys.CONFIG_PROP_FIXED_BUCKET_NAME + "." + repository.getId(),
54                  MinioTransporterConfigurationKeys.DEFAULT_FIXED_BUCKET_NAME);
55          return path -> new ObjectName(bucket, repository.getId() + "/" + ObjectName.normalize(path));
56      }
57  }