ducky/subscriptions
8:61583c1d3886
Go to Latest
ducky/subscriptions/subscriptionsd/server.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.
8 "code.secondbit.org/ducky/subscriptions.hg"
9 "code.secondbit.org/ducky/subscriptions.hg/api"
10 "code.secondbit.org/trout.hg"
12 "github.com/stripe/stripe-go"
14 "golang.org/x/net/context"
18 log.SetFlags(log.LstdFlags | log.Llongfile)
19 log.Printf("Running version '%s'\n", subscriptions.Version)
20 var subscriptionStore subscriptions.SubscriptionStore
21 if os.Getenv("SUBSCRIPTIONS_PG_DB") != "" {
22 p, err := subscriptions.NewPostgres(os.Getenv("SUBSCRIPTIONS_PG_DB"))
28 subscriptionStore = subscriptions.NewMemstore()
30 var stripeClient subscriptions.Stripe
31 if os.Getenv("STRIPE_KEY") != "" {
32 stripeClient = subscriptions.NewStripe(os.Getenv("STRIPE_KEY"), stripe.GetBackend(stripe.APIBackend))
34 log.Fatal("STRIPE_KEY environment variable must be set!")
36 c := api.WithStripeClient(stripeClient, api.WithSubscriptionStore(subscriptionStore, context.Background()))
37 router := trout.Router{}
38 api.HandleSubscriptions(&router, c)
39 http.Handle("/", router)
40 log.Println("Listening on 9001")
41 log.Fatal(http.ListenAndServe("0.0.0.0:9001", nil))