Add generated file

This PR adds generated files under pkg/client and vendor folder.
This commit is contained in:
xing-yang
2018-07-12 10:55:15 -07:00
parent 36b1de0341
commit e213d1890d
17729 changed files with 5090889 additions and 0 deletions

143
vendor/golang.org/x/tools/cmd/tip/Dockerfile generated vendored Normal file
View File

@@ -0,0 +1,143 @@
FROM golang:1.9
RUN apt-get update && apt-get install --no-install-recommends -y -q build-essential git
# golang puts its go install here (weird but true)
ENV GOROOT_BOOTSTRAP /usr/local/go
# BEGIN deps (run `make update-deps` to update)
# Repo cloud.google.com/go at 1d0c2da (2018-01-30)
ENV REV=1d0c2da40456a9b47f5376165f275424acc15c09
RUN go get -d cloud.google.com/go/compute/metadata `#and 6 other pkgs` &&\
(cd /go/src/cloud.google.com/go && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo github.com/golang/protobuf at 9255415 (2018-01-25)
ENV REV=925541529c1fa6821df4e44ce2723319eb2be768
RUN go get -d github.com/golang/protobuf/proto `#and 6 other pkgs` &&\
(cd /go/src/github.com/golang/protobuf && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo github.com/googleapis/gax-go at 317e000 (2017-09-15)
ENV REV=317e0006254c44a0ac427cc52a0e083ff0b9622f
RUN go get -d github.com/googleapis/gax-go &&\
(cd /go/src/github.com/googleapis/gax-go && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo golang.org/x/build at e879390 (2018-02-01)
ENV REV=e8793909ba350594eea4c7c6bdb0f0d9a0d0f77a
RUN go get -d golang.org/x/build/autocertcache &&\
(cd /go/src/golang.org/x/build && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo golang.org/x/crypto at 1875d0a (2018-01-27)
ENV REV=1875d0a70c90e57f11972aefd42276df65e895b9
RUN go get -d golang.org/x/crypto/acme `#and 2 other pkgs` &&\
(cd /go/src/golang.org/x/crypto && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo golang.org/x/net at 6d90978 (2018-02-01)
ENV REV=6d90978dc4889d44e8cfbd04c05d17b5417823c7
RUN go get -d golang.org/x/net/context `#and 8 other pkgs` &&\
(cd /go/src/golang.org/x/net && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo golang.org/x/oauth2 at 30785a2 (2018-01-04)
ENV REV=30785a2c434e431ef7c507b54617d6a951d5f2b4
RUN go get -d golang.org/x/oauth2 `#and 5 other pkgs` &&\
(cd /go/src/golang.org/x/oauth2 && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo golang.org/x/text at e19ae14 (2017-12-27)
ENV REV=e19ae1496984b1c655b8044a65c0300a3c878dd3
RUN go get -d golang.org/x/text/secure/bidirule `#and 4 other pkgs` &&\
(cd /go/src/golang.org/x/text && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo google.golang.org/api at 7d0e2d3 (2018-01-30)
ENV REV=7d0e2d350555821bef5a5b8aecf0d12cc1def633
RUN go get -d google.golang.org/api/gensupport `#and 9 other pkgs` &&\
(cd /go/src/google.golang.org/api && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo google.golang.org/genproto at 4eb30f4 (2018-01-25)
ENV REV=4eb30f4778eed4c258ba66527a0d4f9ec8a36c45
RUN go get -d google.golang.org/genproto/googleapis/api/annotations `#and 3 other pkgs` &&\
(cd /go/src/google.golang.org/genproto && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Repo google.golang.org/grpc at 0bd008f (2018-01-25)
ENV REV=0bd008f5fadb62d228f12b18d016709e8139a7af
RUN go get -d google.golang.org/grpc `#and 23 other pkgs` &&\
(cd /go/src/google.golang.org/grpc && (git cat-file -t $REV 2>/dev/null || git fetch -q origin $REV) && git reset --hard $REV)
# Optimization to speed up iterative development, not necessary for correctness:
RUN go install cloud.google.com/go/compute/metadata \
cloud.google.com/go/iam \
cloud.google.com/go/internal \
cloud.google.com/go/internal/optional \
cloud.google.com/go/internal/version \
cloud.google.com/go/storage \
github.com/golang/protobuf/proto \
github.com/golang/protobuf/protoc-gen-go/descriptor \
github.com/golang/protobuf/ptypes \
github.com/golang/protobuf/ptypes/any \
github.com/golang/protobuf/ptypes/duration \
github.com/golang/protobuf/ptypes/timestamp \
github.com/googleapis/gax-go \
golang.org/x/build/autocertcache \
golang.org/x/crypto/acme \
golang.org/x/crypto/acme/autocert \
golang.org/x/net/context \
golang.org/x/net/context/ctxhttp \
golang.org/x/net/http2 \
golang.org/x/net/http2/hpack \
golang.org/x/net/idna \
golang.org/x/net/internal/timeseries \
golang.org/x/net/lex/httplex \
golang.org/x/net/trace \
golang.org/x/oauth2 \
golang.org/x/oauth2/google \
golang.org/x/oauth2/internal \
golang.org/x/oauth2/jws \
golang.org/x/oauth2/jwt \
golang.org/x/text/secure/bidirule \
golang.org/x/text/transform \
golang.org/x/text/unicode/bidi \
golang.org/x/text/unicode/norm \
google.golang.org/api/gensupport \
google.golang.org/api/googleapi \
google.golang.org/api/googleapi/internal/uritemplates \
google.golang.org/api/googleapi/transport \
google.golang.org/api/internal \
google.golang.org/api/iterator \
google.golang.org/api/option \
google.golang.org/api/storage/v1 \
google.golang.org/api/transport/http \
google.golang.org/genproto/googleapis/api/annotations \
google.golang.org/genproto/googleapis/iam/v1 \
google.golang.org/genproto/googleapis/rpc/status \
google.golang.org/grpc \
google.golang.org/grpc/balancer \
google.golang.org/grpc/balancer/base \
google.golang.org/grpc/balancer/roundrobin \
google.golang.org/grpc/codes \
google.golang.org/grpc/connectivity \
google.golang.org/grpc/credentials \
google.golang.org/grpc/encoding \
google.golang.org/grpc/encoding/proto \
google.golang.org/grpc/grpclb/grpc_lb_v1/messages \
google.golang.org/grpc/grpclog \
google.golang.org/grpc/internal \
google.golang.org/grpc/keepalive \
google.golang.org/grpc/metadata \
google.golang.org/grpc/naming \
google.golang.org/grpc/peer \
google.golang.org/grpc/resolver \
google.golang.org/grpc/resolver/dns \
google.golang.org/grpc/resolver/passthrough \
google.golang.org/grpc/stats \
google.golang.org/grpc/status \
google.golang.org/grpc/tap \
google.golang.org/grpc/transport
# END deps.
# golang sets GOPATH=/go
ADD . /go/src/tip
RUN go install --tags=autocert tip
ENTRYPOINT ["/go/bin/tip"]
# We listen on 8080 (for historical reasons). The service.yaml maps public port 80 to 8080.
# We also listen on 443 for LetsEncrypt TLS.
EXPOSE 8080 443

25
vendor/golang.org/x/tools/cmd/tip/Makefile generated vendored Normal file
View File

@@ -0,0 +1,25 @@
# Copyright 2017 The Go Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
VERSION=v2
.PHONY: usage
usage:
echo "See Makefile"
exit 1
update-deps:
go install golang.org/x/build/cmd/gitlock
gitlock --update=Dockerfile --ignore=NONE --tags=autocert golang.org/x/tools/cmd/tip
docker-prod: Dockerfile
docker build -f Dockerfile --tag=gcr.io/symbolic-datum-552/tip:$(VERSION) .
docker-dev: Dockerfile
docker build -f Dockerfile --tag=gcr.io/go-dashboard-dev/tip:$(VERSION) .
push-prod: docker-prod
gcloud docker -- push gcr.io/symbolic-datum-552/tip:$(VERSION)
push-dev: docker-dev
gcloud docker -- push gcr.io/go-dashboard-dev/tip:$(VERSION)

32
vendor/golang.org/x/tools/cmd/tip/README generated vendored Normal file
View File

@@ -0,0 +1,32 @@
============================================================
Old instructions, only valid for talks.golang.org:
============================================================
1. Deploy the app.
To deploy tip.golang.org:
(See Kubernetes instruction below.)
To deploy talks.golang.org:
$ gcloud --project golang-org app deploy --no-promote talks.yaml
2. Wait until the deployed version is serving requests.
3. Go to the developer console and upgrade the default version.
https://console.developers.google.com/appengine/versions?project=golang-org&moduleId=tip
4. Clean up any old versions (they continue to use at least one instance).
============================================================
New Kubernetes instructions, for tip.golang.org:
============================================================
Kubernetes instructions:
* build & push images (see Makefile for helpers)
* create/update resources:
- kubectl create -f tip-rc.yaml
- kubectl create -f tip-service.yaml
TODO(bradfitz): flesh out these instructions as I gain experience
with updating this over time. Also: move talks.golang.org to GKE too?

63
vendor/golang.org/x/tools/cmd/tip/cert.go generated vendored Normal file
View File

@@ -0,0 +1,63 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// +build autocert
// This file contains autocert and cloud.google.com/go/storage
// dependencies we want to hide by default from the Go build system,
// which currently doesn't know how to fetch non-golang.org/x/*
// dependencies. The Dockerfile builds the production binary
// with this code using --tags=autocert.
package main
import (
"context"
"crypto/tls"
"log"
"net/http"
"cloud.google.com/go/storage"
"golang.org/x/build/autocertcache"
"golang.org/x/crypto/acme/autocert"
)
func init() {
runHTTPS = runHTTPSAutocert
certInit = certInitAutocert
wrapHTTPMux = wrapHTTPMuxAutocert
}
var autocertManager *autocert.Manager
func certInitAutocert() {
var cache autocert.Cache
if b := *autoCertCacheBucket; b != "" {
sc, err := storage.NewClient(context.Background())
if err != nil {
log.Fatalf("storage.NewClient: %v", err)
}
cache = autocertcache.NewGoogleCloudStorageCache(sc, b)
}
autocertManager = &autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(*autoCertDomain),
Cache: cache,
}
}
func runHTTPSAutocert(h http.Handler) error {
s := &http.Server{
Addr: ":https",
Handler: h,
TLSConfig: &tls.Config{
GetCertificate: autocertManager.GetCertificate,
},
}
return s.ListenAndServeTLS("", "")
}
func wrapHTTPMuxAutocert(h http.Handler) http.Handler {
return autocertManager.HTTPHandler(h)
}

73
vendor/golang.org/x/tools/cmd/tip/godoc.go generated vendored Normal file
View File

@@ -0,0 +1,73 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
)
type godocBuilder struct {
}
func (b godocBuilder) Signature(heads map[string]string) string {
return fmt.Sprintf("go=%v/tools=%v", heads["go"], heads["tools"])
}
func (b godocBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
goDir := filepath.Join(dir, "go")
toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
if err := checkout(repoURL+"go", heads["go"], goDir); err != nil {
return nil, err
}
if err := checkout(repoURL+"tools", heads["tools"], toolsDir); err != nil {
return nil, err
}
make := exec.Command(filepath.Join(goDir, "src/make.bash"))
make.Dir = filepath.Join(goDir, "src")
if err := runErr(make); err != nil {
return nil, err
}
goBin := filepath.Join(goDir, "bin/go")
goPath := filepath.Join(dir, "gopath")
install := exec.Command(goBin, "install", "golang.org/x/tools/cmd/godoc")
install.Env = []string{
"GOROOT=" + goDir,
"GOPATH=" + goPath,
"GOROOT_BOOTSTRAP=" + os.Getenv("GOROOT_BOOTSTRAP"),
}
if err := runErr(install); err != nil {
return nil, err
}
godocBin := filepath.Join(goPath, "bin/godoc")
godoc := exec.Command(godocBin, "-http="+hostport, "-index", "-index_interval=-1s")
godoc.Env = []string{"GOROOT=" + goDir}
// TODO(adg): log this somewhere useful
godoc.Stdout = os.Stdout
godoc.Stderr = os.Stderr
if err := godoc.Start(); err != nil {
return nil, err
}
return godoc, nil
}
var indexingMsg = []byte("Indexing in progress: result may be inaccurate")
func (b godocBuilder) HealthCheck(hostport string) error {
body, err := getOK(fmt.Sprintf("http://%v/search?q=FALLTHROUGH", hostport))
if err != nil {
return err
}
if bytes.Contains(body, indexingMsg) {
return errors.New("still indexing")
}
return nil
}

17
vendor/golang.org/x/tools/cmd/tip/godoc.yaml generated vendored Normal file
View File

@@ -0,0 +1,17 @@
module: tip
runtime: custom
vm: true
manual_scaling:
instances: 4
env_variables:
TIP_BUILDER: 'godoc'
health_check:
enable_health_check: True
check_interval_sec: 5
timeout_sec: 4
unhealthy_threshold: 2
healthy_threshold: 2
restart_threshold: 240

73
vendor/golang.org/x/tools/cmd/tip/talks.go generated vendored Normal file
View File

@@ -0,0 +1,73 @@
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
)
type talksBuilder struct {
}
func (b talksBuilder) Signature(heads map[string]string) string {
return heads["talks"]
}
const talksToolsRev = "8cab8a1319f0be9798e7fe78b15da75e5f94b2e9"
func (b talksBuilder) Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error) {
toolsDir := filepath.Join(dir, "gopath/src/golang.org/x/tools")
if err := checkout(repoURL+"tools", talksToolsRev, toolsDir); err != nil {
return nil, err
}
talksDir := filepath.Join(dir, "gopath/src/golang.org/x/talks")
if err := checkout(repoURL+"talks", heads["talks"], talksDir); err != nil {
return nil, err
}
goDir := os.Getenv("GOROOT_BOOTSTRAP")
if goDir == "" {
goDir = runtime.GOROOT()
}
goBin := filepath.Join(goDir, "bin/go")
goPath := filepath.Join(dir, "gopath")
presentPath := "golang.org/x/tools/cmd/present"
install := exec.Command(goBin, "install", "-tags=appenginevm", presentPath)
install.Env = []string{"GOROOT=" + goDir, "GOPATH=" + goPath}
if err := runErr(install); err != nil {
return nil, err
}
talksBin := filepath.Join(goPath, "bin/present")
presentSrc := filepath.Join(goPath, "src", presentPath)
present := exec.Command(talksBin, "-http="+hostport, "-base="+presentSrc)
present.Dir = talksDir
// TODO(adg): log this somewhere useful
present.Stdout = os.Stdout
present.Stderr = os.Stderr
if err := present.Start(); err != nil {
return nil, err
}
return present, nil
}
var talksMsg = []byte("Talks - The Go Programming Language")
func (b talksBuilder) HealthCheck(hostport string) error {
body, err := getOK(fmt.Sprintf("http://%v/", hostport))
if err != nil {
return err
}
if !bytes.Contains(body, talksMsg) {
return errors.New("couldn't match string")
}
return nil
}

12
vendor/golang.org/x/tools/cmd/tip/talks.yaml generated vendored Normal file
View File

@@ -0,0 +1,12 @@
service: talks
runtime: custom
env: flex
manual_scaling:
instances: 1
env_variables:
TIP_BUILDER: 'talks'
health_check:
enable_health_check: False

40
vendor/golang.org/x/tools/cmd/tip/tip-rc.yaml generated vendored Normal file
View File

@@ -0,0 +1,40 @@
apiVersion: v1
kind: ReplicationController
metadata:
name: tipgodoc
spec:
replicas: 1
selector:
app: tipgodoc
template:
metadata:
name: tipgodoc
labels:
app: tipgodoc
spec:
volumes:
- name: cache-volume
emptyDir: {}
containers:
- name: gitmirror
image: gcr.io/symbolic-datum-552/tip:v2
imagePullPolicy: Always
command: ["/go/bin/tip", "--autocert=tip.golang.org", "--autocert-bucket=golang-tip-autocert"]
env:
- name: TMPDIR
value: /build
- name: TIP_BUILDER
value: godoc
volumeMounts:
- mountPath: /build
name: cache-volume
ports:
- containerPort: 8080
- containerPort: 443
resources:
requests:
cpu: "1"
memory: "2Gi"
limits:
cpu: "2"
memory: "4Gi"

16
vendor/golang.org/x/tools/cmd/tip/tip-service.yaml generated vendored Normal file
View File

@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: tipgodoc
spec:
ports:
- port: 80
targetPort: 8080
name: http
- port: 443
targetPort: 443
name: https
selector:
app: tipgodoc
type: LoadBalancer
loadBalancerIP: 130.211.180.236

414
vendor/golang.org/x/tools/cmd/tip/tip.go generated vendored Normal file
View File

@@ -0,0 +1,414 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
// Command tip is the tip.golang.org server,
// serving the latest HEAD straight from the Git oven.
package main
import (
"bufio"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"os/exec"
"path/filepath"
"sync"
"time"
)
const (
repoURL = "https://go.googlesource.com/"
metaURL = "https://go.googlesource.com/?b=master&format=JSON"
startTimeout = 10 * time.Minute
)
var startTime = time.Now()
var (
autoCertDomain = flag.String("autocert", "", "if non-empty, listen on port 443 and serve a LetsEncrypt cert for this hostname")
autoCertCacheBucket = flag.String("autocert-bucket", "", "if non-empty, the Google Cloud Storage bucket in which to store the LetsEncrypt cache")
)
// Hooks that are set non-nil in cert.go if the "autocert" build tag
// is used.
var (
certInit func()
runHTTPS func(http.Handler) error
wrapHTTPMux func(http.Handler) http.Handler
)
func main() {
flag.Parse()
const k = "TIP_BUILDER"
var b Builder
switch os.Getenv(k) {
case "godoc":
b = godocBuilder{}
case "talks":
b = talksBuilder{}
default:
log.Fatalf("Unknown %v value: %q", k, os.Getenv(k))
}
if certInit != nil {
certInit()
}
p := &Proxy{builder: b}
go p.run()
mux := newServeMux(p)
log.Printf("Starting up tip server for builder %q", os.Getenv(k))
errc := make(chan error, 1)
go func() {
var httpMux http.Handler = mux
if wrapHTTPMux != nil {
httpMux = wrapHTTPMux(httpMux)
}
errc <- http.ListenAndServe(":8080", httpMux)
}()
if *autoCertDomain != "" {
if runHTTPS == nil {
errc <- errors.New("can't use --autocert without building binary with the autocert build tag")
} else {
go func() {
errc <- runHTTPS(mux)
}()
}
log.Printf("Listening on port 443 with LetsEncrypt support on domain %q", *autoCertDomain)
}
if err := <-errc; err != nil {
p.stop()
log.Fatal(err)
}
}
// Proxy implements the tip.golang.org server: a reverse-proxy
// that builds and runs godoc instances showing the latest docs.
type Proxy struct {
builder Builder
mu sync.Mutex // protects the followin'
proxy http.Handler
cur string // signature of gorepo+toolsrepo
cmd *exec.Cmd // live godoc instance, or nil for none
side string
hostport string // host and port of the live instance
err error
}
type Builder interface {
Signature(heads map[string]string) string
Init(dir, hostport string, heads map[string]string) (*exec.Cmd, error)
HealthCheck(hostport string) error
}
func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/_tipstatus" {
p.serveStatus(w, r)
return
}
p.mu.Lock()
proxy := p.proxy
err := p.err
p.mu.Unlock()
if proxy == nil {
s := "starting up"
if err != nil {
s = err.Error()
}
http.Error(w, s, http.StatusInternalServerError)
return
}
proxy.ServeHTTP(w, r)
}
func (p *Proxy) serveStatus(w http.ResponseWriter, r *http.Request) {
p.mu.Lock()
defer p.mu.Unlock()
fmt.Fprintf(w, "side=%v\ncurrent=%v\nerror=%v\nuptime=%v\n", p.side, p.cur, p.err, int(time.Since(startTime).Seconds()))
}
func (p *Proxy) serveHealthCheck(w http.ResponseWriter, r *http.Request) {
p.mu.Lock()
defer p.mu.Unlock()
// NOTE: (App Engine only; not GKE) Status 502, 503, 504 are
// the only status codes that signify an unhealthy app. So
// long as this handler returns one of those codes, this
// instance will not be sent any requests.
if p.proxy == nil {
log.Printf("Health check: not ready")
http.Error(w, "Not ready", http.StatusServiceUnavailable)
return
}
if err := p.builder.HealthCheck(p.hostport); err != nil {
log.Printf("Health check failed: %v", err)
http.Error(w, "Health check failed", http.StatusServiceUnavailable)
return
}
io.WriteString(w, "ok")
}
// run runs in its own goroutine.
func (p *Proxy) run() {
p.side = "a"
for {
p.poll()
time.Sleep(30 * time.Second)
}
}
func (p *Proxy) stop() {
p.mu.Lock()
defer p.mu.Unlock()
if p.cmd != nil {
p.cmd.Process.Kill()
}
}
// poll runs from the run loop goroutine.
func (p *Proxy) poll() {
heads := gerritMetaMap()
if heads == nil {
return
}
sig := p.builder.Signature(heads)
p.mu.Lock()
changes := sig != p.cur
curSide := p.side
p.cur = sig
p.mu.Unlock()
if !changes {
return
}
newSide := "b"
if curSide == "b" {
newSide = "a"
}
dir := filepath.Join(os.TempDir(), "tip", newSide)
if err := os.MkdirAll(dir, 0755); err != nil {
p.err = err
return
}
hostport := "localhost:8081"
if newSide == "b" {
hostport = "localhost:8082"
}
cmd, err := p.builder.Init(dir, hostport, heads)
if err != nil {
err = fmt.Errorf("builder.Init: %v", err)
} else {
go func() {
// TODO(adg,bradfitz): be smarter about dead processes
if err := cmd.Wait(); err != nil {
log.Printf("process in %v exited: %v", dir, err)
}
}()
err = waitReady(p.builder, hostport)
if err != nil {
cmd.Process.Kill()
err = fmt.Errorf("waitReady: %v", err)
}
}
p.mu.Lock()
defer p.mu.Unlock()
if err != nil {
log.Println(err)
p.err = err
return
}
u, err := url.Parse(fmt.Sprintf("http://%v/", hostport))
if err != nil {
err = fmt.Errorf("parsing hostport: %v", err)
log.Println(err)
p.err = err
return
}
p.proxy = httputil.NewSingleHostReverseProxy(u)
p.side = newSide
p.hostport = hostport
if p.cmd != nil {
p.cmd.Process.Kill()
}
p.cmd = cmd
}
func newServeMux(p *Proxy) http.Handler {
mux := http.NewServeMux()
mux.Handle("/", httpsOnlyHandler{p})
mux.HandleFunc("/_ah/health", p.serveHealthCheck)
return mux
}
func waitReady(b Builder, hostport string) error {
var err error
deadline := time.Now().Add(startTimeout)
for time.Now().Before(deadline) {
if err = b.HealthCheck(hostport); err == nil {
return nil
}
time.Sleep(time.Second)
}
return fmt.Errorf("timed out waiting for process at %v: %v", hostport, err)
}
func runErr(cmd *exec.Cmd) error {
out, err := cmd.CombinedOutput()
if err != nil {
if len(out) == 0 {
return err
}
return fmt.Errorf("%s\n%v", out, err)
}
return nil
}
func checkout(repo, hash, path string) error {
// Clone git repo if it doesn't exist.
if _, err := os.Stat(filepath.Join(path, ".git")); os.IsNotExist(err) {
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return fmt.Errorf("mkdir: %v", err)
}
if err := runErr(exec.Command("git", "clone", repo, path)); err != nil {
return fmt.Errorf("clone: %v", err)
}
} else if err != nil {
return fmt.Errorf("stat .git: %v", err)
}
// Pull down changes and update to hash.
cmd := exec.Command("git", "fetch")
cmd.Dir = path
if err := runErr(cmd); err != nil {
return fmt.Errorf("fetch: %v", err)
}
cmd = exec.Command("git", "reset", "--hard", hash)
cmd.Dir = path
if err := runErr(cmd); err != nil {
return fmt.Errorf("reset: %v", err)
}
cmd = exec.Command("git", "clean", "-d", "-f", "-x")
cmd.Dir = path
if err := runErr(cmd); err != nil {
return fmt.Errorf("clean: %v", err)
}
return nil
}
var timeoutClient = &http.Client{Timeout: 10 * time.Second}
// gerritMetaMap returns the map from repo name (e.g. "go") to its
// latest master hash.
// The returned map is nil on any transient error.
func gerritMetaMap() map[string]string {
res, err := timeoutClient.Get(metaURL)
if err != nil {
log.Printf("Error getting Gerrit meta map: %v", err)
return nil
}
defer res.Body.Close()
defer io.Copy(ioutil.Discard, res.Body) // ensure EOF for keep-alive
if res.StatusCode != 200 {
return nil
}
var meta map[string]struct {
Branches map[string]string
}
br := bufio.NewReader(res.Body)
// For security reasons or something, this URL starts with ")]}'\n" before
// the JSON object. So ignore that.
// Shawn Pearce says it's guaranteed to always be just one line, ending in '\n'.
for {
b, err := br.ReadByte()
if err != nil {
return nil
}
if b == '\n' {
break
}
}
if err := json.NewDecoder(br).Decode(&meta); err != nil {
log.Printf("JSON decoding error from %v: %s", metaURL, err)
return nil
}
m := map[string]string{}
for repo, v := range meta {
if master, ok := v.Branches["master"]; ok {
m[repo] = master
}
}
return m
}
func getOK(url string) (body []byte, err error) {
res, err := timeoutClient.Get(url)
if err != nil {
return nil, err
}
body, err = ioutil.ReadAll(res.Body)
res.Body.Close()
if err != nil {
return nil, err
}
if res.StatusCode != http.StatusOK {
return nil, errors.New(res.Status)
}
return body, nil
}
// httpsOnlyHandler redirects requests to "http://example.com/foo?bar" to
// "https://example.com/foo?bar". It should be used when the server is listening
// for HTTP traffic behind a proxy that terminates TLS traffic, not when the Go
// server is terminating TLS directly.
type httpsOnlyHandler struct {
h http.Handler
}
// isProxiedReq checks whether the server is running behind a proxy that may be
// terminating TLS.
func isProxiedReq(r *http.Request) bool {
if _, ok := r.Header["X-Appengine-Https"]; ok {
return true
}
if _, ok := r.Header["X-Forwarded-Proto"]; ok {
return true
}
return false
}
func (h httpsOnlyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Appengine-Https") == "off" || r.Header.Get("X-Forwarded-Proto") == "http" ||
(!isProxiedReq(r) && r.TLS == nil) {
r.URL.Scheme = "https"
r.URL.Host = r.Host
http.Redirect(w, r, r.URL.String(), http.StatusFound)
return
}
if r.Header.Get("X-Appengine-Https") == "on" || r.Header.Get("X-Forwarded-Proto") == "https" ||
(!isProxiedReq(r) && r.TLS != nil) {
// Only set this header when we're actually in production.
w.Header().Set("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
}
h.h.ServeHTTP(w, r)
}

25
vendor/golang.org/x/tools/cmd/tip/tip_test.go generated vendored Normal file
View File

@@ -0,0 +1,25 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.
package main
import (
"net/http/httptest"
"testing"
)
func TestTipRedirects(t *testing.T) {
mux := newServeMux(&Proxy{builder: &godocBuilder{}})
req := httptest.NewRequest("GET", "http://example.com/foo?bar=baz", nil)
req.Header.Set("X-Forwarded-Proto", "http")
w := httptest.NewRecorder()
mux.ServeHTTP(w, req)
if w.Code != 302 {
t.Errorf("expected Code to be 302, got %d", w.Code)
}
want := "https://example.com/foo?bar=baz"
if loc := w.Header().Get("Location"); loc != want {
t.Errorf("Location header: got %s, want %s", loc, want)
}
}