KafkaUserModel { public Secret generateSecret() { if (authentication instanceof KafkaUserTlsClientAuthentication) { Map<String, String> data = new HashMap<>(5); data.put("ca.crt", caCert); data.put("user.key", userCertAndKey.keyAsBase64String()); data.put("user.crt", userCertAndKey.certAsBase64String()); data.put("user.p12", userCertAndKey.keyStoreAsBase64String()); data.put("user.password", userCertAndKey.storePasswordAsBase64String()); return createSecret(data); } else if (authentication instanceof KafkaUserScramSha512ClientAuthentication) { Map<String, String> data = new HashMap<>(1); data.put(KafkaUserModel.KEY_PASSWORD, Base64.getEncoder().encodeToString(scramSha512Password.getBytes(StandardCharsets.US_ASCII))); return createSecret(data); } else { return null; } } protected  KafkaUserModel(String namespace, String name, Labels labels); static KafkaUserModel fromCrd(CertManager certManager,
                                         PasswordGenerator passwordGenerator,
                                         KafkaUser kafkaUser,
                                         Secret clientsCaCert,
                                         Secret clientsCaKey,
                                         Secret userSecret); Secret generateSecret(); @SuppressWarnings("checkstyle:BooleanExpressionComplexity") void maybeGenerateCertificates(CertManager certManager, PasswordGenerator passwordGenerator,
                                          Secret clientsCaCertSecret, Secret clientsCaKeySecret,
                                          Secret userSecret, int validityDays, int renewalDays); void maybeGeneratePassword(PasswordGenerator generator, Secret userSecret); static String decodeUsername(String username); static String getTlsUserName(String username); static String getScramUserName(String username); String getUserName(); String getName(); static String getSecretName(String username); String getSecretName(); void setAuthentication(KafkaUserAuthentication authentication); void setQuotas(KafkaUserQuotas quotas); KafkaUserQuotas getQuotas(); Set<SimpleAclRule> getSimpleAclRules(); void setSimpleAclRules(List<AclRule> rules); boolean isTlsUser(); boolean isScramUser(); boolean isNoneUser(); static final String KEY_PASSWORD; static final String ENV_VAR_CLIENTS_CA_VALIDITY; static final String ENV_VAR_CLIENTS_CA_RENEWAL; static final String KAFKA_USER_OPERATOR_NAME; }
@Test public void testGenerateSecret() { KafkaUserModel model = KafkaUserModel.fromCrd(mockCertManager, passwordGenerator, tlsUser, clientsCaCert, clientsCaKey, null); Secret generatedSecret = model.generateSecret(); assertThat(generatedSecret.getData().keySet(), is(set("ca.crt", "user.crt", "user.key", "user.p12", "user.password"))); assertThat(generatedSecret.getMetadata().getName(), is(ResourceUtils.NAME)); assertThat(generatedSecret.getMetadata().getNamespace(), is(ResourceUtils.NAMESPACE)); assertThat(generatedSecret.getMetadata().getAnnotations(), is(emptyMap())); assertThat(generatedSecret.getMetadata().getLabels(), is(Labels.fromMap(ResourceUtils.LABELS) .withStrimziKind(KafkaUser.RESOURCE_KIND) .withKubernetesName(KafkaUserModel.KAFKA_USER_OPERATOR_NAME) .withKubernetesInstance(ResourceUtils.NAME) .withKubernetesPartOf(ResourceUtils.NAME) .withKubernetesManagedBy(KafkaUserModel.KAFKA_USER_OPERATOR_NAME) .toMap())); checkOwnerReference(model.createOwnerReference(), generatedSecret); }