Class R2SettingsValidator
- Namespace
- Cloudflare.NET.R2.Configuration
- Assembly
- Cloudflare.NET.R2.dll
Validates R2Settings to ensure all required configuration is present and valid. This validator
is invoked at startup when using ValidateOnStart(), providing immediate feedback for configuration issues
rather than waiting for the first API call to fail.
public class R2SettingsValidator : IValidateOptions<R2Settings>
- Inheritance
-
R2SettingsValidator
- Implements
- Inherited Members
Remarks
This validator checks that the R2 S3 credentials (AccessKeyId and SecretAccessKey) are provided. It also validates that the EndpointUrl, if customized, contains the required '{0}' placeholder for the Account ID.
The validation errors are designed to be clear and actionable, mentioning "Cloudflare R2" explicitly so developers can quickly identify the source of configuration issues.
For validation of CloudflareApiOptions (AccountId), use CloudflareApiOptionsValidator with ForR2.
When registered as IValidateOptions<TOptions>, this validator skips named options by default. The R2ClientFactory should use ValidateConfiguration(string?, R2Settings) directly for explicit validation with CloudflareR2ConfigurationException.
Constructors
R2SettingsValidator()
Initializes a new instance of the R2SettingsValidator class with default skip behavior for named options.
public R2SettingsValidator()
R2SettingsValidator(bool)
Initializes a new instance of the R2SettingsValidator class with explicit skip behavior control.
public R2SettingsValidator(bool skipNamedOptions)
Parameters
skipNamedOptionsboolIf true, the validator returns Skip for named options (non-default names). Set to false when performing explicit validation in the factory.
Methods
Validate(string?, R2Settings)
Validates a specific named options instance (or all when name is null).
public ValidateOptionsResult Validate(string? name, R2Settings options)
Parameters
namestringThe name of the options instance being validated.
optionsR2SettingsThe options instance.
Returns
- ValidateOptionsResult
The ValidateOptionsResult result.
ValidateConfiguration(string?, R2Settings)
Validates the specified R2Settings and returns a result with error messages. This method is intended for use by the R2ClientFactory to perform explicit validation with proper error messages that include the client name.
public static ValidateOptionsResult ValidateConfiguration(string? name, R2Settings options)
Parameters
namestringThe options name. For named clients, this should be the client name to include in error messages. For default clients, pass null or DefaultName.
optionsR2SettingsThe R2 settings to validate.
Returns
- ValidateOptionsResult
A ValidateOptionsResult indicating success or failure with error messages.