@@ -41,6 +41,107 @@ def strategy
41
41
end
42
42
end
43
43
44
+ # TlsConfig provides configuration for TLS connections to Flipt servers
45
+ class TlsConfig
46
+ attr_reader :ca_cert_file , :ca_cert_data , :insecure_skip_verify ,
47
+ :client_cert_file , :client_key_file , :client_cert_data , :client_key_data
48
+
49
+ # Initialize TLS configuration
50
+ #
51
+ # @param ca_cert_file [String, nil] Path to CA certificate file (PEM format)
52
+ # @param ca_cert_data [String, nil] Raw CA certificate content (PEM format)
53
+ # @param insecure_skip_verify [Boolean, nil] Skip certificate verification (development only)
54
+ # @param client_cert_file [String, nil] Path to client certificate file (PEM format)
55
+ # @param client_key_file [String, nil] Path to client key file (PEM format)
56
+ # @param client_cert_data [String, nil] Raw client certificate content (PEM format)
57
+ # @param client_key_data [String, nil] Raw client key content (PEM format)
58
+ def initialize ( ca_cert_file : nil , ca_cert_data : nil , insecure_skip_verify : nil ,
59
+ client_cert_file : nil , client_key_file : nil ,
60
+ client_cert_data : nil , client_key_data : nil )
61
+ @ca_cert_file = ca_cert_file
62
+ @ca_cert_data = ca_cert_data
63
+ @insecure_skip_verify = insecure_skip_verify
64
+ @client_cert_file = client_cert_file
65
+ @client_key_file = client_key_file
66
+ @client_cert_data = client_cert_data
67
+ @client_key_data = client_key_data
68
+
69
+ validate_files!
70
+ end
71
+
72
+ # Create TLS config for insecure connections (development only)
73
+ # WARNING: Only use this in development environments
74
+ #
75
+ # @return [TlsConfig] TLS config with certificate verification disabled
76
+ def self . insecure
77
+ new ( insecure_skip_verify : true )
78
+ end
79
+
80
+ # Create TLS config with CA certificate file
81
+ #
82
+ # @param ca_cert_file [String] Path to CA certificate file
83
+ # @return [TlsConfig] TLS config with custom CA certificate
84
+ def self . with_ca_cert_file ( ca_cert_file )
85
+ new ( ca_cert_file : ca_cert_file )
86
+ end
87
+
88
+ # Create TLS config with CA certificate data
89
+ #
90
+ # @param ca_cert_data [String] CA certificate content in PEM format
91
+ # @return [TlsConfig] TLS config with custom CA certificate
92
+ def self . with_ca_cert_data ( ca_cert_data )
93
+ new ( ca_cert_data : ca_cert_data )
94
+ end
95
+
96
+ # Create TLS config for mutual TLS with certificate files
97
+ #
98
+ # @param client_cert_file [String] Path to client certificate file
99
+ # @param client_key_file [String] Path to client key file
100
+ # @return [TlsConfig] TLS config with mutual TLS
101
+ def self . with_mutual_tls ( client_cert_file , client_key_file )
102
+ new ( client_cert_file : client_cert_file , client_key_file : client_key_file )
103
+ end
104
+
105
+ # Create TLS config for mutual TLS with certificate data
106
+ #
107
+ # @param client_cert_data [String] Client certificate content in PEM format
108
+ # @param client_key_data [String] Client key content in PEM format
109
+ # @return [TlsConfig] TLS config with mutual TLS
110
+ def self . with_mutual_tls_data ( client_cert_data , client_key_data )
111
+ new ( client_cert_data : client_cert_data , client_key_data : client_key_data )
112
+ end
113
+
114
+ # Convert to hash for JSON serialization
115
+ # @return [Hash] TLS configuration as hash
116
+ def to_h
117
+ hash = { }
118
+ hash [ :ca_cert_file ] = @ca_cert_file if @ca_cert_file
119
+ hash [ :ca_cert_data ] = @ca_cert_data if @ca_cert_data
120
+ hash [ :insecure_skip_verify ] = @insecure_skip_verify unless @insecure_skip_verify . nil?
121
+ hash [ :client_cert_file ] = @client_cert_file if @client_cert_file
122
+ hash [ :client_key_file ] = @client_key_file if @client_key_file
123
+ hash [ :client_cert_data ] = @client_cert_data if @client_cert_data
124
+ hash [ :client_key_data ] = @client_key_data if @client_key_data
125
+ hash
126
+ end
127
+
128
+ private
129
+
130
+ def validate_files!
131
+ validate_file_exists ( @ca_cert_file , 'CA certificate file' ) if @ca_cert_file
132
+ validate_file_exists ( @client_cert_file , 'Client certificate file' ) if @client_cert_file
133
+ validate_file_exists ( @client_key_file , 'Client key file' ) if @client_key_file
134
+ end
135
+
136
+ def validate_file_exists ( file_path , description )
137
+ return if file_path . nil? || file_path . strip . empty?
138
+
139
+ return if File . exist? ( file_path )
140
+
141
+ raise ValidationError , "#{ description } does not exist: #{ file_path } "
142
+ end
143
+ end
144
+
44
145
# VariantEvaluationResponse
45
146
# @attr_reader [String] flag_key
46
147
# @attr_reader [Boolean] match
0 commit comments