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.
12 "code.secondbit.org/uuid.hg"
14 "code.secondbit.org/ducky/subscriptions.hg/api"
18 ErrNilClient = errors.New("nil client wrapper")
19 ErrNilHTTPClient = errors.New("nil client")
28 func New(address string, id uuid.ID) *Client {
29 address = strings.TrimRight(address, "/")
32 client: &http.Client{},
37 func (c *Client) do(method, url string, request interface{}, scopes []string, subject uuid.ID) (api.Response, error) {
39 return api.Response{}, ErrNilClient
42 return api.Response{}, ErrNilHTTPClient
44 var response api.Response
45 if !strings.HasPrefix(url, "http") {
46 url = strings.TrimLeft(url, "/")
52 data, err := json.Marshal(request)
56 body = bytes.NewBuffer(data)
58 req, err := http.NewRequest(method, url, body)
62 req.Header.Set("Ducky-Scope", strings.Join(scopes, " "))
63 req.Header.Set("Ducky-Issuer", c.ID.String())
65 req.Header.Set("Ducky-Subject", subject.String())
67 req.Header.Set("Ducky-Expires", time.Now().Add(time.Hour).String())
68 req.Header.Set("Ducky-Issued-At", time.Now().String())
69 req.Header.Set("Ducky-Not-Before", time.Now().Add(-5*time.Minute).String())
70 resp, err := c.client.Do(req)
74 defer resp.Body.Close()
75 switch resp.Header.Get("Content-Type") {
76 case "application/json":
77 dec := json.NewDecoder(resp.Body)
78 err = dec.Decode(&response)
83 dec := json.NewDecoder(resp.Body)
84 err = dec.Decode(&response)
92 func (c *Client) Get(url string, scopes []string, subject uuid.ID) (api.Response, error) {
93 return c.do("GET", url, nil, scopes, subject)
96 func (c *Client) Post(url string, request interface{}, scopes []string, subject uuid.ID) (api.Response, error) {
97 return c.do("POST", url, request, scopes, subject)
100 func (c *Client) Patch(url string, request interface{}, scopes []string, subject uuid.ID) (api.Response, error) {
101 return c.do("PATCH", url, request, scopes, subject)