Skip to content

Commit

Permalink
Adding endpoints for Data Access configuration (#37)
Browse files Browse the repository at this point in the history
* updating data access endpoints

* refactoring

* cleanup

* PR comment
  • Loading branch information
cworsnop-figure authored Jun 28, 2022
1 parent 57ed893 commit de96258
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.p8e.tx.permissions

enum class DataAccessChangeType {
ADD,
REMOVE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.p8e.tx.permissions

data class DataAccessUpdate(
val type: DataAccessChangeType,
val address: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.provenance.api.models.p8e.tx.permissions

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.ProvenanceConfig
import java.util.UUID

data class UpdateScopeDataAccessRequest(
val scopeUuid: UUID,
val account: AccountInfo = AccountInfo(),
val provenanceConfig: ProvenanceConfig,
val changes: List<DataAccessUpdate>
)
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.provenance.api.domain.usecase.provenance.tx
package io.provenance.api.domain.usecase.provenance.tx.create

import io.provenance.api.domain.usecase.AbstractUseCase
import io.provenance.api.domain.usecase.common.model.ScopeConfig
import io.provenance.api.domain.usecase.common.originator.EntityManager
import io.provenance.api.models.p8e.TxBody
import io.provenance.api.domain.usecase.provenance.account.GetSigner
import io.provenance.api.domain.usecase.provenance.account.models.GetSignerRequest
import io.provenance.api.domain.usecase.provenance.tx.model.CreateTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.create.models.CreateTxRequestWrapper
import io.provenance.api.frameworks.config.ProvenanceProperties
import io.provenance.api.frameworks.provenance.utility.ProvenanceUtils
import io.provenance.api.models.p8e.TxBody
import io.provenance.scope.encryption.util.getAddress
import io.provenance.scope.encryption.util.toJavaPublicKey
import org.springframework.stereotype.Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.domain.usecase.provenance.tx.model
package io.provenance.api.domain.usecase.provenance.tx.create.models

import io.provenance.api.models.p8e.tx.CreateTxRequest
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.provenance.api.domain.usecase.provenance.tx
package io.provenance.api.domain.usecase.provenance.tx.execute

import io.provenance.api.models.p8e.TxResponse
import io.provenance.api.domain.provenance.Provenance
import io.provenance.api.domain.usecase.AbstractUseCase
import io.provenance.api.domain.usecase.provenance.account.GetSigner
import io.provenance.api.domain.usecase.provenance.account.models.GetSignerRequest
import io.provenance.api.domain.usecase.provenance.tx.model.ExecuteTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.execute.models.ExecuteTxRequestWrapper
import io.provenance.api.models.p8e.TxResponse
import org.springframework.stereotype.Component

@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.domain.usecase.provenance.tx.model
package io.provenance.api.domain.usecase.provenance.tx.execute.models

import io.provenance.api.models.p8e.tx.ExecuteTxRequest
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.provenance.api.domain.usecase.provenance.tx.permissions

import io.provenance.api.domain.usecase.AbstractUseCase
import io.provenance.api.domain.usecase.provenance.account.GetSigner
import io.provenance.api.domain.usecase.provenance.account.models.GetSignerRequest
import io.provenance.api.domain.usecase.provenance.tx.permissions.models.UpdateScopeDataAccessRequestWrapper
import io.provenance.api.frameworks.provenance.ProvenanceService
import io.provenance.api.frameworks.provenance.extensions.toTxResponse
import io.provenance.api.models.p8e.TxResponse
import io.provenance.api.models.p8e.tx.permissions.DataAccessChangeType
import io.provenance.client.protobuf.extensions.toAny
import io.provenance.client.protobuf.extensions.toTxBody
import io.provenance.metadata.v1.MsgAddScopeDataAccessRequest
import io.provenance.metadata.v1.MsgDeleteScopeDataAccessRequest
import io.provenance.scope.util.MetadataAddress
import io.provenance.scope.util.toByteString
import org.springframework.stereotype.Component

@Component
class UpdateScopeDataAccess(
private val provenanceService: ProvenanceService,
private val getSigner: GetSigner
) : AbstractUseCase<UpdateScopeDataAccessRequestWrapper, TxResponse>() {
override suspend fun execute(args: UpdateScopeDataAccessRequestWrapper): TxResponse {
val signer = getSigner.execute(GetSignerRequest(args.uuid, args.request.account))

val messages = args.request.changes.map {
when (it.type) {
DataAccessChangeType.ADD -> {
MsgAddScopeDataAccessRequest.newBuilder()
.setScopeId(MetadataAddress.forScope(args.request.scopeUuid).bytes.toByteString())
.addDataAccess(it.address)
.addAllSigners(listOf(signer.address()))
.build().toAny()
}
DataAccessChangeType.REMOVE -> {
MsgDeleteScopeDataAccessRequest.newBuilder()
.setScopeId(MetadataAddress.forScope(args.request.scopeUuid).bytes.toByteString())
.addDataAccess(it.address)
.addAllSigners(listOf(signer.address()))
.build().toAny()
}
}
}.toTxBody()

return provenanceService.executeTransaction(args.request.provenanceConfig, messages, signer).toTxResponse()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.provenance.api.domain.usecase.provenance.tx.permissions.models

import io.provenance.api.models.p8e.tx.permissions.UpdateScopeDataAccessRequest
import java.util.UUID

data class UpdateScopeDataAccessRequestWrapper(
val uuid: UUID,
val request: UpdateScopeDataAccessRequest,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import io.provenance.api.models.p8e.contracts.ClassifyAssetRequest
import io.provenance.api.models.p8e.contracts.VerifyAssetRequest
import io.provenance.api.models.p8e.tx.CreateTxRequest
import io.provenance.api.models.p8e.tx.ExecuteTxRequest
import io.provenance.api.models.p8e.tx.permissions.UpdateScopeDataAccessRequest
import io.provenance.classification.asset.client.domain.model.AssetDefinition
import io.provenance.metadata.v1.ScopeResponse
import io.swagger.v3.oas.annotations.Operation
Expand Down Expand Up @@ -307,6 +308,35 @@ class ProvenanceApi {
]
)
),
RouterOperation(
path = "${Routes.EXTERNAL_BASE_V1}/p8e/permissions",
method = arrayOf(RequestMethod.PATCH),
produces = ["application/json"],
operation = Operation(
tags = ["Provenance"],
operationId = "updateScopeDataAccessRequest",
method = "PATCH",
parameters = [
Parameter(
name = "x-uuid",
required = true,
`in` = ParameterIn.HEADER,
schema = Schema(implementation = UUID::class),
),
],
requestBody = RequestBody(
required = true,
content = [Content(schema = Schema(implementation = UpdateScopeDataAccessRequest::class))]
),
responses = [
ApiResponse(
responseCode = "200",
description = "successful operation",
content = [Content(schema = Schema(implementation = TxResponse::class))]
)
]
)
),
)
fun externalProvenanceApiV1(handler: ProvenanceHandler) = coRouter {
logExchange(log)
Expand All @@ -322,6 +352,7 @@ class ProvenanceApi {
GET("/scope/query", handler::queryScope)
POST("/verify", handler::verifyAsset)
GET("/fees", handler::getFees)
PATCH("/permissions", handler::updateDataAccess)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import io.provenance.api.domain.usecase.provenance.contracts.status.models.GetSt
import io.provenance.api.domain.usecase.provenance.contracts.verify.VerifyAsset
import io.provenance.api.domain.usecase.provenance.contracts.verify.models.VerifyAssetRequestWrapper
import io.provenance.api.domain.usecase.provenance.query.QueryScope
import io.provenance.api.domain.usecase.provenance.tx.CreateTx
import io.provenance.api.domain.usecase.provenance.tx.ExecuteTx
import io.provenance.api.domain.usecase.provenance.tx.model.CreateTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.model.ExecuteTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.create.CreateTx
import io.provenance.api.domain.usecase.provenance.tx.create.models.CreateTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.execute.ExecuteTx
import io.provenance.api.domain.usecase.provenance.tx.execute.models.ExecuteTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.permissions.UpdateScopeDataAccess
import io.provenance.api.domain.usecase.provenance.tx.permissions.models.UpdateScopeDataAccessRequestWrapper
import io.provenance.api.frameworks.web.misc.foldToServerResponse
import io.provenance.api.frameworks.web.misc.getUser
import io.provenance.api.models.p8e.query.QueryScopeRequest
Expand All @@ -30,7 +32,8 @@ class ProvenanceHandler(
private val classifyAsset: ClassifyAsset,
private val verifyAsset: VerifyAsset,
private val getFees: GetFeesForAsset,
private val getClassificationStatus: GetClassificationStatus
private val getClassificationStatus: GetClassificationStatus,
private val updateDataAccess: UpdateScopeDataAccess
) {
suspend fun generateTx(req: ServerRequest): ServerResponse = runCatching {
createTx.execute(CreateTxRequestWrapper(req.getUser(), req.awaitBody()))
Expand Down Expand Up @@ -83,4 +86,13 @@ class ProvenanceHandler(
)
)
}.foldToServerResponse()

suspend fun updateDataAccess(req: ServerRequest): ServerResponse = runCatching {
updateDataAccess.execute(
UpdateScopeDataAccessRequestWrapper(
req.getUser(),
req.awaitBody()
)
)
}.foldToServerResponse()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import io.provenance.api.models.p8e.PermissionInfo
import io.provenance.client.grpc.Signer
import io.provenance.core.Originator
import io.provenance.api.domain.usecase.provenance.account.GetSigner
import io.provenance.api.domain.usecase.provenance.tx.model.CreateTxRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.create.CreateTx
import io.provenance.api.domain.usecase.provenance.tx.create.models.CreateTxRequestWrapper
import io.provenance.api.frameworks.config.ProvenanceProperties
import io.provenance.scope.encryption.util.toJavaPublicKey
import io.provenance.scope.util.toUuid
Expand Down

0 comments on commit de96258

Please sign in to comment.