ApiKey

@Serializable
value class ApiKey : Serializable, Comparable<ApiKey> (source)

Describes a checked Buildless API key, which also carries metadata with it about the key. The key itself can be accessed via the key getter.

Usage examples

Use this value class when constructing a well-typed API key during plugin configuration. For example:

import build.less.plugin.gradle.*
import build.less.plugin.gradle.settings.*

plugin {
id("build.less") version "..."
}

buildless {
apiKey(ApiKey.of("..."))
}

// or, to enforce only `ORG`-type API keys:
buildless {
apiKey(ApiKey.of("...", type = SubjectType.ORG))
}

About API keys in Buildless

API keys are issued at the org and user levels. When a user is added to a Buildless org, they gain permission to access that org tenant's data via their own personal keys.

When you use an org key, no specific user is attached to the request. This is useful for systems like CI which don't run as any specific developer.

Key types

There are two key types in Buildless: the main API key, and the events API key. Users and org tenants both get each kind of key. When configuring the Buildless plugin for Gradle, you should always use your main key.

API key checks

The API key is checked for basic structural validity, and enforced against the type provided by the user, if any. If the key fails these checks, an error is thrown which halts the build.

If it is preferable to only perform cursory checks at runtime and allow the build to proceed in most cases, use any of the environment variable, system/Gradle properties, or configuration file methods to specify your keys. In this case, merely withholding the keys will gracefully skip enabling the cache.

Types

Link copied to clipboard
object Companion

Provides factory methods for easily creating ApiKey objects.

Link copied to clipboard

Exception which is thrown when an API key (detected or provided) is found to be invalid. This is a configuration error which must be remedied by the user.

Link copied to clipboard

Enumerates the types of "subjects" (security principals) for which API keys are made available by the Buildless service.

Properties

Link copied to clipboard
val key: String

API key value held by this object; this value is considered sensitive and should not be logged.

Link copied to clipboard

API key value held by this object; this value is considered sensitive and should not be logged.

Link copied to clipboard

Return the format version of the underlying API key (always 1 at present).

Functions

Link copied to clipboard
open operator override fun compareTo(other: ApiKey): Int

Compare this API key to the other API key.

Link copied to clipboard
open override fun toString(): String

Generate a reasonable string representation which does not show the API key value.