Skip to content

Commit 50579f9

Browse files
committed
added mising docs and modify TlsConfig method
1 parent 19f4879 commit 50579f9

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

docs/modules/cassandra.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,23 @@ In the case you have a custom config file for Cassandra, it's possible to copy t
7070
!!!warning
7171
You should provide a valid Cassandra configuration file, otherwise the container will fail to start.
7272

73+
#### WithTLS
74+
75+
- Not available until the next release <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a>
76+
77+
If you need to enable TLS/SSL encryption for client connections, you can use the `cassandra.WithTLS()` option.
78+
79+
When enabled, the container will:
80+
- Generate self-signed certificates automatically
81+
- Configure Cassandra to use client encryption
82+
- Expose the SSL port (9142)
83+
84+
Use the `TLSConfig()` method on the returned container to get the `*tls.Config` for client connections. The method returns an error if TLS was not enabled via `WithTLS()`.
85+
86+
<!--codeinclude-->
87+
[Using TLS option](../../modules/cassandra/cassandra_test.go) inside_block:withTLS
88+
<!--/codeinclude-->
89+
7390
{% include "../features/common_functional_options_list.md" %}
7491

7592
### Container Methods

modules/cassandra/cassandra.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/tls"
77
_ "embed"
8+
"errors"
89
"fmt"
910
"io"
1011
"path/filepath"
@@ -38,9 +39,12 @@ func (c *CassandraContainer) ConnectionHost(ctx context.Context) (string, error)
3839
}
3940

4041
// TLSConfig returns the TLS configuration for secure client connections.
41-
// Returns nil if TLS is not enabled on the container.
42-
func (c *CassandraContainer) TLSConfig() *tls.Config {
43-
return c.settings.tlsConfig
42+
// Returns an error if TLS is not enabled on the container.
43+
func (c *CassandraContainer) TLSConfig() (*tls.Config, error) {
44+
if !c.settings.tlsEnabled {
45+
return nil, errors.New("TLS is not enabled on this container")
46+
}
47+
return c.settings.tlsConfig, nil
4448
}
4549

4650
// WithConfigFile sets the YAML config file to be used for the cassandra container

modules/cassandra/cassandra_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ func TestCassandraWithTLS(t *testing.T) {
128128
require.NoError(t, err)
129129

130130
// Verify TLS config is available
131-
tlsConfig := ctr.TLSConfig()
131+
tlsConfig, err := ctr.TLSConfig()
132+
require.NoError(t, err)
132133
require.NotNil(t, tlsConfig, "TLSConfig should not be nil when TLS is enabled")
133134

134135
// Get SSL connection host

modules/cassandra/examples_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ func ExampleRun_withTLS() {
103103
}
104104

105105
// Get TLS config for secure connection
106-
tlsConfig := cassandraContainer.TLSConfig()
106+
tlsConfig, err := cassandraContainer.TLSConfig()
107+
if err != nil {
108+
log.Printf("failed to get TLS config: %s", err)
109+
return
110+
}
107111
// }
108112

109113
cluster := gocql.NewCluster(connectionHost)

0 commit comments

Comments
 (0)