Skip to content
This repository was archived by the owner on Jan 25, 2024. It is now read-only.

Commit f34c4d4

Browse files
committed
Remove unused code
1 parent a4048eb commit f34c4d4

File tree

1 file changed

+13
-80
lines changed

1 file changed

+13
-80
lines changed

AkamaiSample/main.js

Lines changed: 13 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ const getPublicKey = async (body, certificateManagerApiUrl) => {
5757
headers: {'Content-Type': 'application/json'},
5858
});
5959

60-
// eg.send(function(error, response, body) {
61-
// if (error) {
62-
// console.log(`Couldn't get TXT record "${recordName}" to zone ${zoneName}. Reason is: ${getErrorString(error)}`);
63-
// throw new Error(`Couldn't get TXT record "${recordName}" to zone ${zoneName}`);
64-
// }
65-
66-
// if (response.statusCode !== 201) {
67-
// console.log(`Couldn't get TXT record "${recordName}" to zone ${zoneName}. Reason is: status code ${response.statusCode} and body ${JSON.stringify(body)}`);
68-
// throw new Error(`Couldn't get TXT record "${recordName}" to zone ${zoneName}`);
69-
// }
70-
71-
// console.log(`Get TXT record "${recordName}" to zone ${zoneName} successfully.`);
72-
// });
73-
7460
let response;
7561
let ret;
7662
try {
@@ -123,20 +109,6 @@ const addTxtRecord = async (zoneName, payload, userInfo) => {
123109
body: data
124110
});
125111

126-
// eg.send(function(error, response, body) {
127-
// if (error) {
128-
// console.log(`Couldn't add TXT record "${recordName}" to zone ${zoneName}. Reason is: ${getErrorString(error)}`);
129-
// throw new Error(`Couldn't add TXT record "${recordName}" to zone ${zoneName}`);
130-
// }
131-
132-
// if (response.statusCode !== 201) {
133-
// console.log(`Couldn't add TXT record "${recordName}" to zone ${zoneName}. Reason is: status code ${response.statusCode} and body ${JSON.stringify(body)}`);
134-
// throw new Error(`Couldn't add TXT record "${recordName}" to zone ${zoneName}`);
135-
// }
136-
137-
// console.log(`TXT record "${recordName}" added to zone ${zoneName} successfully.`);
138-
// });
139-
140112
let response;
141113
try {
142114
response = await request(eg.request);
@@ -176,21 +148,6 @@ const removeTxtRecord = async (zoneName, payload, userInfo) => {
176148
body: {}
177149
});
178150

179-
// eg.send(function(error, response, body) {
180-
// throw new Error(`Couldn't delete TXT record "${recordName}" to zone ${zoneName}`);
181-
// if (error) {
182-
// console.log(`Couldn't delete TXT record "${recordName}" to zone ${zoneName}. Reason is: ${getErrorString(error)}`);
183-
// throw new Error(`Couldn't delete TXT record "${recordName}" to zone ${zoneName}`);
184-
// }
185-
186-
// if (response.statusCode !== 204 && response.statusCode !== 404) {
187-
// console.log(`Couldn't delete TXT record "${recordName}" to zone ${zoneName}. Reason is: status code ${response.statusCode} and body ${JSON.stringify(body)}`);
188-
// throw new Error(`Couldn't delete TXT record "${recordName}" to zone ${zoneName}`);
189-
// }
190-
191-
// console.log(`Delete TXT record "${recordName}" to zone ${zoneName} successfully.`);
192-
// });
193-
194151
let response;
195152
try {
196153
response = await request(eg.request);
@@ -254,47 +211,23 @@ const removeChallenge = async (payload, userInfo) => {
254211
*/
255212
const main = async (params)=> {
256213
console.log("Cloud function invoked.");
257-
// const params = {
258-
// host: "akab-b44g4bn7hhe422bf-tk2nbacgi42fu6fs.luna.akamaiapis.net",
259-
// event_type: "cert_domain_validation_required",
260-
// domain: "cdn-demo.com",
261-
// record_name: "text1.cdn-demo.com",
262-
// record_value: "text1",
263-
// client_secret: "096SIjUzu41XRD/JRKNzfw8uzrWlVn3P3zRzyQjemzw=",
264-
// access_token: "akab-uhgiaytcrvjao6mx-47lm5aqb3wygrje5",
265-
// client_token: "akab-lyqudahrqrw57kko-lfx4rm3yf3xw2au6"
266-
// }
267214

268215
try {
269216

270-
// const body = jwtDecode(params.data);
217+
const body = jwtDecode(params.data);
271218

272-
// // Validate that the notification was sent from a Certificate Manager instance that has allowed access
273-
// if (!params.allowedCertificateManagerCRNs || !params.allowedCertificateManagerCRNs[body.instance_crn]) {
274-
// console.error(`Certificate Manager instance ${body.instance_crn} is not allowed to invoke this action`);
275-
// return Promise.reject({
276-
// statusCode: 403,
277-
// headers: {'Content-Type': 'application/json'},
278-
// body: {message: 'Unauthorized'},
279-
// });
280-
// }
281-
// const certificateManagerApiUrl = `https://${params.cmRegion}.certificate-manager.cloud.ibm.com`;
282-
// const publicKey = await getPublicKey(body, certificateManagerApiUrl);
283-
// const decodedNotification = await jwtVerify(params.data, publicKey);
284-
const decodedNotification = {
285-
event_type: params.event_type,
286-
domain: params.domain,
287-
challenge: {
288-
txt_record_name: params.record_name,
289-
txt_record_val: params.record_value
290-
}
291-
};
292-
akamaiHost = params.host;
293-
const userInfo = {
294-
client_secret: params.client_secret,
295-
access_token: params.access_token,
296-
client_token: params.client_token
297-
};
219+
// Validate that the notification was sent from a Certificate Manager instance that has allowed access
220+
if (!params.allowedCertificateManagerCRNs || !params.allowedCertificateManagerCRNs[body.instance_crn]) {
221+
console.error(`Certificate Manager instance ${body.instance_crn} is not allowed to invoke this action`);
222+
return Promise.reject({
223+
statusCode: 403,
224+
headers: {'Content-Type': 'application/json'},
225+
body: {message: 'Unauthorized'},
226+
});
227+
}
228+
const certificateManagerApiUrl = `https://${params.cmRegion}.certificate-manager.cloud.ibm.com`;
229+
const publicKey = await getPublicKey(body, certificateManagerApiUrl);
230+
const decodedNotification = await jwtVerify(params.data, publicKey);
298231

299232
console.log(`Notification message body: ${JSON.stringify(decodedNotification)}`);
300233
switch (decodedNotification.event_type) {

0 commit comments

Comments
 (0)