Search in sources :

Example 1 with StrictYamlMapping

use of com.amihaiemil.eoyaml.StrictYamlMapping in project front by artipie.

the class YamlStorage method storage.

/**
 * Provides a storage.
 *
 * @return Storage instance.
 */
public Storage storage() {
    @SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
    final String type = strict.string("type");
    final Storage storage;
    if ("fs".equals(type)) {
        storage = new FileStorage(Path.of(strict.string("path")));
    } else if ("s3".equals(type)) {
        storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
    } else if ("etcd".equals(type)) {
        storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
    } else {
        throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
    }
    return storage;
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) S3Storage(com.artipie.asto.s3.S3Storage) FileStorage(com.artipie.asto.fs.FileStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) S3Storage(com.artipie.asto.s3.S3Storage)

Example 2 with StrictYamlMapping

use of com.amihaiemil.eoyaml.StrictYamlMapping in project front by artipie.

the class YamlStorage method s3Client.

/**
 * Creates {@link S3AsyncClient} instance based on YAML config.
 *
 * @return Built S3 client.
 * @checkstyle MethodNameCheck (3 lines)
 */
@SuppressWarnings("deprecation")
private S3AsyncClient s3Client() {
    final S3AsyncClientBuilder builder = S3AsyncClient.builder();
    final String region = this.yaml.string("region");
    if (region != null) {
        builder.region(Region.of(region));
    }
    final String endpoint = this.yaml.string("endpoint");
    if (endpoint != null) {
        builder.endpointOverride(URI.create(endpoint));
    }
    return builder.credentialsProvider(credentials(new StrictYamlMapping(this.yaml).yamlMapping("credentials"))).build();
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder)

Example 3 with StrictYamlMapping

use of com.amihaiemil.eoyaml.StrictYamlMapping in project artipie by artipie.

the class YamlStorage method s3Client.

/**
 * Creates {@link S3AsyncClient} instance based on YAML config.
 *
 * @return Built S3 client.
 * @checkstyle MethodNameCheck (3 lines)
 */
@SuppressWarnings("deprecation")
private S3AsyncClient s3Client() {
    final S3AsyncClientBuilder builder = S3AsyncClient.builder();
    final String region = this.yaml.string("region");
    if (region != null) {
        builder.region(Region.of(region));
    }
    final String endpoint = this.yaml.string("endpoint");
    if (endpoint != null) {
        builder.endpointOverride(URI.create(endpoint));
    }
    return builder.credentialsProvider(credentials(new StrictYamlMapping(this.yaml).yamlMapping("credentials"))).build();
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) S3AsyncClientBuilder(software.amazon.awssdk.services.s3.S3AsyncClientBuilder)

Example 4 with StrictYamlMapping

use of com.amihaiemil.eoyaml.StrictYamlMapping in project artipie by artipie.

the class YamlStorage method storage.

/**
 * Provides a storage.
 *
 * @return Storage instance.
 */
public Storage storage() {
    @SuppressWarnings("deprecation") final YamlMapping strict = new StrictYamlMapping(this.yaml);
    final String type = strict.string("type");
    final Storage storage;
    if ("fs".equals(type)) {
        storage = new FileStorage(Path.of(strict.string("path")));
    } else if ("s3".equals(type)) {
        storage = new S3Storage(this.s3Client(), strict.string("bucket"), !"false".equals(this.yaml.string("multipart")));
    } else if ("etcd".equals(type)) {
        storage = new EtcdStorage(YamlStorage.etcdClient(strict.yamlMapping("connection")));
    } else {
        throw new IllegalStateException(String.format("Unsupported storage type: '%s'", type));
    }
    return storage;
}
Also used : StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) Storage(com.artipie.asto.Storage) FileStorage(com.artipie.asto.fs.FileStorage) S3Storage(com.artipie.asto.s3.S3Storage) FileStorage(com.artipie.asto.fs.FileStorage) YamlMapping(com.amihaiemil.eoyaml.YamlMapping) StrictYamlMapping(com.amihaiemil.eoyaml.StrictYamlMapping) EtcdStorage(com.artipie.asto.etcd.EtcdStorage) S3Storage(com.artipie.asto.s3.S3Storage)

Aggregations

StrictYamlMapping (com.amihaiemil.eoyaml.StrictYamlMapping)4 YamlMapping (com.amihaiemil.eoyaml.YamlMapping)2 Storage (com.artipie.asto.Storage)2 EtcdStorage (com.artipie.asto.etcd.EtcdStorage)2 FileStorage (com.artipie.asto.fs.FileStorage)2 S3Storage (com.artipie.asto.s3.S3Storage)2 S3AsyncClientBuilder (software.amazon.awssdk.services.s3.S3AsyncClientBuilder)2