Skip to content

Commit

Permalink
First pass (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
cworsnop-figure authored Jun 30, 2022
1 parent de96258 commit f6b9e9a
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 20 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Versions {
const val SpringMockk = "3.0.1"
const val Swagger = "1.6.2"
const val AssetModel = "0.1.10"
const val P8eScope = "0.6.1"
const val P8eScope = "0.6.2"
const val ProvenanceHdWallet = "0.1.15"
const val ProvenanceClient = "1.1.1"
const val Unirest = "3.13.6"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.provenance.api.models.p8e.tx.permissions.authz

import java.time.OffsetDateTime

data class AuthzChange(
val type: AuthzChangeType,
val envelopeState: String,
val expiration: OffsetDateTime = OffsetDateTime.now().plusHours(1),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.p8e.tx.permissions.authz

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

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.eos.ObjectStoreConfig
import io.provenance.api.models.p8e.ProvenanceConfig

data class UpdateAuthzRequest(
val client: ObjectStoreConfig,
val account: AccountInfo = AccountInfo(),
val provenanceConfig: ProvenanceConfig,
val changes: List<AuthzChange>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.p8e.tx.permissions.dataAccess

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

data class DataAccessUpdate(
val type: DataAccessChangeType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.provenance.api.models.p8e.tx.permissions
package io.provenance.api.models.p8e.tx.permissions.dataAccess

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.p8e.ProvenanceConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.provenance.api.domain.usecase.provenance.tx.permissions.authz

import io.provenance.api.domain.usecase.AbstractUseCase
import io.provenance.api.domain.usecase.cee.common.client.CreateClient
import io.provenance.api.domain.usecase.cee.common.client.model.CreateClientRequest
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.authz.models.UpdateAuthzRequestWrapper
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.authz.AuthzChangeType
import io.provenance.client.protobuf.extensions.toAny
import io.provenance.client.protobuf.extensions.toTxBody
import io.provenance.scope.contract.proto.Envelopes
import java.util.Base64
import org.springframework.stereotype.Component

@Component
class UpdateAuthzGrant(
private val createClient: CreateClient,
private val provenanceService: ProvenanceService,
private val getSigner: GetSigner
) : AbstractUseCase<UpdateAuthzRequestWrapper, TxResponse>() {
override suspend fun execute(args: UpdateAuthzRequestWrapper): TxResponse {
val signer = getSigner.execute(GetSignerRequest(args.uuid, args.request.account))
val messages = createClient.execute(CreateClientRequest(args.uuid, args.request.account, args.request.client)).let { client ->
args.request.changes.flatMap { change ->
when (change.type) {
AuthzChangeType.ADD -> {
client.approveScopeUpdate(Envelopes.EnvelopeState.newBuilder().mergeFrom(Base64.getDecoder().decode(change.envelopeState)).build(), change.expiration).map { it.toAny() }
}
AuthzChangeType.REMOVE -> {
client.revokeScopeUpdate(Envelopes.EnvelopeState.newBuilder().mergeFrom(Base64.getDecoder().decode(change.envelopeState)).build()).map { it.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.authz.models

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

data class UpdateAuthzRequestWrapper(
val uuid: UUID,
val request: UpdateAuthzRequest
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.provenance.api.domain.usecase.provenance.tx.permissions
package io.provenance.api.domain.usecase.provenance.tx.permissions.dataAccess

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.domain.usecase.provenance.tx.permissions.dataAccess.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.api.models.p8e.tx.permissions.dataAccess.DataAccessChangeType
import io.provenance.client.protobuf.extensions.toAny
import io.provenance.client.protobuf.extensions.toTxBody
import io.provenance.metadata.v1.MsgAddScopeDataAccessRequest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.provenance.api.domain.usecase.provenance.tx.permissions.models
package io.provenance.api.domain.usecase.provenance.tx.permissions.dataAccess.models

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

data class UpdateScopeDataAccessRequestWrapper(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ 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.api.models.p8e.tx.permissions.authz.UpdateAuthzRequest
import io.provenance.api.models.p8e.tx.permissions.dataAccess.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 @@ -309,7 +310,7 @@ class ProvenanceApi {
)
),
RouterOperation(
path = "${Routes.EXTERNAL_BASE_V1}/p8e/permissions",
path = "${Routes.EXTERNAL_BASE_V1}/p8e/permissions/data-access",
method = arrayOf(RequestMethod.PATCH),
produces = ["application/json"],
operation = Operation(
Expand Down Expand Up @@ -337,6 +338,35 @@ class ProvenanceApi {
]
)
),
RouterOperation(
path = "${Routes.EXTERNAL_BASE_V1}/p8e/permissions/authz",
method = arrayOf(RequestMethod.PATCH),
produces = ["application/json"],
operation = Operation(
tags = ["Provenance"],
operationId = "updateAuthzGrant",
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 = UpdateAuthzRequest::class))]
),
responses = [
ApiResponse(
responseCode = "200",
description = "successful operation",
content = [Content(schema = Schema(implementation = TxResponse::class))]
)
]
)
)
)
fun externalProvenanceApiV1(handler: ProvenanceHandler) = coRouter {
logExchange(log)
Expand All @@ -352,7 +382,10 @@ class ProvenanceApi {
GET("/scope/query", handler::queryScope)
POST("/verify", handler::verifyAsset)
GET("/fees", handler::getFees)
PATCH("/permissions", handler::updateDataAccess)
"/permissions".nest {
PATCH("/data-access", handler::updateDataAccess)
PATCH("/authz", handler::updateAuthz)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ 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.domain.usecase.provenance.tx.permissions.authz.UpdateAuthzGrant
import io.provenance.api.domain.usecase.provenance.tx.permissions.authz.models.UpdateAuthzRequestWrapper
import io.provenance.api.domain.usecase.provenance.tx.permissions.dataAccess.UpdateScopeDataAccess
import io.provenance.api.domain.usecase.provenance.tx.permissions.dataAccess.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 @@ -33,7 +35,8 @@ class ProvenanceHandler(
private val verifyAsset: VerifyAsset,
private val getFees: GetFeesForAsset,
private val getClassificationStatus: GetClassificationStatus,
private val updateDataAccess: UpdateScopeDataAccess
private val updateDataAccess: UpdateScopeDataAccess,
private val updateAuthzGrant: UpdateAuthzGrant
) {
suspend fun generateTx(req: ServerRequest): ServerResponse = runCatching {
createTx.execute(CreateTxRequestWrapper(req.getUser(), req.awaitBody()))
Expand Down Expand Up @@ -95,4 +98,13 @@ class ProvenanceHandler(
)
)
}.foldToServerResponse()

suspend fun updateAuthz(req: ServerRequest): ServerResponse = runCatching {
updateAuthzGrant.execute(
UpdateAuthzRequestWrapper(
req.getUser(),
req.awaitBody()
)
)
}.foldToServerResponse()
}

0 comments on commit f6b9e9a

Please sign in to comment.