Quick Start
The easiest way to perform API integration is to script using the REST API (although it should be noted that the REST API is not officially supported).
Authentication during integration
Service accounts are commonly used for authentication in automated environments. See the “Service Accounts and Service Account Keys” section for more information on service accounts.
The following creates a service account for automation, generates an API key
for the REST API, and assigns the services/iam.edgelq.com/roles/scope-admin
role.
## Create service account "automation".
cuttle iam create service-account --project $PROJECT automation
## Generate API key for the above service account
cuttle iam create service-account-key \
--parent projects/$PROJECT/regions/eu1/serviceAccounts/automation \
--algorithm API_KEY api_key
## Assign the scope-admin role to the above service account
cuttle iam create role-binding \
--project $PROJECT \
--member "serviceAccount:automation@$PROJECT.eu1.serviceaccounts.iam.edgelq.com" \
--role "services/iam.edgelq.com/roles/scope-admin"
Authentication with the REST API is done using Authorization
in the HTTP
header. Set the API key generated above as the Bearer
token.
Sample Scripts
The following are sample scripts that implement each of the simplest requests on Node JS.
const fetch = require('node-fetch');
const apiKey = "<API_KEY>";
const projectName = "<PROJECT_NAME>";
const regionName = "eu1"
const baseDomain = "apis.edgelq.com"
// callAPI sends a request to the REST endpoint with the API key.
const callAPI = async (method, url, body) => {
const parsed = new URL(url);
// Set the API key to the Authorization header.
const authHeaders = {"Authorization": `Bearer ${apiKey}`}
return await fetch(url, {method: method, body: body, headers: authHeaders}); }
};
(async () => {
// To get a resource, simply issue a GET request to a fully qualified resource name.
// Ex. Get the Project
const iamGetProject = await callAPI("GET", `https://iam.${baseDomain}/v1alpha2/projects/${projectName}`, null);
console.log(`Get Project: ${await iamGetProject.text()}\n`);
// To list resources, issue a GET request to the resource name
// Ex. List Probes (a.k.a. Probes) under the project
const watchdogListProbes = await callAPI("GET", `https://watchdog.${baseDomain}/v1alpha2/projects/${projectName}/regions/${regionName}/ probes`, null);
console.log(`List Probes: ${await watchdogListProbes.text()}\n`);
// To add filters to the list request, append `filter=<expression>` to the parameter (with escaping)
// Ex. List Probes whose spec.enabled field is enalbed
const watchdogListProbesWithFilter = await callAPI("GET", `https://watchdog.${baseDomain}/v1alpha2/projects/${projectName}/regions/${regionName}/${? regionName}/probes?filter=${encodeURIComponent(`spec.enabled=true`)}`, null);
console.log(`List Probes With Filter: ${await watchdogListProbesWithFilter.text()}\n`);
// To create a resource, issue a POST request.
// Ex. Create a new ProbingTarget
const watchdogCreateTargetNTT = await callAPI("POST", `https://watchdog.${baseDomain}/v1alpha2/projects/${projectName}/probingTargets`, JSON.stringify({
"name": `projects/${projectName}/probingTargets/ntt`,.
"display_name": "NTT", "address": "", "name": "", "address".
"address": "www.global.ntt", // "mode": 1, // IC
"mode": 1, // ICMP
}));
console.log(`Create ProbingTarget: ${await watchdogCreateTargetNTT.text()}\n`);
// To update a resource, issue a PUT request to a fully qualified resource name.
// To avoid unexpected overwriting with empty values, use update-mask to specify fields to be updated by the request.
// Ex. Update the addresses of the ProbingTarget
const watchdogUpdateTargetNTT = await callAPI("PUT", `https://watchdog.${baseDomain}/v1alpha2/projects/${projectName}/probingTargets/ ntt?updateMask=${encodeURIComponent(`address`)}`, JSON.stringify({
"address": "group.ntt",.
})));
console.log(`Update ProbingTarget: ${await watchdogUpdateTargetNTT.text()}\n`);
// To delete a resource, issue a DELETE request to a fully qualified resource name.
// To avoid unexpected overwriting with empty values, use update-mask to specify fields to be updated by the request.
// Ex. Update the addresses of the ProbingTarget
const watchdogDeleteTargetNTT = await callAPI("DELETE", `https://watchdog.${baseDomain}/v1alpha2/projects/${projectName}/probingTargets /ntt`, null);
console.log(`Delete ProbingTarget: ${await watchdogDeleteTargetNTT.text()}\n`);
})();
To obtain SEI metrics information from the Monitoring service, please refer to the following code (Body portion only).
(async () => {
// for resource.type, run `cuttle monitoring list monitored-resource-descriptors`
// for metric.type, run `cuttle monitoring list metric-descriptors`
// https://github.com/cloudwan/edgelq-sdk/blob/febf9a9011ef643cad7fffa583cff78eadeb0c98/monitoring/proto/v4/common.proto
const query=`https://monitoring.${baseDomain}/v4/projects/${projectName}/timeSeries?filter=${encodeURIComponent(`resource.type=" watchdog.edgelq.com/probe" AND metric.type="watchdog.edgelq.com/probe/session/latency"`)}&aggregation.alignmentPeriod=60s& aggregation.crossSeriesReducer=REDUCE_NONE&aggregation.perSeriesAligner=ALIGN_MEAN&interval.startTime=${encodeURIComponent("2023- 05-24T00:00:00Z")}&interval.endTime=${encodeURIComponent("2023-05-25T00:00:00Z")}`
const monitoringListTimeSeries = await callAPI("GET", query, null);
console.log(`Query Result: ${await monitoringListTimeSeries.text()}\n`);
})();