Skip to content

Commit

Permalink
Endpoint Cleanup (#21)
Browse files Browse the repository at this point in the history
* swagger / updating endpoint for audiences on contract execute

* init

* General endpoint cleanup + swagger updates

* cleanup

* lint + test publish fix
  • Loading branch information
cworsnop-figure authored May 20, 2022
1 parent 8688991 commit f0ea177
Show file tree
Hide file tree
Showing 21 changed files with 160 additions and 145 deletions.
1 change: 1 addition & 0 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
permissions:
actions: read
checks: write
pull-requests: write
if: github.event.workflow_run.conclusion != 'skipped'

steps:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package io.provenance.api.models.eos
import io.provenance.objectstore.proto.Objects
import java.util.Base64

data class StoreAssetResponse(
data class StoreProtoResponse(
val hash: String,
val uri: String,
val bucket: String,
val name: String
)

fun Objects.ObjectResponse.toModel() = StoreAssetResponse(Base64.getEncoder().encodeToString(hash.toByteArray()), uri, bucket, name)
fun Objects.ObjectResponse.toModel() = StoreProtoResponse(Base64.getEncoder().encodeToString(hash.toByteArray()), uri, bucket, name)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.provenance.onboarding.domain.objectStore

import com.google.protobuf.Message
import io.provenance.api.models.eos.StoreAssetResponse
import io.provenance.api.models.eos.StoreProtoResponse
import io.provenance.scope.encryption.proto.Encryption
import io.provenance.scope.objectstore.client.OsClient
import java.security.PrivateKey
Expand All @@ -12,5 +12,5 @@ interface ObjectStore {
fun retrieve(client: OsClient, hash: ByteArray, publicKey: PublicKey): ByteArray
fun retrieveWithDIME(client: OsClient, hash: ByteArray, publicKey: PublicKey): Pair<Encryption.DIME, ByteArray>
fun retrieveAndDecrypt(client: OsClient, hash: ByteArray, publicKey: PublicKey, privateKey: PrivateKey): ByteArray
fun storeAsset(client: OsClient, message: Message, publicKey: PublicKey, additionalAudiences: Set<PublicKey>): StoreAssetResponse
fun storeMessage(client: OsClient, message: Message, publicKey: PublicKey, additionalAudiences: Set<PublicKey>): StoreProtoResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.provenance.onboarding.domain.usecase.cee.approve

import com.google.protobuf.Any
import cosmos.tx.v1beta1.TxOuterClass
import io.provenance.api.models.p8e.TxResponse
import io.provenance.onboarding.domain.provenance.Provenance
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.cee.approve.models.ApproveContractRequestWrapper
Expand All @@ -17,23 +18,24 @@ class ApproveContractExecution(
private val createClient: CreateClient,
private val provenance: Provenance,
private val getSigner: GetSigner,
) : AbstractUseCase<ApproveContractRequestWrapper, Unit>() {
override suspend fun execute(args: ApproveContractRequestWrapper) {
) : AbstractUseCase<ApproveContractRequestWrapper, TxResponse>() {
override suspend fun execute(args: ApproveContractRequestWrapper): TxResponse {
val client = createClient.execute(CreateClientRequest(args.uuid, args.request.account, args.request.client))
val envelope = Envelopes.Envelope.newBuilder().mergeFrom(args.request.envelope).build()

when (val result = client.execute(envelope)) {
is FragmentResult -> {
val approvalTxHash = client.approveScopeUpdate(result.envelopeState, args.request.expiration).let {
client.approveScopeUpdate(result.envelopeState, args.request.expiration).let {
val signer = getSigner.execute(args.uuid)
val txBody = TxOuterClass.TxBody.newBuilder().addAllMessages(it.map { msg -> Any.pack(msg, "") }).build()
val broadcast = provenance.executeTransaction(args.request.provenanceConfig, txBody, signer)
provenance.executeTransaction(args.request.provenanceConfig, txBody, signer).also { broadcast ->

broadcast.txhash
client.respondWithApproval(result.envelopeState, broadcast.txhash)
return TxResponse(broadcast.txhash, broadcast.gasWanted.toString(), broadcast.gasUsed.toString(), broadcast.height.toString())
}
}

client.respondWithApproval(result.envelopeState, approvalTxHash)
}
else -> throw IllegalStateException("Unexpected contract state after approving a fragment. Did not receive fragment result!")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.provenance.onboarding.domain.usecase.objectStore.store

import com.google.gson.Gson
import io.provenance.api.models.eos.StoreAssetResponse
import io.provenance.api.models.eos.StoreProtoResponse
import io.provenance.api.models.p8e.AudienceKeyPair
import io.provenance.api.models.p8e.PermissionInfo
import io.provenance.onboarding.domain.objectStore.ObjectStore
Expand All @@ -28,8 +28,8 @@ class StoreFile(
private val objectStore: ObjectStore,
private val objectStoreConfig: ObjectStoreConfig,
private val entityManager: EntityManager,
) : AbstractUseCase<StoreFileRequestWrapper, StoreAssetResponse>() {
override suspend fun execute(args: StoreFileRequestWrapper): StoreAssetResponse {
) : AbstractUseCase<StoreFileRequestWrapper, StoreProtoResponse>() {
override suspend fun execute(args: StoreFileRequestWrapper): StoreProtoResponse {
val originator = entityManager.getEntity(args.uuid)
var additionalAudiences = emptySet<AudienceKeyPair>()
val osClient = OsClient(URI.create(args.request.getAsType<FormFieldPart>("objectStoreAddress").value()), objectStoreConfig.timeoutMs)
Expand All @@ -51,7 +51,7 @@ class StoreFile(
putKv(FileNFT.KEY_CONTENT_TYPE, file.headers().contentType.toString().toProtoAny())
}

return objectStore.storeAsset(osClient, asset, originator.encryptionPublicKey() as PublicKey, additionalAudiences.map { it.encryptionKey.toJavaPublicKey() }.toSet())
return objectStore.storeMessage(osClient, asset, originator.encryptionPublicKey() as PublicKey, additionalAudiences.map { it.encryptionKey.toJavaPublicKey() }.toSet())
}

private inline fun <reified T> Map<String, Part>.getAsType(key: String): T =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.provenance.onboarding.domain.objectStore.ObjectStore
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.common.originator.EntityManager
import io.provenance.onboarding.domain.usecase.objectStore.store.models.StoreProtoRequestWrapper
import io.provenance.api.models.eos.StoreAssetResponse
import io.provenance.api.models.eos.StoreProtoResponse
import io.provenance.onboarding.frameworks.cee.parsers.MessageParser
import io.provenance.onboarding.frameworks.config.ObjectStoreConfig
import io.provenance.scope.encryption.util.toJavaPublicKey
Expand All @@ -20,8 +20,8 @@ class StoreProto(
private val objectStoreConfig: ObjectStoreConfig,
private val entityManager: EntityManager,
private val parser: MessageParser
) : AbstractUseCase<StoreProtoRequestWrapper, StoreAssetResponse>() {
override suspend fun execute(args: StoreProtoRequestWrapper): StoreAssetResponse {
) : AbstractUseCase<StoreProtoRequestWrapper, StoreProtoResponse>() {
override suspend fun execute(args: StoreProtoRequestWrapper): StoreProtoResponse {
val originator = entityManager.getEntity(args.uuid)
val osClient = OsClient(URI.create(args.request.objectStoreAddress), objectStoreConfig.timeoutMs)
val additionalAudiences = entityManager.hydrateKeys(args.request.permissions)
Expand All @@ -31,6 +31,6 @@ class StoreProto(
val publicKey = (originator.encryptionPublicKey() as? PublicKey)
?: throw IllegalStateException("Public key was not present for originator: ${args.uuid}")

return objectStore.storeAsset(osClient, asset, publicKey, additionalAudiences.map { it.encryptionKey.toJavaPublicKey() }.toSet())
return objectStore.storeMessage(osClient, asset, publicKey, additionalAudiences.map { it.encryptionKey.toJavaPublicKey() }.toSet())
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package io.provenance.onboarding.domain.usecase.objectStore.store.models

import java.util.UUID
import org.springframework.http.HttpEntity
import org.springframework.http.codec.multipart.FilePart
import org.springframework.http.codec.multipart.Part

data class StoreFileRequestWrapper(
val uuid: UUID,
val request: Map<String, Part>,
)

data class SwaggerStoreFileRequestWrapper(
val objectStoreAddress: String,
val file: FilePart,
)

data class SwaggerGetFileResponse(
val value: HttpEntity<ByteArray>
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class P8eContractService : ContractService {
}.fold(
onSuccess = { result -> result },
onFailure = { throwable ->
throw ContractExecutionException("Contract execution failed.", throwable)
throw ContractExecutionException("Contract execution failed: ${throwable.message}", throwable)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.provenance.onboarding.frameworks.objectStore
import com.google.protobuf.Message
import io.provenance.objectstore.proto.Objects
import io.provenance.onboarding.domain.objectStore.ObjectStore
import io.provenance.api.models.eos.StoreAssetResponse
import io.provenance.api.models.eos.StoreProtoResponse
import io.provenance.api.models.eos.toModel
import io.provenance.onboarding.frameworks.config.ObjectStoreConfig
import io.provenance.onboarding.frameworks.provenance.extensions.getEncryptedPayload
Expand Down Expand Up @@ -84,10 +84,10 @@ class ObjectStoreService(
return res.getDecryptedPayload(DirectKeyRef(publicKey, privateKey)).readAllBytes()
}

override fun storeAsset(
override fun storeMessage(
client: OsClient,
message: Message,
publicKey: PublicKey,
additionalAudiences: Set<PublicKey>
): StoreAssetResponse = encryptAndStore(client, message, publicKey, additionalAudiences).toModel()
): StoreProtoResponse = encryptAndStore(client, message, publicKey, additionalAudiences).toModel()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ class SecurityConfig {
fun securityWebFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain {
http.authorizeExchange {
it.pathMatchers("${Routes.MANAGE_BASE}/**", "${Routes.EXTERNAL_BASE}/**", "${Routes.INTERNAL_BASE}/**", "${Routes.DOCS_BASE}/**").permitAll()
}.csrf().disable()
}

return http.build()
return http.httpBasic().disable()
.formLogin().disable()
.logout().disable()
.csrf().disable()
.headers().frameOptions().disable()
.cache().disable()
.and()
.authorizeExchange()
.pathMatchers("/").permitAll()
.and().build()
}
}
Loading

0 comments on commit f0ea177

Please sign in to comment.