Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Freeland afreeland

View GitHub Profile
@afreeland
afreeland / WebhookVerification.js
Created Aug 6, 2020
Chargify webhook verification middleware
View WebhookVerification.js
app.use("/chargify", (req, res, next) => {
// This request header contains the signature of the hmac sha 256 of the sites secret with the raw body of the request
const webhookSignature =
req.headers["x-chargify-webhook-signature-hmac-sha-256"];
try {
// Your secret shared site key that you got from Chargify earlier
// This is a SECRET and should be stored/retrieved in a safe manner, not source control (Kube Secret, etc.,)
const sharedKey = "b65ca1b9a6eaea838b7c536ca0ca5fe634214b5d";
// The first step is to create a sha256 of our shared site key
const hmac = crypto.createHmac("sha256", sharedKey);
@afreeland
afreeland / middleware.js
Last active Aug 7, 2020
Webhook middleware (Chargify)
View middleware.js
const app = express();
function rawBodySaver(req, res, buf, encoding) {
if (buf && buf.length) {
req.rawBody = buf.toString(encoding || "utf8");
}
}
// For parsing application/json
app.use(express.json());
// For parsing application/x-www-form-urlencoded (which is the Content-Type from Chargify)
@afreeland
afreeland / gist:7d85e483eb1795bb47af42f8a1115a4d
Last active Mar 13, 2019
Ingress TLS bare-metal Kubernetes
View gist:7d85e483eb1795bb47af42f8a1115a4d
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-connect-timeout: "21600000"
nginx.ingress.kubernetes.io/proxy-read-timeout: "21600000"
nginx.ingress.kubernetes.io/proxy-send-timeout: "21600000"
nginx.ingress.kubernetes.io/rewrite-target: /
name: ds-ingress
namespace: default
@afreeland
afreeland / gist:ee525ba62bba605ad39088e667c13218
Created Oct 5, 2018
Ingress TLS secret Kubernetes bare-metal
View gist:ee525ba62bba605ad39088e667c13218
apiVersion: v1
kind: Secret
metadata:
name: our-tls
namespace: default
type: kubernetes.io/tls
data:
tls.crt: abcde
tls.key: 12345
@afreeland
afreeland / recentQuery.js
Created May 1, 2018
React: Proper declaring enum type
View recentQuery.js
import React, { Component } from 'react';
import { render } from 'react-dom';
const gql = require('graphql-tag');
import { graphql } from 'react-apollo';
import appRoot from 'app-root-path';
import store from '../../store.js';
const Recent_Query = gql(`
query recent_query($username: String! $type: recentTypess! ){
recent (username: $username type: $type){
View gist:0c26acb07558fd730f455f1df4de8300
import React, { Component } from 'react';
import { render } from 'react-dom';
const gql = require('graphql-tag');
import { graphql } from 'react-apollo';
import appRoot from 'app-root-path';
import store from '../../store.js';
const Recent_Query = gql(`
query recent_query($username: String! $type: String! ){
recent (username: $username type: $type){
@afreeland
afreeland / recent.js
Created May 1, 2018
React: Sample Component illustrating Apollo
View recent.js
import React, { Component } from 'react';
import { render } from 'react-dom';
import { ApolloClient, createNetworkInterface, ApolloProvider, graphql } from 'react-apollo';
import History_HOC from './history-hoc'
import appRoot from 'app-root-path';
import store from '../../store';
const config = require(`${appRoot}/config/config.js`);
let graphqlClient = require(appRoot + '/models/graphql-client.js');
export default class RecentHistory extends Component {
@afreeland
afreeland / recentEnum.js
Created May 1, 2018
GraphQL: Enum Sample
View recentEnum.js
import {
GraphQLEnumType,
} from 'graphql';
var recentTypes = new GraphQLEnumType({
name: 'recentTypess',
values: {
// The values are going to be used in the actual redis key itself
// i.e. analytics => recent:analytics:username
"Analytics" : { value: "analytics" },
@afreeland
afreeland / pod.yaml
Created May 1, 2018
k8s: Pod kubernetes bare metal storage
View pod.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
app: lettuce-redis
name: lettuce-redis-6684f999c4-kfdfr
namespace: default
ownerReferences:
- apiVersion: extensions/v1beta1
name: lettuce-redis-6684f999c4