Class EphemeralCredentialsAccessor
- All Implemented Interfaces:
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:
- Plain named methods (
find(java.lang.String)/has(java.lang.String)/put(java.lang.String, com.cloudbees.plugins.credentials.Credentials)/forget(java.lang.String)) - what the separateephemeralCredentialsPut/Find/Has/Forgetglobal steps delegate to, constructing a fresh, one-shot instance per call. - Groovy's operator sugar for
Map-like access -getAt(java.lang.String)/putAt(java.lang.String, com.cloudbees.plugins.credentials.Credentials)/containsKey(java.lang.String)/remove(java.lang.String)- via theephemeralCredentialsglobal variable, which returns one instance bound to the current run for the rest of the script (cached the same waywithEphemeralCredentialsitself is, seeEphemeralCredentialsAccessorGlobalVariable), soephemeralCredentials['FOO'] = someCredentialsandephemeralCredentials['FOO']work directly.
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsKey(String credentialsId) Same ashas(java.lang.String)- offered under theMap-conventional name too.com.cloudbees.plugins.credentials.Credentialsbooleancom.cloudbees.plugins.credentials.CredentialsGroovyephemeralCredentials['id']sugar - same asfind(java.lang.String).booleanvoidput(EphemeralCredentialSpec spec, Map<String, Object> values) Convenience overload matching whatwithEphemeralCredentialsitself does internally: materializesspecfromvalues(the same shapeinput's answer would have been) and caches the result underspec.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 oninputat all.voidCaches an already-builtCredentialsobject undercredentialsId.voidGroovyephemeralCredentials['id'] = credentialssugar - same asput(java.lang.String, com.cloudbees.plugins.credentials.Credentials).booleanSame asforget(java.lang.String)- offered under theMap-conventional name too.
-
Constructor Details
-
EphemeralCredentialsAccessor
-
-
Method Details
-
find
@CheckForNull public com.cloudbees.plugins.credentials.Credentials find(@NonNull String credentialsId) -
has
-
put
public void put(@NonNull String credentialsId, @NonNull com.cloudbees.plugins.credentials.Credentials credentials) Caches an already-builtCredentialsobject undercredentialsId. IfcredentialsisIdCredentials(true of every standard credential type, including everything this plugin's own five factories produce), its owngetId()must equalcredentialsId- otherwise standard lookups likewithCredentialsmatch candidates by callinggetId()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 asephemeralUsernamePassword(id: 'FOO', ...)thenputunder a different ID via this method would remain permanently invisible towithCredentialsfor that other ID, with no error anywhere to explain why. -
put
Convenience overload matching whatwithEphemeralCredentialsitself does internally: materializesspecfromvalues(the same shapeinput's answer would have been) and caches the result underspec.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 oninputat all. -
forget
-
getAt
@CheckForNull public com.cloudbees.plugins.credentials.Credentials getAt(@NonNull String credentialsId) GroovyephemeralCredentials['id']sugar - same asfind(java.lang.String). -
putAt
public void putAt(@NonNull String credentialsId, @NonNull com.cloudbees.plugins.credentials.Credentials credentials) GroovyephemeralCredentials['id'] = credentialssugar - same asput(java.lang.String, com.cloudbees.plugins.credentials.Credentials). -
containsKey
Same ashas(java.lang.String)- offered under theMap-conventional name too. -
remove
Same asforget(java.lang.String)- offered under theMap-conventional name too.
-