Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Intermittently coding

Beth Skurrie bethesque

💭
Intermittently coding
View GitHub Profile
@bethesque
bethesque / authorizer.js
Created Feb 25, 2020
API Gateway custom auth
View authorizer.js
const accountId = process.env.ACCOUNT_ID;
const region = process.env.REGION;
const basicAuthUsername = process.env.BASIC_AUTH_USERNAME;
const basicAuthPassword = process.env.BASIC_AUTH_PASSWORD;
const validateAuth = authorizationHeader => {
if (!authorizationHeader) return false;
const encodedCreds = authorizationHeader.split(" ")[1];
const plainCreds = new Buffer(encodedCreds, "base64").toString().split(":");
@bethesque
bethesque / dynamic-left-outer-join.rb
Last active Dec 20, 2019
Trying to achieve a dynamically filtered left outer join AND eager loading
View dynamic-left-outer-join.rb
require 'spec_helper'
require 'sequel'
DATABASE = Sequel::Model.db
DATABASE.drop_table(:orders) rescue nil
DATABASE.drop_table(:order_lines) rescue nil
DATABASE.drop_table(:customers) rescue nil
DATABASE.create_table(:customers) do
@bethesque
bethesque / test.rb
Last active Aug 14, 2019
synchronous message
View test.rb
some_provider.given("a thing", "foo" => "bar")
.and("another thing", "blah" => "blah")
.upon_receiving("some message")
.with(
contents: {"the" => "contents"},
metadata: {"some" => "info"})
.will_respond_with(
contents: {"the" => "response"},
metadata: {"some" => "other info"}
)
@bethesque
bethesque / index.md
Last active Jul 31, 2019
Using pact with providers that have their own providers
View index.md

Eg. A -> B -> C

A more find grained view of this intergration might go:

|------------------A Codebase------------------||------------------B Codebase------------------||--------C Codebase---...
 A UI -> A Controller -> B Service -> B Client -> B API -> B Controller -> CService -> CClient -> C API etc...  
                                           |---A/B pact------------------------?
                                           |---A/B pact------------------------------------?
@bethesque
bethesque / bethtest.rb
Last active Jan 9, 2018
Making a request to a server with a self signed certificate
View bethtest.rb
require 'openssl'
require 'uri'
require 'net/http'
uri = URI('https://self-signed.badssl.com')
downloaded_cert_path = '/tmp/downloaded_cert.pem'
puts `openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -text`
command = "openssl s_client -showcerts -servername #{uri.host} -connect #{uri.host}:#{uri.port} </dev/null 2>/dev/null|openssl x509 -outform PEM > #{downloaded_cert_path}"
puts command
@bethesque
bethesque / caveats.txt
Last active May 5, 2017
Moderately dirty hack to order pact versions by date instead of version in the pact broker
View caveats.txt
This will sort based on the date that the consumer application version resource is created.
If the pact for that version is updated, the sorting will not consider the date of the updated content.
@bethesque
bethesque / a.md
Last active Dec 18, 2015
Ruby pact libraries
View a.md

https://github.com/realestate-com-au/pact - rpsec specific stuff, top level, executables https://github.com/bethesque/pact-mock_service - standalone, used by javascript, starts up service, listens, writes pact, verification https://github.com/bethesque/pact-support - matching logic, domain objects https://github.com/bethesque/pact-support/blob/master/spec/pact_specification/compliance-2.0.rb - pact specification test, people might want version 3 soonish.

https://github.com/bethesque/pact-mock-service-npm - standalone package using travelling ruby https://github.com/bethesque/pact-mock_service/blob/master/tasks/package.rake - this is the task that builds the packages

https://github.com/DiUS/pact-consumer-js-dsl - the javascript DSL that wraps the ruby or standalone mock server.

@bethesque
bethesque / a.md
Last active Nov 30, 2015
DelegatedProperty - flattening model hierarchy - don't expose your model relationships in your form
View a.md

This allows you do something like:

User = Struct.new(:address)
Address = Struct.new(:street, :suburb)

class UserForm < Reform::Form

  property :address do
    property :street
@bethesque
bethesque / authorise.rb
Created Sep 14, 2015
How we currently authorise our Trailblazer operations (pre policy support)
View authorise.rb
class Thing::Create < Trailblazer::Operation
def process(params)
validate(params[:referral]) do
authorize(params, model, :create?)
form.save
end
end
def setup_model!(params)
@bethesque
bethesque / reverse_proxy.rb
Created Jul 8, 2015
Debug pact-provider-proxy
View reverse_proxy.rb
# pact-provider-proxy/vendor/rack-reverse-proxy/lib/rack/reverse_proxy.rb
require 'net/http'
require 'net/https'
require "rack-proxy"
require "rack/reverse_proxy_matcher"
require "rack/exception"
module Rack
class ReverseProxy
You can’t perform that action at this time.