Skip to content

Commit

Permalink
feat: generate credentials for Java Kafka client (#1783)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkpattnaik780 authored Nov 15, 2022
1 parent 731d530 commit dd956c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import (
)

const (
EnvFormat = "env"
JSONFormat = "json"
PropertiesFormat = "properties"
SecretFormat = "secret"
EnvFormat = "env"
JSONFormat = "json"
PropertiesFormat = "properties"
SecretFormat = "secret"
JavaPropertiesFormat = "java-kafka-properties"
)

// Templates
Expand All @@ -28,6 +29,20 @@ var (
rhoas.service-account.oauthTokenUrl=%v
`)

templateJavaProperties = heredoc.Doc(`
## Generated by rhoas cli
sasl.mechanism=OAUTHBEARER
security.protocol=SASL_SSL
sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required \
clientId="%v" \
clientSecret="%v" ;
sasl.oauthbearer.token.endpoint.url=%v
sasl.login.callback.handler.class=org.apache.kafka.common.security.oauthbearer.secured.OAuthBearerLoginCallbackHandler
`)

templateEnv = heredoc.Doc(`
## Generated by rhoas cli
RHOAS_SERVICE_ACCOUNT_CLIENT_ID=%v
Expand Down Expand Up @@ -68,7 +83,7 @@ func GetDefaultPath(outputFormat string) (filePath string) {
switch outputFormat {
case EnvFormat:
filePath = ".env"
case PropertiesFormat:
case PropertiesFormat, JavaPropertiesFormat:
filePath = "credentials.properties"
case JSONFormat:
filePath = "credentials.json"
Expand Down Expand Up @@ -111,6 +126,8 @@ func getFileFormat(output string) (format string) {
format = templateJSON
case SecretFormat:
format = templateSecret
case JavaPropertiesFormat:
format = templateJavaProperties
}

return format
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import (
)

var (
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat}
CredentialsOutputFormats = []string{credentials.EnvFormat, credentials.JSONFormat, credentials.PropertiesFormat, credentials.SecretFormat, credentials.JavaPropertiesFormat}
)

0 comments on commit dd956c2

Please sign in to comment.