Skip to content

Commit

Permalink
Fixes (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
bufdev committed Feb 23, 2021
1 parent 2558e57 commit 60fca69
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 21 deletions.
4 changes: 3 additions & 1 deletion Dockerfile.buf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ FROM golang:1.16.0-alpine3.12 as builder
WORKDIR /workspace

COPY go.mod go.sum /workspace/
RUN go mod download
# This replaces go mod download so that we only download what we need
# https://github.com/golang/go/issues/18387
RUN go list -test all

COPY cmd /workspace/cmd
COPY internal /workspace/internal
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ RUN wget -q -O /etc/apk/keys/sgerrand.rsa.pub https://alpine-pkgs.sgerrand.com/s
rm -rf /var/cache/apk/*

COPY go.mod go.sum /workspace/
RUN go mod download
# This replaces go mod download so that we only download what we need
# https://github.com/golang/go/issues/18387
RUN go list -test all
COPY make /workspace/make
COPY Makefile /workspace/
RUN make dockerdeps
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ require (
go.opencensus.io v0.22.6
go.uber.org/multierr v1.6.0
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 // indirect
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b // indirect
golang.org/x/net v0.0.0-20210222171744-9060382bd457 // indirect
golang.org/x/sys v0.0.0-20210223095934-7937bea0104d // indirect
golang.org/x/text v0.3.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20210218151259-fe80b386bf06 // indirect
google.golang.org/genproto v0.0.0-20210223151946-22b48be4551b // indirect
google.golang.org/grpc v1.35.0-dev.0.20201218190559-666aea1fb34c
google.golang.org/protobuf v1.25.1-0.20201208041424-160c7477e0e8
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777 h1:003p0dJM77cxMSyCPFphvZf/Y5/NXf5fzg6ufd1/Oew=
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210222171744-9060382bd457 h1:hMm9lBjyNLe/c9C6bElQxp4wsrleaJn1vXMZIQkNN44=
golang.org/x/net v0.0.0-20210222171744-9060382bd457/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand All @@ -311,8 +311,8 @@ golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b h1:lAZ0/chPUDWwjqosYR0X4M490zQhMsiJ4K3DbA7o+3g=
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210223095934-7937bea0104d h1:u0GOGnBJ3EKE/tNqREhhGiCzE9jFXydDo2lf7hOwGuc=
golang.org/x/sys v0.0.0-20210223095934-7937bea0104d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -371,8 +371,8 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
google.golang.org/genproto v0.0.0-20210218151259-fe80b386bf06 h1:Px6YyLaNKEo5eoniIBAv6Es0jbvyEmSYqOac64iS2Rs=
google.golang.org/genproto v0.0.0-20210218151259-fe80b386bf06/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210223151946-22b48be4551b h1:GXCSqFSSKq+L4Pi31A2Ba7j8BZCwHN8oJkREab1VokI=
google.golang.org/genproto v0.0.0-20210223151946-22b48be4551b/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
13 changes: 8 additions & 5 deletions internal/buf/bufcli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e *errInternal) Is(err error) bool {
func NewErrorInterceptor(action string) appflag.Interceptor {
return func(next func(context.Context, appflag.Container) error) func(context.Context, appflag.Container) error {
return func(ctx context.Context, container appflag.Container) error {
return wrapRPCError(action, next(ctx, container))
return wrapError(action, next(ctx, container))
}
}
}
Expand Down Expand Up @@ -129,12 +129,15 @@ func NewTokenNotFoundError(tokenID string) error {
return fmt.Errorf("a token with ID %q does not exist", tokenID)
}

// wrapRPCError is used when an RPC call fails, regardless of its error code.
// wrapError is used when a CLI command fails, regardless of its error code.
// Note that this function will wrap the error so that the underlying error
// can be recovered via 'errors.Is'.
func wrapRPCError(action string, err error) error {
if err == nil {
return nil
func wrapError(action string, err error) error {
if err == nil || err.Error() == "" {
// If the error is nil or empty, we return
// it as-is. This is especially relevant
// for commands like lint and breaking.
return err
}
switch {
case rpc.GetErrorCode(err) == rpc.ErrorCodeUnauthenticated, isEmptyUnknownError(err):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (m *moduleCacher) PutModule(
}

// newCacheKey returns the key associated with the given module pin.
// The cache key is of the form: owner/repository/commit.
// The cache key is of the form: remote/owner/repository/commit.
func newCacheKey(modulePin bufmodule.ModulePin) string {
return normalpath.Join(modulePin.Owner(), modulePin.Repository(), modulePin.Commit())
return normalpath.Join(modulePin.Remote(), modulePin.Owner(), modulePin.Repository(), modulePin.Commit())
}
19 changes: 17 additions & 2 deletions internal/pkg/rpc/rpcauth/rpcauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package rpcauth
import (
"context"
"errors"
"net/http"
"strings"

"github.com/bufbuild/buf/internal/pkg/rpc"
Expand Down Expand Up @@ -66,10 +67,24 @@ func GetTokenFromHeader(ctx context.Context) (string, error) {
if authHeader == "" {
return "", errors.New("no auth header provided")
}
if !strings.HasPrefix(authHeader, authenticationTokenPrefix) {
return getTokenFromString(authHeader)
}

// GetTokenFromHTTPHeaders gets the current authentication token from
// the HTTP headers, if there is one.
func GetTokenFromHTTPHeaders(headers http.Header) (string, error) {
authHeader := headers.Get(authenticationHeader)
if authHeader == "" {
return "", errors.New("no auth header provided")
}
return getTokenFromString(authHeader)
}

func getTokenFromString(value string) (string, error) {
if !strings.HasPrefix(value, authenticationTokenPrefix) {
return "", errors.New("invalid header format")
}
token := strings.TrimPrefix(authHeader, authenticationTokenPrefix)
token := strings.TrimPrefix(value, authenticationTokenPrefix)
if token == "" {
return "", errors.New("invalid header format")
}
Expand Down
4 changes: 3 additions & 1 deletion make/go/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ initmakego:: upgradegodeps

.PHONY: godeps
godeps: deps
go mod download
# This replaces go mod download so that we only download what we need
# https://github.com/golang/go/issues/18387
go list -test all

.PHONY: gofmtmodtidy
gofmtmodtidy:
Expand Down

0 comments on commit 60fca69

Please sign in to comment.