Skip to content

Commit

Permalink
s4u#279 adding auth details for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Gozke authored Aug 3, 2024
1 parent 5a79602 commit b979ba0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ steps:
step:
- uses: s4u/maven-settings-action@v3.0.0
with:
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost"}]'
proxies: '[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol", "host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxUser", "password": "proxPassword"}]'
```
Note: Authentication details are optional.

## ```settings.xml``` with properties
```yml
Expand Down
11 changes: 9 additions & 2 deletions settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ function fillProxies(template) {
return;
}

JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts));
JSON.parse(proxies).forEach((proxy) => fillProxy(template, proxy.id, proxy.active, proxy.protocol, proxy.host, proxy.port, proxy.nonProxyHosts, proxy.user, proxy.password));
}

function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
function fillProxy(template, id, active, protocol, host, port, nonProxyHosts, proxyUser, proxyPassword) {
if(!id || !active || !protocol || !host || !port || !nonProxyHosts) {
core.setFailed('proxies must contain id, active, protocol, host, port and nonProxyHosts');
return;
Expand All @@ -230,6 +230,13 @@ function fillProxy(template, id, active, protocol, host, port, nonProxyHosts) {
proxyXml.getElementsByTagName("port")[0].textContent = port;
proxyXml.getElementsByTagName("nonProxyHosts")[0].textContent = nonProxyHosts;

if(proxyUser) {
jsonToXml(proxyXml, proxyXml.documentElement, {username: proxyUser});
}
if(proxyPassword) {
jsonToXml(proxyXml, proxyXml.documentElement, {password: proxyPassword});
}

const proxiesXml = template.getElementsByTagName('proxies')[0];
proxiesXml.appendChild(proxyXml);
}
Expand Down
20 changes: 20 additions & 0 deletions settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,26 @@ test("fillProxies one proxy", () => {

})

test("fillProxies one proxy with auth info", () => {
const xml = stringAsXml("<proxies/>");

process.env['INPUT_PROXIES'] = `[{"id": "proxyId", "active": "isActive", "protocol": "proxyProtocol",
"host": "proxyHost", "port": "proxyPort", "nonProxyHosts": "nonProxyHost", "user": "proxyUser", "password": "somepassword"}]`;

settings.fillProxies(xml);

const xmlStr = new XMLSerializer().serializeToString(xml);
expect(xmlStr).toBe(`<proxies><proxy>
<id>proxyId</id>
<active>isActive</active>
<protocol>proxyProtocol</protocol>
<host>proxyHost</host>
<port>proxyPort</port>
<nonProxyHosts>nonProxyHost</nonProxyHosts>
<username>proxyUser</username><password>somepassword</password></proxy></proxies>`)

})

test("fillProxies two proxies", () => {
const xml = stringAsXml("<proxies/>");

Expand Down

0 comments on commit b979ba0

Please sign in to comment.