All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.protokt.v1.google.api.backend.kt Maven / Gradle / Ivy

// Generated by protokt version 1.0.0-beta.2. Do not modify.
// Source: google/api/backend.proto
@file:Suppress("DEPRECATION")

package protokt.v1.google.api

import protokt.v1.AbstractDeserializer
import protokt.v1.AbstractMessage
import protokt.v1.BuilderDsl
import protokt.v1.Collections.copyList
import protokt.v1.Collections.copyMap
import protokt.v1.Collections.unmodifiableList
import protokt.v1.Collections.unmodifiableMap
import protokt.v1.Enum
import protokt.v1.EnumReader
import protokt.v1.GeneratedMessage
import protokt.v1.GeneratedProperty
import protokt.v1.Reader
import protokt.v1.SizeCodecs.sizeOf
import protokt.v1.UnknownFieldSet
import protokt.v1.Writer
import kotlin.Any
import kotlin.Boolean
import kotlin.Deprecated
import kotlin.Double
import kotlin.Int
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.Map
import kotlin.collections.MutableList
import kotlin.collections.MutableMap
import kotlin.jvm.JvmStatic

/**
 * `Backend` defines the backend configuration for a service.
 */
@GeneratedMessage("google.api.Backend")
public class Backend private constructor(
  /**
   * A list of API backend rules that apply to individual API methods.
   *
   *  **NOTE:** All service configuration rules follow "last one wins" order.
   */
  @GeneratedProperty(1)
  public val rules: List,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractMessage() {
  private val `$messageSize`: Int by lazy {
    var result = 0
    if (rules.isNotEmpty()) {
      result += (sizeOf(10u) * rules.size) + rules.sumOf { sizeOf(it) }
    }
    result += unknownFields.size()
    result
  }

  override fun messageSize(): Int = `$messageSize`

  override fun serialize(writer: Writer) {
    rules.forEach { writer.writeTag(10u).write(it) }
    writer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is Backend &&
      other.rules == rules &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + rules.hashCode()
    return result
  }

  override fun toString(): String =
    "Backend(" +
      "rules=$rules" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): Backend =
    Builder().apply {
      rules = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  @BuilderDsl
  public class Builder {
    public var rules: List = emptyList()
      set(newValue) {
        field = copyList(newValue)
      }

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): Backend =
      Backend(
        unmodifiableList(rules),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractDeserializer() {
    @JvmStatic
    override fun deserialize(reader: Reader): Backend {
      var rules: MutableList? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (reader.readTag()) {
          0u -> return Backend(
            unmodifiableList(rules),
            UnknownFieldSet.from(unknownFields)
          )
          10u ->
            rules =
              (rules ?: mutableListOf()).apply {
                reader.readRepeated(false) {
                  add(reader.readMessage(BackendRule))
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(reader.readUnknown())
              }
        }
      }
    }

    @JvmStatic
    public operator fun invoke(dsl: Builder.() -> Unit): Backend = Builder().apply(dsl).build()
  }
}

/**
 * A backend rule provides configuration for an individual API element.
 */
@GeneratedMessage("google.api.BackendRule")
public class BackendRule private constructor(
  /**
   * Selects the methods to which this rule applies.
   *
   *  Refer to [selector][google.api.DocumentationRule.selector] for syntax details.
   */
  @GeneratedProperty(1)
  public val selector: String,
  /**
   * The address of the API backend.
   *
   *  The scheme is used to determine the backend protocol and security. The following schemes are
   * accepted:
   *
   *     SCHEME        PROTOCOL    SECURITY    http://       HTTP        None    https://      HTTP
   *       TLS    grpc://       gRPC        None    grpcs://      gRPC        TLS
   *
   *  It is recommended to explicitly include a scheme. Leaving out the scheme may cause
   * constrasting behaviors across platforms.
   *
   *  If the port is unspecified, the default is: - 80 for schemes without TLS - 443 for schemes
   * with TLS
   *
   *  For HTTP backends, use [protocol][google.api.BackendRule.protocol] to specify the protocol
   * version.
   */
  @GeneratedProperty(2)
  public val address: String,
  /**
   * The number of seconds to wait for a response from a request. The default varies based on the
   * request protocol and deployment environment.
   */
  @GeneratedProperty(3)
  public val deadline: Double,
  /**
   * Deprecated, do not use.
   */
  @GeneratedProperty(4)
  @Deprecated("deprecated in proto")
  public val minDeadline: Double,
  /**
   * The number of seconds to wait for the completion of a long running operation. The default is no
   * deadline.
   */
  @GeneratedProperty(5)
  public val operationDeadline: Double,
  @GeneratedProperty(6)
  public val pathTranslation: PathTranslation,
  /**
   * Authentication settings used by the backend.
   *
   *  These are typically used to provide service management functionality to a backend served on a
   * publicly-routable URL. The `authentication` details should match the authentication behavior used
   * by the backend.
   *
   *  For example, specifying `jwt_audience` implies that the backend expects authentication via a
   * JWT.
   *
   *  When authentication is unspecified, the resulting behavior is the same as `disable_auth` set
   * to `true`.
   *
   *  Refer to https://developers.google.com/identity/protocols/OpenIDConnect for JWT ID token.
   */
  public val authentication: Authentication?,
  /**
   * The protocol used for sending a request to the backend. The supported values are "http/1.1" and
   * "h2".
   *
   *  The default value is inferred from the scheme in the [address][google.api.BackendRule.address]
   * field:
   *
   *     SCHEME        PROTOCOL    http://       http/1.1    https://      http/1.1    grpc://
   * h2    grpcs://      h2
   *
   *  For secure HTTP backends (https://) that support HTTP/2, set this field to "h2" for improved
   * performance.
   *
   *  Configuring this field to non-default values is only supported for secure HTTP backends. This
   * field will be ignored for all other backends.
   *
   *  See
   * https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids
   * for more details on the supported values.
   */
  @GeneratedProperty(9)
  public val protocol: String,
  /**
   * The map between request protocol and the backend address.
   */
  @GeneratedProperty(10)
  public val overridesByRequestProtocol: Map,
  public val unknownFields: UnknownFieldSet = UnknownFieldSet.empty()
) : AbstractMessage() {
  private val `$messageSize`: Int by lazy {
    var result = 0
    if (selector.isNotEmpty()) {
      result += sizeOf(10u) + sizeOf(selector)
    }
    if (address.isNotEmpty()) {
      result += sizeOf(18u) + sizeOf(address)
    }
    if (deadline != 0.0) {
      result += sizeOf(25u) + 8
    }
    if (minDeadline != 0.0) {
      result += sizeOf(33u) + 8
    }
    if (operationDeadline != 0.0) {
      result += sizeOf(41u) + 8
    }
    if (pathTranslation.value != 0) {
      result += sizeOf(48u) + sizeOf(pathTranslation)
    }
    when (authentication) {
      is Authentication.JwtAudience ->
        result += sizeOf(58u) + sizeOf(authentication.jwtAudience)
      is Authentication.DisableAuth ->
        result += sizeOf(64u) + 1
      null -> Unit
    }
    if (protocol.isNotEmpty()) {
      result += sizeOf(74u) + sizeOf(protocol)
    }
    if (overridesByRequestProtocol.isNotEmpty()) {
      result +=
        sizeOf(overridesByRequestProtocol, 82u) { k, v ->
          OverridesByRequestProtocolEntry.entrySize(k, v)
        }
    }
    result += unknownFields.size()
    result
  }

  override fun messageSize(): Int = `$messageSize`

  override fun serialize(writer: Writer) {
    if (selector.isNotEmpty()) {
      writer.writeTag(10u).write(selector)
    }
    if (address.isNotEmpty()) {
      writer.writeTag(18u).write(address)
    }
    if (deadline != 0.0) {
      writer.writeTag(25u).write(deadline)
    }
    if (minDeadline != 0.0) {
      writer.writeTag(33u).write(minDeadline)
    }
    if (operationDeadline != 0.0) {
      writer.writeTag(41u).write(operationDeadline)
    }
    if (pathTranslation.value != 0) {
      writer.writeTag(48u).write(pathTranslation)
    }
    when (authentication) {
      is Authentication.JwtAudience ->
        writer.writeTag(58u).write(authentication.jwtAudience)
      is Authentication.DisableAuth ->
        writer.writeTag(64u).write(authentication.disableAuth)
      null -> Unit
    }
    if (protocol.isNotEmpty()) {
      writer.writeTag(74u).write(protocol)
    }
    overridesByRequestProtocol.entries.forEach {
      writer.writeTag(82u).write(OverridesByRequestProtocolEntry(it.key, it.value))
    }
    writer.writeUnknown(unknownFields)
  }

  override fun equals(other: Any?): Boolean =
    other is BackendRule &&
      other.selector == selector &&
      other.address == address &&
      other.deadline == deadline &&
      other.minDeadline == minDeadline &&
      other.operationDeadline == operationDeadline &&
      other.pathTranslation == pathTranslation &&
      other.authentication == authentication &&
      other.protocol == protocol &&
      other.overridesByRequestProtocol == overridesByRequestProtocol &&
      other.unknownFields == unknownFields

  override fun hashCode(): Int {
    var result = unknownFields.hashCode()
    result = 31 * result + selector.hashCode()
    result = 31 * result + address.hashCode()
    result = 31 * result + deadline.hashCode()
    result = 31 * result + minDeadline.hashCode()
    result = 31 * result + operationDeadline.hashCode()
    result = 31 * result + pathTranslation.hashCode()
    result = 31 * result + authentication.hashCode()
    result = 31 * result + protocol.hashCode()
    result = 31 * result + overridesByRequestProtocol.hashCode()
    return result
  }

  override fun toString(): String =
    "BackendRule(" +
      "selector=$selector, " +
      "address=$address, " +
      "deadline=$deadline, " +
      "minDeadline=$minDeadline, " +
      "operationDeadline=$operationDeadline, " +
      "pathTranslation=$pathTranslation, " +
      "authentication=$authentication, " +
      "protocol=$protocol, " +
      "overridesByRequestProtocol=$overridesByRequestProtocol" +
      if (unknownFields.isEmpty()) ")" else ", unknownFields=$unknownFields)"

  public fun copy(builder: Builder.() -> Unit): BackendRule =
    Builder().apply {
      selector = [email protected]
      address = [email protected]
      deadline = [email protected]
      minDeadline = [email protected]
      operationDeadline = [email protected]
      pathTranslation = [email protected]
      authentication = [email protected]
      protocol = [email protected]
      overridesByRequestProtocol = [email protected]
      unknownFields = [email protected]
      builder()
    }.build()

  public sealed class Authentication {
    /**
     * The JWT audience is used when generating a JWT ID token for the backend. This ID token will
     * be added in the HTTP "authorization" header, and sent to the backend.
     */
    public data class JwtAudience(
      @GeneratedProperty(7)
      public val jwtAudience: String
    ) : Authentication()

    /**
     * When disable_auth is true, a JWT ID token won't be generated and the original "Authorization"
     * HTTP header will be preserved. If the header is used to carry the original token and is expected
     * by the backend, this field must be set to true to preserve the header.
     */
    public data class DisableAuth(
      @GeneratedProperty(8)
      public val disableAuth: Boolean
    ) : Authentication()
  }

  @BuilderDsl
  public class Builder {
    public var selector: String = ""

    public var address: String = ""

    public var deadline: Double = 0.0

    @Deprecated("deprecated in proto")
    public var minDeadline: Double = 0.0

    public var operationDeadline: Double = 0.0

    public var pathTranslation: PathTranslation = PathTranslation.from(0)

    public var authentication: Authentication? = null

    public var protocol: String = ""

    public var overridesByRequestProtocol: Map = emptyMap()
      set(newValue) {
        field = copyMap(newValue)
      }

    public var unknownFields: UnknownFieldSet = UnknownFieldSet.empty()

    public fun build(): BackendRule =
      BackendRule(
        selector,
        address,
        deadline,
        minDeadline,
        operationDeadline,
        pathTranslation,
        authentication,
        protocol,
        unmodifiableMap(overridesByRequestProtocol),
        unknownFields
      )
  }

  public companion object Deserializer : AbstractDeserializer() {
    @JvmStatic
    override fun deserialize(reader: Reader): BackendRule {
      var selector = ""
      var address = ""
      var deadline = 0.0
      var minDeadline = 0.0
      var operationDeadline = 0.0
      var pathTranslation = PathTranslation.from(0)
      var authentication: Authentication? = null
      var protocol = ""
      var overridesByRequestProtocol: MutableMap? = null
      var unknownFields: UnknownFieldSet.Builder? = null

      while (true) {
        when (reader.readTag()) {
          0u -> return BackendRule(
            selector,
            address,
            deadline,
            minDeadline,
            operationDeadline,
            pathTranslation,
            authentication,
            protocol,
            unmodifiableMap(overridesByRequestProtocol),
            UnknownFieldSet.from(unknownFields)
          )
          10u -> selector = reader.readString()
          18u -> address = reader.readString()
          25u -> deadline = reader.readDouble()
          33u -> minDeadline = reader.readDouble()
          41u -> operationDeadline = reader.readDouble()
          48u -> pathTranslation = reader.readEnum(PathTranslation)
          58u -> authentication = Authentication.JwtAudience(reader.readString())
          64u -> authentication = Authentication.DisableAuth(reader.readBool())
          74u -> protocol = reader.readString()
          82u ->
            overridesByRequestProtocol =
              (overridesByRequestProtocol ?: mutableMapOf()).apply {
                reader.readRepeated(false) {
                  reader.readMessage(OverridesByRequestProtocolEntry).let {
                    put(it.key, it.value)
                  }
                }
              }
          else ->
            unknownFields =
              (unknownFields ?: UnknownFieldSet.Builder()).also {
                it.add(reader.readUnknown())
              }
        }
      }
    }

    @JvmStatic
    public operator fun invoke(dsl: Builder.() -> Unit): BackendRule = Builder().apply(dsl).build()
  }

  private class OverridesByRequestProtocolEntry(
    public val key: String,
    public val `value`: BackendRule
  ) : AbstractMessage() {
    override fun messageSize(): Int = entrySize(key, value)

    override fun serialize(writer: Writer) {
      writer.writeTag(10u).write(key)
      writer.writeTag(18u).write(`value`)
    }

    public companion object Deserializer : AbstractDeserializer() {
      public fun entrySize(
        key: String,
        `value`: BackendRule
      ): Int =
        sizeOf(10u) + sizeOf(key) +
          sizeOf(18u) + sizeOf(`value`)

      override fun deserialize(reader: Reader): OverridesByRequestProtocolEntry {
        var key = ""
        var value: BackendRule? = null

        while (true) {
          when (reader.readTag()) {
            0u -> return OverridesByRequestProtocolEntry(key, value ?: BackendRule {})
            10u -> key = reader.readString()
            18u -> value = reader.readMessage(BackendRule)
          }
        }
      }
    }
  }

  /**
   * Path Translation specifies how to combine the backend address with the request path in order to
   * produce the appropriate forwarding URL for the request.
   *
   *  Path Translation is applicable only to HTTP-based backends. Backends which do not accept
   * requests over HTTP/HTTPS should leave `path_translation` unspecified.
   */
  public sealed class PathTranslation(
    override val `value`: Int,
    override val name: String
  ) : Enum() {
    public object PATH_TRANSLATION_UNSPECIFIED : PathTranslation(0, "PATH_TRANSLATION_UNSPECIFIED")

    /**
     * Use the backend address as-is, with no modification to the path. If the URL pattern contains
     * variables, the variable names and values will be appended to the query string. If a query string
     * parameter and a URL pattern variable have the same name, this may result in duplicate keys in
     * the query string.
     *
     *  # Examples
     *
     *  Given the following operation config:
     *
     *      Method path:        /api/company/{cid}/user/{uid}     Backend address:
     * https://example.cloudfunctions.net/getUser
     *
     *  Requests to the following request paths will call the backend at the translated path:
     *
     *      Request path: /api/company/widgetworks/user/johndoe     Translated:
     * https://example.cloudfunctions.net/getUser?cid=widgetworks&uid=johndoe
     *
     *      Request path: /api/company/widgetworks/user/johndoe?timezone=EST     Translated:
     * https://example.cloudfunctions.net/getUser?timezone=EST&cid=widgetworks&uid=johndoe
     */
    public object CONSTANT_ADDRESS : PathTranslation(1, "CONSTANT_ADDRESS")

    /**
     * The request path will be appended to the backend address.
     *
     *  # Examples
     *
     *  Given the following operation config:
     *
     *      Method path:        /api/company/{cid}/user/{uid}     Backend address:
     * https://example.appspot.com
     *
     *  Requests to the following request paths will call the backend at the translated path:
     *
     *      Request path: /api/company/widgetworks/user/johndoe     Translated:
     * https://example.appspot.com/api/company/widgetworks/user/johndoe
     *
     *      Request path: /api/company/widgetworks/user/johndoe?timezone=EST     Translated:
     * https://example.appspot.com/api/company/widgetworks/user/johndoe?timezone=EST
     */
    public object APPEND_PATH_TO_ADDRESS : PathTranslation(2, "APPEND_PATH_TO_ADDRESS")

    public class UNRECOGNIZED(
      `value`: Int
    ) : PathTranslation(value, "UNRECOGNIZED")

    public companion object Deserializer : EnumReader {
      override fun from(`value`: Int): PathTranslation =
        when (value) {
          0 -> PATH_TRANSLATION_UNSPECIFIED
          1 -> CONSTANT_ADDRESS
          2 -> APPEND_PATH_TO_ADDRESS
          else -> UNRECOGNIZED(value)
        }
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy