This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @see https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-lambda-authorizer-output.html | |
*/ | |
const generatePolicy = (principalId, effect, resource, context) => ({ | |
context, | |
policyDocument: { | |
Version: '2012-10-17', | |
Statement: [ | |
{ | |
Action: 'execute-api:Invoke', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import jwkToPem from 'jwk-to-pem'; | |
// Simple in-memory cache, optional. In this Lambda it will always have a single promise stored because Region and User | |
// Pool ID are taken from the environment variables and remain unchanged within the life cycle of the Lambda, but I | |
// still kept this flexible in case someone will copy the code. Subject for improvement. | |
const getPemEncodedPublicKeysPromisesCache = new Map(); | |
const getPemEncodedPublicKeysImplementation = async (jwksUrl) => { | |
console.log('jwksUrl', jwksUrl); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { decode, verify } from 'jsonwebtoken'; | |
export const verifyToken = async (region, userPoolId, token) => { | |
var decodedJwt = decode(token, { complete: true }); | |
if (!decodedJwt || !decodedJwt.header || !decodedJwt.header.kid) { | |
return null; | |
} | |
const pemEncodedPublicKeys = await getPemEncodedPublicKeys(region, userPoolId); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defaultProvider } from '@aws-sdk/credential-provider-node'; | |
import { Hash } from '@aws-sdk/hash-node'; | |
import { HttpRequest } from '@aws-sdk/protocol-http'; | |
import { SignatureV4 } from '@aws-sdk/signature-v4'; | |
import { URL } from 'url'; | |
export const sign = async (region, url, query = {}, headers = {}) => { | |
const urlObject = new URL(url); | |
// Add query parameters passed as argument, if any. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[env:nodemcuv2] | |
platform = espressif8266 | |
board = nodemcuv2 | |
framework = arduino | |
monitor_filters = esp8266_exception_decoder | |
upload_protocol = espota | |
upload_port = connected-espresso-machine.local | |
lib_deps = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ArduinoOTA.h" | |
#include "EspressoMachine.h" | |
#include "WiFiManager.h" | |
#define SERIAL_BAUDRATE 9600 | |
#define WIFI_HOSTNAME "Connected-Espresso-Machine" | |
#define WIFI_ACCESS_POINT_SSID "Connected-Espresso-Machine" | |
#define OTA_UPDATES_HOSTNAME "connected-espresso-machine" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "ArduinoOTA.h" | |
// ... | |
#define OTA_UPDATES_HOSTNAME "connected-espresso-machine" | |
// ... | |
/** | |
* @see https://github.com/esp8266/Arduino/blob/master/libraries/ArduinoOTA/examples/BasicOTA/BasicOTA.ino |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "WiFiManager.h" | |
// ... | |
#define WIFI_HOSTNAME "Connected-Espresso-Machine" | |
#define WIFI_ACCESS_POINT_SSID "Connected-Espresso-Machine" | |
// ... | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BASE | |
FROM amazonlinux:2023.3.20231218.0 AS base | |
RUN yum -y install gzip tar zip | |
RUN touch ~/.bashrc | |
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash | |
RUN source ~/.bashrc && nvm install 18.9.0 | |
# BUILD | |
FROM base AS build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "EspressoMachine.h" | |
#define SERIAL_BAUDRATE 9600 | |
#define PUMP_RELAY_PIN D1 | |
#define BOILER_RELAY_PIN D2 | |
#define BOILER_IS_BOILING_PIN D5 | |
#define BOILER_IS_STEAM_PIN D6 | |
#define TOGGLE_PIN A0 | |
#define DONE_PIN D7 |
NewerOlder