Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI command to replace DataProviders duchy list #970

Merged
merged 14 commits into from
May 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import org.wfanet.measurement.api.v2alpha.measurement
import org.wfanet.measurement.api.v2alpha.measurementConsumer
import org.wfanet.measurement.api.v2alpha.measurementSpec
import org.wfanet.measurement.api.v2alpha.publicKey
import org.wfanet.measurement.api.v2alpha.replaceDataProviderRequiredDuchiesRequest
import org.wfanet.measurement.api.v2alpha.requisitionSpec
import org.wfanet.measurement.api.v2alpha.revokeCertificateRequest
import org.wfanet.measurement.api.v2alpha.signedData
Expand Down Expand Up @@ -131,6 +132,7 @@ private val CHANNEL_SHUTDOWN_TIMEOUT = systemDuration.ofSeconds(30)
MeasurementConsumers::class,
Measurements::class,
ApiKeys::class,
DataProviders::class,
]
)
class MeasurementSystem private constructor() : Runnable {
Expand Down Expand Up @@ -1011,6 +1013,51 @@ class GetMeasurement : Runnable {
}
}

@Command(
name = "data-providers",
subcommands = [CommandLine.HelpCommand::class],
)
private class DataProviders {
@ParentCommand
lateinit var parentCommand: MeasurementSystem
private set

val dataProviderStub: DataProvidersCoroutineStub by lazy {
DataProvidersCoroutineStub(parentCommand.kingdomChannel)
}
@Option(
names = ["--name"],
description = ["API resource name of the DataProvider"],
required = true,
)
private lateinit var dataProviderName: String
@Command(name = "replace-required-duchies", description = ["Replaces DataProvider's duchy list"])
fun replaceRequiredDuchyList(
@Option(
names = ["--required-duchies"],
description =
[
"The set of new duchies externals IDS that that will replace the old duchy list for this DataProvider"
],
required = true,
)
requiredDuchies: List<String>,
) {
val request = replaceDataProviderRequiredDuchiesRequest {
name = dataProviderName
requiredExternalDuchies += requiredDuchies
}
val outputDataProvider =
runBlocking(parentCommand.rpcDispatcher) {
dataProviderStub.replaceDataProviderRequiredDuchies(request)
}

println(
"Data Provider ${outputDataProvider.name} duchy list replaced with ${outputDataProvider.requiredExternalDuchyIdsList}"
)
}
}

@Command(
name = "api-keys",
subcommands = [CommandLine.HelpCommand::class],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ import org.wfanet.measurement.api.v2alpha.ApiKeysGrpcKt
import org.wfanet.measurement.api.v2alpha.Certificate
import org.wfanet.measurement.api.v2alpha.CertificatesGrpcKt
import org.wfanet.measurement.api.v2alpha.CreateMeasurementRequest
import org.wfanet.measurement.api.v2alpha.DataProvider
import org.wfanet.measurement.api.v2alpha.DataProvidersGrpcKt
import org.wfanet.measurement.api.v2alpha.DuchyKey
import org.wfanet.measurement.api.v2alpha.EncryptionPublicKey
import org.wfanet.measurement.api.v2alpha.GetMeasurementRequest
import org.wfanet.measurement.api.v2alpha.ListMeasurementsRequest
Expand All @@ -68,6 +70,7 @@ import org.wfanet.measurement.api.v2alpha.MeasurementSpecKt
import org.wfanet.measurement.api.v2alpha.MeasurementsGrpcKt
import org.wfanet.measurement.api.v2alpha.PublicKey
import org.wfanet.measurement.api.v2alpha.PublicKeysGrpcKt
import org.wfanet.measurement.api.v2alpha.ReplaceDataProviderRequiredDuchiesRequest
import org.wfanet.measurement.api.v2alpha.RequisitionSpec
import org.wfanet.measurement.api.v2alpha.RequisitionSpecKt
import org.wfanet.measurement.api.v2alpha.account
Expand All @@ -89,6 +92,7 @@ import org.wfanet.measurement.api.v2alpha.measurement
import org.wfanet.measurement.api.v2alpha.measurementConsumer
import org.wfanet.measurement.api.v2alpha.measurementSpec
import org.wfanet.measurement.api.v2alpha.publicKey
import org.wfanet.measurement.api.v2alpha.replaceDataProviderRequiredDuchiesRequest
import org.wfanet.measurement.api.v2alpha.requisitionSpec
import org.wfanet.measurement.api.v2alpha.revokeCertificateRequest
import org.wfanet.measurement.api.v2alpha.signedData
Expand Down Expand Up @@ -161,6 +165,8 @@ private val DATA_PROVIDER_PUBLIC_KEY =
loadPublicKey(SECRETS_DIR.resolve("edp1_enc_public.tink")).toEncryptionPublicKey()
private val DATA_PROVIDER_PRIVATE_KEY_HANDLE =
loadPrivateKey(SECRETS_DIR.resolve("edp1_enc_private.tink"))
private val DUCHY = DuchyKey("worker1")
private val DUCHIES = listOf(DUCHY).map { it.toName() }

private val DATA_PROVIDER = dataProvider {
name = DATA_PROVIDER_NAME
Expand Down Expand Up @@ -926,6 +932,35 @@ class MeasurementSystemTest {
.isEqualTo(getMeasurementRequest { name = MEASUREMENT_NAME })
}

@Test
fun `replace data providers duchy list with valid request`() {
val args =
commonArgs +
arrayOf(
"data-providers",
"--name=$DATA_PROVIDER_NAME",
"replace-required-duchies",
"--required-duchies=duchies/worker1",
)
callCli(args)

val request =
captureFirst<ReplaceDataProviderRequiredDuchiesRequest> {
runBlocking {
verify(dataProvidersServiceMock).replaceDataProviderRequiredDuchies(capture())
}
}

assertThat(request)
.comparingExpectedFieldsOnly()
.isEqualTo(
replaceDataProviderRequiredDuchiesRequest {
name = DATA_PROVIDER_NAME
requiredExternalDuchies += DUCHIES
}
)
}

companion object {
private val MEASUREMENT_CONSUMER: MeasurementConsumer by lazy {
measurementConsumer {
Expand Down Expand Up @@ -992,6 +1027,14 @@ class MeasurementSystemTest {
}
}
}
private val SUCCEEDED_DATA_PROVIDER: DataProvider by lazy {
dataProvider {
name = DATA_PROVIDER_NAME
certificate = DATA_PROVIDER_CERTIFICATE_NAME
publicKey = signedData { data = DATA_PROVIDER_PUBLIC_KEY.toByteString() }
requiredExternalDuchyIds += DUCHIES
}
}
}
}

Expand Down