Skip to content

Commit

Permalink
luci-app-acme: DNS API store all params
Browse files Browse the repository at this point in the history
Previously only one DNS API field was stored.
Get the current creds list, alter it and save.
Fix #7504

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
  • Loading branch information
stokito committed Dec 29, 2024
1 parent 6404f3a commit c5d330f
Showing 1 changed file with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,43 +529,67 @@ return view.extend({


function _addDnsProviderField(s, provider, env, title, desc) {
let o = s.taboption('challenge_dns', form.Value, '_' + env, _(title),
let o = s.taboption('challenge_dns', form.Value, '_credentials_' + env, _(title),
_(desc));
o.depends('dns', provider);
o.modalonly = true;
o.cfgvalue = function (section_id, stored_val) {
var creds = this.map.data.get(this.map.config, section_id, 'credentials');
return _extractParamValue(creds, env);
};
o.write = function (section_id, value) {
this.map.data.set('acme', section_id, 'credentials', [env + '="' + value + '"']);
};
o.write = function (section_id, value) { };
o.onchange = _handleEditChange;
return o;
}

function _handleEditChange(event, section_id, newVal) {
// Add the provider field value directly to the credentials DynList
let credentialsDynList = this.map.lookupOption('credentials', section_id)[0].getUIElement(section_id);
let creds = credentialsDynList.getValue();
let credsMap = _parseKeyValueListToMap(creds);
let optName = this.option.substring('_credentials_'.length);
if (newVal) {
credsMap.set(optName, newVal);
} else {
credsMap.delete(optName);
}
let newCreds = [];
for (let [key, val] of credsMap) {
newCreds.push(key + '="' + val + '"');
}
credentialsDynList.setValue(newCreds);
}

/**
* @param {string[]} paramsKeyVals
* @param {string} paramName
* @returns {string}
*/
function _extractParamValue(paramsKeyVals, paramName) {
let map = _parseKeyValueListToMap(paramsKeyVals)
return map.get(paramName) || '';
}

/**
* @param {string[]} paramsKeyVals
* @returns {Map}
*/
function _parseKeyValueListToMap(paramsKeyVals) {
let map = new Map();
if (!paramsKeyVals) {
return '';
return map;
}
for (let i = 0; i < paramsKeyVals.length; i++) {
var paramKeyVal = paramsKeyVals[i];
var parts = paramKeyVal.split('=');
if (parts.lenght < 2) {
for (let paramKeyVal of paramsKeyVals) {
let parts = paramKeyVal.split('=');
if (parts.length < 2) {
continue;
}
var name = parts[0];
var val = parts[1];
if (name == paramName) {
// unquote
return val.substring(0, val.length-1).substring(1);
}
let name = parts[0];
let val = parts[1];
let unquotedVal = val.substring(0, val.length - 1).substring(1);
map.set(name, unquotedVal);
}
return '';
return map;
}

function _handleCheckService(c, event, curVal, newVal) {
Expand Down

0 comments on commit c5d330f

Please sign in to comment.