Class EphemeralCredentialsAccessor

java.lang.Object
io.jenkins.plugins.ephemeral_credentials.EphemeralCredentialsAccessor
All Implemented Interfaces:
Serializable

public final class EphemeralCredentialsAccessor extends Object implements Serializable

A convenient, pipeline-facing handle onto EphemeralCredentialsProvider's store, permanently scoped to a single build - every operation is constrained to whichever run this accessor was created for, the same way withEphemeralCredentials itself only ever touches its own run's cache. Exists so pipelines can pre-populate, inspect, or drop entries in that store directly (e.g. computed at runtime, fetched from some other secrets source mid-pipeline) without a plugin release or any custom sandbox approval of their own.

Holds only the run's plain externalizableId String, never a live Run object, for the same reason WithEphemeralCredentials.groovy does: this instance can end up sitting in a pipeline script's own variables, which CPS's program-state serialization walks whenever the build pauses on a step, and WorkflowRun isn't Java-serializable.

Exposes the same four operations two ways:

This does not implement Map itself - only the handful of operations EphemeralCredentialsProvider's own store actually supports (single-key get/put/contains/remove). There is deliberately no entrySet()/values()/clear(): this store already only ever holds what the current run itself put there, so bulk enumeration isn't a scoping concern the way it is for the fallback discussed in EphemeralCredentialsProvider's own javadoc, but offering a full formal Map contract would invite pipelines to write code that assumes semantics (iteration order, equals()/ hashCode() on the whole map, ...) this class was never meant to promise.

See Also:
  • Constructor Details

    • EphemeralCredentialsAccessor

      public EphemeralCredentialsAccessor(@NonNull String runId)
  • Method Details

    • find

      @CheckForNull public com.cloudbees.plugins.credentials.Credentials find(@NonNull String credentialsId)
    • has

      public boolean has(@NonNull String credentialsId)
    • put

      public void put(@NonNull String credentialsId, @NonNull com.cloudbees.plugins.credentials.Credentials credentials)
      Caches an already-built Credentials object under credentialsId. If credentials is IdCredentials (true of every standard credential type, including everything this plugin's own five factories produce), its own getId() must equal credentialsId - otherwise standard lookups like withCredentials match candidates by calling getId() on the credential object itself, not by whatever key this store happens to file it under, so a mismatch here would silently store something that's cached but unfindable through any normal path: a credential materialized as ephemeralUsernamePassword(id: 'FOO', ...) then put under a different ID via this method would remain permanently invisible to withCredentials for that other ID, with no error anywhere to explain why.
    • put

      public void put(@NonNull EphemeralCredentialSpec spec, @NonNull Map<String,Object> values)
      Convenience overload matching what withEphemeralCredentials itself does internally: materializes spec from values (the same shape input's answer would have been) and caches the result under spec.getId() - lets a pipeline pre-populate a credential from data it already has (fetched from some other secrets source mid-pipeline, computed, ...) without ever pausing on input at all.
    • forget

      public boolean forget(@NonNull String credentialsId)
    • getAt

      @CheckForNull public com.cloudbees.plugins.credentials.Credentials getAt(@NonNull String credentialsId)
      Groovy ephemeralCredentials['id'] sugar - same as find(java.lang.String).
    • putAt

      public void putAt(@NonNull String credentialsId, @NonNull com.cloudbees.plugins.credentials.Credentials credentials)
      Groovy ephemeralCredentials['id'] = credentials sugar - same as put(java.lang.String, com.cloudbees.plugins.credentials.Credentials).
    • containsKey

      public boolean containsKey(@NonNull String credentialsId)
      Same as has(java.lang.String) - offered under the Map-conventional name too.
    • remove

      public boolean remove(@NonNull String credentialsId)
      Same as forget(java.lang.String) - offered under the Map-conventional name too.