11package redpanda
22
33import (
4+ "fmt"
45 "net"
56 "strconv"
67
@@ -84,7 +85,7 @@ func defaultOptions() options {
8485var _ testcontainers.ContainerCustomizer = (Option )(nil )
8586
8687// Option is an option for the Redpanda container.
87- type Option func (* options )
88+ type Option func (* options ) error
8889
8990// Customize is a NOOP. It's defined to satisfy the testcontainers.ContainerCustomizer interface.
9091func (o Option ) Customize (* testcontainers.GenericContainerRequest ) error {
@@ -96,16 +97,18 @@ func (o Option) Customize(*testcontainers.GenericContainerRequest) error {
9697// that shall be created, so that you can use these to authenticate against
9798// Redpanda (either for the Kafka API or Schema Registry HTTP access).
9899func WithNewServiceAccount (username , password string ) Option {
99- return func (o * options ) {
100+ return func (o * options ) error {
100101 o .ServiceAccounts [username ] = password
102+ return nil
101103 }
102104}
103105
104106// WithSuperusers defines the superusers added to the redpanda config.
105107// By default, there are no superusers.
106108func WithSuperusers (superusers ... string ) Option {
107- return func (o * options ) {
109+ return func (o * options ) error {
108110 o .Superusers = superusers
111+ return nil
109112 }
110113}
111114
@@ -114,31 +117,35 @@ func WithSuperusers(superusers ...string) Option {
114117// When setting an authentication method, make sure to add users
115118// as well as authorize them using the WithSuperusers() option.
116119func WithEnableSASL () Option {
117- return func (o * options ) {
120+ return func (o * options ) error {
118121 o .KafkaAuthenticationMethod = "sasl"
122+ return nil
119123 }
120124}
121125
122126// WithEnableKafkaAuthorization enables authorization for connections on the Kafka API.
123127func WithEnableKafkaAuthorization () Option {
124- return func (o * options ) {
128+ return func (o * options ) error {
125129 o .KafkaEnableAuthorization = true
130+ return nil
126131 }
127132}
128133
129134// WithEnableWasmTransform enables wasm transform.
130135// Should not be used with RP versions before 23.3
131136func WithEnableWasmTransform () Option {
132- return func (o * options ) {
137+ return func (o * options ) error {
133138 o .EnableWasmTransform = true
139+ return nil
134140 }
135141}
136142
137143// WithEnableSchemaRegistryHTTPBasicAuth enables HTTP basic authentication for
138144// Schema Registry.
139145func WithEnableSchemaRegistryHTTPBasicAuth () Option {
140- return func (o * options ) {
146+ return func (o * options ) error {
141147 o .SchemaRegistryAuthenticationMethod = "http_basic"
148+ return nil
142149 }
143150}
144151
@@ -147,29 +154,33 @@ func WithEnableSchemaRegistryHTTPBasicAuth() Option {
147154func WithHTTPProxyAuthMethod (method HTTPProxyAuthMethod ) Option {
148155 switch method {
149156 case HTTPProxyAuthMethodNone , HTTPProxyAuthMethodHTTPBasic , HTTPProxyAuthMethodOIDC :
150- return func (o * options ) {
157+ return func (o * options ) error {
151158 o .HTTPProxyAuthenticationMethod = method
159+ return nil
152160 }
153161 default :
154- return func (o * options ) {
162+ return func (o * options ) error {
155163 // Invalid method, default to "none"
156164 o .HTTPProxyAuthenticationMethod = HTTPProxyAuthMethodNone
165+ return nil
157166 }
158167 }
159168}
160169
161170// WithAutoCreateTopics enables topic auto creation.
162171func WithAutoCreateTopics () Option {
163- return func (o * options ) {
172+ return func (o * options ) error {
164173 o .AutoCreateTopics = true
174+ return nil
165175 }
166176}
167177
168178func WithTLS (cert , key []byte ) Option {
169- return func (o * options ) {
179+ return func (o * options ) error {
170180 o .EnableTLS = true
171181 o .cert = cert
172182 o .key = key
183+ return nil
173184 }
174185}
175186
@@ -178,22 +189,23 @@ func WithTLS(cert, key []byte) Option {
178189// networks. At least one network must be attached to the container, if not an
179190// error will be thrown when starting the container.
180191func WithListener (lis string ) Option {
181- host , port , err := net .SplitHostPort (lis )
182- if err != nil {
183- return func (_ * options ) {}
184- }
192+ return func (o * options ) error {
193+ host , port , err := net .SplitHostPort (lis )
194+ if err != nil {
195+ return fmt .Errorf ("split host port: %w" , err )
196+ }
185197
186- portInt , err := strconv .Atoi (port )
187- if err != nil {
188- return func ( _ * options ) {}
189- }
198+ portInt , err := strconv .Atoi (port )
199+ if err != nil {
200+ return fmt . Errorf ( "parse port: %w" , err )
201+ }
190202
191- return func (o * options ) {
192203 o .Listeners = append (o .Listeners , listener {
193204 Address : host ,
194205 Port : portInt ,
195206 AuthenticationMethod : o .KafkaAuthenticationMethod ,
196207 })
208+ return nil
197209 }
198210}
199211
@@ -202,16 +214,18 @@ func WithListener(lis string) Option {
202214// config file, which is particularly useful for configs requiring a restart
203215// when otherwise applied to a running Redpanda instance.
204216func WithBootstrapConfig (cfg string , val any ) Option {
205- return func (o * options ) {
217+ return func (o * options ) error {
206218 o .ExtraBootstrapConfig [cfg ] = val
219+ return nil
207220 }
208221}
209222
210223// WithAdminAPIAuthentication enables Admin API Authentication.
211224// It sets `admin_api_require_auth` configuration to true and configures a bootstrap user account.
212225// See https://docs.redpanda.com/current/deploy/deployment-option/self-hosted/manual/production/production-deployment/#bootstrap-a-user-account
213226func WithAdminAPIAuthentication () Option {
214- return func (o * options ) {
227+ return func (o * options ) error {
215228 o .enableAdminAPIAuthentication = true
229+ return nil
216230 }
217231}
0 commit comments