Skip to content

Commit dd956c2

Browse files
feat: generate credentials for Java Kafka client (#1783)
1 parent 731d530 commit dd956c2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

pkg/cmd/serviceaccount/svcaccountcmdutil/credentials/credentials.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
)
1414

1515
const (
16-
EnvFormat = "env"
17-
JSONFormat = "json"
18-
PropertiesFormat = "properties"
19-
SecretFormat = "secret"
16+
EnvFormat = "env"
17+
JSONFormat = "json"
18+
PropertiesFormat = "properties"
19+
SecretFormat = "secret"
20+
JavaPropertiesFormat = "java-kafka-properties"
2021
)
2122

2223
// Templates
@@ -28,6 +29,20 @@ var (
2829
rhoas.service-account.oauthTokenUrl=%v
2930
`)
3031

32+
templateJavaProperties = heredoc.Doc(`
33+
## Generated by rhoas cli
34+
sasl.mechanism=OAUTHBEARER
35+
security.protocol=SASL_SSL
36+
37+
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
38+
clientId="%v" \
39+
clientSecret="%v" ;
40+
41+
sasl.oauthbearer.token.endpoint.url=%v
42+
43+
sasl.login.callback.handler.class=org.apache.kafka.common.security.oauthbearer.secured.OAuthBearerLoginCallbackHandler
44+
`)
45+
3146
templateEnv = heredoc.Doc(`
3247
## Generated by rhoas cli
3348
RHOAS_SERVICE_ACCOUNT_CLIENT_ID=%v
@@ -68,7 +83,7 @@ func GetDefaultPath(outputFormat string) (filePath string) {
6883
switch outputFormat {
6984
case EnvFormat:
7085
filePath = ".env"
71-
case PropertiesFormat:
86+
case PropertiesFormat, JavaPropertiesFormat:
7287
filePath = "credentials.properties"
7388
case JSONFormat:
7489
filePath = "credentials.json"
@@ -111,6 +126,8 @@ func getFileFormat(output string) (format string) {
111126
format = templateJSON
112127
case SecretFormat:
113128
format = templateSecret
129+
case JavaPropertiesFormat:
130+
format = templateJavaProperties
114131
}
115132

116133
return format

pkg/cmd/serviceaccount/svcaccountcmdutil/svcaccount_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import (
55
)
66

77
var (
8-
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat}
8+
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat, credentials.JavaPropertiesFormat}
99
)

0 commit comments

Comments
 (0)