@@ -17,7 +17,14 @@ const (
17
17
dummyProjectID = "111111111111111111111111"
18
18
instanceName = "InstanceName"
19
19
authMechanism = "PLAIN"
20
+ authMechanismOAuth = "OAUTHBEARER"
20
21
authUsername = "user1"
22
+ clientId = "auth0Client"
23
+ clientSecret = "secret"
24
+ tokenEndpointUrl = "https://your-domain.com/oauth2/token"
25
+ scope = "read:messages write:messages"
26
+ saslOauthbearerExtentions = "logicalCluster=cluster-kmo17m,identityPoolId=pool-l7Arl"
27
+ httpsCaPem = "MHWER3343"
21
28
securityProtocol = "SASL_SSL"
22
29
bootstrapServers = "localhost:9092,another.host:9092"
23
30
dbRole = "customRole"
@@ -50,6 +57,7 @@ type sdkToTFModelTestCase struct {
50
57
51
58
func TestStreamConnectionSDKToTFModel (t * testing.T ) {
52
59
var authConfigWithPasswordDefined = tfAuthenticationObject (t , authMechanism , authUsername , "raw password" )
60
+ var authConfigWithOAuth = tfAuthenticationObjectForOAuth (t , authMechanismOAuth , clientId , clientSecret , tokenEndpointUrl , scope , saslOauthbearerExtentions , httpsCaPem )
53
61
54
62
testCases := []sdkToTFModelTestCase {
55
63
{
@@ -146,6 +154,44 @@ func TestStreamConnectionSDKToTFModel(t *testing.T) {
146
154
Headers : types .MapNull (types .StringType ),
147
155
},
148
156
},
157
+ {
158
+ name : "Kafka connection type SDK response for OAuthBearer authentication" ,
159
+ SDKResp : & admin.StreamsConnection {
160
+ Name : admin .PtrString (connectionName ),
161
+ Type : admin .PtrString ("Kafka" ),
162
+ Authentication : & admin.StreamsKafkaAuthentication {
163
+ Mechanism : admin .PtrString (authMechanismOAuth ),
164
+ ClientId : admin .PtrString (clientId ),
165
+ TokenEndpointUrl : admin .PtrString (tokenEndpointUrl ),
166
+ Scope : admin .PtrString (scope ),
167
+ SaslOauthbearerExtensions : admin .PtrString (saslOauthbearerExtentions ),
168
+ HttpsCaPem : admin .PtrString (httpsCaPem ),
169
+ },
170
+ BootstrapServers : admin .PtrString (bootstrapServers ),
171
+ Config : & configMap ,
172
+ Security : & admin.StreamsKafkaSecurity {
173
+ Protocol : admin .PtrString (securityProtocol ),
174
+ BrokerPublicCertificate : admin .PtrString (DummyCACert ),
175
+ },
176
+ },
177
+ providedProjID : dummyProjectID ,
178
+ providedInstanceName : instanceName ,
179
+ providedAuthConfig : & authConfigWithOAuth ,
180
+ expectedTFModel : & streamconnection.TFStreamConnectionModel {
181
+ ProjectID : types .StringValue (dummyProjectID ),
182
+ InstanceName : types .StringValue (instanceName ),
183
+ ConnectionName : types .StringValue (connectionName ),
184
+ Type : types .StringValue ("Kafka" ),
185
+ Authentication : tfAuthenticationObjectForOAuth (t , authMechanismOAuth , clientId , clientSecret , tokenEndpointUrl , scope , saslOauthbearerExtentions , httpsCaPem ), // password value is obtained from config, not api resp.
186
+ BootstrapServers : types .StringValue (bootstrapServers ),
187
+ Config : tfConfigMap (t , configMap ),
188
+ Security : tfSecurityObject (t , DummyCACert , securityProtocol ),
189
+ DBRoleToExecute : types .ObjectNull (streamconnection .DBRoleToExecuteObjectType .AttrTypes ),
190
+ Networking : types .ObjectNull (streamconnection .NetworkingObjectType .AttrTypes ),
191
+ AWS : types .ObjectNull (streamconnection .AWSObjectType .AttrTypes ),
192
+ Headers : types .MapNull (types .StringType ),
193
+ },
194
+ },
149
195
{
150
196
name : "Kafka connection type SDK response with no optional values provided" ,
151
197
SDKResp : & admin.StreamsConnection {
@@ -596,6 +642,23 @@ func tfAuthenticationObject(t *testing.T, mechanism, username, password string)
596
642
return auth
597
643
}
598
644
645
+ func tfAuthenticationObjectForOAuth (t * testing.T , mechanism , clientId , clientSecret , tokenEndpointUrl , scope , saslOauthbearerExtensions , httpsCaPem string ) types.Object {
646
+ t .Helper ()
647
+ auth , diags := types .ObjectValueFrom (t .Context (), streamconnection .ConnectionAuthenticationObjectType .AttrTypes , streamconnection.TFConnectionAuthenticationModel {
648
+ Mechanism : types .StringValue (mechanism ),
649
+ ClientId : types .StringValue (clientId ),
650
+ ClientSecret : types .StringValue (clientSecret ),
651
+ TokenEndpointUrl : types .StringValue (tokenEndpointUrl ),
652
+ Scope : types .StringValue (scope ),
653
+ SaslOauthbearerExtensions : types .StringValue (saslOauthbearerExtensions ),
654
+ HttpsCaPem : types .StringValue (httpsCaPem ),
655
+ })
656
+ if diags .HasError () {
657
+ t .Errorf ("failed to create terraform data model: %s" , diags .Errors ()[0 ].Summary ())
658
+ }
659
+ return auth
660
+ }
661
+
599
662
func tfAuthenticationObjectWithNoPassword (t * testing.T , mechanism , username string ) types.Object {
600
663
t .Helper ()
601
664
auth , diags := types .ObjectValueFrom (t .Context (), streamconnection .ConnectionAuthenticationObjectType .AttrTypes , streamconnection.TFConnectionAuthenticationModel {
0 commit comments