Skip to content

Commit

Permalink
Audience Updates + Object Store Use Cases (#20)
Browse files Browse the repository at this point in the history
* swagger / updating endpoint for audiences on contract execute

* changing how audiences work

* Running tests on build + workflow updates to publish test results.

* cleanup

* updating lint

* disabling test

* using the right annotation

* EOS endpoint updates

* File download, configurable parser

* test fixes

* ignoring test

* Member ids for test

* fixing parsing for configurable types
  • Loading branch information
cworsnop-figure authored May 19, 2022
1 parent 56b8cd6 commit 8688991
Show file tree
Hide file tree
Showing 58 changed files with 702 additions and 419 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/main'"

linting:
name: Linting
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false

steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '11'

- name: Linting
run: ./gradlew clean ktlint --parallel

build:
runs-on: ubuntu-latest
steps:
Expand All @@ -28,4 +48,22 @@ jobs:
java-version: '11'
distribution: 'adopt'
- name: Gradle Build
run: ./gradlew build -i --parallel
run: ./gradlew build -i --parallel -x ktlint

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v2
with:
name: Test Results
path: |
**/build/test-results/**/*.xml
event_file:
name: "Event File"
runs-on: ubuntu-latest
steps:
- name: Upload
uses: actions/upload-artifact@v2
with:
name: Event File
path: ${{ github.event_path }}
41 changes: 41 additions & 0 deletions .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Test Results

on:
workflow_run:
workflows: ["Build"]
types:
- completed
permissions: {}

jobs:
test-results:
name: Test Results
runs-on: ubuntu-latest
permissions:
actions: read
checks: write
if: github.event.workflow_run.conclusion != 'skipped'

steps:
- name: Download and Extract Artifacts
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
run: |
mkdir -p artifacts && cd artifacts
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
gh api "$artifacts_url" -q '.artifacts[] | [.name, .archive_download_url] | @tsv' | while read artifact
do
IFS=$'\t' read name url <<< "$artifact"
gh api $url > "$name.zip"
unzip -d "$name" "$name.zip"
done
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: artifacts/Event File/event.json
event_name: ${{ github.event.workflow_run.event }}
files: "artifacts/**/*.xml"
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object Versions {
const val ProvenanceClient = "1.1.1"
const val Unirest = "3.13.6"
const val KeyAccessLib = "0.2.15"
const val LoanPackage = "0.1.13"
const val LoanPackage = "0.1.14"
const val Grpc = "1.45.0"
const val ProvenanceProto = "1.8.0"
const val Reflections = "0.9.10"
Expand Down Expand Up @@ -185,11 +185,11 @@ object Dependencies {
val Kotest = DependencySpec("io.kotest:kotest-runner-junit5-jvm", Versions.Kotest)
val KotestAssertions = DependencySpec("io.kotest:kotest-assertions-core-jvm", Versions.Kotest)
val KotestAssertionsArrow = DependencySpec("io.kotest.extensions:kotest-assertions-arrow", Versions.KotestExtensionsArrow)
val KotestProperty = DependencySpec("io.kotest:kotest-property", Versions.Kotest)
val Hamkrest = DependencySpec("com.natpryce:hamkrest", Versions.Hamkrest)
val Redisson = DependencySpec("org.redisson:redisson", Versions.Redisson)
val SpringMockk = DependencySpec("com.ninja-squad:springmockk", Versions.SpringMockk)
val KotlinFaker = DependencySpec("io.github.serpro69:kotlin-faker", Versions.KotlinFaker)

object Swagger {
val Annotations = DependencySpec("io.swagger:swagger-annotations", Versions.Swagger)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ data class ContractConfig(
val scopeUuid: UUID,
val sessionUuid: UUID?,
val scopeSpecificationName: String,
val parserConfig: ParserConfig?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.cee

data class ParserConfig(
val name: String,
val descriptors: List<String>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.provenance.api.models.eos

data class GetFileRequest(
val hash: String,
val objectStoreAddress: String
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.provenance.api.models.eos

import java.util.UUID

data class GetAssetRequest(
val originatorUuid: UUID,
data class GetProtoRequest(
val hash: String,
val objectStoreAddress: String,
val type: String
)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.provenance.api.models.eos

import io.provenance.api.models.p8e.PermissionInfo

data class StoreProtoRequest(
val objectStoreAddress: String,
val permissions: PermissionInfo?,
val message: Any,
val type: String,
)
13 changes: 13 additions & 0 deletions models/src/main/kotlin/io/provenance/api/models/p8e/Audience.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.provenance.api.models.p8e

import java.util.UUID

data class Audience(
val uuid: UUID?,
var keys: AudienceKeyPair?
)

data class AudienceKeyPair(
val encryptionKey: String,
val signingKey: String
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.provenance.api.models.p8e

data class PermissionInfo(
val audiences: Set<String> = emptySet(),
val audiences: Set<Audience> = emptySet(),
val permissionDart: Boolean = false,
val permissionPortfolioManager: Boolean = false,
)
5 changes: 2 additions & 3 deletions service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,14 @@ dependencies {
Dependencies.Kotest,
Dependencies.KotestAssertions,
Dependencies.KotestAssertionsArrow,
Dependencies.KotestProperty,
).forEach { testDep ->
testDep.testImplementation(this)
}
}

tasks.withType<Test> {
useJUnitPlatform {
includeEngines("junit-jupiter")
}
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import com.google.protobuf.Message

interface ContractParser {
fun parseInput(input: Any, type: Class<*>): Message
fun getParser(name: String): InputParser?
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import com.google.protobuf.Message

interface InputParser {
val type: Class<*>
fun parse(input: Any, type: Class<*>): Message
fun parse(input: Any, type: Class<*>, includeTypes: List<String> = emptyList()): Message
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.provenance.onboarding.domain.extensions

import org.springframework.http.ContentDisposition
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.InvalidMediaTypeException
import org.springframework.http.MediaType

@Suppress("SwallowedException")
fun ByteArray.toByteResponse(
filename: String,
contentType: String
) = let { bytes ->
bytes to HttpHeaders().also {
it.contentDisposition = ContentDisposition.builder("inline").filename(filename).build()
it.contentLength = bytes.size.toLong()

contentType.run {
try {
MediaType.parseMediaType(contentType)
} catch (e: InvalidMediaTypeException) {
// ignored
MediaType.APPLICATION_OCTET_STREAM
}
}.run { it.contentType = this }
}
}.let { (bytes, headers) -> HttpEntity(bytes, headers) }
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.provenance.onboarding.domain.objectStore

import com.google.protobuf.Message
import io.provenance.api.models.eos.StoreAssetResponse
import io.provenance.scope.encryption.proto.Encryption
import io.provenance.scope.objectstore.client.OsClient
import tech.figure.asset.v1beta1.Asset
import java.security.PrivateKey
import java.security.PublicKey

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, asset: Asset, publicKey: PublicKey, additionalAudiences: Set<PublicKey>): StoreAssetResponse
fun storeAsset(client: OsClient, message: Message, publicKey: PublicKey, additionalAudiences: Set<PublicKey>): StoreAssetResponse
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.provenance.onboarding.domain.usecase.cee.common.client

import io.provenance.core.KeyType
import io.provenance.onboarding.domain.usecase.AbstractUseCase
import io.provenance.onboarding.domain.usecase.cee.common.client.model.CreateClientRequest
import io.provenance.onboarding.domain.usecase.common.originator.GetOriginator
import io.provenance.onboarding.domain.usecase.common.originator.EntityManager
import io.provenance.onboarding.frameworks.config.ProvenanceProperties
import io.provenance.scope.encryption.model.DirectKeyRef
import io.provenance.scope.encryption.util.toJavaPublicKey
Expand All @@ -20,11 +19,11 @@ import java.util.concurrent.TimeUnit

@Component
class CreateClient(
private val getOriginator: GetOriginator,
private val provenanceProperties: ProvenanceProperties,
private val entityManager: EntityManager,
) : AbstractUseCase<CreateClientRequest, Client>() {
override suspend fun execute(args: CreateClientRequest): Client {
val originator = getOriginator.execute(args.uuid)
val originator = entityManager.getEntity(args.uuid)
val affiliate = Affiliate(
signingKeyRef = DirectKeyRef(KeyPair(originator.signingPublicKey() as PublicKey, originator.signingPrivateKey() as PrivateKey)),
encryptionKeyRef = DirectKeyRef(KeyPair(originator.encryptionPublicKey() as PublicKey, originator.encryptionPrivateKey() as PrivateKey)),
Expand All @@ -48,9 +47,8 @@ class CreateClient(
}
)
).also { client ->
args.affiliates.forEach {
val keys = getOriginator.execute(it.uuid).keys
client.affiliateRepository.addAffiliate(keys[KeyType.SIGNING_PUBLIC_KEY].toString().toJavaPublicKey(), keys[KeyType.ENCRYPTION_PUBLIC_KEY].toString().toJavaPublicKey())
args.affiliates.forEach { kp ->
client.affiliateRepository.addAffiliate(kp.signingKey.toJavaPublicKey(), kp.encryptionKey.toJavaPublicKey())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.provenance.onboarding.domain.usecase.cee.common.client.model

import io.provenance.api.models.account.AccountInfo
import io.provenance.api.models.account.Participant
import io.provenance.api.models.eos.ObjectStoreConfig
import io.provenance.api.models.p8e.AudienceKeyPair
import java.util.UUID

data class CreateClientRequest(
val uuid: UUID,
val account: AccountInfo = AccountInfo(),
val client: ObjectStoreConfig,
val affiliates: List<Participant> = emptyList(),
val affiliates: Set<AudienceKeyPair> = emptySet()
)
Loading

0 comments on commit 8688991

Please sign in to comment.