[BAEL-2284] R2DBC Sample Project (#7314)

* [BAEL-2284] Sample project

* [BAEL-2284] Sample project

* [BAEL-2284] Sample code adjustments

* [BAEL-2284] Sample code adjustments

* [BAEL-2284] Sample code adjustments

* [BAEL-2284] Add README
This commit is contained in:
psevestre
2019-07-26 01:32:23 -03:00
committed by Grzegorz Piwowarek
parent c7433926c5
commit 76bb391379
29 changed files with 1408 additions and 31 deletions
@@ -0,0 +1,10 @@
package org.baeldung.spring.cloud.vaultsample;
import org.baeldung.spring.cloud.vaultsample.domain.Account;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface AccountRepo extends JpaRepository<Account, Long>{
}
@@ -0,0 +1,27 @@
package org.baeldung.spring.cloud.vaultsample;
import org.baeldung.spring.cloud.vaultsample.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class AccountResource {
@Autowired
private AccountRepo repo;
@GetMapping("/account/{id}")
public ResponseEntity<Account> getAccount(@PathVariable("id") Long id) {
Account acc = repo.findById(id).orElse(null);
if ( acc != null ) {
return new ResponseEntity<Account>(acc, HttpStatus.OK);
}
else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
@@ -0,0 +1,37 @@
/**
*
*/
package org.baeldung.spring.cloud.vaultsample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
/**
* @author Philippe
*
*/
@RestController
public class SecretResource {
@Autowired
Environment env;
@GetMapping("/secret/{key}")
public ResponseEntity<String> readSecret(@PathVariable("key") String key) {
String value = env.getProperty(key);
if ( value != null ) {
return new ResponseEntity<String>(value, HttpStatus.OK);
}
else {
return new ResponseEntity<String>("not found", HttpStatus.NOT_FOUND);
}
}
}
@@ -0,0 +1,133 @@
/**
*
*/
package org.baeldung.spring.cloud.vaultsample.domain;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
/**
* @author Philippe
*
*/
@Entity
@Table(name = "account")
public class Account {
@Id
private Long id;
@NotNull
private String name;
private Long branchId;
private Long customerId;
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the branchId
*/
public Long getBranchId() {
return branchId;
}
/**
* @param branchId the branchId to set
*/
public void setBranchId(Long branchId) {
this.branchId = branchId;
}
/**
* @return the customerId
*/
public Long getCustomerId() {
return customerId;
}
/**
* @param customerId the customerId to set
*/
public void setCustomerId(Long customerId) {
this.customerId = customerId;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((branchId == null) ? 0 : branchId.hashCode());
result = prime * result + ((customerId == null) ? 0 : customerId.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Account other = (Account) obj;
if (branchId == null) {
if (other.branchId != null)
return false;
} else if (!branchId.equals(other.branchId))
return false;
if (customerId == null) {
if (other.customerId != null)
return false;
} else if (!customerId.equals(other.customerId))
return false;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}
@@ -1,6 +1,11 @@
spring:
application:
name: fakebank
datasource:
url: jdbc:mysql://localhost:3306/fakebank
spring:
application:
name: fakebank
datasource:
url: jdbc:mysql://localhost:3306/fakebank?serverTimezone=GMT-3
hikari:
connection-test-query: select 1
idle-timeout: 5000
max-lifetime: 120000
maximum-pool-size: 5
@@ -4,8 +4,6 @@ spring:
uri: https://localhost:8200
connection-timeout: 5000
read-timeout: 15000
config:
order: -10
ssl:
trust-store: classpath:/vault.jks
@@ -15,17 +13,19 @@ spring:
enabled: true
application-name: fakebank
kv:
enabled: false
backend: kv
application-name: fakebank
# kv:
# enabled: false
# backend: kv
# application-name: fakebank
#
database:
enabled: true
role: fakebank-accounts-rw
# backend: database
# username-property: spring.datasource.username
# password-property: spring.datasource.password
backend: database
username-property: spring.datasource.username
password-property: spring.datasource.password
#
#
@@ -17,4 +17,7 @@ listener "tcp" {
tls_key_file = "./src/test/vault-config/localhost.key"
}
// Audit to stdout