Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/api-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ logging:
co.nilin.opex.api.ports.proxy.impl: DEBUG

app:
base:
url: ${APP_BASE_URL:api}
accountant:
url: http://opex-accountant
profile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface StorageProxy {
suspend fun adminDownload(token: String, bucket: String, key: String): ResponseEntity<ByteArray>
suspend fun adminUpload(token: String, bucket: String, key: String, file: FilePart,isPublic : Boolean? = false)
suspend fun adminDelete(token: String, bucket: String, key: String)
suspend fun publicDownload(bucket: String, key: String): ResponseEntity<ByteArray>

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class SecurityConfig(

// Opex endpoints
.pathMatchers("/opex/v1/admin/transactions/**").hasAnyAuthority("ROLE_monitoring", "ROLE_admin")
.pathMatchers("/opex/v1/storage/**").permitAll()
.pathMatchers("/opex/v1/admin/**").hasAuthority("ROLE_admin")
.pathMatchers("/opex/v1/deposit/**").hasAuthority("PERM_deposit:write")
.pathMatchers(HttpMethod.POST, "/opex/v1/order").hasAuthority("PERM_order:write")
Expand All @@ -65,7 +66,7 @@ class SecurityConfig(
.pathMatchers(HttpMethod.PUT, "/opex/v1/otc/rate").hasAnyAuthority("ROLE_admin", "ROLE_rate_bot")
.pathMatchers(HttpMethod.GET, "/opex/v1/otc/**").permitAll()
.pathMatchers("/opex/v1/otc/**").hasAuthority("ROLE_admin")
.pathMatchers(HttpMethod.GET,"/opex/v1/bank-account").permitAll()
.pathMatchers(HttpMethod.GET, "/opex/v1/bank-account").permitAll()
.pathMatchers("/opex/v1/bank-account/**").hasAuthority("PERM_bank_account:write")
.anyExchange().authenticated()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package co.nilin.opex.api.ports.opex.controller
import co.nilin.opex.api.core.spi.StorageProxy
import co.nilin.opex.api.ports.opex.util.jwtAuthentication
import co.nilin.opex.api.ports.opex.util.tokenValue
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.ResponseEntity
import org.springframework.http.codec.multipart.FilePart
import org.springframework.security.core.annotation.CurrentSecurityContext
Expand All @@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.*
@RequestMapping("/opex/v1/admin/storage")
class StorageAdminController(
private val storageProxy: StorageProxy,
@Value("\${app.base.url}")
private val appBaseUrl: String
) {
@GetMapping
suspend fun download(
Expand All @@ -30,8 +33,9 @@ class StorageAdminController(
@RequestParam("key") key: String,
@RequestPart("file") file: FilePart,
@RequestParam("isPublic") isPublic: Boolean? = false,
) {
): String {
storageProxy.adminUpload(securityContext.jwtAuthentication().tokenValue(), bucket, key, file, isPublic)
return "$appBaseUrl/opex/v1/storage?bucket=$bucket&key=$key"
}

@DeleteMapping
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package co.nilin.opex.api.ports.opex.controller

import co.nilin.opex.api.core.spi.StorageProxy
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/opex/v1/storage")
class StorageController(
private val storageProxy: StorageProxy,
) {
@GetMapping
suspend fun download(
@RequestParam("bucket") bucket: String,
@RequestParam("key") key: String,
): ResponseEntity<ByteArray> {
return storageProxy.publicDownload(bucket, key)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,28 @@ class StorageProxyImpl(@Qualifier("generalWebClient") private val webClient: Web
.onStatus({ it.isError }) { it.createException() }
.awaitBodilessEntity()
}

override suspend fun publicDownload(
bucket: String,
key: String
): ResponseEntity<ByteArray> {
return webClient.get()
.uri("$baseUrl/v2/public") {
it.queryParam("bucket", bucket)
it.queryParam("key", key)
it.build()
}
.accept(
MediaType.APPLICATION_OCTET_STREAM,
MediaType.APPLICATION_JSON
)
.exchangeToMono { response ->
if (response.statusCode().isError) {
response.createException().flatMap { Mono.error(it) }
} else {
response.toEntity(ByteArray::class.java)
}
}
.awaitSingle()
}
}
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ services:
- WITHDRAW_VOLUME_CALCULATION_CURRENCY=${WITHDRAW_VOLUME_CALCULATION_CURRENCY}
- TOTAL_ASSET_CALCULATION_CURRENCY=${TOTAL_ASSET_CALCULATION_CURRENCY}
- TOKEN_ISSUER_URL=${KC_ISSUER_URL}
- APP_BASE_URL=${APP_BASE_URL}
depends_on:
- consul
- vault
Expand Down
Loading