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 <[email protected]>
  • Loading branch information
stokito committed Dec 26, 2024
1 parent 2da1efb commit 7d1052d
Showing 1 changed file with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -529,43 +529,60 @@ 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 = _writeDnsProviderField;
return o;
}

function _writeDnsProviderField(section_id, value) {
let creds = this.map.data.get('acme', section_id, 'credentials');
let credsMap = _parseKeyValueListToMap(creds);
let optName = this.option.substring('_credentials_'.length);
credsMap.set(optName, value);
let newCreds = [];
for (let [key, val] of credsMap) {
newCreds.push(key + '="' + val + '"');
}
this.map.data.set('acme', section_id, 'credentials', 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 7d1052d

Please sign in to comment.