Java CF Env S3 Support Library

Library to obtain credentials of AWS/S3 in Cloudfoundry

License

License

Categories

Categories

Java Languages
GroupId

GroupId

de.hdi.cfenv
ArtifactId

ArtifactId

java-cfenv-s3
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Java CF Env S3 Support Library
Library to obtain credentials of AWS/S3 in Cloudfoundry
Project URL

Project URL

https://github.com/hdisysteme/java-cfenv-s3
Source Code Management

Source Code Management

https://github.com/hdisysteme/java-cfenv-s3/tree/main

Download java-cfenv-s3

How to add to project

<!-- https://jarcasting.com/artifacts/de.hdi.cfenv/java-cfenv-s3/ -->
<dependency>
    <groupId>de.hdi.cfenv</groupId>
    <artifactId>java-cfenv-s3</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/de.hdi.cfenv/java-cfenv-s3/
implementation 'de.hdi.cfenv:java-cfenv-s3:1.0.0'
// https://jarcasting.com/artifacts/de.hdi.cfenv/java-cfenv-s3/
implementation ("de.hdi.cfenv:java-cfenv-s3:1.0.0")
'de.hdi.cfenv:java-cfenv-s3:jar:1.0.0'
<dependency org="de.hdi.cfenv" name="java-cfenv-s3" rev="1.0.0">
  <artifact name="java-cfenv-s3" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.hdi.cfenv', module='java-cfenv-s3', version='1.0.0')
)
libraryDependencies += "de.hdi.cfenv" % "java-cfenv-s3" % "1.0.0"
[de.hdi.cfenv/java-cfenv-s3 "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
io.pivotal.cfenv : java-cfenv-boot jar 2.2.2.RELEASE

test (2)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar 5.6.2
org.mockito : mockito-core jar 3.3.3

Project Modules

There are no modules declared in this project.

java-cfenv-s3

This spring boot library allows easy access to the Cloud Foundry VCAP variables for an S3 bucket, without the values having to be stored as plain text.

Use Case

A spring boot application in Cloud Foundry uses an S3 bucket to store data. The data can only be read and written once the application has been authenticated on the S3 bucket. The data for authentication can be easily determined with the help of this library.

Limitation: This library currently only supports one S3 bucket per app.

HowTo

Embed Maven-Dependency

The following dependency-Entry is required:

<dependency>
  <groupId>de.hdi.cfenv</groupId>
  <artifactId>java-cfenv-s3</artifactId>
  <version>1.0.0</version>
</dependency>

Example

There are two options to gather the S3-Information

  1. Using application Properties
  2. Using the class CfEnvS3

A bean of the type CfEnvS3 must be created for both variants. To get an instance, a method annotated with @Bean is recommended, which must be passed an instance of org.springframework.core.env.Environment:

@Bean
public CfEnvS3 cfEnvS3(Environment environment) {
	return new CfEnvS3(environment);
}

Properties

The S3 information can be determined as usual using the following properties:

  • cfenv.s3.accessKeyId
  • cfenv.s3.secretKey
  • cfenv.s3.region
  • cfenv.s3.bucket

However, these properties must not be present in the application.yml, because the dynamically determined values ​​would be overwritten.

The S3 properties are then accessed via member variables or formal parameters that are annotated with @Value:

@Value("${cfenv.s3.accessKeyId}")
private String accessKeyId;

@Value("${cfenv.s3.secretKey}")
private String secretAccessKey;

@Value("${cfenv.s3.region}")
private String region;

@Value("${cfenv.s3.bucket}")
private String bucket;

CfEnvS3

Alternatively, you can also have an instance of the type CfEnvS3 injected directly and access the S3 information via the getters:

  • public String getRegion()
  • public String getAccessKeyId()
  • public SecretAccessKey getSecretAccessKey()
  • public String getBucket()
de.hdi.cfenv

HDI Systeme AG

HDI Systeme AG. "We (de)code insurance."

Versions

Version
1.0.0