getJaasConfig.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import { isUndefined } from 'lodash';
  2. const JAAS_CONFIGS = {
  3. 'SASL/GSSAPI': 'com.sun.security.auth.module.Krb5LoginModule',
  4. 'SASL/OAUTHBEARER':
  5. 'org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule',
  6. 'SASL/PLAIN': 'org.apache.kafka.common.security.plain.PlainLoginModule',
  7. 'SASL/SCRAM-256': 'org.apache.kafka.common.security.scram.ScramLoginModule',
  8. 'SASL/SCRAM-512': 'org.apache.kafka.common.security.scram.ScramLoginModule',
  9. 'Delegation tokens':
  10. 'org.apache.kafka.common.security.scram.ScramLoginModule',
  11. 'SASL/LDAP': 'org.apache.kafka.common.security.plain.PlainLoginModule',
  12. 'SASL/AWS IAM': 'software.amazon.msk.auth.iam.IAMLoginModule',
  13. };
  14. type MethodName = keyof typeof JAAS_CONFIGS;
  15. export const getJaasConfig = (
  16. method: MethodName,
  17. options: Record<string, string>
  18. ) => {
  19. const optionsString = Object.entries(options)
  20. .map(([key, value]) => {
  21. if (isUndefined(value)) return null;
  22. if (value === 'true' || value === 'false') {
  23. return ` ${key}=${value}`;
  24. }
  25. return ` ${key}="${value}"`;
  26. })
  27. .join('');
  28. return `${JAAS_CONFIGS[method]} required${optionsString};`;
  29. };