I'll create a README for a Netlify provider for StackQL, following the same structure as the previous examples.
netlify provider for stackql
This repository is used to generate and document the netlify provider for StackQL, allowing you to query and manipulate Netlify resources using SQL-like syntax. The provider is built using the @stackql/provider-utils package, which provides tools for converting OpenAPI specifications into StackQL-compatible provider schemas.
To use the Netlify provider with StackQL, you'll need:
- A Netlify account with appropriate API credentials
- Netlify personal access token with sufficient permissions for the resources you want to access
- StackQL CLI installed on your system (see StackQL)
First, download the Netlify API OpenAPI specification:
rm -rf provider-dev/downloaded/*
curl -L https://open-api.netlify.com/swagger.json \
-o provider-dev/downloaded/openapi.jsonNext, split the monolithic OpenAPI specification into service-specific files:
rm -rf provider-dev/source/*
npm run split -- \
--provider-name netlify \
--api-doc provider-dev/downloaded/openapi.json \
--svc-discriminator path \
--output-dir provider-dev/source \
--overwrite \
--svc-name-overrides "$(cat <<EOF
{
"sites": "sites",
"deploys": "deploys",
"builds": "builds",
"functions": "functions",
"dns": "dns",
"forms": "forms",
"hooks": "hooks",
"submissions": "forms",
"files": "files",
"accounts": "accounts",
"users": "users",
"teams": "teams",
"members": "teams",
"plugins": "plugins",
"services": "services",
"service_instances": "services",
"split_tests": "split_tests",
"snippets": "snippets",
"ssl": "ssl",
"assets": "assets",
"domains": "domains"
}
EOF
)"Generate the mapping configuration that connects OpenAPI operations to StackQL resources:
npm run generate-mappings -- \
--provider-name netlify \
--input-dir provider-dev/source \
--output-dir provider-dev/configUpdate the resultant provider-dev/config/all_services.csv to add the stackql_resource_name, stackql_method_name, stackql_verb values for each operation.
This step transforms the split OpenAPI service specs into a fully-functional StackQL provider by applying the resource and method mappings defined in your CSV file.
rm -rf provider-dev/openapi/*
npm run generate-provider -- \
--provider-name netlify \
--input-dir provider-dev/source \
--output-dir provider-dev/openapi/src/netlify \
--config-path provider-dev/config/all_services.csv \
--servers '[{"url": "https://api.netlify.com/api/v1"}]' \
--provider-config '{"auth": { "type": "bearer", "credentialsenvvar": "NETLIFY_ACCESS_TOKEN" }}' \
--overwritesh provider-dev/scripts/fix_broken_links.shBefore running tests, start a StackQL server with your provider:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
npm run start-server -- --provider netlify --registry $PROVIDER_REGISTRY_ROOT_DIRTest all metadata routes (services, resources, methods) in the provider:
npm run test-meta-routes -- netlify --verboseWhen you're done testing, stop the StackQL server:
npm run stop-serverUse this command to view the server status:
npm run server-statusRun some test queries against the provider using the stackql shell:
PROVIDER_REGISTRY_ROOT_DIR="$(pwd)/provider-dev/openapi"
REG_STR='{"url": "file://'${PROVIDER_REGISTRY_ROOT_DIR}'", "localDocRoot": "'${PROVIDER_REGISTRY_ROOT_DIR}'", "verifyConfig": {"nopVerify": true}}'
./stackql shell --registry="${REG_STR}"Example queries to try:
-- List all sites
SELECT
id,
name,
url,
ssl_url,
admin_url,
screenshot_url,
created_at,
updated_at
FROM netlify.sites.list;
-- View recent deploys
SELECT
id,
site_id,
name,
url,
state,
branch,
commit_ref,
created_at,
published_at
FROM netlify.deploys.list
WHERE site_id = 'your-site-id';
-- Check DNS records
SELECT
hostname,
type,
ttl,
value
FROM netlify.dns.list
WHERE zone_id = 'your-zone-id';
-- List functions
SELECT
name,
function_name,
runtime,
url
FROM netlify.functions.list
WHERE site_id = 'your-site-id';
-- View form submissions
SELECT
id,
form_id,
site_id,
created_at,
data
FROM netlify.forms.submissions
WHERE form_id = 'your-form-id';To publish the provider push the netlify dir to providers/src in a feature branch of the stackql-provider-registry. Follow the registry release flow.
Launch the StackQL shell:
export DEV_REG="{ \"url\": \"https://registry-dev.stackql.app/providers\" }"
./stackql --registry="${DEV_REG}" shellPull the latest dev netlify provider:
registry pull netlify;Run some test queries to verify the provider works as expected.
Provider doc microsites are built using Docusaurus and published using GitHub Pages.
a. Update headerContent1.txt and headerContent2.txt accordingly in provider-dev/docgen/provider-data/
b. Update the following in website/docusaurus.config.js:
// Provider configuration - change these for different providers
const providerName = "netlify";
const providerTitle = "Netlify Provider";c. Then generate docs using...
npm run generate-docs -- \
--provider-name netlify \
--provider-dir ./provider-dev/openapi/src/netlify/v00.00.00000 \
--output-dir ./website \
--provider-data-dir ./provider-dev/docgen/provider-datacd website
# test build
yarn build
# run local dev server
yarn startUnder Pages in the repository, in the Build and deployment section select GitHub Actions as the Source. In Netlify DNS create the following records:
| Source Domain | Record Type | Target |
|---|---|---|
| netlify-provider.stackql.io | CNAME | stackql.github.io. |
MIT
Contributions are welcome! Please feel free to submit a Pull Request.