From 5d2a3ae6b31a32dca5672a113eb7ad28a42f92b5 Mon Sep 17 00:00:00 2001 From: Karen Bradshaw Date: Fri, 3 Jul 2020 15:57:00 -0400 Subject: [PATCH] updating packaging --- functions-src/deploy-succeeded.js | 77 ------------------------------- package.json | 7 +-- postcss.config.js | 21 +++++++++ 3 files changed, 22 insertions(+), 83 deletions(-) delete mode 100644 functions-src/deploy-succeeded.js create mode 100644 postcss.config.js diff --git a/functions-src/deploy-succeeded.js b/functions-src/deploy-succeeded.js deleted file mode 100644 index afe5c7e593..0000000000 --- a/functions-src/deploy-succeeded.js +++ /dev/null @@ -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(); -} diff --git a/package.json b/package.json index 139221f29f..f96c7422c8 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/postcss.config.js b/postcss.config.js new file mode 100644 index 0000000000..ad6eb708f9 --- /dev/null +++ b/postcss.config.js @@ -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: {} + }, +}