Class BitwardenConfig
- All Implemented Interfaces:
ExtensionPoint
,Describable<GlobalConfiguration>
,Saveable
,Loadable
,OnMaster
This class is a singleton managed by Jenkins, responsible for storing the plugin's global settings, presenting them in the "Configure System" UI, and handling the logic when the configuration is saved by a user or by JCasC.
-
Nested Class Summary
Nested classes/interfaces inherited from class hudson.model.Descriptor
Descriptor.FormException, Descriptor.PropertyType, Descriptor.Self
Nested classes/interfaces inherited from interface hudson.ExtensionPoint
ExtensionPoint.LegacyInstancesAreScopedToHudson
-
Field Summary
Fields inherited from class hudson.model.Descriptor
clazz
-
Constructor Summary
ConstructorsConstructorDescriptionCalled by Jenkins at startup to create the singleton instance of this class. -
Method Summary
Modifier and TypeMethodDescriptionboolean
configure
(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject json) The entry point for Jenkins when a user saves the global configuration from the UI.An action method for the "Check Version" button in the UI.doFillApiCredentialIdItems
(Jenkins context, String apiCredentialId) Populates the "Bitwarden API Key Credential" dropdown in the UI.doFillMasterPasswordCredentialIdItems
(Jenkins context, String masterPasswordCredentialId) Populates the "Bitwarden Master Password Credential" dropdown in the UI.An action method for the "Download Latest" button in the UI.An action method for the "Refresh Now" button in the UI.An action method for the "Verify Session" button in the UI.int
Provides the display name for this configuration section in the "Configure System" page.static BitwardenConfig
Provides global access to the single instance of this configuration.boolean
A helper method to check if the essential configuration (API key and master password) is present.void
save()
The unified hook for all configuration changes, called by both the UI (viaconfigure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)
) and JCasC.void
setApiCredentialId
(String apiCredentialId) void
setCacheDuration
(int cacheDuration) void
setCliExecutablePath
(String cliExecutablePath) void
setFileCredentialSuffixes
(String fileCredentialSuffixes) void
setMasterPasswordCredentialId
(String masterPasswordCredentialId) void
setServerUrl
(String serverUrl) Methods inherited from class jenkins.model.GlobalConfiguration
all, configure, getDescriptor, getGlobalConfigPage
Methods inherited from class hudson.model.Descriptor
addHelpFileRedirect, bindJSON, bindJSON, calcAutoCompleteSettings, calcFillSettings, configure, doHelp, doHelp, find, find, findByDescribableClassName, findById, getCategory, getCheckMethod, getCheckUrl, getConfigFile, getConfigPage, getCurrentDescriptorByNameUrl, getDescriptorFullUrl, getDescriptorUrl, getGlobalPropertyType, getHelpFile, getHelpFile, getHelpFile, getId, getJsonSafeClassName, getKlass, getPlugin, getPossibleViewNames, getPropertyType, getPropertyType, getPropertyTypeOrDie, getRequiredGlobalConfigPagePermission, getStaticHelpUrl, getStaticHelpUrl, getT, getViewPage, isInstance, isSubTypeOf, load, newInstance, newInstance, newInstance, newInstancesFromHeteroList, newInstancesFromHeteroList, newInstancesFromHeteroList, newInstancesFromHeteroList, self, toArray, toList, toMap
-
Constructor Details
-
BitwardenConfig
public BitwardenConfig()Called by Jenkins at startup to create the singleton instance of this class.The constructor first calls
Descriptor.load()
to populate the fields from the persisted XML configuration on disk.
-
-
Method Details
-
getDisplayName
Provides the display name for this configuration section in the "Configure System" page.- Overrides:
getDisplayName
in classDescriptor<GlobalConfiguration>
- Returns:
- The internationalized display name.
-
getInstance
Provides global access to the single instance of this configuration.- Returns:
- The singleton instance of
BitwardenConfig
.
-
getServerUrl
-
getApiCredentialId
-
getMasterPasswordCredentialId
-
getCliExecutablePath
-
getCacheDuration
public int getCacheDuration() -
getFileCredentialSuffixes
-
setServerUrl
-
setApiCredentialId
-
setMasterPasswordCredentialId
-
setCliExecutablePath
-
setCacheDuration
@DataBoundSetter public void setCacheDuration(int cacheDuration) -
setFileCredentialSuffixes
-
isConfigured
public boolean isConfigured()A helper method to check if the essential configuration (API key and master password) is present.- Returns:
true
if the plugin is configured with the minimum required credentials.
-
configure
public boolean configure(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject json) throws Descriptor.FormException The entry point for Jenkins when a user saves the global configuration from the UI. It binds the form data to this object's fields and then callssave()
.By calling
save()
, we create a single, unified hook that ensures changes made by both users (via this method) and by JCasC are handled consistently.- Overrides:
configure
in classGlobalConfiguration
- Parameters:
req
- The current web request.json
- The JSON object representing the form data for this configuration section.- Returns:
true
to indicate success.- Throws:
Descriptor.FormException
- if the form data cannot be processed.
-
save
public void save()The unified hook for all configuration changes, called by both the UI (viaconfigure(org.kohsuke.stapler.StaplerRequest2, net.sf.json.JSONObject)
) and JCasC.This method performs a "dirty check" to see if any critical settings have actually changed. If they have, it triggers a background task to re-authenticate and refresh the credential cache.
- Specified by:
save
in interfaceSaveable
- Overrides:
save
in classDescriptor<GlobalConfiguration>
-
doFillApiCredentialIdItems
@POST public ListBoxModel doFillApiCredentialIdItems(@AncestorInPath Jenkins context, @QueryParameter String apiCredentialId) Populates the "Bitwarden API Key Credential" dropdown in the UI.This method is called by Stapler.
- Parameters:
context
- The current Jenkins context.apiCredentialId
- The ID of the currently selected credential.- Returns:
- A
ListBoxModel
containing suitable credentials.
-
doFillMasterPasswordCredentialIdItems
@POST public ListBoxModel doFillMasterPasswordCredentialIdItems(@AncestorInPath Jenkins context, @QueryParameter String masterPasswordCredentialId) Populates the "Bitwarden Master Password Credential" dropdown in the UI.This method is called by Stapler.
- Parameters:
context
- The current Jenkins context.masterPasswordCredentialId
- The ID of the currently selected credential.- Returns:
- A
ListBoxModel
containing suitable credentials.
-
doRefreshCache
An action method for the "Refresh Now" button in the UI.This method is called by Stapler.
Forces a re-authentication and triggers a non-destructive background refresh of the cache.
- Returns:
- A
FormValidation
object indicating the action has started.
-
doCheckCliVersion
An action method for the "Check Version" button in the UI.This method is called by Stapler.
- Returns:
- A
FormValidation
object showing the installed CLI version or an error.
-
doForceUpdateCli
An action method for the "Download Latest" button in the UI.This method is called by Stapler.
- Returns:
- A
FormValidation
object indicating the result of the download attempt.
-
doVerifySession
An action method for the "Verify Session" button in the UI.This method is called by Stapler. It performs a fast, read-only check to see if the
BitwardenSessionManager
currently holds a valid, unlocked session token.- Returns:
- A
FormValidation
object indicating if the current session is active or not.
-