Skip to content

Commit 40f13a5

Browse files
committed
Add support for "unique_client_id"
1 parent 981ea0f commit 40f13a5

File tree

3 files changed

+74
-31
lines changed

3 files changed

+74
-31
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ jobs:
2424
organization: ${{ secrets.CLOUDFLARE_ACCESS_ORGANIZATION }}
2525
auth_client_id: ${{ secrets.CLOUDFLARE_ACCESS_CLIENT_ID }}
2626
auth_client_secret: ${{ secrets.CLOUDFLARE_ACCESS_CLIENT_SECRET }}
27+
unique_client_id: 1a9472c0-ada8-42d1-888b-c5b0750a42f0
2728
configure_docker_dns: true
2829
- run: curl -I https://www.google.com

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ inputs:
1515
configure_docker_dns:
1616
description: 'Configure Docker to use Cloudflare WARP for DNS resolution'
1717
default: 'false'
18+
unique_client_id:
19+
description: 'A unique identifier for the client device'
20+
required: false
1821
runs:
1922
using: 'node20'
2023
main: 'dist/index.js'

lib/setup-cloudflare-warp.js

Lines changed: 70 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ const backoffOptions = {
99
maxDelay: 4000,
1010
};
1111

12+
function jsonToXml(config) {
13+
let xml = '';
14+
15+
for (const [key, value] of Object.entries(config)) {
16+
// Skip null, undefined values and empty strings
17+
if (value === undefined || value === null || value === '') continue;
18+
19+
if (typeof value === 'boolean') {
20+
xml += `<key>${key}</key>\n<${value} />\n`;
21+
} else if (typeof value === 'number') {
22+
xml += `<key>${key}</key>\n<integer>${value}</integer>\n`;
23+
} else if (typeof value === 'string') {
24+
xml += `<key>${key}</key>\n<string>${value}</string>\n`;
25+
}
26+
}
27+
28+
return xml;
29+
}
30+
1231
async function installLinuxClient(version) {
1332
const gpgKeyPath = await tc.downloadTool(
1433
"https://pkg.cloudflareclient.com/pubkey.gpg",
@@ -50,17 +69,22 @@ async function writeLinuxConfiguration(
5069
organization,
5170
auth_client_id,
5271
auth_client_secret,
72+
unique_client_id,
5373
) {
74+
const configObj = {
75+
organization,
76+
auth_client_id,
77+
auth_client_secret,
78+
unique_client_id
79+
};
80+
81+
const xmlContent = jsonToXml(configObj);
5482
const config = `
55-
<dict>
56-
<key>organization</key>
57-
<string>${organization}</string>
58-
<key>auth_client_id</key>
59-
<string>${auth_client_id}</string>
60-
<key>auth_client_secret</key>
61-
<string>${auth_client_secret}</string>
62-
</dict>
83+
<dict>
84+
${xmlContent}
85+
</dict>
6386
`;
87+
6488
await exec.exec("sudo mkdir -p /var/lib/cloudflare-warp/");
6589
fs.writeFileSync("/tmp/mdm.xml", config);
6690
await exec.exec("sudo mv /tmp/mdm.xml /var/lib/cloudflare-warp/");
@@ -70,27 +94,29 @@ async function writeMacOSConfiguration(
7094
organization,
7195
auth_client_id,
7296
auth_client_secret,
97+
unique_client_id,
7398
) {
99+
const configObj = {
100+
enable: true,
101+
organization,
102+
auth_client_id,
103+
auth_client_secret,
104+
unique_client_id,
105+
service_mode: "warp",
106+
auto_connect: 1
107+
};
108+
109+
const xmlContent = jsonToXml(configObj);
74110
const config = `
75111
<?xml version="1.0" encoding="UTF-8"?>
76112
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
77113
<plist version="1.0">
78-
<dict>
79-
<key>enable</key>
80-
<true />
81-
<key>organization</key>
82-
<string>${organization}</string>
83-
<key>auth_client_id</key>
84-
<string>${auth_client_id}</string>
85-
<key>auth_client_secret</key>
86-
<string>${auth_client_secret}</string>
87-
<key>service_mode</key>
88-
<string>warp</string>
89-
<key>auto_connect</key>
90-
<integer>1</integer>
114+
<dict>
115+
${xmlContent}
91116
</dict>
92-
</plist>
117+
</plist>
93118
`;
119+
94120
await exec.exec('sudo mkdir -p "/Library/Managed Preferences/"');
95121
fs.writeFileSync("/tmp/com.cloudflare.warp.plist", config);
96122
await exec.exec("plutil -convert binary1 /tmp/com.cloudflare.warp.plist");
@@ -103,18 +129,25 @@ async function writeWindowsConfiguration(
103129
organization,
104130
auth_client_id,
105131
auth_client_secret,
132+
unique_client_id,
106133
) {
134+
const configObj = {
135+
organization,
136+
auth_client_id,
137+
auth_client_secret,
138+
unique_client_id
139+
};
140+
141+
const xmlContent = jsonToXml(configObj);
107142
const config = `
108-
<dict>
109-
<key>organization</key>
110-
<string>${organization}</string>
111-
<key>auth_client_id</key>
112-
<string>${auth_client_id}</string>
113-
<key>auth_client_secret</key>
114-
<string>${auth_client_secret}</string>
115-
</dict>`;
116-
if (!fs.existsSync("C:\\ProgramData\\Cloudflare"))
143+
<dict>
144+
${xmlContent}
145+
</dict>
146+
`;
147+
148+
if (!fs.existsSync("C:\\ProgramData\\Cloudflare")) {
117149
fs.mkdirSync("C:\\ProgramData\\Cloudflare");
150+
}
118151
fs.writeFileSync("C:\\ProgramData\\Cloudflare\\mdm.xml", config);
119152
}
120153

@@ -191,6 +224,9 @@ export async function run() {
191224
const auth_client_secret = core.getInput("auth_client_secret", {
192225
required: true,
193226
});
227+
const unique_client_id = core.getInput("unique_client_id", {
228+
required: false
229+
});
194230
const configure_docker_dns = core.getBooleanInput("configure_docker_dns", {
195231
required: false,
196232
});
@@ -204,6 +240,7 @@ export async function run() {
204240
organization,
205241
auth_client_id,
206242
auth_client_secret,
243+
unique_client_id,
207244
);
208245
await installLinuxClient(version);
209246
break;
@@ -212,6 +249,7 @@ export async function run() {
212249
organization,
213250
auth_client_id,
214251
auth_client_secret,
252+
unique_client_id,
215253
);
216254
await installMacOSClient(version);
217255
break;
@@ -220,6 +258,7 @@ export async function run() {
220258
organization,
221259
auth_client_id,
222260
auth_client_secret,
261+
unique_client_id,
223262
);
224263
await installWindowsClient(version);
225264
break;

0 commit comments

Comments
 (0)