updating packaging

pull/22306/head
Karen Bradshaw 2020-07-03 15:57:00 -04:00
parent 12c5ce2d5a
commit 5d2a3ae6b3
3 changed files with 22 additions and 83 deletions

View File

@ -1,77 +0,0 @@
"use strict";
const
{ IncomingWebhook } = require('@slack/client'),
kubernetesSiteRoot = 'https://kubernetes.io',
fetch = require('node-fetch').default,
{ SLACK_WEBHOOK_URL } = process.env;
const webhook = new IncomingWebhook(SLACK_WEBHOOK_URL);
// A random smattering of Kubernetes documentation pages
// We can add as many pages here as we'd like
const kubernetesEndpoints = [
'docs/home',
'docs/tutorials/configuration/configure-redis-using-configmap',
]
// Ensure that the SLACK_WEBHOOK_URL environment variable is set
const checkEnv = () => {
if (!SLACK_WEBHOOK_URL) {
return {
statusCode: 422,
body: "[FAILURE] The Slack webhook URL must be set via the SLACK_WEBHOOK_URL environment variable"
}
}
}
// This function posts a warning message to Slack
const sendSlackMessage = (msg) => {
const slackMessageObject = {
username: "noindex checker",
text: msg
}
// Send the message to the webhook
webhook.send(slackMessageObject, (err, res) => {
return (err) ? { statusCode: 422, body: `[ERROR] Slack webhook error: ${err}` } :
{ statusCode: 200, body: `[SUCCESS] Response received from Slack: ${JSON.stringify(res)}` };
});
}
// Iterate through each Kubernetes endpoint to check for noindex headers
const checkEndpoints = () => {
kubernetesEndpoints.forEach((endpoint) => {
const url = `${kubernetesSiteRoot}/${endpoint}`;
fetch(url)
.then(res => {
const headers = res.headers;
if ('x-robots-tag' in headers.raw() && (headers.get('x-robots-tag') == 'noindex')) {
const msg = `[WARNING] "X-Robots-Tag: noindex" header found on the following page: ${url}`;
// Send Slack notification
sendSlackMessage(msg);
return { statusCode: 404, body: msg };
} else {
const msg = `[SUCCESS] No improper X-Robots-Tag: noindex headers found on ${url}`;
return { statusCode: 200, body: msg };
}
})
.catch(err => {
return { statusCode: 422, body: err };
});
});
}
// The handler function
exports.handler = async (event, context) => {
checkEnv();
// Below are the various deploy succeeded checks
checkEndpoints();
}

View File

@ -1,12 +1,7 @@
{
"private": true,
"devDependencies": {
"@babel/core": "^7.0.1",
"@slack/client": "^4.4.0",
"autoprefixer": "^9.7.6",
"babel-loader": "^8.0.2",
"netlify-lambda": "^0.4.0",
"node-fetch": "^2.2.0",
"autoprefixer": "^9.8.4",
"postcss-cli": "^7.1.1"
}
}

21
postcss.config.js Normal file
View File

@ -0,0 +1,21 @@
/*
Copyright 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
module.exports = {
plugins: {
autoprefixer: {}
},
}