VersionClient supports getApiFeatures (#12724)

* VersionClient supports getApiFeatures

This exposes the `features` part of the version service's
`GetLedgerApiVersionResponse` protobuf.

Map the protobuf to user-friendly subclasses of `Feature`,
defined in `c.d.ledger.api.domain`.

VersionClient does not expose experimental features, as they
are meant for internal testing only.

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Simon Meier <meiersi-da@users.noreply.github.com>

Co-authored-by: Simon Meier <meiersi-da@users.noreply.github.com>
This commit is contained in:
Adriaan Moors 2022-02-04 17:02:36 +01:00 committed by GitHub
parent 225c58f4b6
commit e3bae961cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 3 deletions

View File

@ -3,7 +3,7 @@
package com.daml.ledger.client.services.version
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.domain.{LedgerId, Feature}
import com.daml.ledger.api.v1.version_service.VersionServiceGrpc.VersionServiceStub
import scala.concurrent.{ExecutionContext, Future}
@ -16,4 +16,10 @@ final class VersionClient(ledgerId: LedgerId, service: VersionServiceStub) {
)(implicit executionContext: ExecutionContext): Future[String] =
it.getApiVersion(ledgerId, token)
def getApiFeatures(
ledgerIdToUse: LedgerId,
token: Option[String] = None,
)(implicit executionContext: ExecutionContext): Future[Seq[Feature]] =
it.getApiFeatures(ledgerIdToUse, token)
}

View File

@ -3,8 +3,9 @@
package com.daml.ledger.client.services.version.withoutledgerid
import com.daml.ledger.api.domain.LedgerId
import com.daml.ledger.api.v1.version_service.GetLedgerApiVersionRequest
import com.daml.ledger.api.domain.{Feature, LedgerId}
import com.daml.ledger.api.v1.version_service.{FeaturesDescriptor, GetLedgerApiVersionRequest}
import com.daml.ledger.api.v1.version_service.VersionServiceGrpc.VersionServiceStub
import com.daml.ledger.client.LedgerClient
import scalaz.syntax.tag._
@ -22,4 +23,26 @@ private[daml] final class VersionClient(service: VersionServiceStub) {
new GetLedgerApiVersionRequest(ledgerIdToUse.unwrap)
)
.map(_.version)
def getApiFeatures(
ledgerIdToUse: LedgerId,
token: Option[String] = None,
)(implicit executionContext: ExecutionContext): Future[Seq[Feature]] =
LedgerClient
.stub(service, token)
.getLedgerApiVersion(
new GetLedgerApiVersionRequest(ledgerIdToUse.unwrap)
)
.map(_.features.toList.flatMap(VersionClient.fromProto))
}
private[daml] object VersionClient {
// see also com.daml.platform.apiserver.services.ApiVersionService.featuresDescriptor
def fromProto(featuresDescriptor: FeaturesDescriptor): Seq[Feature] =
featuresDescriptor match {
// Note that we do not expose experimental features here, as they are used for internal testing only
// and do not have backwards compatibility guarantees. (They should probably be named 'internalFeatures' ;-)
case FeaturesDescriptor(userManagement, _) =>
(userManagement.toList map (_ => Feature.UserManagement))
}
}

View File

@ -399,4 +399,9 @@ object domain {
final case class CanActAs(party: Ref.Party) extends UserRight
final case class CanReadAs(party: Ref.Party) extends UserRight
}
sealed abstract class Feature extends Product with Serializable
object Feature {
case object UserManagement extends Feature
}
}