| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package authdbimpl | 5 package authdbimpl |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "io/ioutil" | 9 "io/ioutil" |
| 10 "net/http" | 10 "net/http" |
| 11 "net/url" | 11 "net/url" |
| 12 | 12 |
| 13 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 14 "google.golang.org/appengine" | 14 "google.golang.org/appengine" |
| 15 | 15 |
| 16 "github.com/luci/gae/service/info" | 16 "github.com/luci/gae/service/info" |
| 17 | 17 |
| 18 "github.com/luci/luci-go/common/errors" | 18 "github.com/luci/luci-go/common/errors" |
| 19 "github.com/luci/luci-go/common/logging" | 19 "github.com/luci/luci-go/common/logging" |
| 20 "github.com/luci/luci-go/common/retry" |
| 20 "github.com/luci/luci-go/server/auth/service" | 21 "github.com/luci/luci-go/server/auth/service" |
| 21 "github.com/luci/luci-go/server/router" | 22 "github.com/luci/luci-go/server/router" |
| 22 ) | 23 ) |
| 23 | 24 |
| 24 const ( | 25 const ( |
| 25 pubSubPullURLPath = "/auth/pubsub/authdb:pull" // dev server only | 26 pubSubPullURLPath = "/auth/pubsub/authdb:pull" // dev server only |
| 26 pubSubPushURLPath = "/auth/pubsub/authdb:push" | 27 pubSubPushURLPath = "/auth/pubsub/authdb:push" |
| 27 ) | 28 ) |
| 28 | 29 |
| 29 // InstallHandlers installs PubSub related HTTP handlers. | 30 // InstallHandlers installs PubSub related HTTP handlers. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 143 } |
| 143 | 144 |
| 144 replyOK( | 145 replyOK( |
| 145 c, rw, "Processed PubSub notification for rev %d: %d -> %d", | 146 c, rw, "Processed PubSub notification for rev %d: %d -> %d", |
| 146 notify.Revision, info.Rev, latest.Rev) | 147 notify.Revision, info.Rev, latest.Rev) |
| 147 } | 148 } |
| 148 | 149 |
| 149 // replyError sends HTTP 500 on transient errors, HTTP 400 on fatal ones. | 150 // replyError sends HTTP 500 on transient errors, HTTP 400 on fatal ones. |
| 150 func replyError(c context.Context, rw http.ResponseWriter, err error) { | 151 func replyError(c context.Context, rw http.ResponseWriter, err error) { |
| 151 logging.Errorf(c, "Error while processing PubSub notification - %s", err
) | 152 logging.Errorf(c, "Error while processing PubSub notification - %s", err
) |
| 152 » if errors.IsTransient(err) { | 153 » if retry.Tag.In(err) { |
| 153 http.Error(rw, err.Error(), http.StatusInternalServerError) | 154 http.Error(rw, err.Error(), http.StatusInternalServerError) |
| 154 } else { | 155 } else { |
| 155 http.Error(rw, err.Error(), http.StatusBadRequest) | 156 http.Error(rw, err.Error(), http.StatusBadRequest) |
| 156 } | 157 } |
| 157 } | 158 } |
| 158 | 159 |
| 159 // replyOK sends HTTP 200. | 160 // replyOK sends HTTP 200. |
| 160 func replyOK(c context.Context, rw http.ResponseWriter, msg string, args ...inte
rface{}) { | 161 func replyOK(c context.Context, rw http.ResponseWriter, msg string, args ...inte
rface{}) { |
| 161 logging.Infof(c, msg, args...) | 162 logging.Infof(c, msg, args...) |
| 162 rw.Write([]byte(fmt.Sprintf(msg, args...))) | 163 rw.Write([]byte(fmt.Sprintf(msg, args...))) |
| 163 } | 164 } |
| OLD | NEW |