Skip to content

Commit

Permalink
Simplify Certificate key parsing and auth using sealed interfaces. (#…
Browse files Browse the repository at this point in the history
…1211)

This is pre-factoring for implementing ListCertificates.
  • Loading branch information
SanjayVas authored and ple13 committed Aug 16, 2024
1 parent 9b501b9 commit 66398fa
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

package org.wfanet.measurement.api.v2alpha

import org.wfanet.measurement.common.api.ChildResourceKey
import org.wfanet.measurement.common.api.ResourceKey

interface CertificateParentKey : ResourceKey {
sealed interface CertificateKey : ChildResourceKey {
val certificateId: String

override val parentKey: CertificateParentKey
}

sealed interface CertificateParentKey : ResourceKey
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
package org.wfanet.measurement.api.v2alpha

import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

private val parser = ResourceNameParser("dataProviders/{data_provider}/certificates/{certificate}")

/** [ResourceKey] of a DataProvider Certificate. */
data class DataProviderCertificateKey(
val dataProviderId: String,
override val certificateId: String
) : CertificateParentKey {
) : CertificateKey {
override val parentKey = DataProviderKey(dataProviderId)

override fun toName(): String {
return parser.assembleName(
mapOf(IdVariable.DATA_PROVIDER to dataProviderId, IdVariable.CERTIFICATE to certificateId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

/** [DataProviderKey] of a Data Provider. */
data class DataProviderKey(val dataProviderId: String) : ResourceKey {
data class DataProviderKey(val dataProviderId: String) : ResourceKey, CertificateParentKey {
override fun toName(): String {
return parser.assembleName(mapOf(IdVariable.DATA_PROVIDER to dataProviderId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@
package org.wfanet.measurement.api.v2alpha

import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

private val parser = ResourceNameParser("duchies/{duchy}/certificates/{certificate}")

/** [ResourceKey] of a Duchy Certificate. */
data class DuchyCertificateKey(val duchyId: String, override val certificateId: String) :
CertificateParentKey {
data class DuchyCertificateKey(
val duchyId: String,
override val certificateId: String,
) : CertificateKey {
override val parentKey = DuchyKey(duchyId)

override fun toName(): String {
return parser.assembleName(
mapOf(IdVariable.DUCHY to duchyId, IdVariable.CERTIFICATE to certificateId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

/** [ResourceKey] of a Duchy. */
data class DuchyKey(val duchyId: String) : ResourceKey {
data class DuchyKey(val duchyId: String) : ResourceKey, CertificateParentKey {
override fun toName(): String {
return parser.assembleName(mapOf(IdVariable.DUCHY to duchyId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.wfanet.measurement.api.v2alpha

import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

private val parser =
ResourceNameParser("measurementConsumers/{measurement_consumer}/certificates/{certificate}")
Expand All @@ -23,7 +24,9 @@ private val parser =
data class MeasurementConsumerCertificateKey(
val measurementConsumerId: String,
override val certificateId: String
) : CertificateParentKey {
) : CertificateKey {
override val parentKey = MeasurementConsumerKey(measurementConsumerId)

override fun toName(): String {
return parser.assembleName(
mapOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

/** [ResourceKey] of a Measurement Consumer. */
data class MeasurementConsumerKey(val measurementConsumerId: String) : ResourceKey {
data class MeasurementConsumerKey(
val measurementConsumerId: String,
) : ResourceKey, CertificateParentKey {
override fun toName(): String {
return parser.assembleName(mapOf(IdVariable.MEASUREMENT_CONSUMER to measurementConsumerId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.wfanet.measurement.api.v2alpha

import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

private val parser =
ResourceNameParser("modelProviders/{model_provider}/certificates/{certificate}")
Expand All @@ -23,7 +24,9 @@ private val parser =
data class ModelProviderCertificateKey(
val modelProviderId: String,
override val certificateId: String
) : CertificateParentKey {
) : CertificateKey {
override val parentKey = ModelProviderKey(modelProviderId)

override fun toName(): String {
return parser.assembleName(
mapOf(IdVariable.MODEL_PROVIDER to modelProviderId, IdVariable.CERTIFICATE to certificateId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.wfanet.measurement.common.ResourceNameParser
import org.wfanet.measurement.common.api.ResourceKey

/** [ModelProviderKey] of a Model Provider. */
data class ModelProviderKey(val modelProviderId: String) : ResourceKey {
data class ModelProviderKey(val modelProviderId: String) : ResourceKey, CertificateParentKey {
override fun toName(): String {
return parser.assembleName(mapOf(IdVariable.MODEL_PROVIDER to modelProviderId))
}
Expand Down
Loading

0 comments on commit 66398fa

Please sign in to comment.