Remove Go 1.9 / AppEngine support; assume go1.12 build tag (#3767)

This commit is contained in:
Doug Fawley 2020-07-30 16:15:35 -07:00 коммит произвёл GitHub
Родитель b72d07f816
Коммит bc714cd8ae
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
50 изменённых файлов: 24 добавлений и 431 удалений

Просмотреть файл

@ -16,8 +16,6 @@ matrix:
env: GO111MODULE=on
- go: 1.12.x
env: GO111MODULE=on
- go: 1.9.x
env: GAE=1
go_import_path: google.golang.org/grpc
@ -30,13 +28,11 @@ before_install:
install:
- try3() { eval "$*" || eval "$*" || eval "$*"; }
- try3 'if [[ "${GO111MODULE}" = "on" ]]; then go mod download; else make testdeps; fi'
- if [[ -n "${GAE}" ]]; then source ./install_gae.sh; make testappenginedeps; fi
- if [[ -n "${VET}" ]]; then ./vet.sh -install; fi
script:
- set -e
- if [[ -n "${TESTEXTRAS}" ]]; then examples/examples_test.sh; interop/interop_test.sh; make testsubmodule; exit 0; fi
- if [[ -n "${VET}" ]]; then ./vet.sh; fi
- if [[ -n "${GAE}" ]]; then make testappengine; exit 0; fi
- if [[ -n "${RACE}" ]]; then make testrace; exit 0; fi
- make test

Просмотреть файл

@ -57,6 +57,5 @@ How to get your contributions merged smoothly and quickly.
- `make vet` to catch vet errors
- `make test` to run the tests
- `make testrace` to run tests in race mode
- optional `make testappengine` to run tests with appengine
- Exceptions to the rules can be made if there's a compelling reason for doing so.

Просмотреть файл

@ -22,12 +22,6 @@ test: testdeps
testsubmodule: testdeps
cd security/advancedtls && go test -cpu 1,4 -timeout 7m google.golang.org/grpc/security/advancedtls/...
testappengine: testappenginedeps
goapp test -cpu 1,4 -timeout 7m google.golang.org/grpc/...
testappenginedeps:
goapp get -d -v -t -tags 'appengine appenginevm' google.golang.org/grpc/...
testdeps:
go get -d -v -t google.golang.org/grpc/...
@ -53,8 +47,6 @@ vetdeps:
deps \
proto \
test \
testappengine \
testappenginedeps \
testdeps \
testrace \
updatedeps \

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2018 gRPC authors.

Просмотреть файл

@ -1,4 +1,4 @@
// +build !linux appengine
// +build !linux
/*
*

Просмотреть файл

@ -1,4 +1,4 @@
// +build linux,!appengine
// +build linux
// +build 386 amd64
/*

Просмотреть файл

@ -58,7 +58,7 @@ type protoToSocketOptFunc func([]*channelzpb.SocketOption) *channelz.SocketOptio
// protoToSocketOpt is used in function socketProtoToStruct to extract socket option
// data from unmarshaled proto message.
// It is only defined under linux, non-appengine environment on x86 architecture.
// It is only defined under linux environment on x86 architecture.
var protoToSocketOpt protoToSocketOptFunc
// emptyTime is used for detecting unset value of time.Time type.

Просмотреть файл

@ -1,4 +1,4 @@
// +build 386,linux,!appengine
// +build 386,linux
/*
*

Просмотреть файл

@ -1,4 +1,4 @@
// +build amd64,linux,!appengine
// +build amd64,linux
/*
*

Просмотреть файл

@ -1,30 +0,0 @@
// +build go1.12
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package credentials
import "crypto/tls"
// This init function adds cipher suite constants only defined in Go 1.12.
func init() {
cipherSuiteLookup[tls.TLS_AES_128_GCM_SHA256] = "TLS_AES_128_GCM_SHA256"
cipherSuiteLookup[tls.TLS_AES_256_GCM_SHA384] = "TLS_AES_256_GCM_SHA384"
cipherSuiteLookup[tls.TLS_CHACHA20_POLY1305_SHA256] = "TLS_CHACHA20_POLY1305_SHA256"
}

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2018 gRPC authors.

Просмотреть файл

@ -1,30 +0,0 @@
// +build appengine
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package internal
import (
"net"
)
// WrapSyscallConn returns newConn on appengine.
func WrapSyscallConn(rawConn, newConn net.Conn) net.Conn {
return newConn
}

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2018 gRPC authors.

Просмотреть файл

@ -241,6 +241,10 @@ var cipherSuiteLookup = map[uint16]string{
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305",
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305: "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
// Go 1.12
tls.TLS_AES_128_GCM_SHA256: "TLS_AES_128_GCM_SHA256",
tls.TLS_AES_256_GCM_SHA384: "TLS_AES_256_GCM_SHA384",
tls.TLS_CHACHA20_POLY1305_SHA256: "TLS_CHACHA20_POLY1305_SHA256",
}
// cloneTLSConfig returns a shallow clone of the exported

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.11
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.11
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,6 +0,0 @@
#!/bin/bash
TMP=$(mktemp -d /tmp/sdk.XXX) \
&& curl -o $TMP.zip "https://storage.googleapis.com/appengine-sdks/featured/go_appengine_sdk_linux_amd64-1.9.68.zip" \
&& unzip -q $TMP.zip -d $TMP \
&& export PATH="$PATH:$TMP/go_appengine"

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2018 gRPC authors.

Просмотреть файл

@ -1,4 +1,4 @@
// +build !linux appengine
// +build !linux
/*
*
@ -37,6 +37,6 @@ type SocketOptionData struct {
// Windows OS doesn't support Socket Option
func (s *SocketOptionData) Getsockopt(fd uintptr) {
once.Do(func() {
logger.Warning("Channelz: socket options are not supported on non-linux os and appengine.")
logger.Warning("Channelz: socket options are not supported on non-linux os.")
})
}

Просмотреть файл

@ -1,4 +1,4 @@
// +build linux,!appengine
// +build linux
/*
*

Просмотреть файл

@ -1,4 +1,4 @@
// +build !linux appengine
// +build !linux
/*
*

Просмотреть файл

@ -1,4 +1,4 @@
// +build linux,go1.10,!appengine
// +build linux
/*
*

Просмотреть файл

@ -1,31 +0,0 @@
// +build !go1.10
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package credentials
import (
"crypto/tls"
"net/url"
)
//TODO(ZhenLian): delete this file when we remove Go 1.9 tests.
func SPIFFEIDFromState(state tls.ConnectionState) *url.URL {
return nil
}

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2019 gRPC authors.

Просмотреть файл

@ -1,43 +0,0 @@
// +build appengine
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package buffer
// CircularBuffer is a no-op implementation for appengine builds.
//
// Appengine does not support stats because of lack of the support for unsafe
// pointers, which are necessary to efficiently store and retrieve things into
// and from a circular buffer. As a result, Push does not do anything and Drain
// returns an empty slice.
type CircularBuffer struct{}
// NewCircularBuffer returns a no-op for appengine builds.
func NewCircularBuffer(size uint32) (*CircularBuffer, error) {
return nil, nil
}
// Push returns a no-op for appengine builds.
func (cb *CircularBuffer) Push(x interface{}) {
}
// Drain returns a no-op for appengine builds.
func (cb *CircularBuffer) Drain() []interface{} {
return nil
}

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2019 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2019 gRPC authors.

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2018 gRPC authors.
@ -43,7 +41,7 @@ func GetCPUTime() int64 {
return ts.Nano()
}
// Rusage is an alias for syscall.Rusage under linux non-appengine environment.
// Rusage is an alias for syscall.Rusage under linux environment.
type Rusage syscall.Rusage
// GetRusage returns the resource usage of current process.

Просмотреть файл

@ -1,4 +1,4 @@
// +build !linux appengine
// +build !linux
/*
*
@ -35,40 +35,40 @@ var logger = grpclog.Component("core")
func log() {
once.Do(func() {
logger.Info("CPU time info is unavailable on non-linux or appengine environment.")
logger.Info("CPU time info is unavailable on non-linux environment.")
})
}
// GetCPUTime returns the how much CPU time has passed since the start of this process.
// It always returns 0 under non-linux or appengine environment.
// It always returns 0 under non-linux environment.
func GetCPUTime() int64 {
log()
return 0
}
// Rusage is an empty struct under non-linux or appengine environment.
// Rusage is an empty struct under non-linux environment.
type Rusage struct{}
// GetRusage is a no-op function under non-linux or appengine environment.
// GetRusage is a no-op function under non-linux environment.
func GetRusage() (rusage *Rusage) {
log()
return nil
}
// CPUTimeDiff returns the differences of user CPU time and system CPU time used
// between two Rusage structs. It a no-op function for non-linux or appengine environment.
// between two Rusage structs. It a no-op function for non-linux environment.
func CPUTimeDiff(first *Rusage, latest *Rusage) (float64, float64) {
log()
return 0, 0
}
// SetTCPUserTimeout is a no-op function under non-linux or appengine environments
// SetTCPUserTimeout is a no-op function under non-linux environments
func SetTCPUserTimeout(conn net.Conn, timeout time.Duration) error {
log()
return nil
}
// GetTCPUserTimeout is a no-op function under non-linux or appengine environments
// GetTCPUserTimeout is a no-op function under non-linux environments
// a negative return value indicates the operation is not supported
func GetTCPUserTimeout(conn net.Conn) (int, error) {
log()

Просмотреть файл

@ -1,6 +1,4 @@
// +build linux
// +build !appengine
// +build go1.11
/*
*

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2020 gRPC authors.

Просмотреть файл

@ -1,41 +0,0 @@
// +build !go1.10
/*
*
* Copyright 2020 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package advancedtls
import (
"crypto/tls"
"fmt"
)
// buildGetCertificates returns the first element of o.GetCertificates.
func buildGetCertificates(clientHello *tls.ClientHelloInfo, o *ServerOptions) (*tls.Certificate, error) {
if o.GetCertificates == nil {
return nil, fmt.Errorf("function GetCertificates must be specified")
}
certificates, err := o.GetCertificates(clientHello)
if err != nil {
return nil, err
}
if len(certificates) == 0 {
return nil, fmt.Errorf("no certificates configured")
}
return certificates[0], nil
}

Просмотреть файл

@ -1,108 +0,0 @@
// +build !go1.10
/*
*
* Copyright 2019 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package advancedtls
import (
"crypto/tls"
"testing"
"github.com/google/go-cmp/cmp"
"google.golang.org/grpc/security/advancedtls/testdata"
)
// TestGetCertificatesSNI tests SNI logic for go1.9.
func TestGetCertificatesSNI(t *testing.T) {
// Load server certificates for setting the serverGetCert callback function.
serverCert1, err := tls.LoadX509KeyPair(testdata.Path("server_cert_1.pem"), testdata.Path("server_key_1.pem"))
if err != nil {
t.Fatalf("tls.LoadX509KeyPair(server_cert_1.pem, server_key_1.pem) failed: %v", err)
}
serverCert2, err := tls.LoadX509KeyPair(testdata.Path("server_cert_2.pem"), testdata.Path("server_key_2.pem"))
if err != nil {
t.Fatalf("tls.LoadX509KeyPair(server_cert_2.pem, server_key_2.pem) failed: %v", err)
}
serverCert3, err := tls.LoadX509KeyPair(testdata.Path("server_cert_3.pem"), testdata.Path("server_key_3.pem"))
if err != nil {
t.Fatalf("tls.LoadX509KeyPair(server_cert_3.pem, server_key_3.pem) failed: %v", err)
}
tests := []struct {
desc string
serverGetCert func(*tls.ClientHelloInfo) ([]*tls.Certificate, error)
serverName string
wantCert tls.Certificate
}{
{
desc: "Select serverCert1",
serverGetCert: func(info *tls.ClientHelloInfo) ([]*tls.Certificate, error) {
return []*tls.Certificate{&serverCert1, &serverCert2, &serverCert3}, nil
},
// "foo.bar.com" is the common name on server certificate server_cert_1.pem.
serverName: "foo.bar.com",
wantCert: serverCert1,
},
{
desc: "Select serverCert2",
serverGetCert: func(info *tls.ClientHelloInfo) ([]*tls.Certificate, error) {
return []*tls.Certificate{&serverCert1, &serverCert2, &serverCert3}, nil
},
// "foo.bar.server2.com" is the common name on server certificate server_cert_2.pem.
serverName: "foo.bar.server2.com",
wantCert: serverCert1,
},
{
desc: "Select serverCert3",
serverGetCert: func(info *tls.ClientHelloInfo) ([]*tls.Certificate, error) {
return []*tls.Certificate{&serverCert1, &serverCert2, &serverCert3}, nil
},
// "google.com" is one of the DNS names on server certificate server_cert_3.pem.
serverName: "google.com",
wantCert: serverCert1,
},
}
for _, test := range tests {
test := test
t.Run(test.desc, func(t *testing.T) {
serverOptions := &ServerOptions{
GetCertificates: test.serverGetCert,
}
serverConfig, err := serverOptions.config()
if err != nil {
t.Fatalf("serverOptions.config() failed: %v", err)
}
pointFormatUncompressed := uint8(0)
clientHello := &tls.ClientHelloInfo{
CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA},
ServerName: test.serverName,
SupportedCurves: []tls.CurveID{tls.CurveP256},
SupportedPoints: []uint8{pointFormatUncompressed},
SupportedVersions: []uint16{tls.VersionTLS10},
}
gotCertificate, err := serverConfig.GetCertificate(clientHello)
if err != nil {
t.Fatalf("serverConfig.GetCertificate(clientHello) failed: %v", err)
}
if !cmp.Equal(gotCertificate, test.wantCert, cmp.AllowUnexported(tls.Certificate{})) {
t.Errorf("GetCertificates() = %v, want %v", gotCertificate, test.wantCert)
}
})
}
}

Просмотреть файл

@ -1,5 +1,3 @@
// +build go1.10
/*
*
* Copyright 2019 gRPC authors.

Просмотреть файл

@ -1,4 +1,4 @@
// +build go1.10,linux,!appengine
// +build linux
/*
*

Просмотреть файл

@ -1,53 +0,0 @@
/*
*
* Copyright 2018 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// vet checks whether files that are supposed to be built on appengine running
// Go 1.10 or earlier import an unsupported package (e.g. "unsafe", "syscall").
package main
import (
"fmt"
"go/build"
"os"
)
func main() {
fail := false
b := build.Default
b.BuildTags = []string{"appengine", "appenginevm"}
argsWithoutProg := os.Args[1:]
for _, dir := range argsWithoutProg {
p, err := b.Import(".", dir, 0)
if _, ok := err.(*build.NoGoError); ok {
continue
} else if err != nil {
fmt.Printf("build.Import failed due to %v\n", err)
fail = true
continue
}
for _, pkg := range p.Imports {
if pkg == "syscall" || pkg == "unsafe" {
fmt.Printf("Package %s/%s importing %s package without appengine build tag is NOT ALLOWED!\n", p.Dir, p.Name, pkg)
fail = true
}
}
}
if fail {
os.Exit(1)
}
}

4
vet.sh
Просмотреть файл

@ -89,10 +89,6 @@ not git grep "\(import \|^\s*\)\"github.com/golang/protobuf/ptypes/" -- "*.go"
# - Ensure all xds proto imports are renamed to *pb or *grpc.
git grep '"github.com/envoyproxy/go-control-plane/envoy' -- '*.go' | not grep -v 'pb "\|grpc "'
# - Check imports that are illegal in appengine (until Go 1.11).
# TODO: Remove when we drop Go 1.10 support
go list -f {{.Dir}} ./... | xargs go run test/go_vet/vet.go
# - gofmt, goimports, golint (with exceptions for generated code), go vet.
gofmt -s -d -l . 2>&1 | fail_on_output
goimports -l . 2>&1 | not grep -vE "\.pb\.go"

Просмотреть файл

@ -1,5 +1,3 @@
// +build !appengine
/*
*
* Copyright 2019 gRPC authors.