1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-07-27 17:28:38 +00:00

Update vendor dependencies

This commit is contained in:
Frédéric Guillot 2018-07-06 21:18:14 -07:00
parent 34a3fe426b
commit 459bb4531f
747 changed files with 89857 additions and 39711 deletions

View file

@ -27,16 +27,24 @@ import (
pb "google.golang.org/appengine/internal/remote_api"
)
// NewRemoteContext returns a context that gives access to the production
// APIs for the application at the given host. All communication will be
// performed over SSL unless the host is localhost.
func NewRemoteContext(host string, client *http.Client) (context.Context, error) {
// Client is a connection to the production APIs for an application.
type Client struct {
hc *http.Client
url string
appID string
}
// NewClient returns a client for the given host. All communication will
// be performed over SSL unless the host is localhost.
func NewClient(host string, client *http.Client) (*Client, error) {
// Add an appcfg header to outgoing requests.
wrapClient := new(http.Client)
*wrapClient = *client
t := client.Transport
if t == nil {
t = http.DefaultTransport
}
client.Transport = &headerAddingRoundTripper{t}
wrapClient.Transport = &headerAddingRoundTripper{t}
url := url.URL{
Scheme: "https",
@ -47,23 +55,35 @@ func NewRemoteContext(host string, client *http.Client) (context.Context, error)
url.Scheme = "http"
}
u := url.String()
appID, err := getAppID(client, u)
appID, err := getAppID(wrapClient, u)
if err != nil {
return nil, fmt.Errorf("unable to contact server: %v", err)
}
rc := &remoteContext{
client: client,
url: u,
}
ctx := internal.WithCallOverride(context.Background(), rc.call)
ctx = internal.WithLogOverride(ctx, rc.logf)
ctx = internal.WithAppIDOverride(ctx, appID)
return ctx, nil
return &Client{
hc: wrapClient,
url: u,
appID: appID,
}, nil
}
type remoteContext struct {
client *http.Client
url string
// NewContext returns a copy of parent that will cause App Engine API
// calls to be sent to the client's remote host.
func (c *Client) NewContext(parent context.Context) context.Context {
ctx := internal.WithCallOverride(parent, c.call)
ctx = internal.WithLogOverride(ctx, c.logf)
ctx = internal.WithAppIDOverride(ctx, c.appID)
return ctx
}
// NewRemoteContext returns a context that gives access to the production
// APIs for the application at the given host. All communication will be
// performed over SSL unless the host is localhost.
func NewRemoteContext(host string, client *http.Client) (context.Context, error) {
c, err := NewClient(host, client)
if err != nil {
return nil, err
}
return c.NewContext(context.Background()), nil
}
var logLevels = map[int64]string{
@ -74,11 +94,11 @@ var logLevels = map[int64]string{
4: "CRITICAL",
}
func (c *remoteContext) logf(level int64, format string, args ...interface{}) {
func (c *Client) logf(level int64, format string, args ...interface{}) {
log.Printf(logLevels[level]+": "+format, args...)
}
func (c *remoteContext) call(ctx context.Context, service, method string, in, out proto.Message) error {
func (c *Client) call(ctx context.Context, service, method string, in, out proto.Message) error {
req, err := proto.Marshal(in)
if err != nil {
return fmt.Errorf("error marshalling request: %v", err)
@ -97,7 +117,7 @@ func (c *remoteContext) call(ctx context.Context, service, method string, in, ou
}
// TODO(djd): Respect ctx.Deadline()?
resp, err := c.client.Post(c.url, "application/octet-stream", bytes.NewReader(req))
resp, err := c.hc.Post(c.url, "application/octet-stream", bytes.NewReader(req))
if err != nil {
return fmt.Errorf("error sending request: %v", err)
}

View file

@ -5,7 +5,12 @@
package remote_api
import (
"log"
"net/http"
"testing"
"golang.org/x/net/context"
"google.golang.org/appengine/datastore"
)
func TestAppIDRE(t *testing.T) {
@ -22,3 +27,17 @@ func TestAppIDRE(t *testing.T) {
}
}
}
func ExampleClient() {
c, err := NewClient("example.appspot.com", http.DefaultClient)
if err != nil {
log.Fatal(err)
}
ctx := context.Background() // or from a request
ctx = c.NewContext(ctx)
_, err = datastore.Put(ctx, datastore.NewIncompleteKey(ctx, "Foo", nil), struct{ Bar int }{42})
if err != nil {
log.Fatal(err)
}
}

View file

@ -39,7 +39,7 @@ func handle(w http.ResponseWriter, req *http.Request) {
)
}
if u == nil || !u.Admin {
if !appengine.IsDevAppServer() && (u == nil || !u.Admin) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(http.StatusUnauthorized)
io.WriteString(w, "You must be logged in as an administrator to access this.\n")