ducky/subscriptions
8:61583c1d3886
Go to Latest
ducky/subscriptions/api/context_helpers.go
Create a listener that will create subscriptions.
We need a listener (as discussed in c4cfceb2f2fb) that will create a
Subscription whenever an auth.Profile is created. This is the beginning of that
effort. It hasn't been tested, and all the pieces aren't in place, but it's a
rough skeleton.
We have a Dockerfile that will correctly build a minimal container for the
listener.
We have a build-docker.sh script that will correctly build a binary that will be
used in the Dockerfile.
We have a ca-certificates.crt, which are pulled from Ubuntu, and are necessary
before we can safely consume SSL endpoints.
We created a small consumer script that listens for events off NSQ, and calls
the appropriate endpoint for our Subscriptions API. This is untested, and it
doesn't build at the moment, but that's awaiting changes in the
code.secondbit.org/auth.hg package.
Finally, we have a wrapper.sh file that will expose the Stripe secret key being
used from a Kubernetes secret file as an environment variable, instead.
6 "code.secondbit.org/ducky/subscriptions.hg"
8 "golang.org/x/net/context"
12 subscriptionStoreKey = "SubscriptionStore"
17 ErrSubscriptionStoreNotSet = errors.New("SubscriptionStore not set")
18 ErrStripeClientNotSet = errors.New("Stripe not set")
21 func getSubscriptionStore(c context.Context) (subscriptions.SubscriptionStore, error) {
22 store := c.Value(subscriptionStoreKey)
24 return nil, ErrSubscriptionStoreNotSet
26 if s, ok := store.(subscriptions.SubscriptionStore); ok {
29 return nil, ErrSubscriptionStoreNotSet
32 func WithSubscriptionStore(store subscriptions.SubscriptionStore, c context.Context) context.Context {
33 return context.WithValue(c, subscriptionStoreKey, store)
36 func getStripeClient(c context.Context) (subscriptions.Stripe, error) {
37 stripe := c.Value(stripeKey)
39 return subscriptions.Stripe{}, ErrStripeClientNotSet
41 if s, ok := stripe.(subscriptions.Stripe); ok {
44 return subscriptions.Stripe{}, ErrStripeClientNotSet
47 func WithStripeClient(stripe subscriptions.Stripe, c context.Context) context.Context {
48 return context.WithValue(c, stripeKey, stripe)