Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
- uses: actions/checkout@v2
with:
submodules: true
- name: libsecret-1-dev
run: |
sudo apt install -y libsecret-1-dev
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v0.0.1-preview
Expand Down
49 changes: 43 additions & 6 deletions api/GetMessage/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,52 @@
const { DefaultAzureCredential } = require("@azure/identity");
const { DnsManagementClient } = require("@azure/arm-dns");

module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');

//const name = (req.query.name || (req.body && req.body.name));
//const responseMessage = name
//? "Hello, " + name + ". This HTTP triggered function executed successfully."
//: "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";
let outputText = 'Hi! -The API';

// when deployed to an azure host the default azure credential will authenticate the specified user assigned managed identity
const credential = new DefaultAzureCredential();
const dnsClient = new DnsManagementClient(credential, process.env["AZURE_SUBSCRIPTION_ID"]);

const recordTypes = ["A", "NS", "CNAME"];

let dnsMappings = [];
try {
for (const recordType of recordTypes) {
const results = await dnsClient.recordSets.listByType(process.env["AZURE_RESOURCE_GROUP"], process.env["AZURE_DNS_ZONE"], recordType)
.then(result => {
context.log(result);
return result;
})
.catch(err => {
context.error(err);
throw err;
});

for (const result of results) {
dnsMappings.push({
name: result.name,
fqdn: result.fqdn,
});
}
}
} catch (err) {
outputText += err;
}

if (dnsMappings.length > 0) {
outputText = '';

for (const dnsMapping of dnsMappings) {
outputText += ` | <a href="${dnsMapping.fqdn}" target="_blank">${dnsMapping.name}</a>`;
}
}

context.res = {
// status: 200, /* Defaults to 200 */
body: {
text: "Hi, from the API!" //responseMessage
text: outputText
}
};
}
Loading