mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
* feat(configurations): Review UI/UX configurations * feat(configurations): fix binary secret value * fix(frontend): populate data between simple and advanced modes (#4503) * fix(configuration): parseYaml before create configuration * fix(configurations): change c to C in ConfigurationOwner * fix(application): change configuration index to configuration key in the view * fix(configuration): resolve problem in application create with configuration not overriden. * fix(configuration): fix bad import in helper Co-authored-by: Simon Meng <simon.meng@portainer.io>
71 lines
2.3 KiB
JavaScript
71 lines
2.3 KiB
JavaScript
import { KubernetesConfigurationTypes } from 'Kubernetes/models/configuration/models';
|
|
import { KubernetesConfigurationFormValuesEntry } from 'Kubernetes/models/configuration/formvalues';
|
|
import _ from 'lodash-es';
|
|
import YAML from 'yaml';
|
|
|
|
class KubernetesConfigurationHelper {
|
|
static getUsingApplications(config, applications) {
|
|
return _.filter(applications, (app) => {
|
|
let envFind;
|
|
let volumeFind;
|
|
if (config.Type === KubernetesConfigurationTypes.CONFIGMAP) {
|
|
envFind = _.find(app.Env, { valueFrom: { configMapKeyRef: { name: config.Name } } });
|
|
volumeFind = _.find(app.Volumes, { configMap: { name: config.Name } });
|
|
} else {
|
|
envFind = _.find(app.Env, { valueFrom: { secretKeyRef: { name: config.Name } } });
|
|
volumeFind = _.find(app.Volumes, { secret: { secretName: config.Name } });
|
|
}
|
|
return envFind || volumeFind;
|
|
});
|
|
}
|
|
|
|
static isSystemToken(config) {
|
|
return _.startsWith(config.Name, 'default-token-');
|
|
}
|
|
|
|
static isBinary(encoding) {
|
|
return encoding !== '' && !_.includes(encoding, 'ISO') && !_.includes(encoding, 'UTF');
|
|
}
|
|
|
|
static setConfigurationUsed(config) {
|
|
config.Used = config.Applications && config.Applications.length !== 0;
|
|
}
|
|
|
|
static setConfigurationsUsed(configurations, applications) {
|
|
_.forEach(configurations, (config) => {
|
|
config.Applications = KubernetesConfigurationHelper.getUsingApplications(config, applications);
|
|
KubernetesConfigurationHelper.setConfigurationUsed(config);
|
|
});
|
|
}
|
|
|
|
static parseYaml(formValues) {
|
|
YAML.defaultOptions.customTags = ['binary'];
|
|
const data = _.map(YAML.parse(formValues.DataYaml), (value, key) => {
|
|
const entry = new KubernetesConfigurationFormValuesEntry();
|
|
entry.Key = key;
|
|
entry.Value = value;
|
|
const oldEntry = _.find(formValues.Data, { Key: entry.Key });
|
|
entry.IsBinary = oldEntry ? oldEntry.IsBinary : false;
|
|
return entry;
|
|
});
|
|
return data;
|
|
}
|
|
|
|
static parseData(formValues) {
|
|
const data = _.reduce(
|
|
formValues.Data,
|
|
(acc, entry) => {
|
|
acc[entry.Key] = entry.Value;
|
|
return acc;
|
|
},
|
|
{}
|
|
);
|
|
return YAML.stringify(data);
|
|
}
|
|
|
|
static isExternalConfiguration(configuration) {
|
|
return !configuration.ConfigurationOwner;
|
|
}
|
|
}
|
|
|
|
export default KubernetesConfigurationHelper;
|