-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
arc-core/src/main/java/fr/insee/arc/core/service/s3/ArcS3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package fr.insee.arc.core.service.s3; | ||
|
||
import fr.insee.arc.utils.minio.S3Template; | ||
import fr.insee.arc.utils.ressourceUtils.PropertiesHandler; | ||
|
||
public class ArcS3 { | ||
|
||
public static final S3Template INPUT_BUCKET = new S3Template( // | ||
PropertiesHandler.getInstance().getS3InputApiUri(), // | ||
PropertiesHandler.getInstance().getS3InputBucket(), // | ||
PropertiesHandler.getInstance().getS3InputAccess(), // | ||
PropertiesHandler.getInstance().getS3InputSecret() // | ||
); | ||
|
||
public static final S3Template OUTPUT_BUCKET = new S3Template( // | ||
PropertiesHandler.getInstance().getS3OutputApiUri(), // | ||
PropertiesHandler.getInstance().getS3OutputBucket(), // | ||
PropertiesHandler.getInstance().getS3OutputAccess(), // | ||
PropertiesHandler.getInstance().getS3OutputSecret() // | ||
); | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
arc-utils/src/main/java/fr/insee/arc/utils/minio/S3Template.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package fr.insee.arc.utils.minio; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.security.InvalidKeyException; | ||
import java.security.KeyManagementException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import fr.insee.arc.utils.exception.ArcException; | ||
import fr.insee.arc.utils.exception.ArcExceptionMessage; | ||
import io.minio.MinioClient; | ||
import io.minio.PutObjectArgs; | ||
import io.minio.errors.ErrorResponseException; | ||
import io.minio.errors.InsufficientDataException; | ||
import io.minio.errors.InternalException; | ||
import io.minio.errors.InvalidResponseException; | ||
import io.minio.errors.ServerException; | ||
import io.minio.errors.XmlParserException; | ||
|
||
public class S3Template { | ||
|
||
public S3Template(String s3ApiUri, String bucket, String accessKey, String secretKey) { | ||
super(); | ||
this.s3ApiUri = s3ApiUri; | ||
this.bucket = bucket; | ||
this.accessKey = accessKey; | ||
this.secretKey = secretKey; | ||
} | ||
|
||
private String s3ApiUri; | ||
private String bucket; | ||
private String accessKey; | ||
private String secretKey; | ||
|
||
private MinioClient minioClient; | ||
|
||
|
||
public MinioClient getMinioClient() { | ||
if (this.minioClient == null) { | ||
try { | ||
buildMinioClient(); | ||
} catch (KeyManagementException | NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
return minioClient; | ||
} | ||
|
||
private void buildMinioClient() throws KeyManagementException, NoSuchAlgorithmException { | ||
|
||
|
||
this.minioClient = MinioClient.builder().endpoint(s3ApiUri).credentials(accessKey, secretKey).build(); | ||
this.minioClient.ignoreCertCheck(); | ||
} | ||
|
||
/** | ||
* Crée un nouveau répertoire dans le bucket à l'emplacement donné | ||
* | ||
* @param path le chemin du répertoire à créer (emplacement et nom) | ||
* @throws ArcException | ||
*/ | ||
public void createDirectory(String path) throws ArcException { | ||
try { | ||
getMinioClient() | ||
.putObject(PutObjectArgs.builder().bucket(bucket).object(path + (path.endsWith("/") ? "" : "/")) | ||
.stream(new ByteArrayInputStream(new byte[] {}), 0, -1).build()); | ||
} catch (InvalidKeyException | ErrorResponseException | InsufficientDataException | InternalException | ||
| InvalidResponseException | NoSuchAlgorithmException | ServerException | XmlParserException | ||
| IllegalArgumentException | IOException e) { | ||
|
||
throw new ArcException(ArcExceptionMessage.FILE_WRITE_FAILED, path); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters