use of org.eclipse.jkube.kit.config.resource.SecretConfig in project jkube by eclipse.
the class SecretEnricher method addSecretsFromXmlConfiguration.
private void addSecretsFromXmlConfiguration(KubernetesListBuilder builder) {
log.verbose("Adding secrets resources from plugin configuration");
List<SecretConfig> secrets = getSecretsFromXmlConfig();
Map<String, Integer> secretToIndexMap = new HashMap<>();
if (secrets == null || secrets.isEmpty()) {
return;
}
for (Integer index = 0; index < builder.buildItems().size(); index++) {
if (builder.buildItems().get(index) instanceof Secret) {
secretToIndexMap.put(builder.buildItems().get(index).getMetadata().getName(), index);
}
}
for (int i = 0; i < secrets.size(); i++) {
SecretConfig secretConfig = secrets.get(i);
if (StringUtils.isBlank(secretConfig.getName())) {
log.warn("Secret name is empty. You should provide a proper name for the secret");
continue;
}
Map<String, String> data = new HashMap<>();
String type = "";
ObjectMeta metadata = new ObjectMetaBuilder().withNamespace(secretConfig.getNamespace()).withName(secretConfig.getName()).build();
// docker-registry
if (secretConfig.getDockerServerId() != null) {
JKubeEnricherContext mavenContext = ((JKubeEnricherContext) getContext());
String dockerSecret = (mavenContext).getDockerJsonConfigString(mavenContext.getSettings(), secretConfig.getDockerServerId());
if (StringUtils.isBlank(dockerSecret)) {
log.warn("Docker secret with id " + secretConfig.getDockerServerId() + " cannot be found in maven settings");
continue;
}
data.put(SecretConstants.DOCKER_DATA_KEY, Base64Util.encodeToString(dockerSecret));
type = SecretConstants.DOCKER_CONFIG_TYPE;
}
if (StringUtils.isBlank(type) || data.isEmpty()) {
log.warn("No data can be found for docker secret with id " + secretConfig.getDockerServerId());
continue;
}
Secret secret = new SecretBuilder().withData(data).withMetadata(metadata).withType(type).build();
if (!secretToIndexMap.containsKey(secretConfig.getName())) {
builder.addToSecretItems(i, secret);
}
}
}
Aggregations